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

lib/crypto: sha3: Support arch overrides of one-shot digest functions

Add support for architecture-specific overrides of sha3_224(),
sha3_256(), sha3_384(), and sha3_512(). This will be used to implement
these functions more efficiently on s390 than is possible via the usual
init + update + final flow.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Harald Freudenberger <freude@linux.ibm.com>
Link: https://lore.kernel.org/r/20251026055032.1413733-12-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+37
+37
lib/crypto/sha3.c
··· 280 280 } 281 281 EXPORT_SYMBOL_GPL(shake_squeeze); 282 282 283 + #ifndef sha3_224_arch 284 + static inline bool sha3_224_arch(const u8 *in, size_t in_len, 285 + u8 out[SHA3_224_DIGEST_SIZE]) 286 + { 287 + return false; 288 + } 289 + #endif 290 + #ifndef sha3_256_arch 291 + static inline bool sha3_256_arch(const u8 *in, size_t in_len, 292 + u8 out[SHA3_256_DIGEST_SIZE]) 293 + { 294 + return false; 295 + } 296 + #endif 297 + #ifndef sha3_384_arch 298 + static inline bool sha3_384_arch(const u8 *in, size_t in_len, 299 + u8 out[SHA3_384_DIGEST_SIZE]) 300 + { 301 + return false; 302 + } 303 + #endif 304 + #ifndef sha3_512_arch 305 + static inline bool sha3_512_arch(const u8 *in, size_t in_len, 306 + u8 out[SHA3_512_DIGEST_SIZE]) 307 + { 308 + return false; 309 + } 310 + #endif 311 + 283 312 void sha3_224(const u8 *in, size_t in_len, u8 out[SHA3_224_DIGEST_SIZE]) 284 313 { 285 314 struct sha3_ctx ctx; 286 315 316 + if (sha3_224_arch(in, in_len, out)) 317 + return; 287 318 sha3_224_init(&ctx); 288 319 sha3_update(&ctx, in, in_len); 289 320 sha3_final(&ctx, out); ··· 325 294 { 326 295 struct sha3_ctx ctx; 327 296 297 + if (sha3_256_arch(in, in_len, out)) 298 + return; 328 299 sha3_256_init(&ctx); 329 300 sha3_update(&ctx, in, in_len); 330 301 sha3_final(&ctx, out); ··· 337 304 { 338 305 struct sha3_ctx ctx; 339 306 307 + if (sha3_384_arch(in, in_len, out)) 308 + return; 340 309 sha3_384_init(&ctx); 341 310 sha3_update(&ctx, in, in_len); 342 311 sha3_final(&ctx, out); ··· 349 314 { 350 315 struct sha3_ctx ctx; 351 316 317 + if (sha3_512_arch(in, in_len, out)) 318 + return; 352 319 sha3_512_init(&ctx); 353 320 sha3_update(&ctx, in, in_len); 354 321 sha3_final(&ctx, out);