OSSL_PARAM_BLD.3ossl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "OSSL_PARAM_BLD 3ossl"
  136. .TH OSSL_PARAM_BLD 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. OSSL_PARAM_BLD, OSSL_PARAM_BLD_new, OSSL_PARAM_BLD_to_param,
  143. OSSL_PARAM_BLD_free, OSSL_PARAM_BLD_push_int,
  144. OSSL_PARAM_BLD_push_uint, OSSL_PARAM_BLD_push_long,
  145. OSSL_PARAM_BLD_push_ulong, OSSL_PARAM_BLD_push_int32,
  146. OSSL_PARAM_BLD_push_uint32, OSSL_PARAM_BLD_push_int64,
  147. OSSL_PARAM_BLD_push_uint64, OSSL_PARAM_BLD_push_size_t,
  148. OSSL_PARAM_BLD_push_time_t, OSSL_PARAM_BLD_push_double,
  149. OSSL_PARAM_BLD_push_BN, OSSL_PARAM_BLD_push_BN_pad,
  150. OSSL_PARAM_BLD_push_utf8_string, OSSL_PARAM_BLD_push_utf8_ptr,
  151. OSSL_PARAM_BLD_push_octet_string, OSSL_PARAM_BLD_push_octet_ptr
  152. \&\- functions to assist in the creation of OSSL_PARAM arrays
  153. .SH "SYNOPSIS"
  154. .IX Header "SYNOPSIS"
  155. .Vb 1
  156. \& #include <openssl/param_build.h>
  157. \&
  158. \& typedef struct OSSL_PARAM_BLD;
  159. \&
  160. \& OSSL_PARAM_BLD *OSSL_PARAM_BLD_new(void);
  161. \& OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld);
  162. \& void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld);
  163. \&
  164. \& int OSSL_PARAM_BLD_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
  165. \&
  166. \& int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
  167. \& const BIGNUM *bn);
  168. \& int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
  169. \& const BIGNUM *bn, size_t sz);
  170. \&
  171. \& int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
  172. \& const char *buf, size_t bsize);
  173. \& int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
  174. \& char *buf, size_t bsize);
  175. \& int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
  176. \& const void *buf, size_t bsize);
  177. \& int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
  178. \& void *buf, size_t bsize);
  179. .Ve
  180. .SH "DESCRIPTION"
  181. .IX Header "DESCRIPTION"
  182. A collection of utility functions that simplify the creation of \s-1OSSL_PARAM\s0
  183. arrays. The \fB\f(BI\s-1TYPE\s0\fB\fR names are as per \fBOSSL_PARAM_int\fR\|(3).
  184. .PP
  185. \&\fBOSSL_PARAM_BLD_new()\fR allocates and initialises a new \s-1OSSL_PARAM_BLD\s0 structure
  186. so that values can be added.
  187. Any existing values are cleared.
  188. .PP
  189. \&\fBOSSL_PARAM_BLD_free()\fR deallocates the memory allocates by \fBOSSL_PARAM_BLD_new()\fR.
  190. If the argument is \s-1NULL,\s0 nothing is done.
  191. .PP
  192. \&\fBOSSL_PARAM_BLD_to_param()\fR converts a built up \s-1OSSL_PARAM_BLD\s0 structure
  193. \&\fIbld\fR into an allocated \s-1OSSL_PARAM\s0 array.
  194. The \s-1OSSL_PARAM\s0 array and all associated storage must be freed by calling
  195. \&\fBOSSL_PARAM_free()\fR with the functions return value.
  196. \&\fBOSSL_PARAM_BLD_free()\fR can safely be called any time after this function is.
  197. .PP
  198. \&\fBOSSL_PARAM_BLD_push_\f(BI\s-1TYPE\s0\fB\fR() are a series of functions which will create
  199. \&\s-1OSSL_PARAM\s0 objects of the specified size and correct type for the \fIval\fR
  200. argument.
  201. \&\fIval\fR is stored by value and an expression or auto variable can be used.
  202. .PP
  203. When \fB\f(BI\s-1TYPE\s0\fB\fR denotes an integer type, signed integer types will normally
  204. get the \s-1OSSL_PARAM\s0 type \fB\s-1OSSL_PARAM_INTEGER\s0\fR params.
  205. When \fB\f(BI\s-1TYPE\s0\fB\fR denotes an unsigned integer type will get the \s-1OSSL_PARAM\s0 type
  206. \&\fB\s-1OSSL_PARAM_UNSIGNED_INTEGER\s0\fR.
  207. .PP
  208. \&\fBOSSL_PARAM_BLD_push_BN()\fR is a function that will create an \s-1OSSL_PARAM\s0 object
  209. that holds the specified \s-1BIGNUM\s0 \fIbn\fR.
  210. When the \fIbn\fR is zero or positive, its \s-1OSSL_PARAM\s0 type becomes
  211. \&\fB\s-1OSSL_PARAM_UNSIGNED_INTEGER\s0\fR.
  212. When the \fIbn\fR is negative, its \s-1OSSL_PARAM\s0 type becomes \fB\s-1OSSL_PARAM_INTEGER\s0\fR.
  213. If \fIbn\fR is marked as being securely allocated, its \s-1OSSL_PARAM\s0 representation
  214. will also be securely allocated.
  215. The \fIbn\fR argument is stored by reference and the underlying \s-1BIGNUM\s0 object
  216. must exist until after \fBOSSL_PARAM_BLD_to_param()\fR has been called.
  217. .PP
  218. \&\fBOSSL_PARAM_BLD_push_BN_pad()\fR is a function that will create an \s-1OSSL_PARAM\s0 object
  219. that holds the specified \s-1BIGNUM\s0 \fIbn\fR.
  220. The object will be padded to occupy exactly \fIsz\fR bytes, if insufficient space
  221. is specified an error results.
  222. When the \fIbn\fR is zero or positive, its \s-1OSSL_PARAM\s0 type becomes
  223. \&\fB\s-1OSSL_PARAM_UNSIGNED_INTEGER\s0\fR.
  224. When the \fIbn\fR is negative, its \s-1OSSL_PARAM\s0 type becomes \fB\s-1OSSL_PARAM_INTEGER\s0\fR.
  225. If \fIbn\fR is marked as being securely allocated, its \s-1OSSL_PARAM\s0 representation
  226. will also be securely allocated.
  227. The \fIbn\fR argument is stored by reference and the underlying \s-1BIGNUM\s0 object
  228. must exist until after \fBOSSL_PARAM_BLD_to_param()\fR has been called.
  229. .PP
  230. \&\fBOSSL_PARAM_BLD_push_utf8_string()\fR is a function that will create an \s-1OSSL_PARAM\s0
  231. object that references the \s-1UTF8\s0 string specified by \fIbuf\fR.
  232. The length of the string \fIbsize\fR should not include the terminating \s-1NUL\s0 byte.
  233. If it is zero then it will be calculated.
  234. The string that \fIbuf\fR points to is stored by reference and must remain in
  235. scope until after \fBOSSL_PARAM_BLD_to_param()\fR has been called.
  236. .PP
  237. \&\fBOSSL_PARAM_BLD_push_octet_string()\fR is a function that will create an \s-1OSSL_PARAM\s0
  238. object that references the octet string specified by \fIbuf\fR and <bsize>.
  239. The memory that \fIbuf\fR points to is stored by reference and must remain in
  240. scope until after \fBOSSL_PARAM_BLD_to_param()\fR has been called.
  241. .PP
  242. \&\fBOSSL_PARAM_BLD_push_utf8_ptr()\fR is a function that will create an \s-1OSSL_PARAM\s0
  243. object that references the \s-1UTF8\s0 string specified by \fIbuf\fR.
  244. The length of the string \fIbsize\fR should not include the terminating \s-1NUL\s0 byte.
  245. If it is zero then it will be calculated.
  246. The string \fIbuf\fR points to is stored by reference and must remain in
  247. scope until the \s-1OSSL_PARAM\s0 array is freed.
  248. .PP
  249. \&\fBOSSL_PARAM_BLD_push_octet_ptr()\fR is a function that will create an \s-1OSSL_PARAM\s0
  250. object that references the octet string specified by \fIbuf\fR.
  251. The memory \fIbuf\fR points to is stored by reference and must remain in
  252. scope until the \s-1OSSL_PARAM\s0 array is freed.
  253. .SH "RETURN VALUES"
  254. .IX Header "RETURN VALUES"
  255. \&\fBOSSL_PARAM_BLD_new()\fR returns the allocated \s-1OSSL_PARAM_BLD\s0 structure, or \s-1NULL\s0
  256. on error.
  257. .PP
  258. \&\fBOSSL_PARAM_BLD_to_param()\fR returns the allocated \s-1OSSL_PARAM\s0 array, or \s-1NULL\s0
  259. on error.
  260. .PP
  261. All of the OSSL_PARAM_BLD_push_TYPE functions return 1 on success and 0
  262. on error.
  263. .SH "NOTES"
  264. .IX Header "NOTES"
  265. \&\fBOSSL_PARAM_BLD_push_BN()\fR and \fBOSSL_PARAM_BLD_push_BN_pad()\fR only
  266. support nonnegative \fB\s-1BIGNUM\s0\fRs. They return an error on negative
  267. \&\fB\s-1BIGNUM\s0\fRs.
  268. To pass signed \fB\s-1BIGNUM\s0\fRs, use \fBOSSL_PARAM_BLD_push_signed_BN()\fR.
  269. .SH "EXAMPLES"
  270. .IX Header "EXAMPLES"
  271. Both examples creating an \s-1OSSL_PARAM\s0 array that contains an \s-1RSA\s0 key.
  272. For both, the predefined key variables are:
  273. .PP
  274. .Vb 6
  275. \& BIGNUM *n; /* modulus */
  276. \& unsigned int e; /* public exponent */
  277. \& BIGNUM *d; /* private exponent */
  278. \& BIGNUM *p, *q; /* first two prime factors */
  279. \& BIGNUM *dmp1, *dmq1; /* first two CRT exponents */
  280. \& BIGNUM *iqmp; /* first CRT coefficient */
  281. .Ve
  282. .SS "Example 1"
  283. .IX Subsection "Example 1"
  284. This example shows how to create an \s-1OSSL_PARAM\s0 array that contains an \s-1RSA\s0
  285. private key.
  286. .PP
  287. .Vb 2
  288. \& OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  289. \& OSSL_PARAM *params = NULL;
  290. \&
  291. \& if (bld == NULL
  292. \& || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
  293. \& || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
  294. \& || !OSSL_PARAM_BLD_push_BN(bld, "d", d)
  295. \& || !OSSL_PARAM_BLD_push_BN(bld, "rsa\-factor1", p)
  296. \& || !OSSL_PARAM_BLD_push_BN(bld, "rsa\-factor2", q)
  297. \& || !OSSL_PARAM_BLD_push_BN(bld, "rsa\-exponent1", dmp1)
  298. \& || !OSSL_PARAM_BLD_push_BN(bld, "rsa\-exponent2", dmq1)
  299. \& || !OSSL_PARAM_BLD_push_BN(bld, "rsa\-coefficient1", iqmp)
  300. \& || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
  301. \& goto err;
  302. \& OSSL_PARAM_BLD_free(bld);
  303. \& /* Use params */
  304. \& ...
  305. \& OSSL_PARAM_free(params);
  306. .Ve
  307. .SS "Example 2"
  308. .IX Subsection "Example 2"
  309. This example shows how to create an \s-1OSSL_PARAM\s0 array that contains an \s-1RSA\s0
  310. public key.
  311. .PP
  312. .Vb 2
  313. \& OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
  314. \& OSSL_PARAM *params = NULL;
  315. \&
  316. \& if (nld == NULL
  317. \& || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
  318. \& || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
  319. \& || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
  320. \& goto err;
  321. \& OSSL_PARAM_BLD_free(bld);
  322. \& /* Use params */
  323. \& ...
  324. \& OSSL_PARAM_free(params);
  325. .Ve
  326. .SH "SEE ALSO"
  327. .IX Header "SEE ALSO"
  328. \&\fBOSSL_PARAM_int\fR\|(3), \s-1\fBOSSL_PARAM\s0\fR\|(3), \fBOSSL_PARAM_free\fR\|(3)
  329. .SH "HISTORY"
  330. .IX Header "HISTORY"
  331. The functions described here were all added in OpenSSL 3.0.
  332. .SH "COPYRIGHT"
  333. .IX Header "COPYRIGHT"
  334. Copyright 2019\-2024 The OpenSSL Project Authors. All Rights Reserved.
  335. .PP
  336. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  337. this file except in compliance with the License. You can obtain a copy
  338. in the file \s-1LICENSE\s0 in the source distribution or at
  339. <https://www.openssl.org/source/license.html>.