diff options
author | Mathias Krause <minipli@googlemail.com> | 2011-08-04 14:19:24 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2011-08-10 07:00:28 -0400 |
commit | 7c390170b49337477985be7a624015160ffeb056 (patch) | |
tree | c688eca7b31c154bc107cc107001fe2ffd4c7d99 | |
parent | b64dc04beba30947dc80745dcb95ae3c04fd18cf (diff) |
crypto: sha1 - export sha1_update for reuse
Export the update function as crypto_sha1_update() to not have the need
to reimplement the same algorithm for each SHA-1 implementation. This
way the generic SHA-1 implementation can be used as fallback for other
implementations that fail to run under certain circumstances, like the
need for an FPU context while executing in IRQ context.
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/sha1_generic.c | 9 | ||||
-rw-r--r-- | include/crypto/sha.h | 3 |
2 files changed, 8 insertions, 4 deletions
diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c index 00ae60eb925..42794803c48 100644 --- a/crypto/sha1_generic.c +++ b/crypto/sha1_generic.c | |||
@@ -36,7 +36,7 @@ static int sha1_init(struct shash_desc *desc) | |||
36 | return 0; | 36 | return 0; |
37 | } | 37 | } |
38 | 38 | ||
39 | static int sha1_update(struct shash_desc *desc, const u8 *data, | 39 | int crypto_sha1_update(struct shash_desc *desc, const u8 *data, |
40 | unsigned int len) | 40 | unsigned int len) |
41 | { | 41 | { |
42 | struct sha1_state *sctx = shash_desc_ctx(desc); | 42 | struct sha1_state *sctx = shash_desc_ctx(desc); |
@@ -71,6 +71,7 @@ static int sha1_update(struct shash_desc *desc, const u8 *data, | |||
71 | 71 | ||
72 | return 0; | 72 | return 0; |
73 | } | 73 | } |
74 | EXPORT_SYMBOL(crypto_sha1_update); | ||
74 | 75 | ||
75 | 76 | ||
76 | /* Add padding and return the message digest. */ | 77 | /* Add padding and return the message digest. */ |
@@ -87,10 +88,10 @@ static int sha1_final(struct shash_desc *desc, u8 *out) | |||
87 | /* Pad out to 56 mod 64 */ | 88 | /* Pad out to 56 mod 64 */ |
88 | index = sctx->count & 0x3f; | 89 | index = sctx->count & 0x3f; |
89 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); | 90 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
90 | sha1_update(desc, padding, padlen); | 91 | crypto_sha1_update(desc, padding, padlen); |
91 | 92 | ||
92 | /* Append length */ | 93 | /* Append length */ |
93 | sha1_update(desc, (const u8 *)&bits, sizeof(bits)); | 94 | crypto_sha1_update(desc, (const u8 *)&bits, sizeof(bits)); |
94 | 95 | ||
95 | /* Store state in digest */ | 96 | /* Store state in digest */ |
96 | for (i = 0; i < 5; i++) | 97 | for (i = 0; i < 5; i++) |
@@ -121,7 +122,7 @@ static int sha1_import(struct shash_desc *desc, const void *in) | |||
121 | static struct shash_alg alg = { | 122 | static struct shash_alg alg = { |
122 | .digestsize = SHA1_DIGEST_SIZE, | 123 | .digestsize = SHA1_DIGEST_SIZE, |
123 | .init = sha1_init, | 124 | .init = sha1_init, |
124 | .update = sha1_update, | 125 | .update = crypto_sha1_update, |
125 | .final = sha1_final, | 126 | .final = sha1_final, |
126 | .export = sha1_export, | 127 | .export = sha1_export, |
127 | .import = sha1_import, | 128 | .import = sha1_import, |
diff --git a/include/crypto/sha.h b/include/crypto/sha.h index 069e85ba97e..83e6be5e270 100644 --- a/include/crypto/sha.h +++ b/include/crypto/sha.h | |||
@@ -82,4 +82,7 @@ struct sha512_state { | |||
82 | u8 buf[SHA512_BLOCK_SIZE]; | 82 | u8 buf[SHA512_BLOCK_SIZE]; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | extern int crypto_sha1_update(struct shash_desc *desc, const u8 *data, | ||
86 | unsigned int len); | ||
87 | |||
85 | #endif | 88 | #endif |