diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2021-04-07 11:27:18 +1000 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2021-04-12 16:55:29 +1000 |
commit | 884314cab786a980189206b2cab5f62878a97669 (patch) | |
tree | d9b618c36ea0ab2a5401cbf592f1c1282f6d6de5 /crypto/param_build.c | |
parent | d36114d7cd363d505940326f5a2512d9661a67ea (diff) |
Add OSSL_PARAM_dup() and OSSL_PARAM_merge().
These functions are prerequisites for implementing EVP_PKEY_todata().
OSSL_PARAM_dup() is required to make a deep copy of the exported
params (since the provider export() uses a OSSL_PARAM_BLD which throws away the
data after the call), and then use OSSL_PARAM_merge() to add some additional params
that can be passed to the EVP_PKEY_todata().
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14785)
Diffstat (limited to 'crypto/param_build.c')
-rw-r--r-- | crypto/param_build.c | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/crypto/param_build.c b/crypto/param_build.c index 6ce0f01685..6ccca9f661 100644 --- a/crypto/param_build.c +++ b/crypto/param_build.c @@ -14,14 +14,12 @@ #include <openssl/params.h> #include <openssl/types.h> #include <openssl/safestack.h> -#include "internal/cryptlib.h" -#include "openssl/param_build.h" +#include "internal/param_build_set.h" /* * Special internal param type to indicate the end of an allocate OSSL_PARAM * array. */ -#define OSSL_PARAM_ALLOCATED_END 127 typedef struct { const char *key; @@ -50,17 +48,6 @@ struct ossl_param_bld_st { STACK_OF(OSSL_PARAM_BLD_DEF) *params; }; -typedef union { - OSSL_UNION_ALIGN; -} OSSL_PARAM_BLD_BLOCK; - -#define ALIGN_SIZE sizeof(OSSL_PARAM_BLD_BLOCK) - -static size_t bytes_to_blocks(size_t bytes) -{ - return (bytes + ALIGN_SIZE - 1) / ALIGN_SIZE; -} - static OSSL_PARAM_BLD_DEF *param_push(OSSL_PARAM_BLD *bld, const char *key, int size, size_t alloc, int type, int secure) @@ -74,7 +61,7 @@ static OSSL_PARAM_BLD_DEF *param_push(OSSL_PARAM_BLD *bld, const char *key, pd->key = key; pd->type = type; pd->size = size; - pd->alloc_blocks = bytes_to_blocks(alloc); + pd->alloc_blocks = ossl_param_bytes_to_blocks(alloc); if ((pd->secure = secure) != 0) bld->secure_blocks += pd->alloc_blocks; else @@ -309,8 +296,8 @@ int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key, } static OSSL_PARAM *param_bld_convert(OSSL_PARAM_BLD *bld, OSSL_PARAM *param, - OSSL_PARAM_BLD_BLOCK *blk, - OSSL_PARAM_BLD_BLOCK *secure) + OSSL_PARAM_ALIGNED_BLOCK *blk, + OSSL_PARAM_ALIGNED_BLOCK *secure) { int i, num = sk_OSSL_PARAM_BLD_DEF_num(bld->params); OSSL_PARAM_BLD_DEF *pd; @@ -360,12 +347,12 @@ static OSSL_PARAM *param_bld_convert(OSSL_PARAM_BLD *bld, OSSL_PARAM *param, OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld) { - OSSL_PARAM_BLD_BLOCK *blk, *s = NULL; + OSSL_PARAM_ALIGNED_BLOCK *blk, *s = NULL; OSSL_PARAM *params, *last; const int num = sk_OSSL_PARAM_BLD_DEF_num(bld->params); - const size_t p_blks = bytes_to_blocks((1 + num) * sizeof(*params)); - const size_t total = ALIGN_SIZE * (p_blks + bld->total_blocks); - const size_t ss = ALIGN_SIZE * bld->secure_blocks; + const size_t p_blks = ossl_param_bytes_to_blocks((1 + num) * sizeof(*params)); + const size_t total = OSSL_PARAM_ALIGN_SIZE * (p_blks + bld->total_blocks); + const size_t ss = OSSL_PARAM_ALIGN_SIZE * bld->secure_blocks; if (ss > 0) { s = OPENSSL_secure_malloc(ss); @@ -380,11 +367,9 @@ OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld) OPENSSL_secure_free(s); return NULL; } - blk = p_blks + (OSSL_PARAM_BLD_BLOCK *)(params); + blk = p_blks + (OSSL_PARAM_ALIGNED_BLOCK *)(params); last = param_bld_convert(bld, params, blk, s); - last->data_size = ss; - last->data = s; - last->data_type = OSSL_PARAM_ALLOCATED_END; + ossl_param_set_secure_block(last, s, ss); /* Reset builder for reuse */ bld->total_blocks = 0; @@ -395,13 +380,5 @@ OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld) void OSSL_PARAM_BLD_free_params(OSSL_PARAM *params) { - if (params != NULL) { - OSSL_PARAM *p; - - for (p = params; p->key != NULL; p++) - ; - if (p->data_type == OSSL_PARAM_ALLOCATED_END) - OPENSSL_secure_clear_free(p->data, p->data_size); - OPENSSL_free(params); - } + OSSL_PARAM_free(params); } |