mirror of https://github.com/openssl/openssl.git
chacha20: convert to using genreated param name decoders
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/28616)
This commit is contained in:
parent
47d8dd2397
commit
f4b535f1a0
|
@ -6,6 +6,9 @@
|
||||||
* in the file LICENSE in the source distribution or at
|
* in the file LICENSE in the source distribution or at
|
||||||
* https://www.openssl.org/source/license.html
|
* https://www.openssl.org/source/license.html
|
||||||
*/
|
*/
|
||||||
|
{-
|
||||||
|
use OpenSSL::paramnames qw(produce_param_decoder);
|
||||||
|
-}
|
||||||
|
|
||||||
/* Dispatch functions for chacha20 cipher */
|
/* Dispatch functions for chacha20 cipher */
|
||||||
|
|
||||||
|
@ -100,29 +103,37 @@ static int chacha20_get_params(OSSL_PARAM params[])
|
||||||
CHACHA20_IVLEN * 8);
|
CHACHA20_IVLEN * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{- produce_param_decoder('chacha20_get_ctx_params',
|
||||||
|
(['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'],
|
||||||
|
['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'],
|
||||||
|
['OSSL_CIPHER_PARAM_UPDATED_IV', 'upd_iv', 'octet_string'],
|
||||||
|
)); -}
|
||||||
|
|
||||||
static int chacha20_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
static int chacha20_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
||||||
{
|
{
|
||||||
PROV_CHACHA20_CTX *ctx = (PROV_CHACHA20_CTX *)vctx;
|
PROV_CHACHA20_CTX *ctx = (PROV_CHACHA20_CTX *)vctx;
|
||||||
unsigned char ivbuf[CHACHA20_IVLEN];
|
unsigned char ivbuf[CHACHA20_IVLEN];
|
||||||
OSSL_PARAM *p;
|
struct chacha20_get_ctx_params_st p;
|
||||||
|
|
||||||
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN);
|
if (ctx == NULL || !chacha20_get_ctx_params_decoder(params, &p))
|
||||||
if (p != NULL && !OSSL_PARAM_set_size_t(p, CHACHA20_IVLEN)) {
|
return 0;
|
||||||
|
|
||||||
|
if (p.ivlen != NULL && !OSSL_PARAM_set_size_t(p.ivlen, CHACHA20_IVLEN)) {
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN);
|
|
||||||
if (p != NULL && !OSSL_PARAM_set_size_t(p, CHACHA20_KEYLEN)) {
|
if (p.keylen != NULL && !OSSL_PARAM_set_size_t(p.keylen, CHACHA20_KEYLEN)) {
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_UPDATED_IV);
|
|
||||||
if (p != NULL) {
|
if (p.upd_iv != NULL) {
|
||||||
CHACHA_U32TOU8(ivbuf, ctx->counter[0]);
|
CHACHA_U32TOU8(ivbuf, ctx->counter[0]);
|
||||||
CHACHA_U32TOU8(ivbuf + 4, ctx->counter[1]);
|
CHACHA_U32TOU8(ivbuf + 4, ctx->counter[1]);
|
||||||
CHACHA_U32TOU8(ivbuf + 8, ctx->counter[2]);
|
CHACHA_U32TOU8(ivbuf + 8, ctx->counter[2]);
|
||||||
CHACHA_U32TOU8(ivbuf + 12, ctx->counter[3]);
|
CHACHA_U32TOU8(ivbuf + 12, ctx->counter[3]);
|
||||||
if (!OSSL_PARAM_set_octet_string(p, ivbuf, CHACHA20_IVLEN)) {
|
if (!OSSL_PARAM_set_octet_string(p.upd_iv, ivbuf, CHACHA20_IVLEN)) {
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -130,29 +141,28 @@ static int chacha20_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const OSSL_PARAM chacha20_known_gettable_ctx_params[] = {
|
|
||||||
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL),
|
|
||||||
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL),
|
|
||||||
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_UPDATED_IV, NULL, 0),
|
|
||||||
OSSL_PARAM_END
|
|
||||||
};
|
|
||||||
const OSSL_PARAM *chacha20_gettable_ctx_params(ossl_unused void *cctx,
|
const OSSL_PARAM *chacha20_gettable_ctx_params(ossl_unused void *cctx,
|
||||||
ossl_unused void *provctx)
|
ossl_unused void *provctx)
|
||||||
{
|
{
|
||||||
return chacha20_known_gettable_ctx_params;
|
return chacha20_get_ctx_params_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{- produce_param_decoder('chacha20_set_ctx_params',
|
||||||
|
(['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'],
|
||||||
|
['OSSL_CIPHER_PARAM_IVLEN', 'ivlen', 'size_t'],
|
||||||
|
)); -}
|
||||||
|
|
||||||
static int chacha20_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
static int chacha20_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||||
{
|
{
|
||||||
const OSSL_PARAM *p;
|
PROV_CHACHA20_CTX *ctx = (PROV_CHACHA20_CTX *)vctx;
|
||||||
|
struct chacha20_set_ctx_params_st p;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (ossl_param_is_empty(params))
|
if (ctx == NULL || !chacha20_set_ctx_params_decoder(params, &p))
|
||||||
return 1;
|
return 0;
|
||||||
|
|
||||||
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
|
if (p.keylen != NULL) {
|
||||||
if (p != NULL) {
|
if (!OSSL_PARAM_get_size_t(p.keylen, &len)) {
|
||||||
if (!OSSL_PARAM_get_size_t(p, &len)) {
|
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -161,9 +171,9 @@ static int chacha20_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_IVLEN);
|
|
||||||
if (p != NULL) {
|
if (p.ivlen != NULL) {
|
||||||
if (!OSSL_PARAM_get_size_t(p, &len)) {
|
if (!OSSL_PARAM_get_size_t(p.ivlen, &len)) {
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -175,15 +185,10 @@ static int chacha20_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const OSSL_PARAM chacha20_known_settable_ctx_params[] = {
|
|
||||||
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL),
|
|
||||||
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL),
|
|
||||||
OSSL_PARAM_END
|
|
||||||
};
|
|
||||||
const OSSL_PARAM *chacha20_settable_ctx_params(ossl_unused void *cctx,
|
const OSSL_PARAM *chacha20_settable_ctx_params(ossl_unused void *cctx,
|
||||||
ossl_unused void *provctx)
|
ossl_unused void *provctx)
|
||||||
{
|
{
|
||||||
return chacha20_known_settable_ctx_params;
|
return chacha20_set_ctx_params_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ossl_chacha20_einit(void *vctx, const unsigned char *key, size_t keylen,
|
int ossl_chacha20_einit(void *vctx, const unsigned char *key, size_t keylen,
|
||||||
|
|
Loading…
Reference in New Issue