From 6dd9303729b430af3eaf1014af5af99c9230e9c7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 30 Jun 2018 14:23:05 +0200 Subject: chachapoly: Use a function instead of an extern variable Signed-off-by: Andreas Schneider --- include/libssh/crypto.h | 2 ++ src/chachapoly.c | 5 +++++ src/libcrypto.c | 3 +-- src/libgcrypt.c | 4 +--- src/libmbedcrypto.c | 4 +--- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/libssh/crypto.h b/include/libssh/crypto.h index d85b74da..490910fa 100644 --- a/include/libssh/crypto.h +++ b/include/libssh/crypto.h @@ -161,4 +161,6 @@ struct ssh_cipher_struct { void (*cleanup)(struct ssh_cipher_struct *cipher); }; +const struct ssh_cipher_struct *ssh_get_chacha20poly1305_cipher(void); + #endif /* _CRYPTO_H_ */ diff --git a/src/chachapoly.c b/src/chachapoly.c index ab4378e6..904303ef 100644 --- a/src/chachapoly.c +++ b/src/chachapoly.c @@ -205,3 +205,8 @@ const struct ssh_cipher_struct chacha20poly1305_cipher = { .aead_decrypt = chacha20_poly1305_aead_decrypt, .cleanup = chacha20_cleanup }; + +const struct ssh_cipher_struct *ssh_get_chacha20poly1305_cipher(void) +{ + return &chacha20poly1305_cipher; +} diff --git a/src/libcrypto.c b/src/libcrypto.c index 186d6105..0e30727f 100644 --- a/src/libcrypto.c +++ b/src/libcrypto.c @@ -60,7 +60,6 @@ #include "libssh/crypto.h" -extern const struct ssh_cipher_struct chacha20poly1305_cipher; struct ssh_mac_ctx_struct { enum ssh_mac_e mac_type; union { @@ -764,7 +763,7 @@ void libcrypto_init(void) cmp = strcmp(ssh_ciphertab[i].name, "chacha20-poly1305@openssh.com"); if (cmp == 0) { memcpy(&ssh_ciphertab[i], - &chacha20poly1305_cipher, + ssh_get_chacha20poly1305_cipher(), sizeof(struct ssh_cipher_struct)); break; } diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 6bf4f8a0..4b84cd40 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -35,8 +35,6 @@ #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; @@ -544,7 +542,7 @@ void libgcrypt_init(void) cmp = strcmp(ssh_ciphertab[i].name, "chacha20-poly1305@openssh.com"); if (cmp == 0) { memcpy(&ssh_ciphertab[i], - &chacha20poly1305_cipher, + ssh_get_chacha20poly1305_cipher(), sizeof(struct ssh_cipher_struct)); break; } diff --git a/src/libmbedcrypto.c b/src/libmbedcrypto.c index 7e77c026..aa183f18 100644 --- a/src/libmbedcrypto.c +++ b/src/libmbedcrypto.c @@ -30,8 +30,6 @@ #ifdef HAVE_LIBMBEDCRYPTO #include -extern const struct ssh_cipher_struct chacha20poly1305_cipher; - struct ssh_mac_ctx_struct { enum ssh_mac_e mac_type; mbedtls_md_context_t ctx; @@ -964,7 +962,7 @@ void ssh_mbedtls_init(void) cmp = strcmp(ssh_ciphertab[i].name, "chacha20-poly1305@openssh.com"); if (cmp == 0) { memcpy(&ssh_ciphertab[i], - &chacha20poly1305_cipher, + ssh_get_chacha20poly1305_cipher(), sizeof(struct ssh_cipher_struct)); break; } -- cgit v1.2.3