| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | =pod | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 NAME | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  | ossl_param_bld_init, ossl_param_bld_to_param, ossl_param_bld_to_param_ex, | 
					
						
							|  |  |  | ossl_param_bld_free, ossl_param_bld_push_int, 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, ossl_param_bld_push_double, | 
					
						
							|  |  |  | ossl_param_bld_push_BN, 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =for comment generic | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  |  #include "internal/params_build.h" | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  #define OSSL_PARAM_BLD_MAX 10 | 
					
						
							|  |  |  |  typedef struct { ... } OSSL_PARAM_BLD; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  |  void ossl_param_bld_init(OSSL_PARAM_BLD *bld); | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  |  OSSL_PARAM *ossl_param_bld_to_param(OSSL_PARAM_BLD *bld); | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  |  OSSL_PARAM *ossl_param_bld_to_param_ex(OSSL_PARAM_BLD *bld, | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |                                         OSSL_PARAM *params, size_t param_n, | 
					
						
							|  |  |  |                                         void *data, size_t data_n, | 
					
						
							|  |  |  |                                         void *secure, size_t secure_n); | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  |  void ossl_param_bld_free(OSSL_PARAM *params); | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  |  int ossl_param_bld_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key, | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |                                      char *buf, size_t bsize); | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +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); | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  |  int ossl_param_bld_push_octet_string(OSSL_PARAM_BLD *bld, const char *key, | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |                                       void *buf, size_t bsize); | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +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 | 
					
						
							|  |  |  | arrays.  The B<TYPE> names are as per L<OSSL_PARAM_int(3)>. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_init() initialises the OSSL_PARAM_BLD structure so that values | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | can be added. | 
					
						
							|  |  |  | Any existing values are cleared. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_to_param() converts a built up OSSL_PARAM_BLD structure | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | B<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 | 
					
						
							|  |  |  | ossl_param_bld_free() with the functions return value. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ossl_param_bld_free() deallocates the memory allocated by | 
					
						
							|  |  |  | ossl_param_bld_to_param(). | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_to_param_ex() behaves like ossl_param_bld_to_param(), except that | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | no additional memory is allocated. | 
					
						
							|  |  |  | An OSSL_PARAM array of at least B<param_n> elements is passed in as B<params>. | 
					
						
							|  |  |  | The auxiliary storage for the parameters is a block of memory pointed to | 
					
						
							|  |  |  | by B<data> of at least B<data_n> bytes in size. | 
					
						
							|  |  |  | If required, secure memory for private BIGNUMs should be pointed to by | 
					
						
							|  |  |  | B<secure> of at least B<secure_n> bytes in size. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_push_TYPE() are a series of functions which will create | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | OSSL_PARAM objects of the specified size and correct type for the B<val> | 
					
						
							|  |  |  | argument. | 
					
						
							|  |  |  | B<val> is stored by value and an expression or auto variable can be used. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_push_BN() is a function that will create an OSSL_PARAM object | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | that holds the specified BIGNUM B<bn>. | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  | If B<bn> is marked as being securely allocated, it's OSSL_PARAM representation | 
					
						
							|  |  |  | will also be securely allocated. | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | The B<bn> argument is stored by reference and the underlying BIGNUM object | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | must exist until after ossl_param_bld_to_param() has been called. | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_push_utf8_string() is a function that will create an OSSL_PARAM | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | object that references the UTF8 string specified by B<buf>. | 
					
						
							|  |  |  | If the length of the string, B<bsize>, is zero then it will be calculated. | 
					
						
							|  |  |  | The string that B<buf> points to is stored by reference and must remain in | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | scope until after ossl_param_bld_to_param() has been called. | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_push_octet_string() is a function that will create an OSSL_PARAM | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | object that references the octet string specified by B<buf> and <bsize>. | 
					
						
							|  |  |  | The memory that B<buf> points to is stored by reference and must remain in | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | scope until after ossl_param_bld_to_param() has been called. | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_push_utf8_ptr() is a function that will create an OSSL_PARAM | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | object that references the UTF8 string specified by B<buf>. | 
					
						
							|  |  |  | If the length of the string, B<bsize>, is zero then it will be calculated. | 
					
						
							|  |  |  | The string B<buf> points to is stored by reference and must remain in | 
					
						
							|  |  |  | scope until the OSSL_PARAM array is freed. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_push_octet_ptr() is a function that will create an OSSL_PARAM | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | object that references the octet string specified by B<buf>. | 
					
						
							|  |  |  | The memory B<buf> points to is stored by reference and must remain in | 
					
						
							|  |  |  | scope until the OSSL_PARAM array is freed. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 RETURN VALUES | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  | ossl_param_bld_to_param() and ossl_param_bld_to_param_ex() return the | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | allocated OSSL_PARAM array, or NULL on error. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +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. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 NOTES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The constant B<OSSL_PARAM_BLD_MAX> specifies the maximum number of parameters | 
					
						
							|  |  |  | that can be added. | 
					
						
							|  |  |  | Exceeding this will result in the push functions returning errors. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The structure B<OSSL_PARAM_BLD> should be considered opaque and subject to | 
					
						
							|  |  |  | change between versions. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 EXAMPLES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Both examples creating an OSSL_PARAM array that contains an RSA key. | 
					
						
							|  |  |  | For both, the predefined key variables are: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BIGNUM *p, *q;  /* both prime */ | 
					
						
							|  |  |  |     BIGNUM *n;      /* = p * q */ | 
					
						
							|  |  |  |     unsigned int e; /* exponent, usually 65537 */ | 
					
						
							|  |  |  |     BIGNUM *d;      /* e^-1 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head2 Example 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This example shows how to create an OSSL_PARAM array that contains an RSA | 
					
						
							|  |  |  | private key. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     OSSL_PARAM_BLD bld; | 
					
						
							|  |  |  |     OSSL_PARAM *params; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  |     ossl_param_bld_init(&bld, &secure); | 
					
						
							|  |  |  |     if (!ossl_param_bld_push_BN(&bld, "p", p) | 
					
						
							|  |  |  |         || !ossl_param_bld_push_BN(&bld, "q", q) | 
					
						
							|  |  |  |         || !ossl_param_bld_push_uint(&bld, "e", e) | 
					
						
							|  |  |  |         || !ossl_param_bld_push_BN(&bld, "n", n) | 
					
						
							|  |  |  |         || !ossl_param_bld_push_BN(&bld, "d", d) | 
					
						
							|  |  |  |         || (params = ossl_param_bld_to_param(&bld)) == NULL) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     /* Use params */ | 
					
						
							|  |  |  |     ... | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  |     ossl_param_bld_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. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     OSSL_PARAM_BLD bld; | 
					
						
							|  |  |  |     OSSL_PARAM *params; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 15:25:24 +08:00
										 |  |  |     ossl_param_bld_init(&bld, &secure); | 
					
						
							|  |  |  |     if (!ossl_param_bld_push_BN(&bld, "n", n) | 
					
						
							|  |  |  |         || !ossl_param_bld_push_BN(&bld, "d", d) | 
					
						
							|  |  |  |         || (params = ossl_param_bld_to_param(&bld)) == NULL) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     /* Use params */ | 
					
						
							|  |  |  |     ... | 
					
						
							| 
									
										
										
										
											2019-07-18 23:14:07 +08:00
										 |  |  |     ossl_param_bld_free(params); | 
					
						
							| 
									
										
										
										
											2019-07-17 14:59:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 SEE ALSO | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | L<OSSL_PARAM_int>, L<OSSL_PARAM> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 HISTORY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The functions described here were all added in OpenSSL 3.0. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 COPYRIGHT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 |