diff options
author | Graham Leggett <minfrin@apache.org> | 2020-03-14 10:27:40 +0000 |
---|---|---|
committer | Graham Leggett <minfrin@apache.org> | 2020-03-14 10:27:40 +0000 |
commit | 0d3396ba10cc9f417c81ef539a6d8a4251812aae (patch) | |
tree | 93d4719354c1bc87a16e0c9d2f100e34ade4d7a1 /crypto | |
parent | 4ee00fc9638278554b3791c379ce66f2bc709346 (diff) | |
download | apr-0d3396ba10cc9f417c81ef539a6d8a4251812aae.tar.gz |
Support both NID_chacha20 and NID_aes_256_ctr, not one or the other.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1875184 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/apr_crypto_openssl.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/crypto/apr_crypto_openssl.c b/crypto/apr_crypto_openssl.c index 4db2f994b..936bf6d5a 100644 --- a/crypto/apr_crypto_openssl.c +++ b/crypto/apr_crypto_openssl.c @@ -1615,18 +1615,28 @@ void cprng_stream_setkey(cprng_stream_ctx_t *sctx, const unsigned char *key, const unsigned char *iv) { + switch(EVP_CIPHER_CTX_nid(sctx->ctx)) { #if defined(NID_chacha20) - /* With CHACHA20, iv=NULL is the same as zeros but it's faster - * to (re-)init; use that for efficiency. - */ - EVP_EncryptInit_ex(sctx->ctx, NULL, NULL, key, NULL); -#else - /* With AES256-CTR, iv=NULL seems to peek up and random one (for - * the initial CTR), while we can live with zeros (fixed CTR); - * efficiency still. - */ - EVP_EncryptInit_ex(sctx->ctx, NULL, NULL, key, iv); + case NID_chacha20: + /* With CHACHA20, iv=NULL is the same as zeros but it's faster + * to (re-)init; use that for efficiency. + */ + EVP_EncryptInit_ex(sctx->ctx, NULL, NULL, key, NULL); + break; +#endif +#if defined(NID_aes_256_ctr) + case NID_aes_256_ctr: + /* With AES256-CTR, iv=NULL seems to peek up and random one (for + * the initial CTR), while we can live with zeros (fixed CTR); + * efficiency still. + */ + EVP_EncryptInit_ex(sctx->ctx, NULL, NULL, key, iv); + break; #endif + default: + assert(0); + break; + } } static apr_status_t cprng_stream_ctx_bytes(cprng_stream_ctx_t **pctx, |