[openssh-commits] [openssh] 02/02: test for compiler feature needed for ML-KEM

git+noreply at mindrot.org git+noreply at mindrot.org
Mon Sep 9 16:08:27 AEST 2024


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 7c07bec1446978bebe0780ed822c8fedfb377ae8
Author: Damien Miller <djm at mindrot.org>
AuthorDate: Mon Sep 9 16:06:21 2024 +1000

    test for compiler feature needed for ML-KEM
    
    The ML-KEM implementation we uses need the compiler to support
    C99-style named struct initialisers (e.g foo = {.bar = 1}). We
    still support (barely) building OpenSSH with older compilers, so
    add a configure test for this.
---
 configure.ac                     | 13 +++++++++++++
 defines.h                        |  4 ++++
 kex-names.c                      |  2 ++
 kexmlkem768x25519.c              |  3 +++
 regress/unittests/kex/test_kex.c |  4 +++-
 5 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 591d5a38..9b8b1ded 100644
--- a/configure.ac
+++ b/configure.ac
@@ -353,6 +353,19 @@ AC_COMPILE_IFELSE(
     [ AC_MSG_RESULT([no]) ]
 )
 
+AC_MSG_CHECKING([if compiler supports named struct initialisers])
+AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[#include <stdlib.h>]],
+    [[	struct foo { int bar; int baz; };
+	struct foo blerg = {.bar = 1, .baz = 2};
+	exit((blerg.bar == 1 && blerg.baz == 2) ? 0 : 1);
+    ]])],
+    [ AC_MSG_RESULT([yes])
+      AC_DEFINE(NAMED_STRUCT_INITIALISERS, [1],
+	 [compiler supports named struct initializers]) ],
+    [ AC_MSG_RESULT([no]) ]
+)
+
 AC_MSG_CHECKING([if compiler accepts variable declarations after code])
 AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM([[#include <stdlib.h>]],
diff --git a/defines.h b/defines.h
index 279e509a..d1f6ce33 100644
--- a/defines.h
+++ b/defines.h
@@ -942,4 +942,8 @@ struct winsize {
 #if defined(VARIABLE_LENGTH_ARRAYS) && defined(VARIABLE_DECLARATION_AFTER_CODE)
 # define USE_SNTRUP761X25519 1
 #endif
+/* The ML-KEM768 imlementation similarly uses named struct initialisers */
+#ifdef NAMED_STRUCT_INITIALISERS
+# define USE_MLKEM768X25519	1
+#endif
 #endif /* _DEFINES_H */
diff --git a/kex-names.c b/kex-names.c
index e5d513d5..ec840c1f 100644
--- a/kex-names.c
+++ b/kex-names.c
@@ -82,8 +82,10 @@ static const struct kexalg kexalgs[] = {
 	{ KEX_SNTRUP761X25519_SHA512_OLD, KEX_KEM_SNTRUP761X25519_SHA512, 0,
 	    SSH_DIGEST_SHA512 },
 #endif
+#ifdef USE_MLKEM768X25519
 	{ KEX_MLKEM768X25519_SHA256, KEX_KEM_MLKEM768X25519_SHA256, 0,
 	    SSH_DIGEST_SHA256 },
+#endif
 #endif /* HAVE_EVP_SHA256 || !WITH_OPENSSL */
 	{ NULL, 0, -1, -1},
 };
diff --git a/kexmlkem768x25519.c b/kexmlkem768x25519.c
index 1339fcf5..fa062dd7 100644
--- a/kexmlkem768x25519.c
+++ b/kexmlkem768x25519.c
@@ -25,6 +25,8 @@
 
 #include "includes.h"
 
+#ifdef USE_MLKEM768X25519
+
 #include <sys/types.h>
 
 #include <stdio.h>
@@ -252,3 +254,4 @@ kex_kem_mlkem768x25519_dec(struct kex *kex,
 	sshbuf_free(buf);
 	return r;
 }
+#endif /* USE_MLKEM768X25519 */
diff --git a/regress/unittests/kex/test_kex.c b/regress/unittests/kex/test_kex.c
index 9476ce68..caf8f57f 100644
--- a/regress/unittests/kex/test_kex.c
+++ b/regress/unittests/kex/test_kex.c
@@ -208,8 +208,10 @@ kex_tests(void)
 	do_kex("diffie-hellman-group-exchange-sha1");
 	do_kex("diffie-hellman-group14-sha1");
 	do_kex("diffie-hellman-group1-sha1");
-# ifdef USE_SNTRUP761X25519
+# ifdef USE_MLKEM768X25519
 	do_kex("mlkem768x25519-sha256");
+# endif /* USE_MLKEM768X25519 */
+# ifdef USE_SNTRUP761X25519
 	do_kex("sntrup761x25519-sha512 at openssh.com");
 # endif /* USE_SNTRUP761X25519 */
 #endif /* WITH_OPENSSL */

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list