[PATCH 5/5] dilithium-kyber: Added ppc64le dilithium and kyber (i)NTT support.

Danny Tsen dtsen at us.ibm.com
Tue Feb 24 01:27:53 CET 2026


Updated the following files to ENABLE_PPC_DILITHIUM and
ENABLE_PPC_KYBER, dilithium-common.c, kyber-common.c and
configure.ac

Signed-off-by: Danny Tsen <dtsen at us.ibm.com>
---
 cipher/dilithium-common.c | 13 +++++++++++++
 cipher/kyber-common.c     | 13 +++++++++++++
 configure.ac              | 20 ++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/cipher/dilithium-common.c b/cipher/dilithium-common.c
index d16f22f7..0f3d2d96 100644
--- a/cipher/dilithium-common.c
+++ b/cipher/dilithium-common.c
@@ -50,6 +50,18 @@ static void invntt_tomont(int32_t a[N]);
 
 /*************** dilithium/ref/ntt.c */
 
+#ifdef ENABLE_PPC_DILITHIUM
+extern void mldsa_ntt_ppc(int32_t a[N]);
+extern void mldsa_intt_ppc(int32_t a[N]);
+
+void ntt(int32_t a[N]) {
+  mldsa_ntt_ppc(a);
+}
+
+void invntt_tomont(int32_t a[N]) {
+  mldsa_intt_ppc(a);
+}
+#else
 static const int32_t zetas[N] = {
          0,    25847, -2608894,  -518909,   237124,  -777960,  -876248,   466468,
    1826347,  2353451,  -359251, -2091905,  3119733, -2884855,  3111497,  2680103,
@@ -143,6 +155,7 @@ void invntt_tomont(int32_t a[N]) {
     a[j] = montgomery_reduce((int64_t)f * a[j]);
   }
 }
+#endif
 /*************** dilithium/ref/rounding.h */
 #if !defined(DILITHIUM_MODE) || DILITHIUM_MODE == 2
 static int32_t decompose_88(int32_t *a0, int32_t a);
diff --git a/cipher/kyber-common.c b/cipher/kyber-common.c
index 54377788..278d0b0b 100644
--- a/cipher/kyber-common.c
+++ b/cipher/kyber-common.c
@@ -273,6 +273,18 @@ static int16_t fqmul(int16_t a, int16_t b) {
   return montgomery_reduce((int32_t)a*b);
 }
 
+#ifdef ENABLE_PPC_KYBER
+extern void ntt_ppc(int16_t r[256]);
+extern void intt_ppc(int16_t r[256]);
+
+void ntt(int16_t r[256]) {
+    ntt_ppc(r);
+}
+
+void invntt(int16_t r[256]) {
+    intt_ppc(r);
+}
+#else
 /*************************************************
 * Name:        ntt
 *
@@ -328,6 +340,7 @@ void invntt(int16_t r[256]) {
   for(j = 0; j < 256; j++)
     r[j] = fqmul(r[j], f);
 }
+#endif
 
 /*************************************************
 * Name:        basemul
diff --git a/configure.ac b/configure.ac
index 00572b45..49a094fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3828,6 +3828,16 @@ if test "$found" = "1" ; then
    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS \
                           kyber.lo"
    AC_DEFINE(USE_KYBER, 1, [Defined if this module should be included])
+
+   case "${host}" in
+      powerpc64le-*-*)
+         if test "$gcry_cv_gcc_inline_asm_ppc_altivec" = "yes" ; then
+             AC_DEFINE(ENABLE_PPC_KYBER, 1, [Enable support for PPC optimized kyber.])
+             GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS kyber_ntt_p8le.lo"
+             GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS kyber_intt_p8le.lo"
+         fi
+      ;;
+   esac
 fi
 
 LIST_MEMBER(dilithium, $enabled_pubkey_ciphers)
@@ -3836,6 +3846,16 @@ if test "$found" = "1" ; then
    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS \
                           dilithium.lo pubkey-dilithium.lo"
    AC_DEFINE(USE_DILITHIUM, 1, [Defined if this module should be included])
+
+   case "${host}" in
+      powerpc64le-*-*)
+         if test "$gcry_cv_gcc_inline_asm_ppc_altivec" = "yes" ; then
+             AC_DEFINE(ENABLE_PPC_DILITHIUM, 1, [Enable support for PPC optimized dilithium.])
+             GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dilithium_ntt_p8le.lo"
+             GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dilithium_intt_p8le.lo"
+         fi
+      ;;
+   esac
 fi
 
 LIST_MEMBER(crc, $enabled_digests)
-- 
2.47.3




More information about the Gcrypt-devel mailing list