From: Leon Timmermans Date: Mon, 11 Aug 2025 20:08:39 +0000 (+0200) Subject: Allow get_params to return length of AES-GCM IV parameters X-Git-Tag: 3.6-PRE-CLANG-FORMAT-WEBKIT~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ff8875d332958785d723ad516028be4267deed7;p=thirdparty%2Fopenssl.git Allow get_params to return length of AES-GCM IV parameters Previously, EVP_CIPHER_CTX_get_params would not report the length of the IV parameters when called with a NULL data pointer. This change makes the function behave as documented. Reviewed-by: Dmitry Belyavskiy Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/28232) (cherry picked from commit ab60626253853eaefb2f786779bc9aefc1de8395) --- diff --git a/providers/implementations/ciphers/ciphercommon_gcm.c.in b/providers/implementations/ciphers/ciphercommon_gcm.c.in index 4964f15e67d..781e6920990 100644 --- a/providers/implementations/ciphers/ciphercommon_gcm.c.in +++ b/providers/implementations/ciphers/ciphercommon_gcm.c.in @@ -194,7 +194,7 @@ int ossl_gcm_get_ctx_params(void *vctx, OSSL_PARAM params[]) if (p.iv != NULL) { if (ctx->iv_state == IV_STATE_UNINITIALISED) return 0; - if (ctx->ivlen > p.iv->data_size) { + if (p.iv->data != NULL && ctx->ivlen > p.iv->data_size) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH); return 0; } @@ -207,7 +207,7 @@ int ossl_gcm_get_ctx_params(void *vctx, OSSL_PARAM params[]) if (p.updiv != NULL) { if (ctx->iv_state == IV_STATE_UNINITIALISED) return 0; - if (ctx->ivlen > p.updiv->data_size) { + if (p.updiv->data != NULL && ctx->ivlen > p.updiv->data_size) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH); return 0; } diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 4a39ed243c3..2ae461d5ae7 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -6304,8 +6304,8 @@ static int aes_gcm_encrypt(const unsigned char *gcm_key, size_t gcm_key_s, int outlen, tmplen; unsigned char outbuf[1024]; unsigned char outtag[16]; - OSSL_PARAM params[2] = { - OSSL_PARAM_END, OSSL_PARAM_END + OSSL_PARAM params[3] = { + OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END }; if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()) @@ -6332,6 +6332,15 @@ static int aes_gcm_encrypt(const unsigned char *gcm_key, size_t gcm_key_s, || !TEST_mem_eq(outtag, gcm_tag_s, gcm_tag, gcm_tag_s)) goto err; + params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_IV, + NULL, 0); + params[1] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_UPDATED_IV, + NULL, 0); + params[2] = OSSL_PARAM_construct_end(); + if (!TEST_true(EVP_CIPHER_CTX_get_params(ctx, params)) + || !TEST_size_t_eq(params[0].return_size, gcm_ivlen) + || !TEST_size_t_eq(params[1].return_size, gcm_ivlen)) + ret = 1; err: EVP_CIPHER_free(cipher);