2019-07-17 14:59:09 +08:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2020-03-27 08:33:46 +08:00
|
|
|
OSSL_PARAM_BLD, OSSL_PARAM_BLD_new, OSSL_PARAM_BLD_to_param,
|
2021-04-07 11:45:19 +08:00
|
|
|
OSSL_PARAM_BLD_free, OSSL_PARAM_BLD_push_int,
|
2020-03-27 08:33:46 +08:00
|
|
|
OSSL_PARAM_BLD_push_uint, OSSL_PARAM_BLD_push_long,
|
|
|
|
OSSL_PARAM_BLD_push_ulong, OSSL_PARAM_BLD_push_int32,
|
|
|
|
OSSL_PARAM_BLD_push_uint32, OSSL_PARAM_BLD_push_int64,
|
|
|
|
OSSL_PARAM_BLD_push_uint64, OSSL_PARAM_BLD_push_size_t,
|
2020-05-25 12:45:49 +08:00
|
|
|
OSSL_PARAM_BLD_push_time_t, OSSL_PARAM_BLD_push_double,
|
|
|
|
OSSL_PARAM_BLD_push_BN, OSSL_PARAM_BLD_push_BN_pad,
|
|
|
|
OSSL_PARAM_BLD_push_utf8_string, OSSL_PARAM_BLD_push_utf8_ptr,
|
|
|
|
OSSL_PARAM_BLD_push_octet_string, OSSL_PARAM_BLD_push_octet_ptr
|
2019-07-17 14:59:09 +08:00
|
|
|
- functions to assist in the creation of OSSL_PARAM arrays
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2019-09-29 23:10:59 +08:00
|
|
|
=for openssl generic
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2021-01-12 22:44:43 +08:00
|
|
|
#include <openssl/param_build.h>
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
typedef struct OSSL_PARAM_BLD;
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
OSSL_PARAM_BLD *OSSL_PARAM_BLD_new(void);
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld);
|
2020-03-24 13:08:00 +08:00
|
|
|
void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld);
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
int OSSL_PARAM_BLD_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
|
2019-07-17 14:59:09 +08:00
|
|
|
const BIGNUM *bn);
|
2020-03-24 12:58:57 +08:00
|
|
|
int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
|
2020-01-14 17:36:39 +08:00
|
|
|
const BIGNUM *bn, size_t sz);
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
|
2019-08-21 13:28:52 +08:00
|
|
|
const char *buf, size_t bsize);
|
2020-03-24 12:58:57 +08:00
|
|
|
int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
|
2019-07-17 14:59:09 +08:00
|
|
|
char *buf, size_t bsize);
|
2020-03-24 12:58:57 +08:00
|
|
|
int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
|
2019-08-21 13:28:52 +08:00
|
|
|
const void *buf, size_t bsize);
|
2020-03-24 12:58:57 +08:00
|
|
|
int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
|
2019-07-17 14:59:09 +08:00
|
|
|
void *buf, size_t bsize);
|
|
|
|
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
A collection of utility functions that simplify the creation of OSSL_PARAM
|
2019-09-28 13:33:38 +08:00
|
|
|
arrays. The B<I<TYPE>> names are as per L<OSSL_PARAM_int(3)>.
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
OSSL_PARAM_BLD_new() allocates and initialises a new OSSL_PARAM_BLD structure
|
|
|
|
so that values can be added.
|
2019-07-17 14:59:09 +08:00
|
|
|
Any existing values are cleared.
|
|
|
|
|
2020-03-24 13:08:00 +08:00
|
|
|
OSSL_PARAM_BLD_free() deallocates the memory allocates by OSSL_PARAM_BLD_new().
|
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_to_param() converts a built up OSSL_PARAM_BLD structure
|
2019-09-27 19:26:22 +08:00
|
|
|
I<bld> into an allocated OSSL_PARAM array.
|
2019-07-18 23:14:07 +08:00
|
|
|
The OSSL_PARAM array and all associated storage must be freed by calling
|
2021-04-07 11:45:19 +08:00
|
|
|
OSSL_PARAM_free() with the functions return value.
|
2020-03-24 13:08:00 +08:00
|
|
|
OSSL_PARAM_BLD_free() can safely be called any time after this function is.
|
2019-07-18 23:14:07 +08:00
|
|
|
|
2019-09-28 11:48:54 +08:00
|
|
|
=begin comment
|
|
|
|
|
|
|
|
POD is pretty good at recognising function names and making them appropriately
|
|
|
|
bold... however, when part of the function name is variable, we have to help
|
|
|
|
the processor along
|
|
|
|
|
|
|
|
=end comment
|
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
B<OSSL_PARAM_BLD_push_I<TYPE>>() are a series of functions which will create
|
2019-09-27 19:26:22 +08:00
|
|
|
OSSL_PARAM objects of the specified size and correct type for the I<val>
|
2019-07-17 14:59:09 +08:00
|
|
|
argument.
|
2019-09-27 19:26:22 +08:00
|
|
|
I<val> is stored by value and an expression or auto variable can be used.
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2021-11-26 01:46:32 +08:00
|
|
|
When B<I<TYPE>> denotes an integer type, signed integer types will normally
|
|
|
|
get the OSSL_PARAM type B<OSSL_PARAM_INTEGER> params.
|
|
|
|
When B<I<TYPE>> denotes an unsigned integer type will get the OSSL_PARAM type
|
|
|
|
B<OSSL_PARAM_UNSIGNED_INTEGER>.
|
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_push_BN() is a function that will create an OSSL_PARAM object
|
2019-09-27 19:26:22 +08:00
|
|
|
that holds the specified BIGNUM I<bn>.
|
2021-11-26 01:46:32 +08:00
|
|
|
When the I<bn> is zero or positive, its OSSL_PARAM type becomes
|
|
|
|
B<OSSL_PARAM_UNSIGNED_INTEGER>.
|
|
|
|
When the I<bn> is negative, its OSSL_PARAM type becomes B<OSSL_PARAM_INTEGER>.
|
2020-02-16 08:55:30 +08:00
|
|
|
If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
|
2019-07-18 23:14:07 +08:00
|
|
|
will also be securely allocated.
|
2019-09-27 19:26:22 +08:00
|
|
|
The I<bn> argument is stored by reference and the underlying BIGNUM object
|
2020-03-24 12:58:57 +08:00
|
|
|
must exist until after OSSL_PARAM_BLD_to_param() has been called.
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_push_BN_pad() is a function that will create an OSSL_PARAM object
|
2020-01-14 17:36:39 +08:00
|
|
|
that holds the specified BIGNUM I<bn>.
|
|
|
|
The object will be padded to occupy exactly I<sz> bytes, if insufficient space
|
|
|
|
is specified an error results.
|
2021-11-26 01:46:32 +08:00
|
|
|
When the I<bn> is zero or positive, its OSSL_PARAM type becomes
|
|
|
|
B<OSSL_PARAM_UNSIGNED_INTEGER>.
|
|
|
|
When the I<bn> is negative, its OSSL_PARAM type becomes B<OSSL_PARAM_INTEGER>.
|
2020-02-16 08:55:30 +08:00
|
|
|
If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
|
2020-01-14 17:36:39 +08:00
|
|
|
will also be securely allocated.
|
|
|
|
The I<bn> argument is stored by reference and the underlying BIGNUM object
|
2020-03-24 12:58:57 +08:00
|
|
|
must exist until after OSSL_PARAM_BLD_to_param() has been called.
|
2020-01-14 17:36:39 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_push_utf8_string() is a function that will create an OSSL_PARAM
|
2019-09-27 19:26:22 +08:00
|
|
|
object that references the UTF8 string specified by I<buf>.
|
2021-08-12 00:46:07 +08:00
|
|
|
The length of the string I<bsize> should not include the terminating NUL byte.
|
|
|
|
If it is zero then it will be calculated.
|
2019-09-27 19:26:22 +08:00
|
|
|
The string that I<buf> points to is stored by reference and must remain in
|
2020-03-24 12:58:57 +08:00
|
|
|
scope until after OSSL_PARAM_BLD_to_param() has been called.
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_push_octet_string() is a function that will create an OSSL_PARAM
|
2019-09-27 19:26:22 +08:00
|
|
|
object that references the octet string specified by I<buf> and <bsize>.
|
|
|
|
The memory that I<buf> points to is stored by reference and must remain in
|
2020-03-24 12:58:57 +08:00
|
|
|
scope until after OSSL_PARAM_BLD_to_param() has been called.
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_push_utf8_ptr() is a function that will create an OSSL_PARAM
|
2019-09-27 19:26:22 +08:00
|
|
|
object that references the UTF8 string specified by I<buf>.
|
2021-08-12 00:46:07 +08:00
|
|
|
The length of the string I<bsize> should not include the terminating NUL byte.
|
|
|
|
If it is zero then it will be calculated.
|
2019-09-27 19:26:22 +08:00
|
|
|
The string I<buf> points to is stored by reference and must remain in
|
2019-07-17 14:59:09 +08:00
|
|
|
scope until the OSSL_PARAM array is freed.
|
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_push_octet_ptr() is a function that will create an OSSL_PARAM
|
2019-09-27 19:26:22 +08:00
|
|
|
object that references the octet string specified by I<buf>.
|
|
|
|
The memory I<buf> points to is stored by reference and must remain in
|
2019-07-17 14:59:09 +08:00
|
|
|
scope until the OSSL_PARAM array is freed.
|
|
|
|
|
|
|
|
=head1 RETURN VALUES
|
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
OSSL_PARAM_BLD_new() returns the allocated OSSL_PARAM_BLD structure, or NULL
|
|
|
|
on error.
|
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
OSSL_PARAM_BLD_to_param() returns the allocated OSSL_PARAM array, or NULL
|
2020-02-11 07:19:19 +08:00
|
|
|
on error.
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-24 12:58:57 +08:00
|
|
|
All of the OSSL_PARAM_BLD_push_TYPE functions return 1 on success and 0
|
2019-07-17 14:59:09 +08:00
|
|
|
on error.
|
|
|
|
|
2021-11-19 20:18:34 +08:00
|
|
|
=head1 NOTES
|
|
|
|
|
2021-11-26 01:46:32 +08:00
|
|
|
OSSL_PARAM_BLD_push_BN() and OSSL_PARAM_BLD_push_BN_pad() only
|
|
|
|
support nonnegative B<BIGNUM>s. They return an error on negative
|
|
|
|
B<BIGNUM>s.
|
|
|
|
To pass signed B<BIGNUM>s, use OSSL_PARAM_BLD_push_signed_BN().
|
2021-11-19 20:18:34 +08:00
|
|
|
|
2019-07-17 14:59:09 +08:00
|
|
|
=head1 EXAMPLES
|
|
|
|
|
|
|
|
Both examples creating an OSSL_PARAM array that contains an RSA key.
|
|
|
|
For both, the predefined key variables are:
|
|
|
|
|
2022-10-20 00:12:39 +08:00
|
|
|
BIGNUM *n; /* modulus */
|
|
|
|
unsigned int e; /* public exponent */
|
|
|
|
BIGNUM *d; /* private exponent */
|
|
|
|
BIGNUM *p, *q; /* first two prime factors */
|
|
|
|
BIGNUM *dmp1, *dmq1; /* first two CRT exponents */
|
|
|
|
BIGNUM *iqmp; /* first CRT coefficient */
|
2019-07-17 14:59:09 +08:00
|
|
|
|
|
|
|
=head2 Example 1
|
|
|
|
|
|
|
|
This example shows how to create an OSSL_PARAM array that contains an RSA
|
|
|
|
private key.
|
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
|
2021-06-09 01:57:48 +08:00
|
|
|
OSSL_PARAM *params = NULL;
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
if (bld == NULL
|
2021-06-09 01:57:48 +08:00
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "n", n)
|
2022-10-20 00:12:39 +08:00
|
|
|
|| !OSSL_PARAM_BLD_push_uint(bld, "e", e)
|
2021-06-09 01:57:48 +08:00
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "d", d)
|
2022-10-20 00:12:39 +08:00
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor1", p)
|
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor2", q)
|
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent1", dmp1)
|
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent2", dmq1)
|
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "rsa-coefficient1", iqmp)
|
2021-06-09 01:57:48 +08:00
|
|
|
|| (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
|
2019-07-17 14:59:09 +08:00
|
|
|
goto err;
|
2020-03-24 13:08:00 +08:00
|
|
|
OSSL_PARAM_BLD_free(bld);
|
2019-07-17 14:59:09 +08:00
|
|
|
/* Use params */
|
|
|
|
...
|
2021-04-07 11:45:19 +08:00
|
|
|
OSSL_PARAM_free(params);
|
2019-07-17 14:59:09 +08:00
|
|
|
|
|
|
|
=head2 Example 2
|
|
|
|
|
|
|
|
This example shows how to create an OSSL_PARAM array that contains an RSA
|
|
|
|
public key.
|
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
|
2021-06-09 01:57:48 +08:00
|
|
|
OSSL_PARAM *params = NULL;
|
2019-07-17 14:59:09 +08:00
|
|
|
|
2020-03-26 07:28:01 +08:00
|
|
|
if (nld == NULL
|
|
|
|
|| !OSSL_PARAM_BLD_push_BN(bld, "n", n)
|
2022-10-20 00:12:39 +08:00
|
|
|
|| !OSSL_PARAM_BLD_push_uint(bld, "e", e)
|
2020-03-26 07:28:01 +08:00
|
|
|
|| (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
|
2019-07-17 14:59:09 +08:00
|
|
|
goto err;
|
2020-03-24 13:08:00 +08:00
|
|
|
OSSL_PARAM_BLD_free(bld);
|
2019-07-17 14:59:09 +08:00
|
|
|
/* Use params */
|
|
|
|
...
|
2021-04-07 11:45:19 +08:00
|
|
|
OSSL_PARAM_free(params);
|
2019-07-17 14:59:09 +08:00
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2021-04-07 11:45:19 +08:00
|
|
|
L<OSSL_PARAM_int(3)>, L<OSSL_PARAM(3)>, L<OSSL_PARAM_free(3)>
|
2019-07-17 14:59:09 +08:00
|
|
|
|
|
|
|
=head1 HISTORY
|
|
|
|
|
|
|
|
The functions described here were all added in OpenSSL 3.0.
|
|
|
|
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
|
2022-05-03 18:52:38 +08:00
|
|
|
Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
|
2019-07-17 14:59:09 +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
|