diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-25 11:38:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-25 11:38:25 -0500 |
commit | eba0e319c12fb098d66316a8eafbaaa9174a07c3 (patch) | |
tree | b2703117db9e36bb3510654efd55361f61c54742 /crypto/sha256_generic.c | |
parent | df8dc74e8a383eaf2d9b44b80a71ec6f0e52b42e (diff) | |
parent | 15e7b4452b72ae890f2fcb027b4c4fa63a1c9a7a (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (125 commits)
[CRYPTO] twofish: Merge common glue code
[CRYPTO] hifn_795x: Fixup container_of() usage
[CRYPTO] cast6: inline bloat--
[CRYPTO] api: Set default CRYPTO_MINALIGN to unsigned long long
[CRYPTO] tcrypt: Make xcbc available as a standalone test
[CRYPTO] xcbc: Remove bogus hash/cipher test
[CRYPTO] xcbc: Fix algorithm leak when block size check fails
[CRYPTO] tcrypt: Zero axbuf in the right function
[CRYPTO] padlock: Only reset the key once for each CBC and ECB operation
[CRYPTO] api: Include sched.h for cond_resched in scatterwalk.h
[CRYPTO] salsa20-asm: Remove unnecessary dependency on CRYPTO_SALSA20
[CRYPTO] tcrypt: Add select of AEAD
[CRYPTO] salsa20: Add x86-64 assembly version
[CRYPTO] salsa20_i586: Salsa20 stream cipher algorithm (i586 version)
[CRYPTO] gcm: Introduce rfc4106
[CRYPTO] api: Show async type
[CRYPTO] chainiv: Avoid lock spinning where possible
[CRYPTO] seqiv: Add select AEAD in Kconfig
[CRYPTO] scatterwalk: Handle zero nbytes in scatterwalk_map_and_copy
[CRYPTO] null: Allow setkey on digest_null
...
Diffstat (limited to 'crypto/sha256_generic.c')
-rw-r--r-- | crypto/sha256_generic.c | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c index fd3918be58b5..3cc93fd61043 100644 --- a/crypto/sha256_generic.c +++ b/crypto/sha256_generic.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> | 9 | * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> |
10 | * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> | 10 | * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> |
11 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | 11 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
12 | * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com> | ||
12 | * | 13 | * |
13 | * This program is free software; you can redistribute it and/or modify it | 14 | * This program is free software; you can redistribute it and/or modify it |
14 | * under the terms of the GNU General Public License as published by the Free | 15 | * under the terms of the GNU General Public License as published by the Free |
@@ -218,6 +219,22 @@ static void sha256_transform(u32 *state, const u8 *input) | |||
218 | memset(W, 0, 64 * sizeof(u32)); | 219 | memset(W, 0, 64 * sizeof(u32)); |
219 | } | 220 | } |
220 | 221 | ||
222 | |||
223 | static void sha224_init(struct crypto_tfm *tfm) | ||
224 | { | ||
225 | struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); | ||
226 | sctx->state[0] = SHA224_H0; | ||
227 | sctx->state[1] = SHA224_H1; | ||
228 | sctx->state[2] = SHA224_H2; | ||
229 | sctx->state[3] = SHA224_H3; | ||
230 | sctx->state[4] = SHA224_H4; | ||
231 | sctx->state[5] = SHA224_H5; | ||
232 | sctx->state[6] = SHA224_H6; | ||
233 | sctx->state[7] = SHA224_H7; | ||
234 | sctx->count[0] = 0; | ||
235 | sctx->count[1] = 0; | ||
236 | } | ||
237 | |||
221 | static void sha256_init(struct crypto_tfm *tfm) | 238 | static void sha256_init(struct crypto_tfm *tfm) |
222 | { | 239 | { |
223 | struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); | 240 | struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); |
@@ -294,8 +311,17 @@ static void sha256_final(struct crypto_tfm *tfm, u8 *out) | |||
294 | memset(sctx, 0, sizeof(*sctx)); | 311 | memset(sctx, 0, sizeof(*sctx)); |
295 | } | 312 | } |
296 | 313 | ||
314 | static void sha224_final(struct crypto_tfm *tfm, u8 *hash) | ||
315 | { | ||
316 | u8 D[SHA256_DIGEST_SIZE]; | ||
317 | |||
318 | sha256_final(tfm, D); | ||
319 | |||
320 | memcpy(hash, D, SHA224_DIGEST_SIZE); | ||
321 | memset(D, 0, SHA256_DIGEST_SIZE); | ||
322 | } | ||
297 | 323 | ||
298 | static struct crypto_alg alg = { | 324 | static struct crypto_alg sha256 = { |
299 | .cra_name = "sha256", | 325 | .cra_name = "sha256", |
300 | .cra_driver_name= "sha256-generic", | 326 | .cra_driver_name= "sha256-generic", |
301 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 327 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, |
@@ -303,28 +329,58 @@ static struct crypto_alg alg = { | |||
303 | .cra_ctxsize = sizeof(struct sha256_ctx), | 329 | .cra_ctxsize = sizeof(struct sha256_ctx), |
304 | .cra_module = THIS_MODULE, | 330 | .cra_module = THIS_MODULE, |
305 | .cra_alignmask = 3, | 331 | .cra_alignmask = 3, |
306 | .cra_list = LIST_HEAD_INIT(alg.cra_list), | 332 | .cra_list = LIST_HEAD_INIT(sha256.cra_list), |
307 | .cra_u = { .digest = { | 333 | .cra_u = { .digest = { |
308 | .dia_digestsize = SHA256_DIGEST_SIZE, | 334 | .dia_digestsize = SHA256_DIGEST_SIZE, |
309 | .dia_init = sha256_init, | 335 | .dia_init = sha256_init, |
310 | .dia_update = sha256_update, | 336 | .dia_update = sha256_update, |
311 | .dia_final = sha256_final } } | 337 | .dia_final = sha256_final } } |
338 | }; | ||
339 | |||
340 | static struct crypto_alg sha224 = { | ||
341 | .cra_name = "sha224", | ||
342 | .cra_driver_name = "sha224-generic", | ||
343 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | ||
344 | .cra_blocksize = SHA224_BLOCK_SIZE, | ||
345 | .cra_ctxsize = sizeof(struct sha256_ctx), | ||
346 | .cra_module = THIS_MODULE, | ||
347 | .cra_alignmask = 3, | ||
348 | .cra_list = LIST_HEAD_INIT(sha224.cra_list), | ||
349 | .cra_u = { .digest = { | ||
350 | .dia_digestsize = SHA224_DIGEST_SIZE, | ||
351 | .dia_init = sha224_init, | ||
352 | .dia_update = sha256_update, | ||
353 | .dia_final = sha224_final } } | ||
312 | }; | 354 | }; |
313 | 355 | ||
314 | static int __init init(void) | 356 | static int __init init(void) |
315 | { | 357 | { |
316 | return crypto_register_alg(&alg); | 358 | int ret = 0; |
359 | |||
360 | ret = crypto_register_alg(&sha224); | ||
361 | |||
362 | if (ret < 0) | ||
363 | return ret; | ||
364 | |||
365 | ret = crypto_register_alg(&sha256); | ||
366 | |||
367 | if (ret < 0) | ||
368 | crypto_unregister_alg(&sha224); | ||
369 | |||
370 | return ret; | ||
317 | } | 371 | } |
318 | 372 | ||
319 | static void __exit fini(void) | 373 | static void __exit fini(void) |
320 | { | 374 | { |
321 | crypto_unregister_alg(&alg); | 375 | crypto_unregister_alg(&sha224); |
376 | crypto_unregister_alg(&sha256); | ||
322 | } | 377 | } |
323 | 378 | ||
324 | module_init(init); | 379 | module_init(init); |
325 | module_exit(fini); | 380 | module_exit(fini); |
326 | 381 | ||
327 | MODULE_LICENSE("GPL"); | 382 | MODULE_LICENSE("GPL"); |
328 | MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm"); | 383 | MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm"); |
329 | 384 | ||
385 | MODULE_ALIAS("sha224"); | ||
330 | MODULE_ALIAS("sha256"); | 386 | MODULE_ALIAS("sha256"); |