mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
prov: support params argument to CHACHA20 ciphers
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/14383)
This commit is contained in:
parent
8f42380a21
commit
f336f98dbf
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user