Skip to content

Commit

Permalink
test for compiler feature needed for ML-KEM
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
djmdjm committed Sep 9, 2024
1 parent d469d5f commit 7c07bec
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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>]],
Expand Down
4 changes: 4 additions & 0 deletions defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions kex-names.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
3 changes: 3 additions & 0 deletions kexmlkem768x25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "includes.h"

#ifdef USE_MLKEM768X25519

#include <sys/types.h>

#include <stdio.h>
Expand Down Expand Up @@ -252,3 +254,4 @@ kex_kem_mlkem768x25519_dec(struct kex *kex,
sshbuf_free(buf);
return r;
}
#endif /* USE_MLKEM768X25519 */
4 changes: 3 additions & 1 deletion regress/unittests/kex/test_kex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 7c07bec

Please sign in to comment.