summaryrefslogtreecommitdiff
path: root/providers/implementations/ciphers/cipher_chacha20_poly1305.c
diff options
context:
space:
mode:
authorslontis <shane.lontis@oracle.com>2023-01-27 13:18:17 +1000
committerTomas Mraz <tomas@openssl.org>2023-01-30 09:48:50 +0100
commita01152370676e7e11fb461cff8628eb50fa41b81 (patch)
treed455f9b1995ccc694a6d771701bd674dd7447bd7 /providers/implementations/ciphers/cipher_chacha20_poly1305.c
parent2477e99f1055194902dc4864124316ea57ac3efa (diff)
downloadopenssl-new-a01152370676e7e11fb461cff8628eb50fa41b81.tar.gz
ChaCha20-Poly1305 no longer supports truncated IV's.
Fixes #20084 In the 3.0 provider implementation the generic code that handles IV's only allows a 12 byte IV. Older code intentionally added the ability for the IV to be truncated. As this truncation is unsafe, the documentation has been updated to state that this in no longer allowed. The code has been updated to produce an error when the iv length is set to any value other than 12. NOTE: It appears that this additional padding may have originated from the code which uses a 12 byte IV, that is then passed to CHACHA which zero pads it to 16 bytes. Note that legacy behaviour in e_chacha20_poly1305.c has not been updated. Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20151)
Diffstat (limited to 'providers/implementations/ciphers/cipher_chacha20_poly1305.c')
-rw-r--r--providers/implementations/ciphers/cipher_chacha20_poly1305.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305.c b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
index 0ba7483780..8cbaa50d95 100644
--- a/providers/implementations/ciphers/cipher_chacha20_poly1305.c
+++ b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
@@ -14,7 +14,6 @@
#include "prov/implementations.h"
#include "prov/providercommon.h"
-
#define CHACHA20_POLY1305_KEYLEN CHACHA_KEY_SIZE
#define CHACHA20_POLY1305_BLKLEN 1
#define CHACHA20_POLY1305_MAX_IVLEN 12
@@ -53,7 +52,6 @@ static void *chacha20_poly1305_newctx(void *provctx)
ossl_prov_cipher_hw_chacha20_poly1305(
CHACHA20_POLY1305_KEYLEN * 8),
NULL);
- ctx->nonce_len = CHACHA20_POLY1305_IVLEN;
ctx->tls_payload_length = NO_TLS_PAYLOAD_LENGTH;
ossl_chacha20_initctx(&ctx->chacha);
}
@@ -85,7 +83,7 @@ static int chacha20_poly1305_get_ctx_params(void *vctx, OSSL_PARAM params[])
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN);
if (p != NULL) {
- if (!OSSL_PARAM_set_size_t(p, ctx->nonce_len)) {
+ if (!OSSL_PARAM_set_size_t(p, CHACHA20_POLY1305_IVLEN)) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
return 0;
}
@@ -169,11 +167,10 @@ static int chacha20_poly1305_set_ctx_params(void *vctx,
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
return 0;
}
- if (len == 0 || len > CHACHA20_POLY1305_MAX_IVLEN) {
+ if (len != CHACHA20_POLY1305_MAX_IVLEN) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
return 0;
}
- ctx->nonce_len = len;
}
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_TAG);