diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-22 00:37:06 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-22 02:38:13 -0400 |
commit | f592682f9fca18d336ac068a1abc8507b4a1d936 (patch) | |
tree | 4f50efe420d0ecf523adff5301aaff014c357070 | |
parent | 9fadfd1adff28a8895de8df9e8a778c44958840f (diff) |
crypto: shash - Require all algorithms to support export/import
This patch provides a default export/import function for all
shash algorithms. It simply copies the descriptor context as
is done by sha1_generic.
This in essence means that all existing shash algorithms now
support export/import. This is something that will be depended
upon in implementations such as hmac. Therefore all new shash
and ahash implementations must support export/import.
For those that cannot obtain a partial result, padlock-sha's
fallback model should be used so that a partial result is always
available.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/shash.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/crypto/shash.c b/crypto/shash.c index 7713b520bc98..98b7f46ca1ed 100644 --- a/crypto/shash.c +++ b/crypto/shash.c | |||
@@ -183,14 +183,16 @@ int crypto_shash_digest(struct shash_desc *desc, const u8 *data, | |||
183 | } | 183 | } |
184 | EXPORT_SYMBOL_GPL(crypto_shash_digest); | 184 | EXPORT_SYMBOL_GPL(crypto_shash_digest); |
185 | 185 | ||
186 | static int shash_no_export(struct shash_desc *desc, void *out) | 186 | static int shash_default_export(struct shash_desc *desc, void *out) |
187 | { | 187 | { |
188 | return -ENOSYS; | 188 | memcpy(out, shash_desc_ctx(desc), crypto_shash_descsize(desc->tfm)); |
189 | return 0; | ||
189 | } | 190 | } |
190 | 191 | ||
191 | static int shash_no_import(struct shash_desc *desc, const void *in) | 192 | static int shash_default_import(struct shash_desc *desc, const void *in) |
192 | { | 193 | { |
193 | return -ENOSYS; | 194 | memcpy(shash_desc_ctx(desc), in, crypto_shash_descsize(desc->tfm)); |
195 | return 0; | ||
194 | } | 196 | } |
195 | 197 | ||
196 | static int shash_async_setkey(struct crypto_ahash *tfm, const u8 *key, | 198 | static int shash_async_setkey(struct crypto_ahash *tfm, const u8 *key, |
@@ -563,10 +565,11 @@ static int shash_prepare_alg(struct shash_alg *alg) | |||
563 | alg->finup = shash_finup_unaligned; | 565 | alg->finup = shash_finup_unaligned; |
564 | if (!alg->digest) | 566 | if (!alg->digest) |
565 | alg->digest = shash_digest_unaligned; | 567 | alg->digest = shash_digest_unaligned; |
566 | if (!alg->import) | 568 | if (!alg->export) { |
567 | alg->import = shash_no_import; | 569 | alg->export = shash_default_export; |
568 | if (!alg->export) | 570 | alg->import = shash_default_import; |
569 | alg->export = shash_no_export; | 571 | alg->statesize = alg->descsize; |
572 | } | ||
570 | if (!alg->setkey) | 573 | if (!alg->setkey) |
571 | alg->setkey = shash_no_setkey; | 574 | alg->setkey = shash_no_setkey; |
572 | 575 | ||