]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
S390X: Accelerate keccak XOF
authorJuergen Christ <jchrist@linux.ibm.com>
Fri, 3 Mar 2023 13:36:08 +0000 (14:36 +0100)
committerTomas Mraz <tomas@openssl.org>
Tue, 7 Mar 2023 17:21:51 +0000 (18:21 +0100)
The keccak XOF used for KMAC can be simplified by using klmd.  This speeds up
XOF processing in cases where more than one result block is needed.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20431)

crypto/s390x_arch.h
providers/implementations/digests/sha3_prov.c

index cfb3460d5bafdfbfe221a8fcca48afb557aeba3d..3f7dac2e7424c6a7425ed2dc691a743ad0e73317 100644 (file)
@@ -182,5 +182,6 @@ extern int OPENSSL_s390xcex;
 # define S390X_KMA_LAAD         0x200
 # define S390X_KMA_HS           0x400
 # define S390X_KDSA_D           0x80
+# define S390X_KLMD_PS          0x100
 
 #endif
index 33dc6660bf6741c9487e531ac86b148e9106e3ff..825d3249fabd0228d651e5fe7e68faf1419dd21b 100644 (file)
@@ -183,7 +183,6 @@ static int s390x_keccakc_final(unsigned char *md, void *vctx, int padding)
     size_t bsz = ctx->block_size;
     size_t num = ctx->bufsz;
     size_t needed = ctx->md_size;
-    static const unsigned char empty[KECCAK1600_WIDTH / 8] = {0};
 
     if (!ossl_prov_is_running())
         return 0;
@@ -193,13 +192,11 @@ static int s390x_keccakc_final(unsigned char *md, void *vctx, int padding)
     ctx->buf[num] = padding;
     ctx->buf[bsz - 1] |= 0x80;
     s390x_kimd(ctx->buf, bsz, ctx->pad, ctx->A);
-    while (needed > bsz) {
-        memcpy(md, ctx->A, bsz);
-        needed -= bsz;
-        md += bsz;
-        s390x_kimd(empty, bsz, ctx->pad, ctx->A);
-    }
-    memcpy(md, ctx->A, needed);
+    num = needed > bsz ? bsz : needed;
+    memcpy(md, ctx->A, num);
+    needed -= num;
+    if (needed > 0)
+        s390x_klmd(NULL, 0, md + bsz, needed, ctx->pad | S390X_KLMD_PS, ctx->A);
 
     return 1;
 }