diff --git a/src/crypto.h b/src/crypto.h index 7269c36e..8cf34f5b 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -113,4 +113,6 @@ int _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, const char *privatekey, const char *passphrase); +void _libssh2_init_aes_ctr(void); + #endif diff --git a/src/global.c b/src/global.c index 9f54c353..409e8e85 100644 --- a/src/global.c +++ b/src/global.c @@ -46,6 +46,7 @@ libssh2_init(int flags) { if (_libssh2_initialized == 0 && !(flags & LIBSSH2_INIT_NO_CRYPTO)) { libssh2_crypto_init(); + _libssh2_init_aes_ctr(); } _libssh2_initialized++; diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 8d1dcef0..c3be56c3 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -585,4 +585,8 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, libssh2_error */ } +void _libssh2_init_aes_ctr(void) +{ + /* no implementation */ +} #endif /* LIBSSH2_LIBGCRYPT */ diff --git a/src/openssl.c b/src/openssl.c index 51023e89..5fec5110 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -317,8 +317,6 @@ aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) /* cleanup ctx */ static const EVP_CIPHER * make_ctr_evp (size_t keylen, EVP_CIPHER *aes_ctr_cipher) { - memset(aes_ctr_cipher, 0, sizeof(aes_ctr_cipher)); - aes_ctr_cipher->block_size = 16; aes_ctr_cipher->key_len = keylen; aes_ctr_cipher->iv_len = 16; @@ -333,22 +331,33 @@ const EVP_CIPHER * _libssh2_EVP_aes_128_ctr(void) { static EVP_CIPHER aes_ctr_cipher; - return make_ctr_evp (16, &aes_ctr_cipher); + return !aes_ctr_cipher.key_len? + make_ctr_evp (16, &aes_ctr_cipher) : &aes_ctr_cipher; } const EVP_CIPHER * _libssh2_EVP_aes_192_ctr(void) { static EVP_CIPHER aes_ctr_cipher; - return make_ctr_evp (24, &aes_ctr_cipher); + return !aes_ctr_cipher.key_len? + make_ctr_evp (24, &aes_ctr_cipher) : &aes_ctr_cipher; } const EVP_CIPHER * _libssh2_EVP_aes_256_ctr(void) { static EVP_CIPHER aes_ctr_cipher; - return make_ctr_evp (32, &aes_ctr_cipher); + return !aes_ctr_cipher.key_len? + make_ctr_evp (32, &aes_ctr_cipher) : &aes_ctr_cipher; } + +void _libssh2_init_aes_ctr(void) +{ + _libssh2_EVP_aes_128_ctr(); + _libssh2_EVP_aes_192_ctr(); + _libssh2_EVP_aes_256_ctr(); +} + #endif /* LIBSSH2_AES_CTR */ /* TODO: Optionally call a passphrase callback specified by the