diff options
-rw-r--r-- | crypto/shash.c | 25 | ||||
-rw-r--r-- | include/crypto/hash.h | 18 |
2 files changed, 28 insertions, 15 deletions
diff --git a/crypto/shash.c b/crypto/shash.c index 23e05a1e9038..14a3b707a31f 100644 --- a/crypto/shash.c +++ b/crypto/shash.c | |||
@@ -172,19 +172,15 @@ int crypto_shash_digest(struct shash_desc *desc, const u8 *data, | |||
172 | } | 172 | } |
173 | EXPORT_SYMBOL_GPL(crypto_shash_digest); | 173 | EXPORT_SYMBOL_GPL(crypto_shash_digest); |
174 | 174 | ||
175 | int crypto_shash_import(struct shash_desc *desc, const u8 *in) | 175 | static int shash_no_export(struct shash_desc *desc, void *out) |
176 | { | 176 | { |
177 | struct crypto_shash *tfm = desc->tfm; | 177 | return -ENOSYS; |
178 | struct shash_alg *alg = crypto_shash_alg(tfm); | 178 | } |
179 | |||
180 | memcpy(shash_desc_ctx(desc), in, crypto_shash_descsize(tfm)); | ||
181 | |||
182 | if (alg->reinit) | ||
183 | return alg->reinit(desc); | ||
184 | 179 | ||
185 | return 0; | 180 | static int shash_no_import(struct shash_desc *desc, const void *in) |
181 | { | ||
182 | return -ENOSYS; | ||
186 | } | 183 | } |
187 | EXPORT_SYMBOL_GPL(crypto_shash_import); | ||
188 | 184 | ||
189 | static int shash_async_setkey(struct crypto_ahash *tfm, const u8 *key, | 185 | static int shash_async_setkey(struct crypto_ahash *tfm, const u8 *key, |
190 | unsigned int keylen) | 186 | unsigned int keylen) |
@@ -484,12 +480,19 @@ static int shash_prepare_alg(struct shash_alg *alg) | |||
484 | struct crypto_alg *base = &alg->base; | 480 | struct crypto_alg *base = &alg->base; |
485 | 481 | ||
486 | if (alg->digestsize > PAGE_SIZE / 8 || | 482 | if (alg->digestsize > PAGE_SIZE / 8 || |
487 | alg->descsize > PAGE_SIZE / 8) | 483 | alg->descsize > PAGE_SIZE / 8 || |
484 | alg->statesize > PAGE_SIZE / 8) | ||
488 | return -EINVAL; | 485 | return -EINVAL; |
489 | 486 | ||
490 | base->cra_type = &crypto_shash_type; | 487 | base->cra_type = &crypto_shash_type; |
491 | base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; | 488 | base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; |
492 | base->cra_flags |= CRYPTO_ALG_TYPE_SHASH; | 489 | base->cra_flags |= CRYPTO_ALG_TYPE_SHASH; |
490 | |||
491 | if (!alg->import) | ||
492 | alg->import = shash_no_import; | ||
493 | if (!alg->export) | ||
494 | alg->export = shash_no_export; | ||
495 | |||
493 | return 0; | 496 | return 0; |
494 | } | 497 | } |
495 | 498 | ||
diff --git a/include/crypto/hash.h b/include/crypto/hash.h index d56bb71617c3..3c4cce6a425c 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h | |||
@@ -24,7 +24,6 @@ struct shash_desc { | |||
24 | 24 | ||
25 | struct shash_alg { | 25 | struct shash_alg { |
26 | int (*init)(struct shash_desc *desc); | 26 | int (*init)(struct shash_desc *desc); |
27 | int (*reinit)(struct shash_desc *desc); | ||
28 | int (*update)(struct shash_desc *desc, const u8 *data, | 27 | int (*update)(struct shash_desc *desc, const u8 *data, |
29 | unsigned int len); | 28 | unsigned int len); |
30 | int (*final)(struct shash_desc *desc, u8 *out); | 29 | int (*final)(struct shash_desc *desc, u8 *out); |
@@ -32,11 +31,14 @@ struct shash_alg { | |||
32 | unsigned int len, u8 *out); | 31 | unsigned int len, u8 *out); |
33 | int (*digest)(struct shash_desc *desc, const u8 *data, | 32 | int (*digest)(struct shash_desc *desc, const u8 *data, |
34 | unsigned int len, u8 *out); | 33 | unsigned int len, u8 *out); |
34 | int (*export)(struct shash_desc *desc, void *out); | ||
35 | int (*import)(struct shash_desc *desc, const void *in); | ||
35 | int (*setkey)(struct crypto_shash *tfm, const u8 *key, | 36 | int (*setkey)(struct crypto_shash *tfm, const u8 *key, |
36 | unsigned int keylen); | 37 | unsigned int keylen); |
37 | 38 | ||
38 | unsigned int descsize; | 39 | unsigned int descsize; |
39 | unsigned int digestsize; | 40 | unsigned int digestsize; |
41 | unsigned int statesize; | ||
40 | 42 | ||
41 | struct crypto_alg base; | 43 | struct crypto_alg base; |
42 | }; | 44 | }; |
@@ -251,6 +253,11 @@ static inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm) | |||
251 | return crypto_shash_alg(tfm)->digestsize; | 253 | return crypto_shash_alg(tfm)->digestsize; |
252 | } | 254 | } |
253 | 255 | ||
256 | static inline unsigned int crypto_shash_statesize(struct crypto_shash *tfm) | ||
257 | { | ||
258 | return crypto_shash_alg(tfm)->statesize; | ||
259 | } | ||
260 | |||
254 | static inline u32 crypto_shash_get_flags(struct crypto_shash *tfm) | 261 | static inline u32 crypto_shash_get_flags(struct crypto_shash *tfm) |
255 | { | 262 | { |
256 | return crypto_tfm_get_flags(crypto_shash_tfm(tfm)); | 263 | return crypto_tfm_get_flags(crypto_shash_tfm(tfm)); |
@@ -281,12 +288,15 @@ int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key, | |||
281 | int crypto_shash_digest(struct shash_desc *desc, const u8 *data, | 288 | int crypto_shash_digest(struct shash_desc *desc, const u8 *data, |
282 | unsigned int len, u8 *out); | 289 | unsigned int len, u8 *out); |
283 | 290 | ||
284 | static inline void crypto_shash_export(struct shash_desc *desc, u8 *out) | 291 | static inline int crypto_shash_export(struct shash_desc *desc, void *out) |
285 | { | 292 | { |
286 | memcpy(out, shash_desc_ctx(desc), crypto_shash_descsize(desc->tfm)); | 293 | return crypto_shash_alg(desc->tfm)->export(desc, out); |
287 | } | 294 | } |
288 | 295 | ||
289 | int crypto_shash_import(struct shash_desc *desc, const u8 *in); | 296 | static inline int crypto_shash_import(struct shash_desc *desc, const void *in) |
297 | { | ||
298 | return crypto_shash_alg(desc->tfm)->import(desc, in); | ||
299 | } | ||
290 | 300 | ||
291 | static inline int crypto_shash_init(struct shash_desc *desc) | 301 | static inline int crypto_shash_init(struct shash_desc *desc) |
292 | { | 302 | { |