From 238202d38032762c2fec641a90712eaf0ff7bfae Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Wed, 28 Feb 2018 10:24:55 -0600 Subject: libgcrypt: make it compatible with chacha20 Signed-off-by: Aris Adamantiadis Reviewed-by: Andreas Schneider --- include/libssh/libgcrypt.h | 1 + src/dh.c | 1 + src/libgcrypt.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/include/libssh/libgcrypt.h b/include/libssh/libgcrypt.h index ec353910..307920d3 100644 --- a/include/libssh/libgcrypt.h +++ b/include/libssh/libgcrypt.h @@ -88,6 +88,7 @@ ssh_string ssh_sexp_extract_mpi(const gcry_sexp_t sexp, #endif /* HAVE_LIBGCRYPT */ +void libgcrypt_init(void); struct ssh_cipher_struct *ssh_get_ciphertab(void); #endif /* LIBGCRYPT_H_ */ diff --git a/src/dh.c b/src/dh.c index 02935795..f485617b 100644 --- a/src/dh.c +++ b/src/dh.c @@ -190,6 +190,7 @@ int ssh_crypto_init(void) { p_group1 = NULL; return -1; } + libgcrypt_init(); #elif defined HAVE_LIBCRYPTO p_group1 = bignum_new(); diff --git a/src/libgcrypt.c b/src/libgcrypt.c index d9dd5be6..b695b6bb 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -35,6 +35,8 @@ #ifdef HAVE_LIBGCRYPT #include +extern const struct ssh_cipher_struct chacha20poly1305_cipher; + struct ssh_mac_ctx_struct { enum ssh_mac_e mac_type; gcry_md_hd_t ctx; @@ -637,6 +639,9 @@ static struct ssh_cipher_struct ssh_ciphertab[] = { .encrypt = des1_1_encrypt, .decrypt = des1_1_decrypt }, + { + .name = "chacha20-poly1305@openssh.com" + }, { .name = NULL, .blocksize = 0, @@ -650,6 +655,22 @@ static struct ssh_cipher_struct ssh_ciphertab[] = { } }; +void libgcrypt_init(void) +{ + size_t i; + + for (i = 0; ssh_ciphertab[i].name != NULL; i++) { + int cmp; + cmp = strcmp(ssh_ciphertab[i].name, "chacha20-poly1305@openssh.com"); + if (cmp == 0) { + memcpy(&ssh_ciphertab[i], + &chacha20poly1305_cipher, + sizeof(struct ssh_cipher_struct)); + break; + } + } +} + struct ssh_cipher_struct *ssh_get_ciphertab(void) { return ssh_ciphertab; -- cgit v1.2.3