OSSL_PARAM_BLD.pod 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. =pod
  2. =head1 NAME
  3. OSSL_PARAM_BLD, OSSL_PARAM_BLD_new, OSSL_PARAM_BLD_to_param,
  4. OSSL_PARAM_BLD_free_params, 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_params(OSSL_PARAM *params);
  21. void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld);
  22. int OSSL_PARAM_BLD_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
  23. int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
  24. const BIGNUM *bn);
  25. int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
  26. const BIGNUM *bn, size_t sz);
  27. int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
  28. const char *buf, size_t bsize);
  29. int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
  30. char *buf, size_t bsize);
  31. int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
  32. const void *buf, size_t bsize);
  33. int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
  34. void *buf, size_t bsize);
  35. =head1 DESCRIPTION
  36. A collection of utility functions that simplify the creation of OSSL_PARAM
  37. arrays. The B<I<TYPE>> names are as per L<OSSL_PARAM_int(3)>.
  38. OSSL_PARAM_BLD_new() allocates and initialises a new OSSL_PARAM_BLD structure
  39. so that values can be added.
  40. Any existing values are cleared.
  41. OSSL_PARAM_BLD_free() deallocates the memory allocates by OSSL_PARAM_BLD_new().
  42. OSSL_PARAM_BLD_to_param() converts a built up OSSL_PARAM_BLD structure
  43. I<bld> into an allocated OSSL_PARAM array.
  44. The OSSL_PARAM array and all associated storage must be freed by calling
  45. OSSL_PARAM_BLD_free_params() with the functions return value.
  46. OSSL_PARAM_BLD_free() can safely be called any time after this function is.
  47. OSSL_PARAM_BLD_free_params() deallocates the memory allocated by
  48. OSSL_PARAM_BLD_to_param().
  49. =begin comment
  50. POD is pretty good at recognising function names and making them appropriately
  51. bold... however, when part of the function name is variable, we have to help
  52. the processor along
  53. =end comment
  54. B<OSSL_PARAM_BLD_push_I<TYPE>>() are a series of functions which will create
  55. OSSL_PARAM objects of the specified size and correct type for the I<val>
  56. argument.
  57. I<val> is stored by value and an expression or auto variable can be used.
  58. OSSL_PARAM_BLD_push_BN() is a function that will create an OSSL_PARAM object
  59. that holds the specified BIGNUM I<bn>.
  60. If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
  61. will also be securely allocated.
  62. The I<bn> argument is stored by reference and the underlying BIGNUM object
  63. must exist until after OSSL_PARAM_BLD_to_param() has been called.
  64. OSSL_PARAM_BLD_push_BN_pad() is a function that will create an OSSL_PARAM object
  65. that holds the specified BIGNUM I<bn>.
  66. The object will be padded to occupy exactly I<sz> bytes, if insufficient space
  67. is specified an error results.
  68. If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
  69. will also be securely allocated.
  70. The I<bn> argument is stored by reference and the underlying BIGNUM object
  71. must exist until after OSSL_PARAM_BLD_to_param() has been called.
  72. OSSL_PARAM_BLD_push_utf8_string() is a function that will create an OSSL_PARAM
  73. object that references the UTF8 string specified by I<buf>.
  74. If the length of the string, I<bsize>, is zero then it will be calculated.
  75. The string that I<buf> points to is stored by reference and must remain in
  76. scope until after OSSL_PARAM_BLD_to_param() has been called.
  77. OSSL_PARAM_BLD_push_octet_string() is a function that will create an OSSL_PARAM
  78. object that references the octet string specified by I<buf> and <bsize>.
  79. The memory that I<buf> points to is stored by reference and must remain in
  80. scope until after OSSL_PARAM_BLD_to_param() has been called.
  81. OSSL_PARAM_BLD_push_utf8_ptr() is a function that will create an OSSL_PARAM
  82. object that references the UTF8 string specified by I<buf>.
  83. If the length of the string, I<bsize>, is zero then it will be calculated.
  84. The string I<buf> points to is stored by reference and must remain in
  85. scope until the OSSL_PARAM array is freed.
  86. OSSL_PARAM_BLD_push_octet_ptr() is a function that will create an OSSL_PARAM
  87. object that references the octet string specified by I<buf>.
  88. The memory I<buf> points to is stored by reference and must remain in
  89. scope until the OSSL_PARAM array is freed.
  90. =head1 RETURN VALUES
  91. OSSL_PARAM_BLD_new() returns the allocated OSSL_PARAM_BLD structure, or NULL
  92. on error.
  93. OSSL_PARAM_BLD_to_param() returns the allocated OSSL_PARAM array, or NULL
  94. on error.
  95. All of the OSSL_PARAM_BLD_push_TYPE functions return 1 on success and 0
  96. on error.
  97. =head1 EXAMPLES
  98. Both examples creating an OSSL_PARAM array that contains an RSA key.
  99. For both, the predefined key variables are:
  100. BIGNUM *p, *q; /* both prime */
  101. BIGNUM *n; /* = p * q */
  102. unsigned int e; /* exponent, usually 65537 */
  103. BIGNUM *d; /* e^-1 */
  104. =head2 Example 1
  105. This example shows how to create an OSSL_PARAM array that contains an RSA
  106. private key.
  107. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  108. OSSL_PARAM *params;
  109. if (bld == NULL
  110. || !OSSL_PARAM_BLD_push_BN(&bld, "p", p)
  111. || !OSSL_PARAM_BLD_push_BN(&bld, "q", q)
  112. || !OSSL_PARAM_BLD_push_uint(&bld, "e", e)
  113. || !OSSL_PARAM_BLD_push_BN(&bld, "n", n)
  114. || !OSSL_PARAM_BLD_push_BN(&bld, "d", d)
  115. || (params = OSSL_PARAM_BLD_to_param(&bld)) == NULL)
  116. goto err;
  117. OSSL_PARAM_BLD_free(bld);
  118. /* Use params */
  119. ...
  120. OSSL_PARAM_BLD_free_params(params);
  121. =head2 Example 2
  122. This example shows how to create an OSSL_PARAM array that contains an RSA
  123. public key.
  124. OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  125. OSSL_PARAM *params;
  126. if (nld == NULL
  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_BLD_free_params(params);
  135. =head1 SEE ALSO
  136. L<OSSL_PARAM_int(3)>, L<OSSL_PARAM(3)>
  137. =head1 HISTORY
  138. The functions described here were all added in OpenSSL 3.0.
  139. =head1 COPYRIGHT
  140. Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  141. Licensed under the Apache License 2.0 (the "License"). You may not use
  142. this file except in compliance with the License. You can obtain a copy
  143. in the file LICENSE in the source distribution or at
  144. L<https://www.openssl.org/source/license.html>.
  145. =cut