summaryrefslogtreecommitdiffstats
path: root/providers
diff options
context:
space:
mode:
authorPauli <ppzgs1@gmail.com>2021-03-02 22:44:53 +1000
committerPauli <ppzgs1@gmail.com>2021-03-12 08:27:21 +1000
commitf336f98dbf80af632ea142ea3d43fe1e9d727e14 (patch)
treeb0c72865f12f902ab8d93447ba2e1b51613d3de3 /providers
parent8f42380a21e7732cc0931be1921e24d360285278 (diff)
prov: support params argument to CHACHA20 ciphers
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/14383)
Diffstat (limited to 'providers')
-rw-r--r--providers/implementations/ciphers/cipher_chacha20.c17
-rw-r--r--providers/implementations/ciphers/cipher_chacha20_poly1305.c15
-rw-r--r--providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c8
3 files changed, 28 insertions, 12 deletions
diff --git a/providers/implementations/ciphers/cipher_chacha20.c b/providers/implementations/ciphers/cipher_chacha20.c
index 9bce5b0914..386c865d83 100644
--- a/providers/implementations/ciphers/cipher_chacha20.c
+++ b/providers/implementations/ciphers/cipher_chacha20.c
@@ -106,6 +106,9 @@ static int chacha20_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
size_t len;
+ if (params == NULL)
+ return 1;
+
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
if (p != NULL) {
if (!OSSL_PARAM_get_size_t(p, &len)) {
@@ -143,34 +146,40 @@ const OSSL_PARAM *chacha20_settable_ctx_params(ossl_unused void *cctx,
}
int ossl_chacha20_einit(void *vctx, const unsigned char *key, size_t keylen,
- const unsigned char *iv, size_t ivlen)
+ const unsigned char *iv, size_t ivlen,
+ const OSSL_PARAM params[])
{
int ret;
/* The generic function checks for ossl_prov_is_running() */
- ret= ossl_cipher_generic_einit(vctx, key, keylen, iv, ivlen);
+ ret = ossl_cipher_generic_einit(vctx, key, keylen, iv, ivlen, NULL);
if (ret && iv != NULL) {
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
PROV_CIPHER_HW_CHACHA20 *hw = (PROV_CIPHER_HW_CHACHA20 *)ctx->hw;
hw->initiv(ctx);
}
+ if (ret && !chacha20_set_ctx_params(vctx, params))
+ ret = 0;
return ret;
}
int ossl_chacha20_dinit(void *vctx, const unsigned char *key, size_t keylen,
- const unsigned char *iv, size_t ivlen)
+ const unsigned char *iv, size_t ivlen,
+ const OSSL_PARAM params[])
{
int ret;
/* The generic function checks for ossl_prov_is_running() */
- ret= ossl_cipher_generic_dinit(vctx, key, keylen, iv, ivlen);
+ ret = ossl_cipher_generic_dinit(vctx, key, keylen, iv, ivlen, NULL);
if (ret && iv != NULL) {
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
PROV_CIPHER_HW_CHACHA20 *hw = (PROV_CIPHER_HW_CHACHA20 *)ctx->hw;
hw->initiv(ctx);
}
+ if (ret && !chacha20_set_ctx_params(vctx, params))
+ ret = 0;
return ret;
}
diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305.c b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
index 78ede20b44..0ba7483780 100644
--- a/providers/implementations/ciphers/cipher_chacha20_poly1305.c
+++ b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
@@ -149,6 +149,9 @@ static int chacha20_poly1305_set_ctx_params(void *vctx,
PROV_CIPHER_HW_CHACHA20_POLY1305 *hw =
(PROV_CIPHER_HW_CHACHA20_POLY1305 *)ctx->base.hw;
+ if (params == NULL)
+ return 1;
+
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
if (p != NULL) {
if (!OSSL_PARAM_get_size_t(p, &len)) {
@@ -224,12 +227,12 @@ static int chacha20_poly1305_set_ctx_params(void *vctx,
static int chacha20_poly1305_einit(void *vctx, const unsigned char *key,
size_t keylen, const unsigned char *iv,
- size_t ivlen)
+ size_t ivlen, const OSSL_PARAM params[])
{
int ret;
/* The generic function checks for ossl_prov_is_running() */
- ret = ossl_cipher_generic_einit(vctx, key, keylen, iv, ivlen);
+ ret = ossl_cipher_generic_einit(vctx, key, keylen, iv, ivlen, NULL);
if (ret && iv != NULL) {
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
PROV_CIPHER_HW_CHACHA20_POLY1305 *hw =
@@ -237,17 +240,19 @@ static int chacha20_poly1305_einit(void *vctx, const unsigned char *key,
hw->initiv(ctx);
}
+ if (ret && !chacha20_poly1305_set_ctx_params(vctx, params))
+ ret = 0;
return ret;
}
static int chacha20_poly1305_dinit(void *vctx, const unsigned char *key,
size_t keylen, const unsigned char *iv,
- size_t ivlen)
+ size_t ivlen, const OSSL_PARAM params[])
{
int ret;
/* The generic function checks for ossl_prov_is_running() */
- ret = ossl_cipher_generic_dinit(vctx, key, keylen, iv, ivlen);
+ ret = ossl_cipher_generic_dinit(vctx, key, keylen, iv, ivlen, NULL);
if (ret && iv != NULL) {
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
PROV_CIPHER_HW_CHACHA20_POLY1305 *hw =
@@ -255,6 +260,8 @@ static int chacha20_poly1305_dinit(void *vctx, const unsigned char *key,
hw->initiv(ctx);
}
+ if (ret && !chacha20_poly1305_set_ctx_params(vctx, params))
+ ret = 0;
return ret;
}
diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c b/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c
index 4e4165868e..1533a3869b 100644
--- a/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c
+++ b/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c
@@ -68,9 +68,9 @@ static int chacha20_poly1305_initkey(PROV_CIPHER_CTX *bctx,
ctx->tls_payload_length = NO_TLS_PAYLOAD_LENGTH;
if (bctx->enc)
- return ossl_chacha20_einit(&ctx->chacha, key, keylen, NULL, 0);
+ return ossl_chacha20_einit(&ctx->chacha, key, keylen, NULL, 0, NULL);
else
- return ossl_chacha20_dinit(&ctx->chacha, key, keylen, NULL, 0);
+ return ossl_chacha20_dinit(&ctx->chacha, key, keylen, NULL, 0, NULL);
}
static int chacha20_poly1305_initiv(PROV_CIPHER_CTX *bctx)
@@ -92,10 +92,10 @@ static int chacha20_poly1305_initiv(PROV_CIPHER_CTX *bctx)
if (bctx->enc)
ret = ossl_chacha20_einit(&ctx->chacha, NULL, 0,
- tempiv, sizeof(tempiv));
+ tempiv, sizeof(tempiv), NULL);
else
ret = ossl_chacha20_dinit(&ctx->chacha, NULL, 0,
- tempiv, sizeof(tempiv));
+ tempiv, sizeof(tempiv), NULL);
ctx->nonce[0] = ctx->chacha.counter[1];
ctx->nonce[1] = ctx->chacha.counter[2];
ctx->nonce[2] = ctx->chacha.counter[3];