[PATCH 3/3] sm4: add missing OCB 16-way GFNI-AVX512 path

Jussi Kivilinna jussi.kivilinna at iki.fi
Wed Jan 4 18:53:05 CET 2023


* cipher/sm4.c (_gcry_sm4_ocb_crypt) [USE_GFNI_AVX512]: Add 16-way
GFNI-AVX512 handling.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/sm4.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/cipher/sm4.c b/cipher/sm4.c
index 0e89be78..b0402b64 100644
--- a/cipher/sm4.c
+++ b/cipher/sm4.c
@@ -1663,6 +1663,26 @@ _gcry_sm4_ocb_crypt (gcry_cipher_hd_t c, void *outbuf_arg,
 	      inbuf += 32 * 16;
 	    }
 	}
+
+      if (nblocks >= 16)
+	{
+          l = bulk_ocb_prepare_L_pointers_array_blk16 (c, Ls, blkn);
+
+	  /* Process data in 16 block chunks. */
+	  blkn += 16;
+	  *l = (uintptr_t)(void *)ocb_get_l(c, blkn - blkn % 16);
+
+	  if (encrypt)
+	    _gcry_sm4_gfni_avx512_ocb_enc(ctx->rkey_enc, outbuf, inbuf,
+					  c->u_iv.iv, c->u_ctr.ctr, Ls);
+	  else
+	    _gcry_sm4_gfni_avx512_ocb_dec(ctx->rkey_dec, outbuf, inbuf,
+					  c->u_iv.iv, c->u_ctr.ctr, Ls);
+
+	  nblocks -= 16;
+	  outbuf += 16 * 16;
+	  inbuf += 16 * 16;
+	}
     }
 #endif
 
-- 
2.37.2




More information about the Gcrypt-devel mailing list