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.
This commit is contained in:
Damien Miller 2024-09-09 16:06:21 +10:00
parent d469d5f348
commit 7c07bec144
No known key found for this signature in database
5 changed files with 25 additions and 1 deletions

View File

@ -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>]],

View File

@ -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 */

View File

@ -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},
};

View File

@ -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 */

View File

@ -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@openssh.com");
# endif /* USE_SNTRUP761X25519 */
#endif /* WITH_OPENSSL */