OSSL_PARAM.3ossl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "OSSL_PARAM 3ossl"
  58. .TH OSSL_PARAM 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. OSSL_PARAM \- a structure to pass or request object parameters
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 1
  68. \& #include <openssl/core.h>
  69. \&
  70. \& typedef struct ossl_param_st OSSL_PARAM;
  71. \& struct ossl_param_st {
  72. \& const char *key; /* the name of the parameter */
  73. \& unsigned int data_type; /* declare what kind of content is in data */
  74. \& void *data; /* value being passed in or out */
  75. \& size_t data_size; /* data size */
  76. \& size_t return_size; /* returned size */
  77. \& };
  78. .Ve
  79. .SH DESCRIPTION
  80. .IX Header "DESCRIPTION"
  81. \&\fBOSSL_PARAM\fR is a type that allows passing arbitrary data for some
  82. object between two parties that have no or very little shared
  83. knowledge about their respective internal structures for that object.
  84. .PP
  85. A typical usage example could be an application that wants to set some
  86. parameters for an object, or wants to find out some parameters of an
  87. object.
  88. .PP
  89. Arrays of this type can be used for the following purposes:
  90. .IP \(bu 4
  91. Setting parameters for some object
  92. .Sp
  93. The caller sets up the \fBOSSL_PARAM\fR array and calls some function
  94. (the \fIsetter\fR) that has intimate knowledge about the object that can
  95. take the data from the \fBOSSL_PARAM\fR array and assign them in a
  96. suitable form for the internal structure of the object.
  97. .IP \(bu 4
  98. Request parameters of some object
  99. .Sp
  100. The caller (the \fIrequester\fR) sets up the \fBOSSL_PARAM\fR array and
  101. calls some function (the \fIresponder\fR) that has intimate knowledge
  102. about the object, which can take the internal data of the object and
  103. copy (possibly convert) that to the memory prepared by the
  104. \&\fIrequester\fR and pointed at with the \fBOSSL_PARAM\fR \fIdata\fR.
  105. .IP \(bu 4
  106. Request parameter descriptors
  107. .Sp
  108. The caller gets an array of constant \fBOSSL_PARAM\fR, which describe
  109. available parameters and some of their properties; name, data type and
  110. expected data size.
  111. For a detailed description of each field for this use, see the field
  112. descriptions below.
  113. .Sp
  114. The caller may then use the information from this descriptor array to
  115. build up its own \fBOSSL_PARAM\fR array to pass down to a \fIsetter\fR or
  116. \&\fIresponder\fR.
  117. .PP
  118. Normally, the order of the an \fBOSSL_PARAM\fR array is not relevant.
  119. However, if the \fIresponder\fR can handle multiple elements with the
  120. same key, those elements must be handled in the order they are in.
  121. .PP
  122. An \fBOSSL_PARAM\fR array must have a terminating element, where \fIkey\fR
  123. is NULL. The usual full terminating template is:
  124. .PP
  125. .Vb 1
  126. \& { NULL, 0, NULL, 0, 0 }
  127. .Ve
  128. .PP
  129. This can also be specified using \fBOSSL_PARAM_END\fR\|(3).
  130. .SS "Functional support"
  131. .IX Subsection "Functional support"
  132. Libcrypto offers a limited set of helper functions to handle
  133. \&\fBOSSL_PARAM\fR items and arrays, please see \fBOSSL_PARAM_get_int\fR\|(3).
  134. Developers are free to extend or replace those as they see fit.
  135. .SS "\fBOSSL_PARAM\fP fields"
  136. .IX Subsection "OSSL_PARAM fields"
  137. .IP \fIkey\fR 4
  138. .IX Item "key"
  139. The identity of the parameter in the form of a string.
  140. .Sp
  141. In an \fBOSSL_PARAM\fR array, an item with this field set to NULL is
  142. considered a terminating item.
  143. .IP \fIdata_type\fR 4
  144. .IX Item "data_type"
  145. The \fIdata_type\fR is a value that describes the type and organization of
  146. the data.
  147. See "Supported types" below for a description of the types.
  148. .IP \fIdata\fR 4
  149. .IX Item "data"
  150. .PD 0
  151. .IP \fIdata_size\fR 4
  152. .IX Item "data_size"
  153. .PD
  154. \&\fIdata\fR is a pointer to the memory where the parameter data is (when
  155. setting parameters) or shall (when requesting parameters) be stored,
  156. and \fIdata_size\fR is its size in bytes.
  157. The organization of the data depends on the parameter type and flag.
  158. .Sp
  159. The \fIdata_size\fR needs special attention with the parameter type
  160. \&\fBOSSL_PARAM_UTF8_STRING\fR in relation to C strings. When setting
  161. parameters, the size should be set to the length of the string, not
  162. counting the terminating NUL byte. When requesting parameters, the
  163. size should be set to the size of the buffer to be populated, which
  164. should accommodate enough space for a terminating NUL byte.
  165. .Sp
  166. When \fIrequesting parameters\fR, it's acceptable for \fIdata\fR to be NULL.
  167. This can be used by the \fIrequester\fR to figure out dynamically exactly
  168. how much buffer space is needed to store the parameter data.
  169. In this case, \fIdata_size\fR is ignored.
  170. .Sp
  171. When the \fBOSSL_PARAM\fR is used as a parameter descriptor, \fIdata\fR
  172. should be ignored.
  173. If \fIdata_size\fR is zero, it means that an arbitrary data size is
  174. accepted, otherwise it specifies the maximum size allowed.
  175. .IP \fIreturn_size\fR 4
  176. .IX Item "return_size"
  177. When an array of \fBOSSL_PARAM\fR is used to request data, the
  178. \&\fIresponder\fR must set this field to indicate size of the parameter
  179. data, including padding as the case may be.
  180. In case the \fIdata_size\fR is an unsuitable size for the data, the
  181. \&\fIresponder\fR must still set this field to indicate the minimum data
  182. size required.
  183. (further notes on this in "NOTES" below).
  184. .Sp
  185. When the \fBOSSL_PARAM\fR is used as a parameter descriptor,
  186. \&\fIreturn_size\fR should be ignored.
  187. .PP
  188. \&\fBNOTE:\fR
  189. .PP
  190. The key names and associated types are defined by the entity that
  191. offers these parameters, i.e. names for parameters provided by the
  192. OpenSSL libraries are defined by the libraries, and names for
  193. parameters provided by providers are defined by those providers,
  194. except for the pointer form of strings (see data type descriptions
  195. below).
  196. Entities that want to set or request parameters need to know what
  197. those keys are and of what type, any functionality between those two
  198. entities should remain oblivious and just pass the \fBOSSL_PARAM\fR array
  199. along.
  200. .SS "Supported types"
  201. .IX Subsection "Supported types"
  202. The \fIdata_type\fR field can be one of the following types:
  203. .IP \fBOSSL_PARAM_INTEGER\fR 4
  204. .IX Item "OSSL_PARAM_INTEGER"
  205. .PD 0
  206. .IP \fBOSSL_PARAM_UNSIGNED_INTEGER\fR 4
  207. .IX Item "OSSL_PARAM_UNSIGNED_INTEGER"
  208. .PD
  209. The parameter data is an integer (signed or unsigned) of arbitrary
  210. length, organized in native form, i.e. most significant byte first on
  211. Big-Endian systems, and least significant byte first on Little-Endian
  212. systems.
  213. .IP \fBOSSL_PARAM_REAL\fR 4
  214. .IX Item "OSSL_PARAM_REAL"
  215. The parameter data is a floating point value in native form.
  216. .IP \fBOSSL_PARAM_UTF8_STRING\fR 4
  217. .IX Item "OSSL_PARAM_UTF8_STRING"
  218. The parameter data is a printable string.
  219. .IP \fBOSSL_PARAM_OCTET_STRING\fR 4
  220. .IX Item "OSSL_PARAM_OCTET_STRING"
  221. The parameter data is an arbitrary string of bytes.
  222. .IP \fBOSSL_PARAM_UTF8_PTR\fR 4
  223. .IX Item "OSSL_PARAM_UTF8_PTR"
  224. The parameter data is a pointer to a printable string.
  225. .Sp
  226. The difference between this and \fBOSSL_PARAM_UTF8_STRING\fR is that \fIdata\fR
  227. doesn't point directly at the data, but to a pointer that points to the data.
  228. .Sp
  229. If there is any uncertainty about which to use, \fBOSSL_PARAM_UTF8_STRING\fR is
  230. almost certainly the correct choice.
  231. .Sp
  232. This is used to indicate that constant data is or will be passed,
  233. and there is therefore no need to copy the data that is passed, just
  234. the pointer to it.
  235. .Sp
  236. \&\fIdata_size\fR must be set to the size of the data, not the size of the
  237. pointer to the data.
  238. If this is used in a parameter request,
  239. \&\fIdata_size\fR is not relevant. However, the \fIresponder\fR will set
  240. \&\fIreturn_size\fR to the size of the data.
  241. .Sp
  242. Note that the use of this type is \fBfragile\fR and can only be safely
  243. used for data that remains constant and in a constant location for a
  244. long enough duration (such as the life-time of the entity that
  245. offers these parameters).
  246. .IP \fBOSSL_PARAM_OCTET_PTR\fR 4
  247. .IX Item "OSSL_PARAM_OCTET_PTR"
  248. The parameter data is a pointer to an arbitrary string of bytes.
  249. .Sp
  250. The difference between this and \fBOSSL_PARAM_OCTET_STRING\fR is that
  251. \&\fIdata\fR doesn't point directly at the data, but to a pointer that
  252. points to the data.
  253. .Sp
  254. If there is any uncertainty about which to use, \fBOSSL_PARAM_OCTET_STRING\fR is
  255. almost certainly the correct choice.
  256. .Sp
  257. This is used to indicate that constant data is or will be passed, and
  258. there is therefore no need to copy the data that is passed, just the
  259. pointer to it.
  260. .Sp
  261. \&\fIdata_size\fR must be set to the size of the data, not the size of the
  262. pointer to the data.
  263. If this is used in a parameter request,
  264. \&\fIdata_size\fR is not relevant. However, the \fIresponder\fR will set
  265. \&\fIreturn_size\fR to the size of the data.
  266. .Sp
  267. Note that the use of this type is \fBfragile\fR and can only be safely
  268. used for data that remains constant and in a constant location for a
  269. long enough duration (such as the life-time of the entity that
  270. offers these parameters).
  271. .SH NOTES
  272. .IX Header "NOTES"
  273. Both when setting and requesting parameters, the functions that are
  274. called will have to decide what is and what is not an error.
  275. The recommended behaviour is:
  276. .IP \(bu 4
  277. Keys that a \fIsetter\fR or \fIresponder\fR doesn't recognise should simply
  278. be ignored.
  279. That in itself isn't an error.
  280. .IP \(bu 4
  281. If the keys that a called \fIsetter\fR recognises form a consistent
  282. enough set of data, that call should succeed.
  283. .IP \(bu 4
  284. Apart from the \fIreturn_size\fR, a \fIresponder\fR must never change the fields
  285. of an \fBOSSL_PARAM\fR.
  286. To return a value, it should change the contents of the memory that
  287. \&\fIdata\fR points at.
  288. .IP \(bu 4
  289. If the data type for a key that it's associated with is incorrect,
  290. the called function may return an error.
  291. .Sp
  292. The called function may also try to convert the data to a suitable
  293. form (for example, it's plausible to pass a large number as an octet
  294. string, so even though a given key is defined as an
  295. \&\fBOSSL_PARAM_UNSIGNED_INTEGER\fR, is plausible to pass the value as an
  296. \&\fBOSSL_PARAM_OCTET_STRING\fR), but this is in no way mandatory.
  297. .IP \(bu 4
  298. If \fIdata\fR for a \fBOSSL_PARAM_OCTET_STRING\fR or a
  299. \&\fBOSSL_PARAM_UTF8_STRING\fR is NULL, the \fIresponder\fR should
  300. set \fIreturn_size\fR to the size of the item to be returned
  301. and return success. Later the responder will be called again
  302. with \fIdata\fR pointing at the place for the value to be put.
  303. .IP \(bu 4
  304. If a \fIresponder\fR finds that some data sizes are too small for the
  305. requested data, it must set \fIreturn_size\fR for each such
  306. \&\fBOSSL_PARAM\fR item to the minimum required size, and eventually return
  307. an error.
  308. .IP \(bu 4
  309. For the integer type parameters (\fBOSSL_PARAM_UNSIGNED_INTEGER\fR and
  310. \&\fBOSSL_PARAM_INTEGER\fR), a \fIresponder\fR may choose to return an error
  311. if the \fIdata_size\fR isn't a suitable size (even if \fIdata_size\fR is
  312. bigger than needed). If the \fIresponder\fR finds the size suitable, it
  313. must fill all \fIdata_size\fR bytes and ensure correct padding for the
  314. native endianness, and set \fIreturn_size\fR to the same value as
  315. \&\fIdata_size\fR.
  316. .SH EXAMPLES
  317. .IX Header "EXAMPLES"
  318. A couple of examples to just show how \fBOSSL_PARAM\fR arrays could be
  319. set up.
  320. .PP
  321. \fIExample 1\fR
  322. .IX Subsection "Example 1"
  323. .PP
  324. This example is for setting parameters on some object:
  325. .PP
  326. .Vb 1
  327. \& #include <openssl/core.h>
  328. \&
  329. \& const char *foo = "some string";
  330. \& size_t foo_l = strlen(foo);
  331. \& const char bar[] = "some other string";
  332. \& OSSL_PARAM set[] = {
  333. \& { "foo", OSSL_PARAM_UTF8_PTR, &foo, foo_l, 0 },
  334. \& { "bar", OSSL_PARAM_UTF8_STRING, (void *)&bar, sizeof(bar) \- 1, 0 },
  335. \& { NULL, 0, NULL, 0, 0 }
  336. \& };
  337. .Ve
  338. .PP
  339. \fIExample 2\fR
  340. .IX Subsection "Example 2"
  341. .PP
  342. This example is for requesting parameters on some object:
  343. .PP
  344. .Vb 9
  345. \& const char *foo = NULL;
  346. \& size_t foo_l;
  347. \& char bar[1024];
  348. \& size_t bar_l;
  349. \& OSSL_PARAM request[] = {
  350. \& { "foo", OSSL_PARAM_UTF8_PTR, &foo, 0 /*irrelevant*/, 0 },
  351. \& { "bar", OSSL_PARAM_UTF8_STRING, &bar, sizeof(bar), 0 },
  352. \& { NULL, 0, NULL, 0, 0 }
  353. \& };
  354. .Ve
  355. .PP
  356. A \fIresponder\fR that receives this array (as \fIparams\fR in this example)
  357. could fill in the parameters like this:
  358. .PP
  359. .Vb 1
  360. \& /* OSSL_PARAM *params */
  361. \&
  362. \& int i;
  363. \&
  364. \& for (i = 0; params[i].key != NULL; i++) {
  365. \& if (strcmp(params[i].key, "foo") == 0) {
  366. \& *(char **)params[i].data = "foo value";
  367. \& params[i].return_size = 9; /* length of "foo value" string */
  368. \& } else if (strcmp(params[i].key, "bar") == 0) {
  369. \& memcpy(params[i].data, "bar value", 10);
  370. \& params[i].return_size = 9; /* length of "bar value" string */
  371. \& }
  372. \& /* Ignore stuff we don\*(Aqt know */
  373. \& }
  374. .Ve
  375. .SH "SEE ALSO"
  376. .IX Header "SEE ALSO"
  377. \&\fBopenssl\-core.h\fR\|(7), \fBOSSL_PARAM_get_int\fR\|(3), \fBOSSL_PARAM_dup\fR\|(3)
  378. .SH HISTORY
  379. .IX Header "HISTORY"
  380. \&\fBOSSL_PARAM\fR was added in OpenSSL 3.0.
  381. .SH COPYRIGHT
  382. .IX Header "COPYRIGHT"
  383. Copyright 2019\-2024 The OpenSSL Project Authors. All Rights Reserved.
  384. .PP
  385. Licensed under the Apache License 2.0 (the "License"). You may not use
  386. this file except in compliance with the License. You can obtain a copy
  387. in the file LICENSE in the source distribution or at
  388. <https://www.openssl.org/source/license.html>.