]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/crypto: sha3: Support arch overrides of one-shot digest functions
authorEric Biggers <ebiggers@kernel.org>
Sun, 26 Oct 2025 05:50:28 +0000 (22:50 -0700)
committerEric Biggers <ebiggers@kernel.org>
Thu, 6 Nov 2025 04:02:35 +0000 (20:02 -0800)
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>
lib/crypto/sha3.c

index 8434f9bff13858346ea89563a604e7945abb97ea..32b7074de7927136593c312a541661a14e93786e 100644 (file)
@@ -280,10 +280,41 @@ void shake_squeeze(struct shake_ctx *shake_ctx, u8 *out, size_t out_len)
 }
 EXPORT_SYMBOL_GPL(shake_squeeze);
 
+#ifndef sha3_224_arch
+static inline bool sha3_224_arch(const u8 *in, size_t in_len,
+                                u8 out[SHA3_224_DIGEST_SIZE])
+{
+       return false;
+}
+#endif
+#ifndef sha3_256_arch
+static inline bool sha3_256_arch(const u8 *in, size_t in_len,
+                                u8 out[SHA3_256_DIGEST_SIZE])
+{
+       return false;
+}
+#endif
+#ifndef sha3_384_arch
+static inline bool sha3_384_arch(const u8 *in, size_t in_len,
+                                u8 out[SHA3_384_DIGEST_SIZE])
+{
+       return false;
+}
+#endif
+#ifndef sha3_512_arch
+static inline bool sha3_512_arch(const u8 *in, size_t in_len,
+                                u8 out[SHA3_512_DIGEST_SIZE])
+{
+       return false;
+}
+#endif
+
 void sha3_224(const u8 *in, size_t in_len, u8 out[SHA3_224_DIGEST_SIZE])
 {
        struct sha3_ctx ctx;
 
+       if (sha3_224_arch(in, in_len, out))
+               return;
        sha3_224_init(&ctx);
        sha3_update(&ctx, in, in_len);
        sha3_final(&ctx, out);
@@ -294,6 +325,8 @@ void sha3_256(const u8 *in, size_t in_len, u8 out[SHA3_256_DIGEST_SIZE])
 {
        struct sha3_ctx ctx;
 
+       if (sha3_256_arch(in, in_len, out))
+               return;
        sha3_256_init(&ctx);
        sha3_update(&ctx, in, in_len);
        sha3_final(&ctx, out);
@@ -304,6 +337,8 @@ void sha3_384(const u8 *in, size_t in_len, u8 out[SHA3_384_DIGEST_SIZE])
 {
        struct sha3_ctx ctx;
 
+       if (sha3_384_arch(in, in_len, out))
+               return;
        sha3_384_init(&ctx);
        sha3_update(&ctx, in, in_len);
        sha3_final(&ctx, out);
@@ -314,6 +349,8 @@ void sha3_512(const u8 *in, size_t in_len, u8 out[SHA3_512_DIGEST_SIZE])
 {
        struct sha3_ctx ctx;
 
+       if (sha3_512_arch(in, in_len, out))
+               return;
        sha3_512_init(&ctx);
        sha3_update(&ctx, in, in_len);
        sha3_final(&ctx, out);