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: sha512 - Implement export_core() and import_core()

Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in
API"), the recently-added export_core() and import_core() methods in
struct shash_alg have effectively become mandatory (even though it is
not tested or enforced), since legacy drivers that need a fallback
depend on them. Make crypto/sha512.c compatible with these legacy
drivers by adding export_core() and import_core() methods to it.

Reported-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reported-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Closes: https://lore.kernel.org/r/aLSnCc9Ws5L9y+8X@gcabiddu-mobl.ger.corp.intel.com
Fixes: 4bc7f7b687a2 ("crypto: sha512 - Use same state format as legacy drivers")
Tested-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Tested-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Link: https://lore.kernel.org/r/20250901165013.48649-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+71
+71
crypto/sha512.c
··· 50 50 return 0; 51 51 } 52 52 53 + static int __crypto_sha512_export_core(const struct __sha512_ctx *ctx, 54 + void *out) 55 + { 56 + memcpy(out, ctx, offsetof(struct __sha512_ctx, buf)); 57 + return 0; 58 + } 59 + 60 + static int __crypto_sha512_import_core(struct __sha512_ctx *ctx, const void *in) 61 + { 62 + memcpy(ctx, in, offsetof(struct __sha512_ctx, buf)); 63 + return 0; 64 + } 65 + 53 66 /* SHA-384 */ 54 67 55 68 const u8 sha384_zero_message_hash[SHA384_DIGEST_SIZE] = { ··· 111 98 static int crypto_sha384_import(struct shash_desc *desc, const void *in) 112 99 { 113 100 return __crypto_sha512_import(&SHA384_CTX(desc)->ctx, in); 101 + } 102 + 103 + static int crypto_sha384_export_core(struct shash_desc *desc, void *out) 104 + { 105 + return __crypto_sha512_export_core(&SHA384_CTX(desc)->ctx, out); 106 + } 107 + 108 + static int crypto_sha384_import_core(struct shash_desc *desc, const void *in) 109 + { 110 + return __crypto_sha512_import_core(&SHA384_CTX(desc)->ctx, in); 114 111 } 115 112 116 113 /* SHA-512 */ ··· 175 152 return __crypto_sha512_import(&SHA512_CTX(desc)->ctx, in); 176 153 } 177 154 155 + static int crypto_sha512_export_core(struct shash_desc *desc, void *out) 156 + { 157 + return __crypto_sha512_export_core(&SHA512_CTX(desc)->ctx, out); 158 + } 159 + 160 + static int crypto_sha512_import_core(struct shash_desc *desc, const void *in) 161 + { 162 + return __crypto_sha512_import_core(&SHA512_CTX(desc)->ctx, in); 163 + } 164 + 178 165 /* HMAC-SHA384 */ 179 166 180 167 #define HMAC_SHA384_KEY(tfm) ((struct hmac_sha384_key *)crypto_shash_ctx(tfm)) ··· 235 202 236 203 ctx->ctx.ostate = HMAC_SHA384_KEY(desc->tfm)->key.ostate; 237 204 return __crypto_sha512_import(&ctx->ctx.sha_ctx, in); 205 + } 206 + 207 + static int crypto_hmac_sha384_export_core(struct shash_desc *desc, void *out) 208 + { 209 + return __crypto_sha512_export_core(&HMAC_SHA384_CTX(desc)->ctx.sha_ctx, 210 + out); 211 + } 212 + 213 + static int crypto_hmac_sha384_import_core(struct shash_desc *desc, 214 + const void *in) 215 + { 216 + struct hmac_sha384_ctx *ctx = HMAC_SHA384_CTX(desc); 217 + 218 + ctx->ctx.ostate = HMAC_SHA384_KEY(desc->tfm)->key.ostate; 219 + return __crypto_sha512_import_core(&ctx->ctx.sha_ctx, in); 238 220 } 239 221 240 222 /* HMAC-SHA512 */ ··· 304 256 return __crypto_sha512_import(&ctx->ctx.sha_ctx, in); 305 257 } 306 258 259 + static int crypto_hmac_sha512_export_core(struct shash_desc *desc, void *out) 260 + { 261 + return __crypto_sha512_export_core(&HMAC_SHA512_CTX(desc)->ctx.sha_ctx, 262 + out); 263 + } 264 + 265 + static int crypto_hmac_sha512_import_core(struct shash_desc *desc, 266 + const void *in) 267 + { 268 + struct hmac_sha512_ctx *ctx = HMAC_SHA512_CTX(desc); 269 + 270 + ctx->ctx.ostate = HMAC_SHA512_KEY(desc->tfm)->key.ostate; 271 + return __crypto_sha512_import_core(&ctx->ctx.sha_ctx, in); 272 + } 273 + 307 274 /* Algorithm definitions */ 308 275 309 276 static struct shash_alg algs[] = { ··· 335 272 .digest = crypto_sha384_digest, 336 273 .export = crypto_sha384_export, 337 274 .import = crypto_sha384_import, 275 + .export_core = crypto_sha384_export_core, 276 + .import_core = crypto_sha384_import_core, 338 277 .descsize = sizeof(struct sha384_ctx), 339 278 .statesize = SHA512_SHASH_STATE_SIZE, 340 279 }, ··· 353 288 .digest = crypto_sha512_digest, 354 289 .export = crypto_sha512_export, 355 290 .import = crypto_sha512_import, 291 + .export_core = crypto_sha512_export_core, 292 + .import_core = crypto_sha512_import_core, 356 293 .descsize = sizeof(struct sha512_ctx), 357 294 .statesize = SHA512_SHASH_STATE_SIZE, 358 295 }, ··· 373 306 .digest = crypto_hmac_sha384_digest, 374 307 .export = crypto_hmac_sha384_export, 375 308 .import = crypto_hmac_sha384_import, 309 + .export_core = crypto_hmac_sha384_export_core, 310 + .import_core = crypto_hmac_sha384_import_core, 376 311 .descsize = sizeof(struct hmac_sha384_ctx), 377 312 .statesize = SHA512_SHASH_STATE_SIZE, 378 313 }, ··· 393 324 .digest = crypto_hmac_sha512_digest, 394 325 .export = crypto_hmac_sha512_export, 395 326 .import = crypto_hmac_sha512_import, 327 + .export_core = crypto_hmac_sha512_export_core, 328 + .import_core = crypto_hmac_sha512_import_core, 396 329 .descsize = sizeof(struct hmac_sha512_ctx), 397 330 .statesize = SHA512_SHASH_STATE_SIZE, 398 331 },