mirror of https://github.com/openssl/openssl.git
params: add helper functions that don't locate the parameters
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/27923)
This commit is contained in:
parent
dd266b4426
commit
b5828dbbf2
|
@ -1562,10 +1562,10 @@ OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
|
|||
* *out and *out_len are guaranteed to be untouched if this function
|
||||
* doesn't return success.
|
||||
*/
|
||||
int ossl_param_get1_octet_string(const OSSL_PARAM *params, const char *name,
|
||||
unsigned char **out, size_t *out_len)
|
||||
int ossl_param_get1_octet_string_from_param(const OSSL_PARAM *p,
|
||||
unsigned char **out,
|
||||
size_t *out_len)
|
||||
{
|
||||
const OSSL_PARAM *p = OSSL_PARAM_locate_const(params, name);
|
||||
void *buf = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
|
@ -1583,11 +1583,20 @@ int ossl_param_get1_octet_string(const OSSL_PARAM *params, const char *name,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int setbuf_fromparams(const OSSL_PARAM *p, const char *name,
|
||||
int ossl_param_get1_octet_string(const OSSL_PARAM *params, const char *name,
|
||||
unsigned char **out, size_t *out_len)
|
||||
{
|
||||
const OSSL_PARAM *p = OSSL_PARAM_locate_const(params, name);
|
||||
|
||||
return ossl_param_get1_octet_string_from_param(p, out, out_len);
|
||||
}
|
||||
|
||||
static int setbuf_fromparams(size_t n, OSSL_PARAM *p[],
|
||||
unsigned char *out, size_t *outlen)
|
||||
{
|
||||
int ret = 0;
|
||||
WPACKET pkt;
|
||||
size_t i;
|
||||
|
||||
if (out == NULL) {
|
||||
if (!WPACKET_init_null(&pkt, 0))
|
||||
|
@ -1597,12 +1606,12 @@ static int setbuf_fromparams(const OSSL_PARAM *p, const char *name,
|
|||
return 0;
|
||||
}
|
||||
|
||||
for (; p != NULL; p = OSSL_PARAM_locate_const(p + 1, name)) {
|
||||
if (p->data_type != OSSL_PARAM_OCTET_STRING)
|
||||
for (i = 0; i < n; i++) {
|
||||
if (p[i]->data_type != OSSL_PARAM_OCTET_STRING)
|
||||
goto err;
|
||||
if (p->data != NULL
|
||||
&& p->data_size != 0
|
||||
&& !WPACKET_memcpy(&pkt, p->data, p->data_size))
|
||||
if (p[i]->data != NULL
|
||||
&& p[i]->data_size != 0
|
||||
&& !WPACKET_memcpy(&pkt, p[i]->data, p[i]->data_size))
|
||||
goto err;
|
||||
}
|
||||
if (!WPACKET_get_total_written(&pkt, outlen)
|
||||
|
@ -1614,19 +1623,18 @@ err:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int ossl_param_get1_concat_octet_string(const OSSL_PARAM *params, const char *name,
|
||||
int ossl_param_get1_concat_octet_string(size_t n, OSSL_PARAM *params[],
|
||||
unsigned char **out,
|
||||
size_t *out_len, size_t maxsize)
|
||||
{
|
||||
const OSSL_PARAM *p = OSSL_PARAM_locate_const(params, name);
|
||||
unsigned char *res;
|
||||
size_t sz = 0;
|
||||
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
if (n == 0)
|
||||
return 1;
|
||||
|
||||
/* Calculate the total size */
|
||||
if (!setbuf_fromparams(p, name, NULL, &sz))
|
||||
if (!setbuf_fromparams(n, params, NULL, &sz))
|
||||
return 0;
|
||||
|
||||
/* Check that it's not oversized */
|
||||
|
@ -1646,7 +1654,7 @@ int ossl_param_get1_concat_octet_string(const OSSL_PARAM *params, const char *na
|
|||
return 0;
|
||||
|
||||
/* Concat one or more OSSL_KDF_PARAM_INFO fields */
|
||||
if (!setbuf_fromparams(p, name, res, &sz)) {
|
||||
if (!setbuf_fromparams(n, params, res, &sz)) {
|
||||
OPENSSL_clear_free(res, sz);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,12 @@
|
|||
* *out and *out_len are guaranteed to be untouched if this function
|
||||
* doesn't return success.
|
||||
*/
|
||||
int ossl_param_get1_octet_string_from_param(const OSSL_PARAM *p,
|
||||
unsigned char **out,
|
||||
size_t *out_len);
|
||||
int ossl_param_get1_octet_string(const OSSL_PARAM *params, const char *name,
|
||||
unsigned char **out, size_t *out_len);
|
||||
|
||||
/*
|
||||
* Concatenate all of the matching params together.
|
||||
* *out will point to an allocated buffer on successful return.
|
||||
|
@ -28,11 +32,11 @@ int ossl_param_get1_octet_string(const OSSL_PARAM *params, const char *name,
|
|||
*
|
||||
* Passing 0 for maxsize means unlimited size output.
|
||||
*
|
||||
* Returns 1 on success, 0 on failure and -1 if there are no matching params.
|
||||
* Returns 1 on success and 0 on failure.
|
||||
*
|
||||
* *out and *out_len are guaranteed to be untouched if this function
|
||||
* doesn't return success.
|
||||
*/
|
||||
int ossl_param_get1_concat_octet_string(const OSSL_PARAM *params, const char *name,
|
||||
unsigned char **out, size_t *out_len,
|
||||
size_t maxsize);
|
||||
int ossl_param_get1_concat_octet_string(size_t n, OSSL_PARAM *params[],
|
||||
unsigned char **out,
|
||||
size_t *out_len, size_t maxsize);
|
||||
|
|
Loading…
Reference in New Issue