diff options
author | Pauli <ppzgs1@gmail.com> | 2021-02-25 13:54:55 +1000 |
---|---|---|
committer | Pauli <ppzgs1@gmail.com> | 2021-02-28 17:25:49 +1000 |
commit | 1dfe97530f3ec50541810e1aca99343c68fd40fb (patch) | |
tree | 35ad8333e386c1b9c6d17b7bad93864ad8855dca /providers/implementations/macs/poly1305_prov.c | |
parent | 80ba2526fa8605d0a3848a6d90f9ae5a0125505a (diff) |
update poly1305 to have additional init arguments
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14310)
Diffstat (limited to 'providers/implementations/macs/poly1305_prov.c')
-rw-r--r-- | providers/implementations/macs/poly1305_prov.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/providers/implementations/macs/poly1305_prov.c b/providers/implementations/macs/poly1305_prov.c index 3f784e9c28..5a09926551 100644 --- a/providers/implementations/macs/poly1305_prov.c +++ b/providers/implementations/macs/poly1305_prov.c @@ -77,10 +77,28 @@ static size_t poly1305_size(void) return POLY1305_DIGEST_SIZE; } -static int poly1305_init(void *vmacctx) +static int poly1305_setkey(struct poly1305_data_st *ctx, + const unsigned char *key, size_t keylen) { + if (keylen != POLY1305_KEY_SIZE) { + ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); + return 0; + } + Poly1305_Init(&ctx->poly1305, key); + return 1; +} + +static int poly1305_init(void *vmacctx, const unsigned char *key, + size_t keylen, const OSSL_PARAM params[]) +{ + struct poly1305_data_st *ctx = vmacctx; + /* initialize the context in MAC_ctrl function */ - return ossl_prov_is_running(); + if (!ossl_prov_is_running() || !poly1305_set_ctx_params(ctx, params)) + return 0; + if (key != NULL) + return poly1305_setkey(ctx, key, keylen); + return 1; } static int poly1305_update(void *vmacctx, const unsigned char *data, @@ -140,16 +158,11 @@ static const OSSL_PARAM *poly1305_settable_ctx_params(ossl_unused void *ctx, static int poly1305_set_ctx_params(void *vmacctx, const OSSL_PARAM *params) { struct poly1305_data_st *ctx = vmacctx; - const OSSL_PARAM *p = NULL; - - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) { - if (p->data_type != OSSL_PARAM_OCTET_STRING - || p->data_size != POLY1305_KEY_SIZE) { - ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); - return 0; - } - Poly1305_Init(&ctx->poly1305, p->data); - } + const OSSL_PARAM *p; + + if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL + && !poly1305_setkey(ctx, p->data, p->data_size)) + return 0; return 1; } |