OSSL_PARAM_int.pod 13 KB

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