OSSL_PARAM_BLD.pod 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. =pod
  2. =head1 NAME
  3. OSSL_PARAM_BLD, OSSL_PARAM_BLD_new, OSSL_PARAM_BLD_to_param,
  4. OSSL_PARAM_BLD_free, OSSL_PARAM_BLD_push_int,
  5. OSSL_PARAM_BLD_push_uint, OSSL_PARAM_BLD_push_long,
  6. OSSL_PARAM_BLD_push_ulong, OSSL_PARAM_BLD_push_int32,
  7. OSSL_PARAM_BLD_push_uint32, OSSL_PARAM_BLD_push_int64,
  8. OSSL_PARAM_BLD_push_uint64, OSSL_PARAM_BLD_push_size_t,
  9. OSSL_PARAM_BLD_push_time_t, OSSL_PARAM_BLD_push_double,
  10. OSSL_PARAM_BLD_push_BN, OSSL_PARAM_BLD_push_BN_pad,
  11. OSSL_PARAM_BLD_push_utf8_string, OSSL_PARAM_BLD_push_utf8_ptr,
  12. OSSL_PARAM_BLD_push_octet_string, OSSL_PARAM_BLD_push_octet_ptr
  13. - functions to assist in the creation of OSSL_PARAM arrays
  14. =head1 SYNOPSIS
  15. =for openssl generic
  16. #include <openssl/param_build.h>
  17. typedef struct OSSL_PARAM_BLD;
  18. OSSL_PARAM_BLD *OSSL_PARAM_BLD_new(void);
  19. OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld);
  20. void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld);
  21. int OSSL_PARAM_BLD_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
  22. int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
  23. const BIGNUM *bn);
  24. int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
  25. const BIGNUM *bn, size_t sz);
  26. int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
  27. const char *buf, size_t bsize);
  28. int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
  29. char *buf, size_t bsize);
  30. int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
  31. const void *buf, size_t bsize);
  32. int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
  33. void *buf, size_t bsize);
  34. =head1 DESCRIPTION
  35. A collection of utility functions that simplify the creation of OSSL_PARAM
  36. arrays. The B<I<TYPE>> names are as per L<OSSL_PARAM_int(3)>.
  37. OSSL_PARAM_BLD_new() allocates and initialises a new OSSL_PARAM_BLD structure
  38. so that values can be added.
  39. Any existing values are cleared.
  40. OSSL_PARAM_BLD_free() deallocates the memory allocates by OSSL_PARAM_BLD_new().
  41. OSSL_PARAM_BLD_to_param() converts a built up OSSL_PARAM_BLD structure
  42. I<bld> into an allocated OSSL_PARAM array.
  43. The OSSL_PARAM array and all associated storage must be freed by calling
  44. OSSL_PARAM_free() with the functions return value.
  45. OSSL_PARAM_BLD_free() can safely be called any time after this function is.
  46. =begin comment
  47. POD is pretty good at recognising function names and making them appropriately
  48. bold... however, when part of the function name is variable, we have to help
  49. the processor along
  50. =end comment
  51. B<OSSL_PARAM_BLD_push_I<TYPE>>() are a series of functions which will create
  52. OSSL_PARAM objects of the specified size and correct type for the I<val>
  53. argument.
  54. I<val> is stored by value and an expression or auto variable can be used.
  55. When B<I<TYPE>> denotes an integer type, signed integer types will normally
  56. get the OSSL_PARAM type B<OSSL_PARAM_INTEGER> params.
  57. When B<I<TYPE>> denotes an unsigned integer type will get the OSSL_PARAM type
  58. B<OSSL_PARAM_UNSIGNED_INTEGER>.
  59. OSSL_PARAM_BLD_push_BN() is a function that will create an OSSL_PARAM object
  60. that holds the specified BIGNUM I<bn>.
  61. When the I<bn> is zero or positive, its OSSL_PARAM type becomes
  62. B<OSSL_PARAM_UNSIGNED_INTEGER>.
  63. When the I<bn> is negative, its OSSL_PARAM type becomes B<OSSL_PARAM_INTEGER>.
  64. If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
  65. will also be securely allocated.
  66. The I<bn> argument is stored by reference and the underlying BIGNUM object
  67. must exist until after OSSL_PARAM_BLD_to_param() has been called.
  68. OSSL_PARAM_BLD_push_BN_pad() is a function that will create an OSSL_PARAM object
  69. that holds the specified BIGNUM I<bn>.
  70. The object will be padded to occupy exactly I<sz> bytes, if insufficient space
  71. is specified an error results.
  72. When the I<bn> is zero or positive, its OSSL_PARAM type becomes
  73. B<OSSL_PARAM_UNSIGNED_INTEGER>.
  74. When the I<bn> is negative, its OSSL_PARAM type becomes B<OSSL_PARAM_INTEGER>.
  75. If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
  76. will also be securely allocated.
  77. The I<bn> argument is stored by reference and the underlying BIGNUM object
  78. must exist until after OSSL_PARAM_BLD_to_param() has been called.
  79. OSSL_PARAM_BLD_push_utf8_string() is a function that will create an OSSL_PARAM
  80. object that references the UTF8 string specified by I<buf>.
  81. The length of the string I<bsize> should not include the terminating NUL byte.
  82. If it is zero then it will be calculated.
  83. The string that I<buf> points to is stored by reference and must remain in
  84. scope until after OSSL_PARAM_BLD_to_param() has been called.
  85. OSSL_PARAM_BLD_push_octet_string() is a function that will create an OSSL_PARAM
  86. object that references the octet string specified by I<buf> and <bsize>.
  87. The memory that I<buf> points to is stored by reference and must remain in
  88. scope until after OSSL_PARAM_BLD_to_param() has been called.
  89. OSSL_PARAM_BLD_push_utf8_ptr() is a function that will create an OSSL_PARAM
  90. object that references the UTF8 string specified by I<buf>.
  91. The length of the string I<bsize> should not include the terminating NUL byte.
  92. If it is zero then it will be calculated.
  93. The string I<buf> points to is stored by reference and must remain in
  94. scope until the OSSL_PARAM array is freed.
  95. OSSL_PARAM_BLD_push_octet_ptr() is a function that will create an OSSL_PARAM
  96. object that references the octet string specified by I<buf>.
  97. The memory I<buf> points to is stored by reference and must remain in
  98. scope until the OSSL_PARAM array is freed.
  99. =head1 RETURN VALUES
  100. OSSL_PARAM_BLD_new() returns the allocated OSSL_PARAM_BLD structure, or NULL
  101. on error.
  102. OSSL_PARAM_BLD_to_param() returns the allocated OSSL_PARAM array, or NULL
  103. on error.
  104. All of the OSSL_PARAM_BLD_push_TYPE functions return 1 on success and 0
  105. on error.
  106. =head1 NOTES
  107. OSSL_PARAM_BLD_push_BN() and OSSL_PARAM_BLD_push_BN_pad() only
  108. support nonnegative B<BIGNUM>s. They return an error on negative
  109. B<BIGNUM>s.
  110. To pass signed B<BIGNUM>s, use OSSL_PARAM_BLD_push_signed_BN().
  111. =head1 EXAMPLES
  112. Both examples creating an OSSL_PARAM array that contains an RSA key.
  113. For both, the predefined key variables are:
  114. BIGNUM *n; /* modulus */
  115. unsigned int e; /* public exponent */
  116. BIGNUM *d; /* private exponent */
  117. BIGNUM *p, *q; /* first two prime factors */
  118. BIGNUM *dmp1, *dmq1; /* first two CRT exponents */
  119. BIGNUM *iqmp; /* first CRT coefficient */
  120. =head2 Example 1
  121. This example shows how to create an OSSL_PARAM array that contains an RSA
  122. private key.
  123. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  124. OSSL_PARAM *params = NULL;
  125. if (bld == NULL
  126. || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
  127. || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
  128. || !OSSL_PARAM_BLD_push_BN(bld, "d", d)
  129. || !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor1", p)
  130. || !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor2", q)
  131. || !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent1", dmp1)
  132. || !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent2", dmq1)
  133. || !OSSL_PARAM_BLD_push_BN(bld, "rsa-coefficient1", iqmp)
  134. || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
  135. goto err;
  136. OSSL_PARAM_BLD_free(bld);
  137. /* Use params */
  138. ...
  139. OSSL_PARAM_free(params);
  140. =head2 Example 2
  141. This example shows how to create an OSSL_PARAM array that contains an RSA
  142. public key.
  143. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  144. OSSL_PARAM *params = NULL;
  145. if (nld == NULL
  146. || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
  147. || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
  148. || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
  149. goto err;
  150. OSSL_PARAM_BLD_free(bld);
  151. /* Use params */
  152. ...
  153. OSSL_PARAM_free(params);
  154. =head1 SEE ALSO
  155. L<OSSL_PARAM_int(3)>, L<OSSL_PARAM(3)>, L<OSSL_PARAM_free(3)>
  156. =head1 HISTORY
  157. The functions described here were all added in OpenSSL 3.0.
  158. =head1 COPYRIGHT
  159. Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
  160. Licensed under the Apache License 2.0 (the "License"). You may not use
  161. this file except in compliance with the License. You can obtain a copy
  162. in the file LICENSE in the source distribution or at
  163. L<https://www.openssl.org/source/license.html>.
  164. =cut