OSSL_PARAM_BLD.pod 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 *p, *q; /* both prime */
  115. BIGNUM *n; /* = p * q */
  116. unsigned int e; /* exponent, usually 65537 */
  117. BIGNUM *d; /* e^-1 */
  118. =head2 Example 1
  119. This example shows how to create an OSSL_PARAM array that contains an RSA
  120. private key.
  121. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  122. OSSL_PARAM *params = NULL;
  123. if (bld == NULL
  124. || !OSSL_PARAM_BLD_push_BN(bld, "p", p)
  125. || !OSSL_PARAM_BLD_push_BN(bld, "q", q)
  126. || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
  127. || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
  128. || !OSSL_PARAM_BLD_push_BN(bld, "d", d)
  129. || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
  130. goto err;
  131. OSSL_PARAM_BLD_free(bld);
  132. /* Use params */
  133. ...
  134. OSSL_PARAM_free(params);
  135. =head2 Example 2
  136. This example shows how to create an OSSL_PARAM array that contains an RSA
  137. public key.
  138. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  139. OSSL_PARAM *params = NULL;
  140. if (nld == NULL
  141. || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
  142. || !OSSL_PARAM_BLD_push_BN(bld, "e", e)
  143. || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
  144. goto err;
  145. OSSL_PARAM_BLD_free(bld);
  146. /* Use params */
  147. ...
  148. OSSL_PARAM_free(params);
  149. =head1 SEE ALSO
  150. L<OSSL_PARAM_int(3)>, L<OSSL_PARAM(3)>, L<OSSL_PARAM_free(3)>
  151. =head1 HISTORY
  152. The functions described here were all added in OpenSSL 3.0.
  153. =head1 COPYRIGHT
  154. Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
  155. Licensed under the Apache License 2.0 (the "License"). You may not use
  156. this file except in compliance with the License. You can obtain a copy
  157. in the file LICENSE in the source distribution or at
  158. L<https://www.openssl.org/source/license.html>.
  159. =cut