diff options
Diffstat (limited to 'crypto/sha512.c')
-rw-r--r-- | crypto/sha512.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/crypto/sha512.c b/crypto/sha512.c index 3e6e9392310c..2dfe7f170b48 100644 --- a/crypto/sha512.c +++ b/crypto/sha512.c | |||
@@ -161,9 +161,9 @@ sha512_transform(u64 *state, u64 *W, const u8 *input) | |||
161 | } | 161 | } |
162 | 162 | ||
163 | static void | 163 | static void |
164 | sha512_init(void *ctx) | 164 | sha512_init(struct crypto_tfm *tfm) |
165 | { | 165 | { |
166 | struct sha512_ctx *sctx = ctx; | 166 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); |
167 | sctx->state[0] = H0; | 167 | sctx->state[0] = H0; |
168 | sctx->state[1] = H1; | 168 | sctx->state[1] = H1; |
169 | sctx->state[2] = H2; | 169 | sctx->state[2] = H2; |
@@ -173,13 +173,12 @@ sha512_init(void *ctx) | |||
173 | sctx->state[6] = H6; | 173 | sctx->state[6] = H6; |
174 | sctx->state[7] = H7; | 174 | sctx->state[7] = H7; |
175 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 175 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; |
176 | memset(sctx->buf, 0, sizeof(sctx->buf)); | ||
177 | } | 176 | } |
178 | 177 | ||
179 | static void | 178 | static void |
180 | sha384_init(void *ctx) | 179 | sha384_init(struct crypto_tfm *tfm) |
181 | { | 180 | { |
182 | struct sha512_ctx *sctx = ctx; | 181 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); |
183 | sctx->state[0] = HP0; | 182 | sctx->state[0] = HP0; |
184 | sctx->state[1] = HP1; | 183 | sctx->state[1] = HP1; |
185 | sctx->state[2] = HP2; | 184 | sctx->state[2] = HP2; |
@@ -189,13 +188,12 @@ sha384_init(void *ctx) | |||
189 | sctx->state[6] = HP6; | 188 | sctx->state[6] = HP6; |
190 | sctx->state[7] = HP7; | 189 | sctx->state[7] = HP7; |
191 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 190 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; |
192 | memset(sctx->buf, 0, sizeof(sctx->buf)); | ||
193 | } | 191 | } |
194 | 192 | ||
195 | static void | 193 | static void |
196 | sha512_update(void *ctx, const u8 *data, unsigned int len) | 194 | sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) |
197 | { | 195 | { |
198 | struct sha512_ctx *sctx = ctx; | 196 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); |
199 | 197 | ||
200 | unsigned int i, index, part_len; | 198 | unsigned int i, index, part_len; |
201 | 199 | ||
@@ -233,9 +231,9 @@ sha512_update(void *ctx, const u8 *data, unsigned int len) | |||
233 | } | 231 | } |
234 | 232 | ||
235 | static void | 233 | static void |
236 | sha512_final(void *ctx, u8 *hash) | 234 | sha512_final(struct crypto_tfm *tfm, u8 *hash) |
237 | { | 235 | { |
238 | struct sha512_ctx *sctx = ctx; | 236 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); |
239 | static u8 padding[128] = { 0x80, }; | 237 | static u8 padding[128] = { 0x80, }; |
240 | __be64 *dst = (__be64 *)hash; | 238 | __be64 *dst = (__be64 *)hash; |
241 | __be32 bits[4]; | 239 | __be32 bits[4]; |
@@ -251,10 +249,10 @@ sha512_final(void *ctx, u8 *hash) | |||
251 | /* Pad out to 112 mod 128. */ | 249 | /* Pad out to 112 mod 128. */ |
252 | index = (sctx->count[0] >> 3) & 0x7f; | 250 | index = (sctx->count[0] >> 3) & 0x7f; |
253 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); | 251 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); |
254 | sha512_update(sctx, padding, pad_len); | 252 | sha512_update(tfm, padding, pad_len); |
255 | 253 | ||
256 | /* Append length (before padding) */ | 254 | /* Append length (before padding) */ |
257 | sha512_update(sctx, (const u8 *)bits, sizeof(bits)); | 255 | sha512_update(tfm, (const u8 *)bits, sizeof(bits)); |
258 | 256 | ||
259 | /* Store state in digest */ | 257 | /* Store state in digest */ |
260 | for (i = 0; i < 8; i++) | 258 | for (i = 0; i < 8; i++) |
@@ -264,12 +262,11 @@ sha512_final(void *ctx, u8 *hash) | |||
264 | memset(sctx, 0, sizeof(struct sha512_ctx)); | 262 | memset(sctx, 0, sizeof(struct sha512_ctx)); |
265 | } | 263 | } |
266 | 264 | ||
267 | static void sha384_final(void *ctx, u8 *hash) | 265 | static void sha384_final(struct crypto_tfm *tfm, u8 *hash) |
268 | { | 266 | { |
269 | struct sha512_ctx *sctx = ctx; | ||
270 | u8 D[64]; | 267 | u8 D[64]; |
271 | 268 | ||
272 | sha512_final(sctx, D); | 269 | sha512_final(tfm, D); |
273 | 270 | ||
274 | memcpy(hash, D, 48); | 271 | memcpy(hash, D, 48); |
275 | memset(D, 0, 64); | 272 | memset(D, 0, 64); |
@@ -281,6 +278,7 @@ static struct crypto_alg sha512 = { | |||
281 | .cra_blocksize = SHA512_HMAC_BLOCK_SIZE, | 278 | .cra_blocksize = SHA512_HMAC_BLOCK_SIZE, |
282 | .cra_ctxsize = sizeof(struct sha512_ctx), | 279 | .cra_ctxsize = sizeof(struct sha512_ctx), |
283 | .cra_module = THIS_MODULE, | 280 | .cra_module = THIS_MODULE, |
281 | .cra_alignmask = 3, | ||
284 | .cra_list = LIST_HEAD_INIT(sha512.cra_list), | 282 | .cra_list = LIST_HEAD_INIT(sha512.cra_list), |
285 | .cra_u = { .digest = { | 283 | .cra_u = { .digest = { |
286 | .dia_digestsize = SHA512_DIGEST_SIZE, | 284 | .dia_digestsize = SHA512_DIGEST_SIZE, |
@@ -295,6 +293,7 @@ static struct crypto_alg sha384 = { | |||
295 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 293 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, |
296 | .cra_blocksize = SHA384_HMAC_BLOCK_SIZE, | 294 | .cra_blocksize = SHA384_HMAC_BLOCK_SIZE, |
297 | .cra_ctxsize = sizeof(struct sha512_ctx), | 295 | .cra_ctxsize = sizeof(struct sha512_ctx), |
296 | .cra_alignmask = 3, | ||
298 | .cra_module = THIS_MODULE, | 297 | .cra_module = THIS_MODULE, |
299 | .cra_list = LIST_HEAD_INIT(sha384.cra_list), | 298 | .cra_list = LIST_HEAD_INIT(sha384.cra_list), |
300 | .cra_u = { .digest = { | 299 | .cra_u = { .digest = { |