diff options
author | Eric Biggers <ebiggers@google.com> | 2018-11-16 20:26:27 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-11-20 01:26:56 -0500 |
commit | 878afc35cd28bcd93cd3c5e1985ef39a104a4d45 (patch) | |
tree | e17291b3c2ea1c786fceb3ee4f78cf175273a0cc /crypto/poly1305_generic.c | |
parent | bdb063a79f6da589af1de3f10a7c8f654fba9ae8 (diff) |
crypto: poly1305 - use structures for key and accumulator
In preparation for exposing a low-level Poly1305 API which implements
the ε-almost-∆-universal (εA∆U) hash function underlying the Poly1305
MAC and supports block-aligned inputs only, create structures
poly1305_key and poly1305_state which hold the limbs of the Poly1305
"r" key and accumulator, respectively.
These structures could actually have the same type (e.g. poly1305_val),
but different types are preferable, to prevent misuse.
Acked-by: Martin Willi <martin@strongswan.org>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/poly1305_generic.c')
-rw-r--r-- | crypto/poly1305_generic.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/crypto/poly1305_generic.c b/crypto/poly1305_generic.c index 47d3a6b83931..a23173f351b7 100644 --- a/crypto/poly1305_generic.c +++ b/crypto/poly1305_generic.c | |||
@@ -38,7 +38,7 @@ int crypto_poly1305_init(struct shash_desc *desc) | |||
38 | { | 38 | { |
39 | struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc); | 39 | struct poly1305_desc_ctx *dctx = shash_desc_ctx(desc); |
40 | 40 | ||
41 | memset(dctx->h, 0, sizeof(dctx->h)); | 41 | memset(dctx->h.h, 0, sizeof(dctx->h.h)); |
42 | dctx->buflen = 0; | 42 | dctx->buflen = 0; |
43 | dctx->rset = false; | 43 | dctx->rset = false; |
44 | dctx->sset = false; | 44 | dctx->sset = false; |
@@ -50,11 +50,11 @@ EXPORT_SYMBOL_GPL(crypto_poly1305_init); | |||
50 | static void poly1305_setrkey(struct poly1305_desc_ctx *dctx, const u8 *key) | 50 | static void poly1305_setrkey(struct poly1305_desc_ctx *dctx, const u8 *key) |
51 | { | 51 | { |
52 | /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */ | 52 | /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */ |
53 | dctx->r[0] = (get_unaligned_le32(key + 0) >> 0) & 0x3ffffff; | 53 | dctx->r.r[0] = (get_unaligned_le32(key + 0) >> 0) & 0x3ffffff; |
54 | dctx->r[1] = (get_unaligned_le32(key + 3) >> 2) & 0x3ffff03; | 54 | dctx->r.r[1] = (get_unaligned_le32(key + 3) >> 2) & 0x3ffff03; |
55 | dctx->r[2] = (get_unaligned_le32(key + 6) >> 4) & 0x3ffc0ff; | 55 | dctx->r.r[2] = (get_unaligned_le32(key + 6) >> 4) & 0x3ffc0ff; |
56 | dctx->r[3] = (get_unaligned_le32(key + 9) >> 6) & 0x3f03fff; | 56 | dctx->r.r[3] = (get_unaligned_le32(key + 9) >> 6) & 0x3f03fff; |
57 | dctx->r[4] = (get_unaligned_le32(key + 12) >> 8) & 0x00fffff; | 57 | dctx->r.r[4] = (get_unaligned_le32(key + 12) >> 8) & 0x00fffff; |
58 | } | 58 | } |
59 | 59 | ||
60 | static void poly1305_setskey(struct poly1305_desc_ctx *dctx, const u8 *key) | 60 | static void poly1305_setskey(struct poly1305_desc_ctx *dctx, const u8 *key) |
@@ -107,22 +107,22 @@ static unsigned int poly1305_blocks(struct poly1305_desc_ctx *dctx, | |||
107 | srclen = datalen; | 107 | srclen = datalen; |
108 | } | 108 | } |
109 | 109 | ||
110 | r0 = dctx->r[0]; | 110 | r0 = dctx->r.r[0]; |
111 | r1 = dctx->r[1]; | 111 | r1 = dctx->r.r[1]; |
112 | r2 = dctx->r[2]; | 112 | r2 = dctx->r.r[2]; |
113 | r3 = dctx->r[3]; | 113 | r3 = dctx->r.r[3]; |
114 | r4 = dctx->r[4]; | 114 | r4 = dctx->r.r[4]; |
115 | 115 | ||
116 | s1 = r1 * 5; | 116 | s1 = r1 * 5; |
117 | s2 = r2 * 5; | 117 | s2 = r2 * 5; |
118 | s3 = r3 * 5; | 118 | s3 = r3 * 5; |
119 | s4 = r4 * 5; | 119 | s4 = r4 * 5; |
120 | 120 | ||
121 | h0 = dctx->h[0]; | 121 | h0 = dctx->h.h[0]; |
122 | h1 = dctx->h[1]; | 122 | h1 = dctx->h.h[1]; |
123 | h2 = dctx->h[2]; | 123 | h2 = dctx->h.h[2]; |
124 | h3 = dctx->h[3]; | 124 | h3 = dctx->h.h[3]; |
125 | h4 = dctx->h[4]; | 125 | h4 = dctx->h.h[4]; |
126 | 126 | ||
127 | while (likely(srclen >= POLY1305_BLOCK_SIZE)) { | 127 | while (likely(srclen >= POLY1305_BLOCK_SIZE)) { |
128 | 128 | ||
@@ -157,11 +157,11 @@ static unsigned int poly1305_blocks(struct poly1305_desc_ctx *dctx, | |||
157 | srclen -= POLY1305_BLOCK_SIZE; | 157 | srclen -= POLY1305_BLOCK_SIZE; |
158 | } | 158 | } |
159 | 159 | ||
160 | dctx->h[0] = h0; | 160 | dctx->h.h[0] = h0; |
161 | dctx->h[1] = h1; | 161 | dctx->h.h[1] = h1; |
162 | dctx->h[2] = h2; | 162 | dctx->h.h[2] = h2; |
163 | dctx->h[3] = h3; | 163 | dctx->h.h[3] = h3; |
164 | dctx->h[4] = h4; | 164 | dctx->h.h[4] = h4; |
165 | 165 | ||
166 | return srclen; | 166 | return srclen; |
167 | } | 167 | } |
@@ -220,11 +220,11 @@ int crypto_poly1305_final(struct shash_desc *desc, u8 *dst) | |||
220 | } | 220 | } |
221 | 221 | ||
222 | /* fully carry h */ | 222 | /* fully carry h */ |
223 | h0 = dctx->h[0]; | 223 | h0 = dctx->h.h[0]; |
224 | h1 = dctx->h[1]; | 224 | h1 = dctx->h.h[1]; |
225 | h2 = dctx->h[2]; | 225 | h2 = dctx->h.h[2]; |
226 | h3 = dctx->h[3]; | 226 | h3 = dctx->h.h[3]; |
227 | h4 = dctx->h[4]; | 227 | h4 = dctx->h.h[4]; |
228 | 228 | ||
229 | h2 += (h1 >> 26); h1 = h1 & 0x3ffffff; | 229 | h2 += (h1 >> 26); h1 = h1 & 0x3ffffff; |
230 | h3 += (h2 >> 26); h2 = h2 & 0x3ffffff; | 230 | h3 += (h2 >> 26); h2 = h2 & 0x3ffffff; |