forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CRYPTO] sha256-generic: Extend sha256_generic.c to support SHA-224
Resubmitting this patch which extends sha256_generic.c to support SHA-224 as described in FIPS 180-2 and RFC 3874. HMAC-SHA-224 as described in RFC4231 is then supported through the hmac interface. Patch includes test vectors for SHA-224 and HMAC-SHA-224. SHA-224 chould be chosen as a hash algorithm when 112 bits of security strength is required. Patch generated against the 2.6.24-rc1 kernel and tested against 2.6.24-rc1-git14 which includes fix for scatter gather implementation for HMAC. Signed-off-by: Jonathan Lynch <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
- Loading branch information
Showing
5 changed files
with
241 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* Copyright (c) Jean-Luc Cooke <[email protected]> | ||
* Copyright (c) Andrew McDonald <[email protected]> | ||
* Copyright (c) 2002 James Morris <[email protected]> | ||
* SHA224 Support Copyright 2007 Intel Corporation <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* 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) | |
memset(W, 0, 64 * sizeof(u32)); | ||
} | ||
|
||
|
||
static void sha224_init(struct crypto_tfm *tfm) | ||
{ | ||
struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); | ||
sctx->state[0] = SHA224_H0; | ||
sctx->state[1] = SHA224_H1; | ||
sctx->state[2] = SHA224_H2; | ||
sctx->state[3] = SHA224_H3; | ||
sctx->state[4] = SHA224_H4; | ||
sctx->state[5] = SHA224_H5; | ||
sctx->state[6] = SHA224_H6; | ||
sctx->state[7] = SHA224_H7; | ||
sctx->count[0] = 0; | ||
sctx->count[1] = 0; | ||
} | ||
|
||
static void sha256_init(struct crypto_tfm *tfm) | ||
{ | ||
struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); | ||
|
@@ -294,37 +311,76 @@ static void sha256_final(struct crypto_tfm *tfm, u8 *out) | |
memset(sctx, 0, sizeof(*sctx)); | ||
} | ||
|
||
static void sha224_final(struct crypto_tfm *tfm, u8 *hash) | ||
{ | ||
u8 D[SHA256_DIGEST_SIZE]; | ||
|
||
sha256_final(tfm, D); | ||
|
||
memcpy(hash, D, SHA224_DIGEST_SIZE); | ||
memset(D, 0, SHA256_DIGEST_SIZE); | ||
} | ||
|
||
static struct crypto_alg alg = { | ||
static struct crypto_alg sha256 = { | ||
.cra_name = "sha256", | ||
.cra_driver_name= "sha256-generic", | ||
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, | ||
.cra_blocksize = SHA256_BLOCK_SIZE, | ||
.cra_ctxsize = sizeof(struct sha256_ctx), | ||
.cra_module = THIS_MODULE, | ||
.cra_alignmask = 3, | ||
.cra_list = LIST_HEAD_INIT(alg.cra_list), | ||
.cra_list = LIST_HEAD_INIT(sha256.cra_list), | ||
.cra_u = { .digest = { | ||
.dia_digestsize = SHA256_DIGEST_SIZE, | ||
.dia_init = sha256_init, | ||
.dia_update = sha256_update, | ||
.dia_final = sha256_final } } | ||
.dia_init = sha256_init, | ||
.dia_update = sha256_update, | ||
.dia_final = sha256_final } } | ||
}; | ||
|
||
static struct crypto_alg sha224 = { | ||
.cra_name = "sha224", | ||
.cra_driver_name = "sha224-generic", | ||
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, | ||
.cra_blocksize = SHA224_BLOCK_SIZE, | ||
.cra_ctxsize = sizeof(struct sha256_ctx), | ||
.cra_module = THIS_MODULE, | ||
.cra_alignmask = 3, | ||
.cra_list = LIST_HEAD_INIT(sha224.cra_list), | ||
.cra_u = { .digest = { | ||
.dia_digestsize = SHA224_DIGEST_SIZE, | ||
.dia_init = sha224_init, | ||
.dia_update = sha256_update, | ||
.dia_final = sha224_final } } | ||
}; | ||
|
||
static int __init init(void) | ||
{ | ||
return crypto_register_alg(&alg); | ||
int ret = 0; | ||
|
||
ret = crypto_register_alg(&sha224); | ||
|
||
if (ret < 0) | ||
return ret; | ||
|
||
ret = crypto_register_alg(&sha256); | ||
|
||
if (ret < 0) | ||
crypto_unregister_alg(&sha224); | ||
|
||
return ret; | ||
} | ||
|
||
static void __exit fini(void) | ||
{ | ||
crypto_unregister_alg(&alg); | ||
crypto_unregister_alg(&sha224); | ||
crypto_unregister_alg(&sha256); | ||
} | ||
|
||
module_init(init); | ||
module_exit(fini); | ||
|
||
MODULE_LICENSE("GPL"); | ||
MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm"); | ||
MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm"); | ||
|
||
MODULE_ALIAS("sha224"); | ||
MODULE_ALIAS("sha256"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* 2007-11-06 Added SHA-224 and SHA-224-HMAC tests | ||
* 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests | ||
* 2004-08-09 Added cipher speed tests (Reyk Floeter <[email protected]>) | ||
* 2003-09-14 Rewritten by Kartikey Mahendra Bhatt | ||
|
@@ -74,8 +75,9 @@ static char *xbuf; | |
static char *tvmem; | ||
|
||
static char *check[] = { | ||
"des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", | ||
"twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", | ||
"des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", | ||
"blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", | ||
"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | ||
"arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | ||
"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", | ||
"camellia", "seed", NULL | ||
|
@@ -918,6 +920,8 @@ static void do_test(void) | |
|
||
test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); | ||
|
||
test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); | ||
|
||
test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); | ||
|
||
//BLOWFISH | ||
|
@@ -1067,6 +1071,8 @@ static void do_test(void) | |
HMAC_MD5_TEST_VECTORS); | ||
test_hash("hmac(sha1)", hmac_sha1_tv_template, | ||
HMAC_SHA1_TEST_VECTORS); | ||
test_hash("hmac(sha224)", hmac_sha224_tv_template, | ||
HMAC_SHA224_TEST_VECTORS); | ||
test_hash("hmac(sha256)", hmac_sha256_tv_template, | ||
HMAC_SHA256_TEST_VECTORS); | ||
test_hash("hmac(sha384)", hmac_sha384_tv_template, | ||
|
@@ -1299,6 +1305,9 @@ static void do_test(void) | |
camellia_cbc_dec_tv_template, | ||
CAMELLIA_CBC_DEC_TEST_VECTORS); | ||
break; | ||
case 33: | ||
test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); | ||
break; | ||
|
||
case 100: | ||
test_hash("hmac(md5)", hmac_md5_tv_template, | ||
|
@@ -1324,7 +1333,10 @@ static void do_test(void) | |
test_hash("hmac(sha512)", hmac_sha512_tv_template, | ||
HMAC_SHA512_TEST_VECTORS); | ||
break; | ||
|
||
case 105: | ||
test_hash("hmac(sha224)", hmac_sha224_tv_template, | ||
HMAC_SHA224_TEST_VECTORS); | ||
break; | ||
|
||
case 200: | ||
test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, | ||
|
@@ -1459,6 +1471,10 @@ static void do_test(void) | |
test_hash_speed("tgr192", sec, generic_hash_speed_template); | ||
if (mode > 300 && mode < 400) break; | ||
|
||
case 313: | ||
test_hash_speed("sha224", sec, generic_hash_speed_template); | ||
if (mode > 300 && mode < 400) break; | ||
|
||
case 399: | ||
break; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters