diff options
| author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-12 09:25:20 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 00:58:08 -0400 |
| commit | 7eddf95ec5440d60f10963f453e27f82f394044e (patch) | |
| tree | 4b1ba4bbf01f381a45d5bd6d26811f51ab81a3ff | |
| parent | 6941c3a0aabb6ad4167827360f384e9daed7dd7f (diff) | |
crypto: shash - Export async functions
This patch exports the async functions so that they can be reused
by cryptd when it switches over to using shash.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
| -rw-r--r-- | crypto/shash.c | 42 | ||||
| -rw-r--r-- | include/crypto/internal/hash.h | 3 |
2 files changed, 25 insertions, 20 deletions
diff --git a/crypto/shash.c b/crypto/shash.c index d8e0f8f8d672..3b1b06b3dcf3 100644 --- a/crypto/shash.c +++ b/crypto/shash.c | |||
| @@ -202,9 +202,8 @@ static int shash_async_init(struct ahash_request *req) | |||
| 202 | return crypto_shash_init(desc); | 202 | return crypto_shash_init(desc); |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | static int shash_async_update(struct ahash_request *req) | 205 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc) |
| 206 | { | 206 | { |
| 207 | struct shash_desc *desc = ahash_request_ctx(req); | ||
| 208 | struct crypto_hash_walk walk; | 207 | struct crypto_hash_walk walk; |
| 209 | int nbytes; | 208 | int nbytes; |
| 210 | 209 | ||
| @@ -214,13 +213,19 @@ static int shash_async_update(struct ahash_request *req) | |||
| 214 | 213 | ||
| 215 | return nbytes; | 214 | return nbytes; |
| 216 | } | 215 | } |
| 216 | EXPORT_SYMBOL_GPL(shash_ahash_update); | ||
| 217 | |||
| 218 | static int shash_async_update(struct ahash_request *req) | ||
| 219 | { | ||
| 220 | return shash_ahash_update(req, ahash_request_ctx(req)); | ||
| 221 | } | ||
| 217 | 222 | ||
| 218 | static int shash_async_final(struct ahash_request *req) | 223 | static int shash_async_final(struct ahash_request *req) |
| 219 | { | 224 | { |
| 220 | return crypto_shash_final(ahash_request_ctx(req), req->result); | 225 | return crypto_shash_final(ahash_request_ctx(req), req->result); |
| 221 | } | 226 | } |
| 222 | 227 | ||
| 223 | static int shash_async_digest(struct ahash_request *req) | 228 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc) |
| 224 | { | 229 | { |
| 225 | struct scatterlist *sg = req->src; | 230 | struct scatterlist *sg = req->src; |
| 226 | unsigned int offset = sg->offset; | 231 | unsigned int offset = sg->offset; |
| @@ -228,34 +233,31 @@ static int shash_async_digest(struct ahash_request *req) | |||
| 228 | int err; | 233 | int err; |
| 229 | 234 | ||
| 230 | if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) { | 235 | if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) { |
| 231 | struct crypto_shash **ctx = | ||
| 232 | crypto_ahash_ctx(crypto_ahash_reqtfm(req)); | ||
| 233 | struct shash_desc *desc = ahash_request_ctx(req); | ||
| 234 | void *data; | 236 | void *data; |
| 235 | 237 | ||
| 236 | desc->tfm = *ctx; | ||
| 237 | desc->flags = req->base.flags; | ||
| 238 | |||
| 239 | data = crypto_kmap(sg_page(sg), 0); | 238 | data = crypto_kmap(sg_page(sg), 0); |
| 240 | err = crypto_shash_digest(desc, data + offset, nbytes, | 239 | err = crypto_shash_digest(desc, data + offset, nbytes, |
| 241 | req->result); | 240 | req->result); |
| 242 | crypto_kunmap(data, 0); | 241 | crypto_kunmap(data, 0); |
| 243 | crypto_yield(desc->flags); | 242 | crypto_yield(desc->flags); |
| 244 | goto out; | 243 | } else |
| 245 | } | 244 | err = crypto_shash_init(desc) ?: |
| 245 | shash_ahash_update(req, desc) ?: | ||
| 246 | crypto_shash_final(desc, req->result); | ||
| 246 | 247 | ||
| 247 | err = shash_async_init(req); | 248 | return err; |
| 248 | if (err) | 249 | } |
| 249 | goto out; | 250 | EXPORT_SYMBOL_GPL(shash_ahash_digest); |
| 250 | 251 | ||
| 251 | err = shash_async_update(req); | 252 | static int shash_async_digest(struct ahash_request *req) |
| 252 | if (err) | 253 | { |
| 253 | goto out; | 254 | struct crypto_shash **ctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req)); |
| 255 | struct shash_desc *desc = ahash_request_ctx(req); | ||
| 254 | 256 | ||
| 255 | err = shash_async_final(req); | 257 | desc->tfm = *ctx; |
| 258 | desc->flags = req->base.flags; | ||
| 256 | 259 | ||
| 257 | out: | 260 | return shash_ahash_digest(req, desc); |
| 258 | return err; | ||
| 259 | } | 261 | } |
| 260 | 262 | ||
| 261 | static void crypto_exit_shash_ops_async(struct crypto_tfm *tfm) | 263 | static void crypto_exit_shash_ops_async(struct crypto_tfm *tfm) |
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 2d1b10f23c91..6e283495374e 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h | |||
| @@ -63,6 +63,9 @@ int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn, | |||
| 63 | 63 | ||
| 64 | struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask); | 64 | struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask); |
| 65 | 65 | ||
| 66 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); | ||
| 67 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc); | ||
| 68 | |||
| 66 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | 69 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) |
| 67 | { | 70 | { |
| 68 | return crypto_tfm_ctx(&tfm->base); | 71 | return crypto_tfm_ctx(&tfm->base); |
