OSSL_PARAM_int.pod 14 KB

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