OSSL_PARAM_int.pod 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. =pod
  2. =head1 NAME
  3. OSSL_PARAM_double, OSSL_PARAM_int, OSSL_PARAM_int32, OSSL_PARAM_int64,
  4. OSSL_PARAM_long, OSSL_PARAM_size_t, OSSL_PARAM_uint, OSSL_PARAM_uint32,
  5. OSSL_PARAM_uint64, OSSL_PARAM_ulong, OSSL_PARAM_BN, OSSL_PARAM_utf8_string,
  6. OSSL_PARAM_octet_string, OSSL_PARAM_utf8_ptr, OSSL_PARAM_octet_ptr,
  7. OSSL_PARAM_END,
  8. OSSL_PARAM_construct_double, OSSL_PARAM_construct_int,
  9. OSSL_PARAM_construct_int32, OSSL_PARAM_construct_int64,
  10. OSSL_PARAM_construct_long, OSSL_PARAM_construct_size_t,
  11. OSSL_PARAM_construct_uint, OSSL_PARAM_construct_uint32,
  12. OSSL_PARAM_construct_uint64, OSSL_PARAM_construct_ulong,
  13. OSSL_PARAM_construct_BN, OSSL_PARAM_construct_utf8_string,
  14. OSSL_PARAM_construct_utf8_ptr, OSSL_PARAM_construct_octet_string,
  15. OSSL_PARAM_construct_octet_ptr, OSSL_PARAM_construct_end,
  16. OSSL_PARAM_locate, OSSL_PARAM_locate_const,
  17. OSSL_PARAM_get_double, OSSL_PARAM_get_int, OSSL_PARAM_get_int32,
  18. OSSL_PARAM_get_int64, OSSL_PARAM_get_long, OSSL_PARAM_get_size_t,
  19. OSSL_PARAM_get_uint, OSSL_PARAM_get_uint32, OSSL_PARAM_get_uint64,
  20. OSSL_PARAM_get_ulong, OSSL_PARAM_get_BN, OSSL_PARAM_get_utf8_string,
  21. OSSL_PARAM_get_octet_string, OSSL_PARAM_get_utf8_ptr,
  22. OSSL_PARAM_get_octet_ptr,
  23. OSSL_PARAM_set_double, OSSL_PARAM_set_int, OSSL_PARAM_set_int32,
  24. OSSL_PARAM_set_int64, OSSL_PARAM_set_long, OSSL_PARAM_set_size_t,
  25. OSSL_PARAM_set_uint, OSSL_PARAM_set_uint32, OSSL_PARAM_set_uint64,
  26. OSSL_PARAM_set_ulong, OSSL_PARAM_set_BN, OSSL_PARAM_set_utf8_string,
  27. OSSL_PARAM_set_octet_string, OSSL_PARAM_set_utf8_ptr,
  28. OSSL_PARAM_set_octet_ptr
  29. - OSSL_PARAM helpers
  30. =head1 SYNOPSIS
  31. =for openssl generic
  32. #include <openssl/params.h>
  33. /*
  34. * TYPE in function names is one of:
  35. * double, int, int32, int64, long, size_t, uint, uint32, uint64, ulong
  36. * Corresponding TYPE in function arguments is one of:
  37. * double, int, int32_t, int64_t, long, size_t, unsigned int, uint32_t,
  38. * uint64_t, unsigned long
  39. */
  40. #define OSSL_PARAM_TYPE(key, address)
  41. #define OSSL_PARAM_BN(key, address, size)
  42. #define OSSL_PARAM_utf8_string(key, address, size)
  43. #define OSSL_PARAM_octet_string(key, address, size)
  44. #define OSSL_PARAM_utf8_ptr(key, address, size)
  45. #define OSSL_PARAM_octet_ptr(key, address, size)
  46. #define OSSL_PARAM_END
  47. OSSL_PARAM OSSL_PARAM_construct_TYPE(const char *key, TYPE *buf);
  48. OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
  49. size_t bsize);
  50. OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
  51. size_t bsize);
  52. OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
  53. size_t bsize);
  54. OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
  55. size_t bsize);
  56. OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
  57. size_t bsize);
  58. OSSL_PARAM OSSL_PARAM_construct_end(void);
  59. OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *array, const char *key);
  60. const OSSL_PARAM *OSSL_PARAM_locate_const(const OSSL_PARAM *array,
  61. const char *key);
  62. int OSSL_PARAM_get_TYPE(const OSSL_PARAM *p, TYPE *val);
  63. int OSSL_PARAM_set_TYPE(OSSL_PARAM *p, TYPE val);
  64. int OSSL_PARAM_get_BN(const OSSL_PARAM *p, BIGNUM **val);
  65. int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val);
  66. int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val,
  67. size_t max_len);
  68. int OSSL_PARAM_set_utf8_string(OSSL_PARAM *p, const char *val);
  69. int OSSL_PARAM_get_octet_string(const OSSL_PARAM *p, void **val,
  70. size_t max_len, size_t *used_len);
  71. int OSSL_PARAM_set_octet_string(OSSL_PARAM *p, const void *val, size_t len);
  72. int OSSL_PARAM_get_utf8_ptr(const OSSL_PARAM *p, const char **val);
  73. int OSSL_PARAM_set_utf8_ptr(OSSL_PARAM *p, const char *val);
  74. int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, const void **val,
  75. size_t *used_len);
  76. int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
  77. size_t used_len);
  78. =head1 DESCRIPTION
  79. A collection of utility functions that simplify and add type safety to the
  80. OSSL_PARAM arrays. The following B<TYPE> names are supported:
  81. =over 1
  82. =item *
  83. double
  84. =item *
  85. int
  86. =item *
  87. int32 (int32_t)
  88. =item *
  89. int64 (int64_t)
  90. =item *
  91. long int (long)
  92. =item *
  93. size_t
  94. =item *
  95. uint32 (uint32_t)
  96. =item *
  97. uint64 (uint64_t)
  98. =item *
  99. unsigned int (uint)
  100. =item *
  101. unsigned long int (ulong)
  102. =back
  103. OSSL_PARAM_TYPE() are a series of macros designed to assist initialising an
  104. array of OSSL_PARAM structures.
  105. Each of these macros defines a parameter of the specified B<TYPE> with the
  106. provided B<key> and parameter variable B<address>.
  107. OSSL_PARAM_utf8_string(), OSSL_PARAM_octet_string(), OSSL_PARAM_utf8_ptr(),
  108. OSSL_PARAM_octet_ptr(), OSSL_PARAM_BN() are macros that provide support
  109. for defining UTF8 strings, OCTET strings and big numbers.
  110. A parameter with name B<key> is defined.
  111. The storage for this parameter is at B<address> and is of B<size> bytes.
  112. OSSL_PARAM_END provides an end of parameter list marker.
  113. This should terminate all OSSL_PARAM arrays.
  114. OSSL_PARAM_construct_TYPE() are a series of functions that create OSSL_PARAM
  115. records dynamically.
  116. A parameter with name B<key> is created.
  117. The parameter will use storage pointed to by B<buf> and return size of B<ret>.
  118. OSSL_PARAM_construct_BN() is a function that constructs a large integer
  119. OSSL_PARAM structure.
  120. A parameter with name B<key>, storage B<buf>, size B<bsize> and return
  121. size B<rsize> is created.
  122. OSSL_PARAM_construct_utf8_string() is a function that constructs a UTF8
  123. string OSSL_PARAM structure.
  124. A parameter with name B<key>, storage B<buf> and size B<bsize> is created.
  125. If B<bsize> is zero, the string length is determined using strlen(3).
  126. OSSL_PARAM_construct_octet_string() is a function that constructs an OCTET
  127. string OSSL_PARAM structure.
  128. A parameter with name B<key>, storage B<buf> and size B<bsize> is created.
  129. OSSL_PARAM_construct_utf8_ptr() is a function that constructes a UTF string
  130. pointer OSSL_PARAM structure.
  131. A parameter with name B<key>, storage pointer B<*buf> and size B<bsize>
  132. is created.
  133. OSSL_PARAM_construct_octet_ptr() is a function that constructes an OCTET string
  134. pointer OSSL_PARAM structure.
  135. A parameter with name B<key>, storage pointer B<*buf> and size B<bsize>
  136. is created.
  137. OSSL_PARAM_construct_end() is a function that constructs the terminating
  138. OSSL_PARAM structure.
  139. OSSL_PARAM_locate() is a function that searches an B<array> of parameters for
  140. the one matching the B<key> name.
  141. OSSL_PARAM_locate_const() behaves exactly like OSSL_PARAM_locate() except for
  142. the presence of I<const> for the B<array> argument and its return value.
  143. OSSL_PARAM_get_TYPE() retrieves a value of type B<TYPE> from the parameter B<p>.
  144. The value is copied to the address B<val>.
  145. Type coercion takes place as discussed in the NOTES section.
  146. OSSL_PARAM_set_TYPE() stores a value B<val> of type B<TYPE> into the parameter
  147. B<p>.
  148. If the parameter's I<data> field is NULL, then only its I<return_size> field
  149. will be assigned the size the parameter's I<data> buffer should have.
  150. Type coercion takes place as discussed in the NOTES section.
  151. OSSL_PARAM_get_BN() retrieves a BIGNUM from the parameter pointed to by B<p>.
  152. The BIGNUM referenced by B<val> is updated and is allocated if B<*val> is
  153. B<NULL>.
  154. OSSL_PARAM_set_BN() stores the BIGNUM B<val> into the parameter B<p>.
  155. If the parameter's I<data> field is NULL, then only its I<return_size> field
  156. will be assigned the size the parameter's I<data> buffer should have.
  157. OSSL_PARAM_get_utf8_string() retrieves a UTF8 string from the parameter
  158. pointed to by B<p>.
  159. The string is either stored into B<*val> with a length limit of B<max_len> or,
  160. in the case when B<*val> is B<NULL>, memory is allocated for the string and
  161. B<max_len> is ignored.
  162. If memory is allocated by this function, it must be freed by the caller.
  163. OSSL_PARAM_set_utf8_string() sets a UTF8 string from the parameter pointed to
  164. by B<p> to the value referenced by B<val>.
  165. If the parameter's I<data> field is NULL, then only its I<return_size> field
  166. will be assigned the size the parameter's I<data> buffer should have.
  167. OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter
  168. pointed to by B<p>.
  169. The OCTETs are either stored into B<*val> with a length limit of B<max_len> or,
  170. in the case when B<*val> is B<NULL>, memory is allocated and
  171. B<max_len> is ignored.
  172. If memory is allocated by this function, it must be freed by the caller.
  173. OSSL_PARAM_set_octet_string() sets an OCTET string from the parameter
  174. pointed to by B<p> to the value referenced by B<val>.
  175. If the parameter's I<data> field is NULL, then only its I<return_size> field
  176. will be assigned the size the parameter's I<data> buffer should have.
  177. OSSL_PARAM_get_utf8_ptr() retrieves the UTF8 string pointer from the parameter
  178. referenced by B<p> and stores it in B<*val>.
  179. OSSL_PARAM_set_utf8_ptr() sets the UTF8 string pointer in the parameter
  180. referenced by B<p> to the values B<val>.
  181. OSSL_PARAM_get_octet_ptr() retrieves the OCTET string pointer from the parameter
  182. referenced by B<p> and stores it in B<*val>.
  183. The length of the OCTET string is stored in B<*used_len>.
  184. OSSL_PARAM_set_octet_ptr() sets the OCTET string pointer in the parameter
  185. referenced by B<p> to the values B<val>.
  186. The length of the OCTET string is provided by B<used_len>.
  187. =head1 RETURN VALUES
  188. OSSL_PARAM_construct_TYPE(), OSSL_PARAM_construct_BN(),
  189. OSSL_PARAM_construct_utf8_string(), OSSL_PARAM_construct_octet_string(),
  190. OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_construct_octet_ptr()
  191. return a populated OSSL_PARAM structure.
  192. OSSL_PARAM_locate() and OSSL_PARAM_locate_const() return a pointer to
  193. the matching OSSL_PARAM object. They return B<NULL> on error or when
  194. no object matching B<key> exists in the B<array>.
  195. All other functions return B<1> on success and B<0> on failure.
  196. =head1 NOTES
  197. Native types will be converted as required only if the value is exactly
  198. representable by the target type or parameter.
  199. Apart from that, the functions must be used appropriately for the
  200. expected type of the parameter.
  201. For OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_consstruct_octet_ptr(),
  202. B<bsize> is not relevant if the purpose is to send the B<OSSL_PARAM> array
  203. to a I<responder>, i.e. to get parameter data back.
  204. In that case, B<bsize> can safely be given zero.
  205. See L<OSSL_PARAM(3)/DESCRIPTION> for further information on the
  206. possible purposes.
  207. =head1 EXAMPLES
  208. Reusing the examples from L<OSSL_PARAM(3)> to just show how
  209. C<OSSL_PARAM> arrays can be handled using the macros and functions
  210. defined herein.
  211. =head2 Example 1
  212. This example is for setting parameters on some object:
  213. #include <openssl/core.h>
  214. const char *foo = "some string";
  215. size_t foo_l = strlen(foo) + 1;
  216. const char bar[] = "some other string";
  217. const OSSL_PARAM set[] = {
  218. OSSL_PARAM_utf8_ptr("foo", foo, foo_l),
  219. OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
  220. OSSL_PARAM_END
  221. };
  222. =head2 Example 2
  223. This example is for requesting parameters on some object, and also
  224. demonstrates that the requestor isn't obligated to request all
  225. available parameters:
  226. const char *foo = NULL;
  227. char bar[1024];
  228. OSSL_PARAM request[] = {
  229. OSSL_PARAM_utf8_ptr("foo", foo, 0),
  230. OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
  231. OSSL_PARAM_END
  232. };
  233. A I<responder> that receives this array (as C<params> in this example)
  234. could fill in the parameters like this:
  235. /* OSSL_PARAM *params */
  236. OSSL_PARAM *p;
  237. if ((p = OSSL_PARAM_locate(params, "foo")) == NULL)
  238. OSSL_PARAM_set_utf8_ptr(p, "foo value");
  239. if ((p = OSSL_PARAM_locate(params, "bar")) == NULL)
  240. OSSL_PARAM_set_utf8_ptr(p, "bar value");
  241. if ((p = OSSL_PARAM_locate(params, "cookie")) == NULL)
  242. OSSL_PARAM_set_utf8_ptr(p, "cookie value");
  243. =head1 SEE ALSO
  244. L<openssl-core.h(7)>, L<OSSL_PARAM(3)>
  245. =head1 HISTORY
  246. These APIs were introduced in OpenSSL 3.0.
  247. =head1 COPYRIGHT
  248. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  249. Licensed under the Apache License 2.0 (the "License"). You may not use
  250. this file except in compliance with the License. You can obtain a copy
  251. in the file LICENSE in the source distribution or at
  252. L<https://www.openssl.org/source/license.html>.
  253. =cut