mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 12:20:42 +09:00
kex: Add sntrup761x25519-sha512@openssh.com.
All of the initial work was done by Simon. Jakub cleaned up the formatting issues, resolved the padding of bignum to match specs and be interoperable with OpenSSH (and few more minor details). Closes: #194. Signed-off-by: Simon Josefsson <simon@josefsson.org> Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
3468cc0dc5
commit
4becc8eb82
@@ -135,6 +135,7 @@ if (SSH_EXECUTABLE)
|
||||
diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 diffie-hellman-group14-sha256
|
||||
diffie-hellman-group16-sha512 diffie-hellman-group18-sha512 diffie-hellman-group-exchange-sha1
|
||||
diffie-hellman-group-exchange-sha256 ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521
|
||||
sntrup761x25519-sha512@openssh.com
|
||||
curve25519-sha256 curve25519-sha256@libssh.org
|
||||
ssh-ed25519 ssh-ed25519-cert-v01@openssh.com ssh-rsa
|
||||
ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521
|
||||
|
||||
@@ -718,6 +718,23 @@ static void torture_algorithms_ecdh_curve25519_sha256_libssh_org(void **state) {
|
||||
}
|
||||
#endif /* OPENSSH_CURVE25519_SHA256_LIBSSH_ORG */
|
||||
|
||||
#ifdef OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM
|
||||
static void
|
||||
torture_algorithms_ecdh_sntrup761x25519_sha512_openssh_com(void **state)
|
||||
{
|
||||
struct torture_state *s = *state;
|
||||
|
||||
if (ssh_fips_mode()) {
|
||||
skip();
|
||||
}
|
||||
|
||||
test_algorithm(s->ssh.session,
|
||||
"sntrup761x25519-sha512@openssh.com",
|
||||
NULL /*cipher*/,
|
||||
NULL /*hmac*/);
|
||||
}
|
||||
#endif /* OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM */
|
||||
|
||||
static void torture_algorithms_dh_group1(void **state) {
|
||||
struct torture_state *s = *state;
|
||||
|
||||
@@ -985,6 +1002,11 @@ int torture_run_tests(void) {
|
||||
session_setup,
|
||||
session_teardown),
|
||||
#endif /* OPENSSH_CURVE25519_SHA256_LIBSSH_ORG */
|
||||
#ifdef OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM
|
||||
cmocka_unit_test_setup_teardown(torture_algorithms_ecdh_sntrup761x25519_sha512_openssh_com,
|
||||
session_setup,
|
||||
session_teardown),
|
||||
#endif /* OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM */
|
||||
#if defined(HAVE_ECC)
|
||||
cmocka_unit_test_setup_teardown(torture_algorithms_ecdh_sha2_nistp256,
|
||||
session_setup,
|
||||
|
||||
@@ -255,6 +255,37 @@ static void torture_override_ecdh_curve25519_sha256_libssh_org(void **state)
|
||||
}
|
||||
#endif /* OPENSSH_CURVE25519_SHA256_LIBSSH_ORG */
|
||||
|
||||
#ifdef OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM
|
||||
static void
|
||||
torture_override_ecdh_sntrup761x25519_sha512_openssh_com(void **state)
|
||||
{
|
||||
struct torture_state *s = *state;
|
||||
bool internal_curve25519_called;
|
||||
|
||||
if (ssh_fips_mode()) {
|
||||
skip();
|
||||
}
|
||||
|
||||
test_algorithm(s->ssh.session,
|
||||
"sntrup761x25519-sha512@openssh.com",
|
||||
NULL, /* cipher */
|
||||
NULL /* hostkey */);
|
||||
|
||||
internal_curve25519_called = internal_curve25519_function_called();
|
||||
|
||||
/* TODO: when non-internal sntrup761 is supported, this is a good
|
||||
place to add override checks of the sntrup761-related functions
|
||||
too. Currently none of our external crypto libraries supports
|
||||
sntrup761. */
|
||||
|
||||
#if SHOULD_CALL_INTERNAL_CURVE25519
|
||||
assert_true(internal_curve25519_called);
|
||||
#else
|
||||
assert_false(internal_curve25519_called);
|
||||
#endif
|
||||
}
|
||||
#endif /* OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM */
|
||||
|
||||
#ifdef OPENSSH_SSH_ED25519
|
||||
static void torture_override_ed25519(void **state)
|
||||
{
|
||||
@@ -299,6 +330,11 @@ int torture_run_tests(void)
|
||||
session_setup,
|
||||
session_teardown),
|
||||
#endif /* OPENSSH_CURVE25519_SHA256_LIBSSH_ORG */
|
||||
#ifdef OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM
|
||||
cmocka_unit_test_setup_teardown(torture_override_ecdh_sntrup761x25519_sha512_openssh_com,
|
||||
session_setup,
|
||||
session_teardown),
|
||||
#endif /* OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM */
|
||||
#ifdef OPENSSH_SSH_ED25519
|
||||
cmocka_unit_test_setup_teardown(torture_override_ed25519,
|
||||
session_setup,
|
||||
|
||||
@@ -280,8 +280,19 @@ static int torture_pkd_setup_ecdsa_521(void **state) {
|
||||
f(client, ecdsa_521_diffie_hellman_group18_sha512,kexcmd("diffie-hellman-group18-sha512"), setup_ecdsa_521, teardown)
|
||||
#endif
|
||||
|
||||
#ifdef OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM
|
||||
#define PKDTESTS_KEX_SNTRUP761(f, client, kexcmd) \
|
||||
f(client, rsa_sntrup761x25519_sha512_openssh_com, kexcmd("sntrup761x25519-sha512@openssh.com"), setup_rsa, teardown) \
|
||||
f(client, ecdsa_256_sntrup761x25519_sha512_openssh_com, kexcmd("sntrup761x25519-sha512@openssh.com"), setup_ecdsa_256, teardown) \
|
||||
f(client, ecdsa_384_sntrup761x25519_sha512_openssh_com, kexcmd("sntrup761x25519-sha512@openssh.com"), setup_ecdsa_384, teardown) \
|
||||
f(client, ecdsa_521_sntrup761x25519_sha512_openssh_com, kexcmd("sntrup761x25519-sha512@openssh.com"), setup_ecdsa_521, teardown)
|
||||
#else
|
||||
#define PKDTESTS_KEX_SNTRUP761(f, client, kexcmd)
|
||||
#endif
|
||||
|
||||
#define PKDTESTS_KEX_COMMON(f, client, kexcmd) \
|
||||
PKDTESTS_KEX_FIPS(f, client, kexcmd) \
|
||||
PKDTESTS_KEX_SNTRUP761(f, client, kexcmd) \
|
||||
f(client, rsa_curve25519_sha256, kexcmd("curve25519-sha256"), setup_rsa, teardown) \
|
||||
f(client, rsa_curve25519_sha256_libssh_org, kexcmd("curve25519-sha256@libssh.org"), setup_rsa, teardown) \
|
||||
f(client, rsa_diffie_hellman_group14_sha1, kexcmd("diffie-hellman-group14-sha1"), setup_rsa, teardown) \
|
||||
@@ -314,8 +325,16 @@ static int torture_pkd_setup_ecdsa_521(void **state) {
|
||||
PKDTESTS_KEX_COMMON(f, client, kexcmd)
|
||||
#endif
|
||||
|
||||
#ifdef OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM
|
||||
#define PKDTESTS_KEX_OPENSSHONLY_SNTRUP761(f, client, kexcmd) \
|
||||
f(client, ed25519_sntrup761x25519_sha512_openssh_com, kexcmd("sntrup761x25519-sha512@openssh.com"), setup_ed25519, teardown)
|
||||
#else
|
||||
#define PKDTESTS_KEX_OPENSSHONLY_SNTRUP761(f, client, kexcmd)
|
||||
#endif
|
||||
|
||||
#define PKDTESTS_KEX_OPENSSHONLY(f, client, kexcmd) \
|
||||
/* Kex algorithms. */ \
|
||||
PKDTESTS_KEX_OPENSSHONLY_SNTRUP761(f, client, kexcmd) \
|
||||
f(client, ed25519_curve25519_sha256, kexcmd("curve25519-sha256"), setup_ed25519, teardown) \
|
||||
f(client, ed25519_curve25519_sha256_libssh_org, kexcmd("curve25519-sha256@libssh.org"), setup_ed25519, teardown) \
|
||||
f(client, ed25519_ecdh_sha2_nistp256, kexcmd("ecdh-sha2-nistp256"), setup_ed25519, teardown) \
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#cmakedefine OPENSSH_ECDH_SHA2_NISTP521 1
|
||||
#cmakedefine OPENSSH_CURVE25519_SHA256 1
|
||||
#cmakedefine OPENSSH_CURVE25519_SHA256_LIBSSH_ORG 1
|
||||
#cmakedefine OPENSSH_SNTRUP761X25519_SHA512_OPENSSH_COM 1
|
||||
#cmakedefine OPENSSH_SSH_ED25519 1
|
||||
#cmakedefine OPENSSH_SSH_ED25519_CERT_V01_OPENSSH_COM 1
|
||||
#cmakedefine OPENSSH_SSH_RSA 1
|
||||
|
||||
@@ -216,6 +216,7 @@ static void torture_options_set_key_exchange(void **state)
|
||||
/* Test known kexes */
|
||||
rc = ssh_options_set(session,
|
||||
SSH_OPTIONS_KEY_EXCHANGE,
|
||||
"sntrup761x25519-sha512@openssh.com,"
|
||||
"curve25519-sha256,curve25519-sha256@libssh.org,"
|
||||
"ecdh-sha2-nistp256,diffie-hellman-group16-sha512,"
|
||||
"diffie-hellman-group18-sha512,"
|
||||
@@ -230,6 +231,7 @@ static void torture_options_set_key_exchange(void **state)
|
||||
"diffie-hellman-group14-sha256");
|
||||
} else {
|
||||
assert_string_equal(session->opts.wanted_methods[SSH_KEX],
|
||||
"sntrup761x25519-sha512@openssh.com,"
|
||||
"curve25519-sha256,curve25519-sha256@libssh.org,"
|
||||
"ecdh-sha2-nistp256,diffie-hellman-group16-sha512,"
|
||||
"diffie-hellman-group18-sha512,"
|
||||
@@ -278,6 +280,7 @@ static void torture_options_get_key_exchange(void **state)
|
||||
} else {
|
||||
assert_string_equal(value,
|
||||
"curve25519-sha256,curve25519-sha256@libssh.org,"
|
||||
"sntrup761x25519-sha512@openssh.com,"
|
||||
"ecdh-sha2-nistp256,ecdh-sha2-nistp384,"
|
||||
"ecdh-sha2-nistp521,diffie-hellman-group18-sha512,"
|
||||
"diffie-hellman-group16-sha512,"
|
||||
@@ -1312,7 +1315,7 @@ static void torture_options_copy(void **state)
|
||||
"BindAddress 127.0.0.2\n"
|
||||
"GlobalKnownHostsFile /etc/ssh/known_hosts2\n"
|
||||
"UserKnownHostsFile ~/.ssh/known_hosts2\n"
|
||||
"KexAlgorithms curve25519-sha256,ecdh-sha2-nistp521\n"
|
||||
"KexAlgorithms curve25519-sha256,sntrup761x25519-sha512@openssh.com,ecdh-sha2-nistp521\n"
|
||||
"Ciphers aes256-ctr\n"
|
||||
"MACs hmac-sha2-256\n"
|
||||
"HostKeyAlgorithms ssh-ed25519,ecdsa-sha2-nistp521\n"
|
||||
|
||||
Reference in New Issue
Block a user