2019-02-22 10:21:33 +08:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2019-06-17 09:34:09 +08:00
|
|
|
OSSL_PARAM_double, OSSL_PARAM_int, OSSL_PARAM_int32, OSSL_PARAM_int64,
|
2020-05-25 12:45:49 +08:00
|
|
|
OSSL_PARAM_long, OSSL_PARAM_size_t, OSSL_PARAM_time_t, OSSL_PARAM_uint,
|
|
|
|
OSSL_PARAM_uint32, OSSL_PARAM_uint64, OSSL_PARAM_ulong, OSSL_PARAM_BN,
|
|
|
|
OSSL_PARAM_utf8_string, OSSL_PARAM_octet_string, OSSL_PARAM_utf8_ptr,
|
|
|
|
OSSL_PARAM_octet_ptr,
|
2021-02-18 01:41:10 +08:00
|
|
|
OSSL_PARAM_END, OSSL_PARAM_DEFN,
|
2019-07-18 15:25:24 +08:00
|
|
|
OSSL_PARAM_construct_double, OSSL_PARAM_construct_int,
|
|
|
|
OSSL_PARAM_construct_int32, OSSL_PARAM_construct_int64,
|
2020-05-25 12:45:49 +08:00
|
|
|
OSSL_PARAM_construct_long, OSSL_PARAM_construct_size_t,
|
|
|
|
OSSL_PARAM_construct_time_t, OSSL_PARAM_construct_uint,
|
|
|
|
OSSL_PARAM_construct_uint32, OSSL_PARAM_construct_uint64,
|
|
|
|
OSSL_PARAM_construct_ulong, OSSL_PARAM_construct_BN,
|
|
|
|
OSSL_PARAM_construct_utf8_string, OSSL_PARAM_construct_utf8_ptr,
|
|
|
|
OSSL_PARAM_construct_octet_string, OSSL_PARAM_construct_octet_ptr,
|
|
|
|
OSSL_PARAM_construct_end,
|
2019-07-18 15:25:24 +08:00
|
|
|
OSSL_PARAM_locate, OSSL_PARAM_locate_const,
|
2019-06-24 12:43:55 +08:00
|
|
|
OSSL_PARAM_get_double, OSSL_PARAM_get_int, OSSL_PARAM_get_int32,
|
2020-05-25 12:45:49 +08:00
|
|
|
OSSL_PARAM_get_int64, OSSL_PARAM_get_long, OSSL_PARAM_get_size_t,
|
|
|
|
OSSL_PARAM_get_time_t, OSSL_PARAM_get_uint, OSSL_PARAM_get_uint32,
|
|
|
|
OSSL_PARAM_get_uint64, OSSL_PARAM_get_ulong, OSSL_PARAM_get_BN,
|
|
|
|
OSSL_PARAM_get_utf8_string, OSSL_PARAM_get_octet_string,
|
|
|
|
OSSL_PARAM_get_utf8_ptr, OSSL_PARAM_get_octet_ptr,
|
2020-07-29 04:00:09 +08:00
|
|
|
OSSL_PARAM_get_utf8_string_ptr, OSSL_PARAM_get_octet_string_ptr,
|
2019-07-18 15:25:24 +08:00
|
|
|
OSSL_PARAM_set_double, OSSL_PARAM_set_int, OSSL_PARAM_set_int32,
|
2020-05-25 12:45:49 +08:00
|
|
|
OSSL_PARAM_set_int64, OSSL_PARAM_set_long, OSSL_PARAM_set_size_t,
|
|
|
|
OSSL_PARAM_set_time_t, OSSL_PARAM_set_uint, OSSL_PARAM_set_uint32,
|
|
|
|
OSSL_PARAM_set_uint64, OSSL_PARAM_set_ulong, OSSL_PARAM_set_BN,
|
|
|
|
OSSL_PARAM_set_utf8_string, OSSL_PARAM_set_octet_string,
|
|
|
|
OSSL_PARAM_set_utf8_ptr, OSSL_PARAM_set_octet_ptr,
|
2020-06-19 15:17:37 +08:00
|
|
|
OSSL_PARAM_UNMODIFIED, OSSL_PARAM_modified, OSSL_PARAM_set_all_unmodified
|
2019-02-22 10:21:33 +08:00
|
|
|
- OSSL_PARAM helpers
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2019-09-29 23:10:59 +08:00
|
|
|
=for openssl generic
|
2019-06-17 09:34:09 +08:00
|
|
|
|
2019-02-22 10:21:33 +08:00
|
|
|
#include <openssl/params.h>
|
|
|
|
|
2019-07-18 15:25:24 +08:00
|
|
|
/*
|
|
|
|
* TYPE in function names is one of:
|
2020-05-11 07:37:45 +08:00
|
|
|
* double, int, int32, int64, long, size_t, time_t, uint, uint32, uint64, ulong
|
2019-07-18 15:25:24 +08:00
|
|
|
* Corresponding TYPE in function arguments is one of:
|
2020-05-11 07:37:45 +08:00
|
|
|
* double, int, int32_t, int64_t, long, size_t, time_t, unsigned int, uint32_t,
|
2019-07-18 15:25:24 +08:00
|
|
|
* uint64_t, unsigned long
|
|
|
|
*/
|
|
|
|
|
2019-02-22 10:21:33 +08:00
|
|
|
#define OSSL_PARAM_TYPE(key, address)
|
2019-07-18 15:25:24 +08:00
|
|
|
#define OSSL_PARAM_BN(key, address, size)
|
2019-02-22 10:21:33 +08:00
|
|
|
#define OSSL_PARAM_utf8_string(key, address, size)
|
|
|
|
#define OSSL_PARAM_octet_string(key, address, size)
|
|
|
|
#define OSSL_PARAM_utf8_ptr(key, address, size)
|
|
|
|
#define OSSL_PARAM_octet_ptr(key, address, size)
|
|
|
|
#define OSSL_PARAM_END
|
|
|
|
|
2020-04-21 08:49:19 +08:00
|
|
|
#define OSSL_PARAM_UNMODIFIED
|
|
|
|
|
2021-02-18 01:41:10 +08:00
|
|
|
#define OSSL_PARAM_DEFN(key, type, addr, sz) \
|
|
|
|
{ (key), (type), (addr), (sz), OSSL_PARAM_UNMODIFIED }
|
|
|
|
|
2019-07-18 15:25:24 +08:00
|
|
|
OSSL_PARAM OSSL_PARAM_construct_TYPE(const char *key, TYPE *buf);
|
2019-02-22 10:21:33 +08:00
|
|
|
OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
|
2019-06-24 12:43:55 +08:00
|
|
|
size_t bsize);
|
2019-02-22 10:21:33 +08:00
|
|
|
OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
|
2019-06-24 12:43:55 +08:00
|
|
|
size_t bsize);
|
2019-02-22 10:21:33 +08:00
|
|
|
OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
|
2019-06-24 12:43:55 +08:00
|
|
|
size_t bsize);
|
2019-02-22 10:21:33 +08:00
|
|
|
OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
|
2019-06-24 12:43:55 +08:00
|
|
|
size_t bsize);
|
2019-02-22 10:21:33 +08:00
|
|
|
OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
|
2019-06-24 12:43:55 +08:00
|
|
|
size_t bsize);
|
2019-04-09 15:49:58 +08:00
|
|
|
OSSL_PARAM OSSL_PARAM_construct_end(void);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *array, const char *key);
|
2019-06-24 12:43:55 +08:00
|
|
|
const OSSL_PARAM *OSSL_PARAM_locate_const(const OSSL_PARAM *array,
|
|
|
|
const char *key);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-07-18 15:25:24 +08:00
|
|
|
int OSSL_PARAM_get_TYPE(const OSSL_PARAM *p, TYPE *val);
|
|
|
|
int OSSL_PARAM_set_TYPE(OSSL_PARAM *p, TYPE val);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-07-18 15:25:24 +08:00
|
|
|
int OSSL_PARAM_get_BN(const OSSL_PARAM *p, BIGNUM **val);
|
|
|
|
int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val,
|
|
|
|
size_t max_len);
|
2019-06-24 12:43:55 +08:00
|
|
|
int OSSL_PARAM_set_utf8_string(OSSL_PARAM *p, const char *val);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
int OSSL_PARAM_get_octet_string(const OSSL_PARAM *p, void **val,
|
|
|
|
size_t max_len, size_t *used_len);
|
2019-06-24 12:43:55 +08:00
|
|
|
int OSSL_PARAM_set_octet_string(OSSL_PARAM *p, const void *val, size_t len);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-07-18 15:25:24 +08:00
|
|
|
int OSSL_PARAM_get_utf8_ptr(const OSSL_PARAM *p, const char **val);
|
|
|
|
int OSSL_PARAM_set_utf8_ptr(OSSL_PARAM *p, const char *val);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-07-18 15:25:24 +08:00
|
|
|
int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, const void **val,
|
2019-02-22 10:21:33 +08:00
|
|
|
size_t *used_len);
|
2019-07-18 15:25:24 +08:00
|
|
|
int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
|
|
|
|
size_t used_len);
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2020-07-29 04:00:09 +08:00
|
|
|
int OSSL_PARAM_get_utf8_string_ptr(const OSSL_PARAM *p, const char **val);
|
|
|
|
int OSSL_PARAM_get_octet_string_ptr(const OSSL_PARAM *p, const void **val,
|
|
|
|
size_t *used_len);
|
|
|
|
|
2020-04-23 18:23:48 +08:00
|
|
|
int OSSL_PARAM_modified(const OSSL_PARAM *param);
|
|
|
|
void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *params);
|
2020-04-21 08:49:19 +08:00
|
|
|
|
2019-02-22 10:21:33 +08:00
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
A collection of utility functions that simplify and add type safety to the
|
2022-12-05 23:59:06 +08:00
|
|
|
L<OSSL_PARAM(3)> arrays. The following B<I<TYPE>> names are supported:
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
=over 1
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
double
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
int32 (int32_t)
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
int64 (int64_t)
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
long int (long)
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
2020-05-11 07:37:45 +08:00
|
|
|
time_t
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
2019-02-22 10:21:33 +08:00
|
|
|
size_t
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
uint32 (uint32_t)
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
uint64 (uint64_t)
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
unsigned int (uint)
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
unsigned long int (ulong)
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
OSSL_PARAM_TYPE() are a series of macros designed to assist initialising an
|
2022-12-05 23:59:06 +08:00
|
|
|
array of L<OSSL_PARAM(3)> structures.
|
2021-01-12 23:10:15 +08:00
|
|
|
Each of these macros defines a parameter of the specified B<I<TYPE>> with the
|
|
|
|
provided I<key> and parameter variable I<address>.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_utf8_string(), OSSL_PARAM_octet_string(), OSSL_PARAM_utf8_ptr(),
|
2019-06-24 12:43:55 +08:00
|
|
|
OSSL_PARAM_octet_ptr(), OSSL_PARAM_BN() are macros that provide support
|
|
|
|
for defining UTF8 strings, OCTET strings and big numbers.
|
2021-01-12 23:10:15 +08:00
|
|
|
A parameter with name I<key> is defined.
|
|
|
|
The storage for this parameter is at I<address> and is of I<size> bytes.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_END provides an end of parameter list marker.
|
2022-12-05 23:59:06 +08:00
|
|
|
This should terminate all L<OSSL_PARAM(3)> arrays.
|
2021-02-18 01:41:10 +08:00
|
|
|
|
|
|
|
The OSSL_PARAM_DEFN() macro provides the ability to construct a single
|
2022-12-05 23:59:06 +08:00
|
|
|
L<OSSL_PARAM(3)> (typically used in the construction of B<OSSL_PARAM> arrays). The
|
2021-02-18 01:41:10 +08:00
|
|
|
I<key>, I<type>, I<addr> and I<sz> arguments correspond to the I<key>,
|
2022-12-05 23:59:06 +08:00
|
|
|
I<data_type>, I<data> and I<data_size> fields of the L<OSSL_PARAM(3)> structure as
|
2021-02-18 01:41:10 +08:00
|
|
|
described on the L<OSSL_PARAM(3)> page.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2022-12-05 23:59:06 +08:00
|
|
|
OSSL_PARAM_construct_TYPE() are a series of functions that create L<OSSL_PARAM(3)>
|
2019-02-22 10:21:33 +08:00
|
|
|
records dynamically.
|
2021-01-12 23:10:15 +08:00
|
|
|
A parameter with name I<key> is created.
|
|
|
|
The parameter will use storage pointed to by I<buf> and return size of I<ret>.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_construct_BN() is a function that constructs a large integer
|
2022-12-05 23:59:06 +08:00
|
|
|
L<OSSL_PARAM(3)> structure.
|
2021-01-12 23:10:15 +08:00
|
|
|
A parameter with name I<key>, storage I<buf>, size I<bsize> and return
|
|
|
|
size I<rsize> is created.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_construct_utf8_string() is a function that constructs a UTF8
|
2022-12-05 23:59:06 +08:00
|
|
|
string L<OSSL_PARAM(3)> structure.
|
2021-01-12 23:10:15 +08:00
|
|
|
A parameter with name I<key>, storage I<buf> and size I<bsize> is created.
|
OSSL_PARAM: Correct the assumptions on the UTF8 string length
When the string "ABCDEFGH" is passed, what's considered its data, this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' }
or this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '\0' }
If it's passed as a pass phrase, should the terminating NUL byte be
considered part of the pass phrase, or not?
Our treatment of OSSL_PARAMs with the data type OSSL_PARAM_UTF8_STRING
set the length of the string to include the terminating NUL byte,
which is quite confusing. What should the recipient of such a string
believe?
Instead of perpetuating this confusion, we change the assumption to
set the OSSL_PARAM to the length of the string, not including the
terminating NUL byte, thereby giving it the same value as a strlen()
call would give.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14168)
2021-02-13 03:30:40 +08:00
|
|
|
If I<bsize> is zero, the string length is determined using strlen(3).
|
2021-01-12 23:10:15 +08:00
|
|
|
Generally pass zero for I<bsize> instead of calling strlen(3) yourself.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_construct_octet_string() is a function that constructs an OCTET
|
2022-12-05 23:59:06 +08:00
|
|
|
string L<OSSL_PARAM(3)> structure.
|
2021-01-12 23:10:15 +08:00
|
|
|
A parameter with name I<key>, storage I<buf> and size I<bsize> is created.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2021-08-12 00:46:07 +08:00
|
|
|
OSSL_PARAM_construct_utf8_ptr() is a function that constructs a UTF8 string
|
2022-12-05 23:59:06 +08:00
|
|
|
pointer L<OSSL_PARAM(3)> structure.
|
2021-01-12 23:10:15 +08:00
|
|
|
A parameter with name I<key>, storage pointer I<*buf> and size I<bsize>
|
2019-09-04 17:27:08 +08:00
|
|
|
is created.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2020-06-30 03:13:07 +08:00
|
|
|
OSSL_PARAM_construct_octet_ptr() is a function that constructs an OCTET string
|
2022-12-05 23:59:06 +08:00
|
|
|
pointer L<OSSL_PARAM(3)> structure.
|
2021-01-12 23:10:15 +08:00
|
|
|
A parameter with name I<key>, storage pointer I<*buf> and size I<bsize>
|
2019-09-04 17:27:08 +08:00
|
|
|
is created.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-04-09 15:49:58 +08:00
|
|
|
OSSL_PARAM_construct_end() is a function that constructs the terminating
|
2022-12-05 23:59:06 +08:00
|
|
|
L<OSSL_PARAM(3)> structure.
|
2019-04-09 15:49:58 +08:00
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
OSSL_PARAM_locate() is a function that searches an I<array> of parameters for
|
|
|
|
the one matching the I<key> name.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-06-24 12:43:55 +08:00
|
|
|
OSSL_PARAM_locate_const() behaves exactly like OSSL_PARAM_locate() except for
|
2021-01-12 23:10:15 +08:00
|
|
|
the presence of I<const> for the I<array> argument and its return value.
|
2019-06-24 12:43:55 +08:00
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
OSSL_PARAM_get_TYPE() retrieves a value of type B<I<TYPE>> from the parameter
|
|
|
|
I<p>.
|
|
|
|
The value is copied to the address I<val>.
|
2019-02-22 10:21:33 +08:00
|
|
|
Type coercion takes place as discussed in the NOTES section.
|
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
OSSL_PARAM_set_TYPE() stores a value I<val> of type B<I<TYPE>> into the
|
|
|
|
parameter I<p>.
|
2019-09-26 13:45:33 +08:00
|
|
|
If the parameter's I<data> field is NULL, then only its I<return_size> field
|
|
|
|
will be assigned the size the parameter's I<data> buffer should have.
|
2019-02-22 10:21:33 +08:00
|
|
|
Type coercion takes place as discussed in the NOTES section.
|
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
OSSL_PARAM_get_BN() retrieves a BIGNUM from the parameter pointed to by I<p>.
|
|
|
|
The BIGNUM referenced by I<val> is updated and is allocated if I<*val> is
|
|
|
|
NULL.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
OSSL_PARAM_set_BN() stores the BIGNUM I<val> into the parameter I<p>.
|
2019-09-26 13:45:33 +08:00
|
|
|
If the parameter's I<data> field is NULL, then only its I<return_size> field
|
|
|
|
will be assigned the size the parameter's I<data> buffer should have.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_get_utf8_string() retrieves a UTF8 string from the parameter
|
2021-01-12 23:10:15 +08:00
|
|
|
pointed to by I<p>.
|
OSSL_PARAM: Correct the assumptions on the UTF8 string length
When the string "ABCDEFGH" is passed, what's considered its data, this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' }
or this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '\0' }
If it's passed as a pass phrase, should the terminating NUL byte be
considered part of the pass phrase, or not?
Our treatment of OSSL_PARAMs with the data type OSSL_PARAM_UTF8_STRING
set the length of the string to include the terminating NUL byte,
which is quite confusing. What should the recipient of such a string
believe?
Instead of perpetuating this confusion, we change the assumption to
set the OSSL_PARAM to the length of the string, not including the
terminating NUL byte, thereby giving it the same value as a strlen()
call would give.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14168)
2021-02-13 03:30:40 +08:00
|
|
|
The string is stored into I<*val> with a size limit of I<max_len>,
|
2022-01-03 07:00:27 +08:00
|
|
|
which must be large enough to accommodate a terminating NUL byte,
|
2021-08-16 18:14:30 +08:00
|
|
|
otherwise this function will fail.
|
2021-08-12 00:46:07 +08:00
|
|
|
If I<*val> is NULL, memory is allocated for the string (including the
|
|
|
|
terminating NUL byte) and I<max_len> is ignored.
|
2019-02-22 10:21:33 +08:00
|
|
|
If memory is allocated by this function, it must be freed by the caller.
|
|
|
|
|
|
|
|
OSSL_PARAM_set_utf8_string() sets a UTF8 string from the parameter pointed to
|
2021-01-12 23:10:15 +08:00
|
|
|
by I<p> to the value referenced by I<val>.
|
2021-08-16 18:14:30 +08:00
|
|
|
If the parameter's I<data> field isn't NULL, its I<data_size> must indicate
|
2022-01-03 07:00:27 +08:00
|
|
|
that the buffer is large enough to accommodate the string that I<val> points at,
|
2021-08-16 18:14:30 +08:00
|
|
|
not including the terminating NUL byte, or this function will fail.
|
|
|
|
A terminating NUL byte is added only if the parameter's I<data_size> indicates
|
|
|
|
the buffer is longer than the string length, otherwise the string will not be
|
|
|
|
NUL terminated.
|
2019-09-26 13:45:33 +08:00
|
|
|
If the parameter's I<data> field is NULL, then only its I<return_size> field
|
OSSL_PARAM: Correct the assumptions on the UTF8 string length
When the string "ABCDEFGH" is passed, what's considered its data, this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' }
or this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '\0' }
If it's passed as a pass phrase, should the terminating NUL byte be
considered part of the pass phrase, or not?
Our treatment of OSSL_PARAMs with the data type OSSL_PARAM_UTF8_STRING
set the length of the string to include the terminating NUL byte,
which is quite confusing. What should the recipient of such a string
believe?
Instead of perpetuating this confusion, we change the assumption to
set the OSSL_PARAM to the length of the string, not including the
terminating NUL byte, thereby giving it the same value as a strlen()
call would give.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14168)
2021-02-13 03:30:40 +08:00
|
|
|
will be assigned the minimum size the parameter's I<data> buffer should have
|
2022-01-03 07:00:27 +08:00
|
|
|
to accommodate the string, not including a terminating NUL byte.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter
|
2021-01-12 23:10:15 +08:00
|
|
|
pointed to by I<p>.
|
|
|
|
The OCTETs are either stored into I<*val> with a length limit of I<max_len> or,
|
|
|
|
in the case when I<*val> is NULL, memory is allocated and
|
|
|
|
I<max_len> is ignored. I<*used_len> is populated with the number of OCTETs
|
|
|
|
stored. If I<val> is NULL then the OCTETS are not stored, but I<*used_len> is
|
2020-04-29 00:45:53 +08:00
|
|
|
still populated.
|
2019-02-22 10:21:33 +08:00
|
|
|
If memory is allocated by this function, it must be freed by the caller.
|
|
|
|
|
|
|
|
OSSL_PARAM_set_octet_string() sets an OCTET string from the parameter
|
2021-01-12 23:10:15 +08:00
|
|
|
pointed to by I<p> to the value referenced by I<val>.
|
2019-09-26 13:45:33 +08:00
|
|
|
If the parameter's I<data> field is NULL, then only its I<return_size> field
|
|
|
|
will be assigned the size the parameter's I<data> buffer should have.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_get_utf8_ptr() retrieves the UTF8 string pointer from the parameter
|
2021-01-12 23:10:15 +08:00
|
|
|
referenced by I<p> and stores it in I<*val>.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_set_utf8_ptr() sets the UTF8 string pointer in the parameter
|
2021-01-12 23:10:15 +08:00
|
|
|
referenced by I<p> to the values I<val>.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_get_octet_ptr() retrieves the OCTET string pointer from the parameter
|
2021-01-12 23:10:15 +08:00
|
|
|
referenced by I<p> and stores it in I<*val>.
|
|
|
|
The length of the OCTET string is stored in I<*used_len>.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
OSSL_PARAM_set_octet_ptr() sets the OCTET string pointer in the parameter
|
2021-01-12 23:10:15 +08:00
|
|
|
referenced by I<p> to the values I<val>.
|
|
|
|
The length of the OCTET string is provided by I<used_len>.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2020-07-29 04:00:09 +08:00
|
|
|
OSSL_PARAM_get_utf8_string_ptr() retrieves the pointer to a UTF8 string from
|
2021-01-12 23:10:15 +08:00
|
|
|
the parameter pointed to by I<p>, and stores that pointer in I<*val>.
|
2020-07-29 04:00:09 +08:00
|
|
|
This is different from OSSL_PARAM_get_utf8_string(), which copies the
|
|
|
|
string.
|
|
|
|
|
|
|
|
OSSL_PARAM_get_octet_string_ptr() retrieves the pointer to a octet string
|
2021-01-12 23:10:15 +08:00
|
|
|
from the parameter pointed to by I<p>, and stores that pointer in I<*val>,
|
|
|
|
along with the string's length in I<*used_len>.
|
2020-07-29 04:00:09 +08:00
|
|
|
This is different from OSSL_PARAM_get_octet_string(), which copies the
|
|
|
|
string.
|
|
|
|
|
2020-04-21 08:49:19 +08:00
|
|
|
The OSSL_PARAM_UNMODIFIED macro is used to detect if a parameter was set. On
|
|
|
|
creation, via either the macros or construct calls, the I<return_size> field
|
|
|
|
is set to this. If the parameter is set using the calls defined herein, the
|
|
|
|
I<return_size> field is changed.
|
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
OSSL_PARAM_modified() queries if the parameter I<param> has been set or not
|
2020-04-23 18:23:48 +08:00
|
|
|
using the calls defined herein.
|
2020-04-21 08:49:19 +08:00
|
|
|
|
2020-04-23 18:23:48 +08:00
|
|
|
OSSL_PARAM_set_all_unmodified() resets the unused indicator for all parameters
|
2021-01-12 23:10:15 +08:00
|
|
|
in the array I<params>.
|
2020-04-21 08:49:19 +08:00
|
|
|
|
2019-02-22 10:21:33 +08:00
|
|
|
=head1 RETURN VALUES
|
|
|
|
|
|
|
|
OSSL_PARAM_construct_TYPE(), OSSL_PARAM_construct_BN(),
|
|
|
|
OSSL_PARAM_construct_utf8_string(), OSSL_PARAM_construct_octet_string(),
|
|
|
|
OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_construct_octet_ptr()
|
2022-12-05 23:59:06 +08:00
|
|
|
return a populated L<OSSL_PARAM(3)> structure.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-06-24 12:43:55 +08:00
|
|
|
OSSL_PARAM_locate() and OSSL_PARAM_locate_const() return a pointer to
|
2022-12-05 23:59:06 +08:00
|
|
|
the matching L<OSSL_PARAM(3)> object. They return NULL on error or when
|
2021-01-12 23:10:15 +08:00
|
|
|
no object matching I<key> exists in the I<array>.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
OSSL_PARAM_modified() returns 1 if the parameter was set and 0 otherwise.
|
2020-04-21 08:49:19 +08:00
|
|
|
|
2021-01-12 23:10:15 +08:00
|
|
|
All other functions return 1 on success and 0 on failure.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
=head1 NOTES
|
|
|
|
|
2019-05-21 05:42:26 +08:00
|
|
|
Native types will be converted as required only if the value is exactly
|
|
|
|
representable by the target type or parameter.
|
2019-02-22 10:21:33 +08:00
|
|
|
Apart from that, the functions must be used appropriately for the
|
|
|
|
expected type of the parameter.
|
|
|
|
|
2021-11-26 01:45:50 +08:00
|
|
|
OSSL_PARAM_get_BN() and OSSL_PARAM_set_BN() only support nonnegative
|
|
|
|
B<BIGNUM>s when the desired data type is B<OSSL_PARAM_UNSIGNED_INTEGER>.
|
2022-12-05 23:59:06 +08:00
|
|
|
OSSL_PARAM_construct_BN() currently constructs an L<OSSL_PARAM(3)> structure
|
2021-11-26 01:45:50 +08:00
|
|
|
with the data type B<OSSL_PARAM_UNSIGNED_INTEGER>.
|
2021-11-21 16:48:05 +08:00
|
|
|
|
2019-09-26 13:45:33 +08:00
|
|
|
For OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_consstruct_octet_ptr(),
|
2022-12-05 23:59:06 +08:00
|
|
|
I<bsize> is not relevant if the purpose is to send the L<OSSL_PARAM(3)> array
|
2019-09-26 13:45:33 +08:00
|
|
|
to a I<responder>, i.e. to get parameter data back.
|
2021-01-12 23:10:15 +08:00
|
|
|
In that case, I<bsize> can safely be given zero.
|
2019-04-09 14:31:09 +08:00
|
|
|
See L<OSSL_PARAM(3)/DESCRIPTION> for further information on the
|
|
|
|
possible purposes.
|
|
|
|
|
2019-02-22 10:21:33 +08:00
|
|
|
=head1 EXAMPLES
|
|
|
|
|
|
|
|
Reusing the examples from L<OSSL_PARAM(3)> to just show how
|
2022-12-05 23:59:06 +08:00
|
|
|
L<OSSL_PARAM(3)> arrays can be handled using the macros and functions
|
2019-02-22 10:21:33 +08:00
|
|
|
defined herein.
|
|
|
|
|
|
|
|
=head2 Example 1
|
|
|
|
|
|
|
|
This example is for setting parameters on some object:
|
|
|
|
|
|
|
|
#include <openssl/core.h>
|
|
|
|
|
|
|
|
const char *foo = "some string";
|
OSSL_PARAM: Correct the assumptions on the UTF8 string length
When the string "ABCDEFGH" is passed, what's considered its data, this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' }
or this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '\0' }
If it's passed as a pass phrase, should the terminating NUL byte be
considered part of the pass phrase, or not?
Our treatment of OSSL_PARAMs with the data type OSSL_PARAM_UTF8_STRING
set the length of the string to include the terminating NUL byte,
which is quite confusing. What should the recipient of such a string
believe?
Instead of perpetuating this confusion, we change the assumption to
set the OSSL_PARAM to the length of the string, not including the
terminating NUL byte, thereby giving it the same value as a strlen()
call would give.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14168)
2021-02-13 03:30:40 +08:00
|
|
|
size_t foo_l = strlen(foo);
|
2019-02-22 10:21:33 +08:00
|
|
|
const char bar[] = "some other string";
|
|
|
|
const OSSL_PARAM set[] = {
|
2021-01-25 00:45:57 +08:00
|
|
|
OSSL_PARAM_utf8_ptr("foo", &foo, foo_l),
|
OSSL_PARAM: Correct the assumptions on the UTF8 string length
When the string "ABCDEFGH" is passed, what's considered its data, this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' }
or this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '\0' }
If it's passed as a pass phrase, should the terminating NUL byte be
considered part of the pass phrase, or not?
Our treatment of OSSL_PARAMs with the data type OSSL_PARAM_UTF8_STRING
set the length of the string to include the terminating NUL byte,
which is quite confusing. What should the recipient of such a string
believe?
Instead of perpetuating this confusion, we change the assumption to
set the OSSL_PARAM to the length of the string, not including the
terminating NUL byte, thereby giving it the same value as a strlen()
call would give.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14168)
2021-02-13 03:30:40 +08:00
|
|
|
OSSL_PARAM_utf8_string("bar", bar, sizeof(bar) - 1),
|
2019-02-22 10:21:33 +08:00
|
|
|
OSSL_PARAM_END
|
|
|
|
};
|
|
|
|
|
|
|
|
=head2 Example 2
|
|
|
|
|
2019-03-19 13:52:15 +08:00
|
|
|
This example is for requesting parameters on some object, and also
|
|
|
|
demonstrates that the requestor isn't obligated to request all
|
|
|
|
available parameters:
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
const char *foo = NULL;
|
|
|
|
char bar[1024];
|
2019-06-24 12:43:55 +08:00
|
|
|
OSSL_PARAM request[] = {
|
2021-01-25 00:45:57 +08:00
|
|
|
OSSL_PARAM_utf8_ptr("foo", &foo, 0),
|
2019-06-24 12:43:55 +08:00
|
|
|
OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
|
2019-02-22 10:21:33 +08:00
|
|
|
OSSL_PARAM_END
|
|
|
|
};
|
|
|
|
|
|
|
|
A I<responder> that receives this array (as C<params> in this example)
|
|
|
|
could fill in the parameters like this:
|
|
|
|
|
2019-06-24 12:43:55 +08:00
|
|
|
/* OSSL_PARAM *params */
|
2019-02-22 10:21:33 +08:00
|
|
|
|
2019-06-24 12:43:55 +08:00
|
|
|
OSSL_PARAM *p;
|
2019-03-19 13:52:15 +08:00
|
|
|
|
2020-11-17 16:55:49 +08:00
|
|
|
if ((p = OSSL_PARAM_locate(params, "foo")) != NULL)
|
2019-03-19 13:52:15 +08:00
|
|
|
OSSL_PARAM_set_utf8_ptr(p, "foo value");
|
2020-11-17 16:55:49 +08:00
|
|
|
if ((p = OSSL_PARAM_locate(params, "bar")) != NULL)
|
OSSL_PARAM: Correct the assumptions on the UTF8 string length
When the string "ABCDEFGH" is passed, what's considered its data, this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' }
or this?
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '\0' }
If it's passed as a pass phrase, should the terminating NUL byte be
considered part of the pass phrase, or not?
Our treatment of OSSL_PARAMs with the data type OSSL_PARAM_UTF8_STRING
set the length of the string to include the terminating NUL byte,
which is quite confusing. What should the recipient of such a string
believe?
Instead of perpetuating this confusion, we change the assumption to
set the OSSL_PARAM to the length of the string, not including the
terminating NUL byte, thereby giving it the same value as a strlen()
call would give.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14168)
2021-02-13 03:30:40 +08:00
|
|
|
OSSL_PARAM_set_utf8_string(p, "bar value");
|
2020-11-17 16:55:49 +08:00
|
|
|
if ((p = OSSL_PARAM_locate(params, "cookie")) != NULL)
|
2019-03-19 13:52:15 +08:00
|
|
|
OSSL_PARAM_set_utf8_ptr(p, "cookie value");
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
|
|
|
L<openssl-core.h(7)>, L<OSSL_PARAM(3)>
|
|
|
|
|
|
|
|
=head1 HISTORY
|
|
|
|
|
2019-07-15 21:03:44 +08:00
|
|
|
These APIs were introduced in OpenSSL 3.0.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
|
2022-05-03 18:52:38 +08:00
|
|
|
Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
|
2019-02-22 10:21:33 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
this file except in compliance with the License. You can obtain a copy
|
|
|
|
in the file LICENSE in the source distribution or at
|
|
|
|
L<https://www.openssl.org/source/license.html>.
|
|
|
|
|
|
|
|
=cut
|