Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: hash - Add export_core and import_core hooks

Add export_core and import_core hooks. These are intended to be
used by algorithms which are wrappers around block-only algorithms,
but are not themselves block-only, e.g., hmac.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+68 -11
+19 -3
crypto/ahash.c
··· 704 704 705 705 if (likely(tfm->using_shash)) 706 706 return crypto_shash_export_core(ahash_request_ctx(req), out); 707 - return crypto_ahash_alg(tfm)->export(req, out); 707 + return crypto_ahash_alg(tfm)->export_core(req, out); 708 708 } 709 709 EXPORT_SYMBOL_GPL(crypto_ahash_export_core); 710 710 ··· 727 727 in); 728 728 if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) 729 729 return -ENOKEY; 730 - return crypto_ahash_alg(tfm)->import(req, in); 730 + return crypto_ahash_alg(tfm)->import_core(req, in); 731 731 } 732 732 EXPORT_SYMBOL_GPL(crypto_ahash_import_core); 733 733 ··· 739 739 return crypto_shash_import(prepare_shash_desc(req, tfm), in); 740 740 if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) 741 741 return -ENOKEY; 742 - return crypto_ahash_import_core(req, in); 742 + return crypto_ahash_alg(tfm)->import(req, in); 743 743 } 744 744 EXPORT_SYMBOL_GPL(crypto_ahash_import); 745 745 ··· 971 971 } 972 972 EXPORT_SYMBOL_GPL(crypto_clone_ahash); 973 973 974 + static int ahash_default_export_core(struct ahash_request *req, void *out) 975 + { 976 + return -ENOSYS; 977 + } 978 + 979 + static int ahash_default_import_core(struct ahash_request *req, const void *in) 980 + { 981 + return -ENOSYS; 982 + } 983 + 974 984 static int ahash_prepare_alg(struct ahash_alg *alg) 975 985 { 976 986 struct crypto_alg *base = &alg->halg.base; ··· 1005 995 1006 996 if (!alg->setkey) 1007 997 alg->setkey = ahash_nosetkey; 998 + 999 + if (!alg->export_core || !alg->import_core) { 1000 + alg->export_core = ahash_default_export_core; 1001 + alg->import_core = ahash_default_import_core; 1002 + base->cra_flags |= CRYPTO_AHASH_ALG_NO_EXPORT_CORE; 1003 + } 1008 1004 1009 1005 return 0; 1010 1006 }
+36 -8
crypto/shash.c
··· 203 203 } 204 204 EXPORT_SYMBOL_GPL(crypto_shash_tfm_digest); 205 205 206 - int crypto_shash_export_core(struct shash_desc *desc, void *out) 206 + static int __crypto_shash_export(struct shash_desc *desc, void *out, 207 + int (*export)(struct shash_desc *desc, 208 + void *out)) 207 209 { 208 - int (*export)(struct shash_desc *desc, void *out); 209 210 struct crypto_shash *tfm = desc->tfm; 210 211 u8 *buf = shash_desc_ctx(desc); 211 212 unsigned int plen, ss; ··· 215 214 ss = crypto_shash_statesize(tfm); 216 215 if (crypto_shash_block_only(tfm)) 217 216 ss -= plen; 218 - export = crypto_shash_alg(tfm)->export; 219 217 if (!export) { 220 218 memcpy(out, buf, ss); 221 219 return 0; 222 220 } 223 221 224 222 return export(desc, out); 223 + } 224 + 225 + int crypto_shash_export_core(struct shash_desc *desc, void *out) 226 + { 227 + return __crypto_shash_export(desc, out, 228 + crypto_shash_alg(desc->tfm)->export_core); 225 229 } 226 230 EXPORT_SYMBOL_GPL(crypto_shash_export_core); 227 231 ··· 242 236 243 237 memcpy(out + ss - plen, buf + descsize - plen, plen); 244 238 } 245 - return crypto_shash_export_core(desc, out); 239 + return __crypto_shash_export(desc, out, crypto_shash_alg(tfm)->export); 246 240 } 247 241 EXPORT_SYMBOL_GPL(crypto_shash_export); 248 242 249 - int crypto_shash_import_core(struct shash_desc *desc, const void *in) 243 + static int __crypto_shash_import(struct shash_desc *desc, const void *in, 244 + int (*import)(struct shash_desc *desc, 245 + const void *in)) 250 246 { 251 - int (*import)(struct shash_desc *desc, const void *in); 252 247 struct crypto_shash *tfm = desc->tfm; 253 248 unsigned int descsize, plen, ss; 254 249 u8 *buf = shash_desc_ctx(desc); ··· 263 256 buf[descsize - 1] = 0; 264 257 if (crypto_shash_block_only(tfm)) 265 258 ss -= plen; 266 - import = crypto_shash_alg(tfm)->import; 267 259 if (!import) { 268 260 memcpy(buf, in, ss); 269 261 return 0; 270 262 } 271 263 272 264 return import(desc, in); 265 + } 266 + 267 + int crypto_shash_import_core(struct shash_desc *desc, const void *in) 268 + { 269 + return __crypto_shash_import(desc, in, 270 + crypto_shash_alg(desc->tfm)->import_core); 273 271 } 274 272 EXPORT_SYMBOL_GPL(crypto_shash_import_core); 275 273 ··· 283 271 struct crypto_shash *tfm = desc->tfm; 284 272 int err; 285 273 286 - err = crypto_shash_import_core(desc, in); 274 + err = __crypto_shash_import(desc, in, crypto_shash_alg(tfm)->import); 287 275 if (crypto_shash_block_only(tfm)) { 288 276 unsigned int plen = crypto_shash_blocksize(tfm) + 1; 289 277 unsigned int descsize = crypto_shash_descsize(tfm); ··· 448 436 return 0; 449 437 } 450 438 439 + static int shash_default_export_core(struct shash_desc *desc, void *out) 440 + { 441 + return -ENOSYS; 442 + } 443 + 444 + static int shash_default_import_core(struct shash_desc *desc, const void *in) 445 + { 446 + return -ENOSYS; 447 + } 448 + 451 449 static int shash_prepare_alg(struct shash_alg *alg) 452 450 { 453 451 struct crypto_alg *base = &alg->halg.base; ··· 498 476 BUILD_BUG_ON(MAX_ALGAPI_BLOCKSIZE >= 256); 499 477 alg->descsize += base->cra_blocksize + 1; 500 478 alg->statesize += base->cra_blocksize + 1; 479 + alg->export_core = alg->export; 480 + alg->import_core = alg->import; 481 + } else if (!alg->export_core || !alg->import_core) { 482 + alg->export_core = shash_default_export_core; 483 + alg->import_core = shash_default_import_core; 484 + base->cra_flags |= CRYPTO_AHASH_ALG_NO_EXPORT_CORE; 501 485 } 502 486 503 487 if (alg->descsize > HASH_MAX_DESCSIZE)
+10
include/crypto/hash.h
··· 129 129 * data so the transformation can continue from this point onward. No 130 130 * data processing happens at this point. Driver must not use 131 131 * req->result. 132 + * @export_core: Export partial state without partial block. Only defined 133 + * for algorithms that are not block-only. 134 + * @import_core: Import partial state without partial block. Only defined 135 + * for algorithms that are not block-only. 132 136 * @init_tfm: Initialize the cryptographic transformation object. 133 137 * This function is called only once at the instantiation 134 138 * time, right after the transformation context was ··· 155 151 int (*digest)(struct ahash_request *req); 156 152 int (*export)(struct ahash_request *req, void *out); 157 153 int (*import)(struct ahash_request *req, const void *in); 154 + int (*export_core)(struct ahash_request *req, void *out); 155 + int (*import_core)(struct ahash_request *req, const void *in); 158 156 int (*setkey)(struct crypto_ahash *tfm, const u8 *key, 159 157 unsigned int keylen); 160 158 int (*init_tfm)(struct crypto_ahash *tfm); ··· 206 200 * @digest: see struct ahash_alg 207 201 * @export: see struct ahash_alg 208 202 * @import: see struct ahash_alg 203 + * @export_core: see struct ahash_alg 204 + * @import_core: see struct ahash_alg 209 205 * @setkey: see struct ahash_alg 210 206 * @init_tfm: Initialize the cryptographic transformation object. 211 207 * This function is called only once at the instantiation ··· 238 230 unsigned int len, u8 *out); 239 231 int (*export)(struct shash_desc *desc, void *out); 240 232 int (*import)(struct shash_desc *desc, const void *in); 233 + int (*export_core)(struct shash_desc *desc, void *out); 234 + int (*import_core)(struct shash_desc *desc, const void *in); 241 235 int (*setkey)(struct crypto_shash *tfm, const u8 *key, 242 236 unsigned int keylen); 243 237 int (*init_tfm)(struct crypto_shash *tfm);
+3
include/crypto/internal/hash.h
··· 20 20 /* Set this bit if finup can deal with multiple blocks. */ 21 21 #define CRYPTO_AHASH_ALG_FINUP_MAX 0x04000000 22 22 23 + /* This bit is set by the Crypto API if export_core is not supported. */ 24 + #define CRYPTO_AHASH_ALG_NO_EXPORT_CORE 0x08000000 25 + 23 26 #define HASH_FBREQ_ON_STACK(name, req) \ 24 27 char __##name##_req[sizeof(struct ahash_request) + \ 25 28 MAX_SYNC_HASH_REQSIZE] CRYPTO_MINALIGN_ATTR; \