OSSL_PARAM_int.pod 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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<I<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<I<TYPE>> with the
  118. provided I<key> and parameter variable I<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 I<key> is defined.
  123. The storage for this parameter is at I<address> and is of I<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 I<key> is created.
  129. The parameter will use storage pointed to by I<buf> and return size of I<ret>.
  130. OSSL_PARAM_construct_BN() is a function that constructs a large integer
  131. OSSL_PARAM structure.
  132. A parameter with name I<key>, storage I<buf>, size I<bsize> and return
  133. size I<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 I<key>, storage I<buf> and size I<bsize> is created.
  137. If I<bsize> is zero, the string length is determined using strlen(3) + 1 for the
  138. null termination byte.
  139. Generally pass zero for I<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 I<key>, storage I<buf> and size I<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 I<key>, storage pointer I<*buf> and size I<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 I<key>, storage pointer I<*buf> and size I<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 I<array> of parameters for
  154. the one matching the I<key> name.
  155. OSSL_PARAM_locate_const() behaves exactly like OSSL_PARAM_locate() except for
  156. the presence of I<const> for the I<array> argument and its return value.
  157. OSSL_PARAM_get_TYPE() retrieves a value of type B<I<TYPE>> from the parameter
  158. I<p>.
  159. The value is copied to the address I<val>.
  160. Type coercion takes place as discussed in the NOTES section.
  161. OSSL_PARAM_set_TYPE() stores a value I<val> of type B<I<TYPE>> into the
  162. parameter I<p>.
  163. If the parameter's I<data> field is NULL, then only its I<return_size> field
  164. will be assigned the size the parameter's I<data> buffer should have.
  165. Type coercion takes place as discussed in the NOTES section.
  166. OSSL_PARAM_get_BN() retrieves a BIGNUM from the parameter pointed to by I<p>.
  167. The BIGNUM referenced by I<val> is updated and is allocated if I<*val> is
  168. NULL.
  169. OSSL_PARAM_set_BN() stores the BIGNUM I<val> into the parameter I<p>.
  170. If the parameter's I<data> field is NULL, then only its I<return_size> field
  171. will be assigned the size the parameter's I<data> buffer should have.
  172. OSSL_PARAM_get_utf8_string() retrieves a UTF8 string from the parameter
  173. pointed to by I<p>.
  174. The string is either stored into I<*val> with a length limit of I<max_len> or,
  175. in the case when I<*val> is NULL, memory is allocated for the string and
  176. I<max_len> is ignored.
  177. If memory is allocated by this function, it must be freed by the caller.
  178. OSSL_PARAM_set_utf8_string() sets a UTF8 string from the parameter pointed to
  179. by I<p> to the value referenced by I<val>.
  180. If the parameter's I<data> field is NULL, then only its I<return_size> field
  181. will be assigned the size the parameter's I<data> buffer should have.
  182. OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter
  183. pointed to by I<p>.
  184. The OCTETs are either stored into I<*val> with a length limit of I<max_len> or,
  185. in the case when I<*val> is NULL, memory is allocated and
  186. I<max_len> is ignored. I<*used_len> is populated with the number of OCTETs
  187. stored. If I<val> is NULL then the OCTETS are not stored, but I<*used_len> is
  188. still populated.
  189. If memory is allocated by this function, it must be freed by the caller.
  190. OSSL_PARAM_set_octet_string() sets an OCTET string from the parameter
  191. pointed to by I<p> to the value referenced by I<val>.
  192. If the parameter's I<data> field is NULL, then only its I<return_size> field
  193. will be assigned the size the parameter's I<data> buffer should have.
  194. OSSL_PARAM_get_utf8_ptr() retrieves the UTF8 string pointer from the parameter
  195. referenced by I<p> and stores it in I<*val>.
  196. OSSL_PARAM_set_utf8_ptr() sets the UTF8 string pointer in the parameter
  197. referenced by I<p> to the values I<val>.
  198. OSSL_PARAM_get_octet_ptr() retrieves the OCTET string pointer from the parameter
  199. referenced by I<p> and stores it in I<*val>.
  200. The length of the OCTET string is stored in I<*used_len>.
  201. OSSL_PARAM_set_octet_ptr() sets the OCTET string pointer in the parameter
  202. referenced by I<p> to the values I<val>.
  203. The length of the OCTET string is provided by I<used_len>.
  204. OSSL_PARAM_get_utf8_string_ptr() retrieves the pointer to a UTF8 string from
  205. the parameter pointed to by I<p>, and stores that pointer in I<*val>.
  206. This is different from OSSL_PARAM_get_utf8_string(), which copies the
  207. string.
  208. OSSL_PARAM_get_octet_string_ptr() retrieves the pointer to a octet string
  209. from the parameter pointed to by I<p>, and stores that pointer in I<*val>,
  210. along with the string's length in I<*used_len>.
  211. This is different from OSSL_PARAM_get_octet_string(), which copies the
  212. string.
  213. The OSSL_PARAM_UNMODIFIED macro is used to detect if a parameter was set. On
  214. creation, via either the macros or construct calls, the I<return_size> field
  215. is set to this. If the parameter is set using the calls defined herein, the
  216. I<return_size> field is changed.
  217. OSSL_PARAM_modified() queries if the parameter I<param> has been set or not
  218. using the calls defined herein.
  219. OSSL_PARAM_set_all_unmodified() resets the unused indicator for all parameters
  220. in the array I<params>.
  221. =head1 RETURN VALUES
  222. OSSL_PARAM_construct_TYPE(), OSSL_PARAM_construct_BN(),
  223. OSSL_PARAM_construct_utf8_string(), OSSL_PARAM_construct_octet_string(),
  224. OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_construct_octet_ptr()
  225. return a populated OSSL_PARAM structure.
  226. OSSL_PARAM_locate() and OSSL_PARAM_locate_const() return a pointer to
  227. the matching OSSL_PARAM object. They return NULL on error or when
  228. no object matching I<key> exists in the I<array>.
  229. OSSL_PARAM_modified() returns 1 if the parameter was set and 0 otherwise.
  230. All other functions return 1 on success and 0 on failure.
  231. =head1 NOTES
  232. Native types will be converted as required only if the value is exactly
  233. representable by the target type or parameter.
  234. Apart from that, the functions must be used appropriately for the
  235. expected type of the parameter.
  236. For OSSL_PARAM_construct_utf8_ptr() and OSSL_PARAM_consstruct_octet_ptr(),
  237. I<bsize> is not relevant if the purpose is to send the B<OSSL_PARAM> array
  238. to a I<responder>, i.e. to get parameter data back.
  239. In that case, I<bsize> can safely be given zero.
  240. See L<OSSL_PARAM(3)/DESCRIPTION> for further information on the
  241. possible purposes.
  242. =head1 EXAMPLES
  243. Reusing the examples from L<OSSL_PARAM(3)> to just show how
  244. C<OSSL_PARAM> arrays can be handled using the macros and functions
  245. defined herein.
  246. =head2 Example 1
  247. This example is for setting parameters on some object:
  248. #include <openssl/core.h>
  249. const char *foo = "some string";
  250. size_t foo_l = strlen(foo) + 1;
  251. const char bar[] = "some other string";
  252. const OSSL_PARAM set[] = {
  253. OSSL_PARAM_utf8_ptr("foo", &foo, foo_l),
  254. OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
  255. OSSL_PARAM_END
  256. };
  257. =head2 Example 2
  258. This example is for requesting parameters on some object, and also
  259. demonstrates that the requestor isn't obligated to request all
  260. available parameters:
  261. const char *foo = NULL;
  262. char bar[1024];
  263. OSSL_PARAM request[] = {
  264. OSSL_PARAM_utf8_ptr("foo", &foo, 0),
  265. OSSL_PARAM_utf8_string("bar", bar, sizeof(bar)),
  266. OSSL_PARAM_END
  267. };
  268. A I<responder> that receives this array (as C<params> in this example)
  269. could fill in the parameters like this:
  270. /* OSSL_PARAM *params */
  271. OSSL_PARAM *p;
  272. if ((p = OSSL_PARAM_locate(params, "foo")) != NULL)
  273. OSSL_PARAM_set_utf8_ptr(p, "foo value");
  274. if ((p = OSSL_PARAM_locate(params, "bar")) != NULL)
  275. OSSL_PARAM_set_utf8_ptr(p, "bar value");
  276. if ((p = OSSL_PARAM_locate(params, "cookie")) != NULL)
  277. OSSL_PARAM_set_utf8_ptr(p, "cookie value");
  278. =head1 SEE ALSO
  279. L<openssl-core.h(7)>, L<OSSL_PARAM(3)>
  280. =head1 HISTORY
  281. These APIs were introduced in OpenSSL 3.0.
  282. =head1 COPYRIGHT
  283. Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  284. Licensed under the Apache License 2.0 (the "License"). You may not use
  285. this file except in compliance with the License. You can obtain a copy
  286. in the file LICENSE in the source distribution or at
  287. L<https://www.openssl.org/source/license.html>.
  288. =cut