From: Herbert Xu <herbert@gondor.apana.org.au>
To: Martin Willi <martin@strongswan.org>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
linux-crypto@vger.kernel.org
Subject: Re: [PATCH 3/9] crypto: Add a generic Poly1305 authenticator implementation
Date: Thu, 4 Jun 2015 17:59:10 +0800 [thread overview]
Message-ID: <20150604095910.GA24246@gondor.apana.org.au> (raw)
In-Reply-To: <1433159044-30753-4-git-send-email-martin@strongswan.org>
On Mon, Jun 01, 2015 at 01:43:58PM +0200, Martin Willi wrote:
>
> +static int poly1305_setkey(struct crypto_shash *tfm,
> + const u8 *key, unsigned int keylen)
> +{
> + struct poly1305_ctx *ctx = crypto_shash_ctx(tfm);
> +
> + if (keylen != POLY1305_KEY_SIZE) {
> + crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
> + return -EINVAL;
> + }
> +
> + /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
> + ctx->r[0] = (le32_to_cpuvp(key + 0) >> 0) & 0x3ffffff;
> + ctx->r[1] = (le32_to_cpuvp(key + 3) >> 2) & 0x3ffff03;
> + ctx->r[2] = (le32_to_cpuvp(key + 6) >> 4) & 0x3ffc0ff;
> + ctx->r[3] = (le32_to_cpuvp(key + 9) >> 6) & 0x3f03fff;
> + ctx->r[4] = (le32_to_cpuvp(key + 12) >> 8) & 0x00fffff;
> +
> + ctx->s[0] = le32_to_cpuvp(key + 16);
> + ctx->s[1] = le32_to_cpuvp(key + 20);
> + ctx->s[2] = le32_to_cpuvp(key + 24);
> + ctx->s[3] = le32_to_cpuvp(key + 28);
> +
> + return 0;
> +}
I just realised that this doesn't quite work. The key is shared
by all users of the tfm, yet in your case you need it to be local
to the shash_desc as otherwise two packets processed in parallel
will overwrite each other's key.
I think the simplest solution is to make the key the beginning
of the hashed text instead. So the first two blocks that you
process get used as the key.
What do you think?
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2015-06-04 9:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-01 11:43 [PATCH 0/9] crypto: Add ChaCha20-Poly1305 AEAD support for IPsec Martin Willi
2015-06-01 11:43 ` [PATCH 1/9] crypto: Add a generic ChaCha20 stream cipher implementation Martin Willi
2015-06-01 11:43 ` [PATCH 2/9] crypto: testmgr - Add ChaCha20 test vectors from RFC7539 Martin Willi
2015-06-01 11:43 ` [PATCH 3/9] crypto: Add a generic Poly1305 authenticator implementation Martin Willi
2015-06-04 9:59 ` Herbert Xu [this message]
2015-06-04 19:42 ` Martin Willi
2015-06-01 11:43 ` [PATCH 4/9] crypto: testmgr - Add Poly1305 test vectors from RFC7539 Martin Willi
2015-06-01 11:44 ` [PATCH 5/9] crypto: Add a ChaCha20-Poly1305 AEAD construction, RFC7539 Martin Willi
2015-06-01 11:44 ` [PATCH 6/9] crypto: testmgr - Add ChaCha20-Poly1305 test vectors from RFC7539 Martin Willi
2015-06-01 11:44 ` [PATCH 7/9] crypto: chacha20poly1305 - Add an IPsec variant for RFC7539 AEAD Martin Willi
2015-06-01 11:44 ` [PATCH 8/9] crypto: testmgr - Add draft-ietf-ipsecme-chacha20-poly1305 test vector Martin Willi
2015-06-01 11:44 ` [PATCH 9/9] xfrm: Define ChaCha20-Poly1305 AEAD XFRM algo for IPsec users Martin Willi
2015-06-03 2:44 ` [PATCH 0/9] crypto: Add ChaCha20-Poly1305 AEAD support for IPsec Herbert Xu
2015-06-03 7:53 ` Steffen Klassert
2015-06-04 8:13 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150604095910.GA24246@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=martin@strongswan.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox