provider-encoder.7ossl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 "PROVIDER-ENCODER 7ossl"
  58. .TH PROVIDER-ENCODER 7ossl 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. provider\-encoder \- The OSSL_ENCODER library <\-> provider functions
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 1
  68. \& #include <openssl/core_dispatch.h>
  69. \&
  70. \& /*
  71. \& * None of these are actual functions, but are displayed like this for
  72. \& * the function signatures for functions that are offered as function
  73. \& * pointers in OSSL_DISPATCH arrays.
  74. \& */
  75. \&
  76. \& /* Encoder parameter accessor and descriptor */
  77. \& const OSSL_PARAM *OSSL_FUNC_encoder_gettable_params(void *provctx);
  78. \& int OSSL_FUNC_encoder_get_params(OSSL_PARAM params[]);
  79. \&
  80. \& /* Functions to construct / destruct / manipulate the encoder context */
  81. \& void *OSSL_FUNC_encoder_newctx(void *provctx);
  82. \& void OSSL_FUNC_encoder_freectx(void *ctx);
  83. \& int OSSL_FUNC_encoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  84. \& const OSSL_PARAM *OSSL_FUNC_encoder_settable_ctx_params(void *provctx);
  85. \&
  86. \& /* Functions to check selection support */
  87. \& int OSSL_FUNC_encoder_does_selection(void *provctx, int selection);
  88. \&
  89. \& /* Functions to encode object data */
  90. \& int OSSL_FUNC_encoder_encode(void *ctx, OSSL_CORE_BIO *out,
  91. \& const void *obj_raw,
  92. \& const OSSL_PARAM obj_abstract[],
  93. \& int selection,
  94. \& OSSL_PASSPHRASE_CALLBACK *cb,
  95. \& void *cbarg);
  96. \&
  97. \& /* Functions to import and free a temporary object to be encoded */
  98. \& void *OSSL_FUNC_encoder_import_object(void *ctx, int selection,
  99. \& const OSSL_PARAM params[]);
  100. \& void OSSL_FUNC_encoder_free_object(void *obj);
  101. .Ve
  102. .SH DESCRIPTION
  103. .IX Header "DESCRIPTION"
  104. \&\fIWe use the wide term "encode" in this manual. This includes but is
  105. not limited to serialization.\fR
  106. .PP
  107. The ENCODER operation is a generic method to encode a provider-native
  108. object (\fIobj_raw\fR) or an object abstraction (\fIobject_abstract\fR, see
  109. \&\fBprovider\-object\fR\|(7)) into an encoded form, and write the result to
  110. the given OSSL_CORE_BIO. If the caller wants to get the encoded
  111. stream to memory, it should provide a \fBBIO_s_mem\fR\|(3) \fBBIO\fR.
  112. .PP
  113. The encoder doesn't need to know more about the \fBOSSL_CORE_BIO\fR
  114. pointer than being able to pass it to the appropriate BIO upcalls (see
  115. "Core functions" in \fBprovider\-base\fR\|(7)).
  116. .PP
  117. The ENCODER implementation may be part of a chain, where data is
  118. passed from one to the next. For example, there may be an
  119. implementation to encode an object to DER (that object is assumed to
  120. be provider-native and thereby passed via \fIobj_raw\fR), and another one
  121. that encodes DER to PEM (that one would receive the DER encoding via
  122. \&\fIobj_abstract\fR).
  123. .PP
  124. The encoding using the \fBOSSL_PARAM\fR\|(3) array form allows a
  125. encoder to be used for data that's been exported from another
  126. provider, and thereby allow them to exist independently of each
  127. other.
  128. .PP
  129. The encoding using a provider side object can only be safely used
  130. with provider data coming from the same provider, for example keys
  131. with the KEYMGMT provider.
  132. .PP
  133. All "functions" mentioned here are passed as function pointers between
  134. \&\fIlibcrypto\fR and the provider in \fBOSSL_DISPATCH\fR\|(3) arrays via
  135. \&\fBOSSL_ALGORITHM\fR\|(3) arrays that are returned by the provider's
  136. \&\fBprovider_query_operation()\fR function
  137. (see "Provider Functions" in \fBprovider\-base\fR\|(7)).
  138. .PP
  139. All these "functions" have a corresponding function type definition
  140. named \fBOSSL_FUNC_{name}_fn\fR, and a helper function to retrieve the
  141. function pointer from an \fBOSSL_DISPATCH\fR\|(3) element named
  142. \&\fBOSSL_FUNC_{name}\fR.
  143. For example, the "function" \fBOSSL_FUNC_encoder_encode()\fR has these:
  144. .PP
  145. .Vb 8
  146. \& typedef int
  147. \& (OSSL_FUNC_encoder_encode_fn)(void *ctx, OSSL_CORE_BIO *out,
  148. \& const void *obj_raw,
  149. \& const OSSL_PARAM obj_abstract[],
  150. \& int selection,
  151. \& OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
  152. \& static ossl_inline OSSL_FUNC_encoder_encode_fn
  153. \& OSSL_FUNC_encoder_encode(const OSSL_DISPATCH *opf);
  154. .Ve
  155. .PP
  156. \&\fBOSSL_DISPATCH\fR\|(3) arrays are indexed by numbers that are provided as
  157. macros in \fBopenssl\-core_dispatch.h\fR\|(7), as follows:
  158. .PP
  159. .Vb 2
  160. \& OSSL_FUNC_encoder_get_params OSSL_FUNC_ENCODER_GET_PARAMS
  161. \& OSSL_FUNC_encoder_gettable_params OSSL_FUNC_ENCODER_GETTABLE_PARAMS
  162. \&
  163. \& OSSL_FUNC_encoder_newctx OSSL_FUNC_ENCODER_NEWCTX
  164. \& OSSL_FUNC_encoder_freectx OSSL_FUNC_ENCODER_FREECTX
  165. \& OSSL_FUNC_encoder_set_ctx_params OSSL_FUNC_ENCODER_SET_CTX_PARAMS
  166. \& OSSL_FUNC_encoder_settable_ctx_params OSSL_FUNC_ENCODER_SETTABLE_CTX_PARAMS
  167. \&
  168. \& OSSL_FUNC_encoder_does_selection OSSL_FUNC_ENCODER_DOES_SELECTION
  169. \&
  170. \& OSSL_FUNC_encoder_encode OSSL_FUNC_ENCODER_ENCODE
  171. \&
  172. \& OSSL_FUNC_encoder_import_object OSSL_FUNC_ENCODER_IMPORT_OBJECT
  173. \& OSSL_FUNC_encoder_free_object OSSL_FUNC_ENCODER_FREE_OBJECT
  174. .Ve
  175. .SS "Names and properties"
  176. .IX Subsection "Names and properties"
  177. The name of an implementation should match the type of object it handles.
  178. For example, an implementation that encodes an RSA key should be named "RSA".
  179. Likewise, an implementation that further encodes DER should be named "DER".
  180. .PP
  181. Properties can be used to further specify details about an implementation:
  182. .IP output 4
  183. .IX Item "output"
  184. This property is used to specify what type of output the implementation
  185. produces.
  186. .Sp
  187. This property is \fImandatory\fR.
  188. .Sp
  189. OpenSSL providers recognize the following output types:
  190. .RS 4
  191. .IP text 4
  192. .IX Item "text"
  193. An implementation with that output type outputs human readable text, making
  194. that implementation suitable for \f(CW\*(C`\-text\*(C'\fR output in diverse \fBopenssl\fR\|(1)
  195. commands.
  196. .IP pem 4
  197. .IX Item "pem"
  198. An implementation with that output type outputs PEM formatted data.
  199. .IP der 4
  200. .IX Item "der"
  201. An implementation with that output type outputs DER formatted data.
  202. .IP msblob 4
  203. .IX Item "msblob"
  204. An implementation with that output type outputs MSBLOB formatted data.
  205. .IP pvk 4
  206. .IX Item "pvk"
  207. An implementation with that output type outputs PVK formatted data.
  208. .RE
  209. .RS 4
  210. .RE
  211. .IP structure 4
  212. .IX Item "structure"
  213. This property is used to specify the structure that is used for the encoded
  214. object. An example could be \f(CW\*(C`pkcs8\*(C'\fR, to specify explicitly that an object
  215. (presumably an asymmetric key pair, in this case) will be wrapped in a
  216. PKCS#8 structure as part of the encoding.
  217. .Sp
  218. This property is \fIoptional\fR.
  219. .PP
  220. The possible values of both these properties is open ended. A provider may
  221. very well specify output types and structures that libcrypto doesn't know
  222. anything about.
  223. .SS "Subset selections"
  224. .IX Subsection "Subset selections"
  225. Sometimes, an object has more than one subset of data that is interesting to
  226. treat separately or together. It's possible to specify what subsets are to
  227. be encoded, with a set of bits \fIselection\fR that are passed in an \fBint\fR.
  228. .PP
  229. This set of bits depend entirely on what kind of provider-side object is
  230. passed. For example, those bits are assumed to be the same as those used
  231. with \fBprovider\-keymgmt\fR\|(7) (see "Key Objects" in \fBprovider\-keymgmt\fR\|(7)) when
  232. the object is an asymmetric keypair.
  233. .PP
  234. ENCODER implementations are free to regard the \fIselection\fR as a set of
  235. hints, but must do so with care. In the end, the output must make sense,
  236. and if there's a corresponding decoder, the resulting decoded object must
  237. match the original object that was encoded.
  238. .PP
  239. \&\fBOSSL_FUNC_encoder_does_selection()\fR should tell if a particular implementation
  240. supports any of the combinations given by \fIselection\fR.
  241. .SS "Context functions"
  242. .IX Subsection "Context functions"
  243. \&\fBOSSL_FUNC_encoder_newctx()\fR returns a context to be used with the rest of
  244. the functions.
  245. .PP
  246. \&\fBOSSL_FUNC_encoder_freectx()\fR frees the given \fIctx\fR, if it was created by
  247. \&\fBOSSL_FUNC_encoder_newctx()\fR.
  248. .PP
  249. \&\fBOSSL_FUNC_encoder_set_ctx_params()\fR sets context data according to parameters
  250. from \fIparams\fR that it recognises. Unrecognised parameters should be
  251. ignored.
  252. Passing NULL for \fIparams\fR should return true.
  253. .PP
  254. \&\fBOSSL_FUNC_encoder_settable_ctx_params()\fR returns a constant \fBOSSL_PARAM\fR\|(3)
  255. array describing the parameters that \fBOSSL_FUNC_encoder_set_ctx_params()\fR
  256. can handle.
  257. .PP
  258. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure used by
  259. \&\fBOSSL_FUNC_encoder_set_ctx_params()\fR and \fBOSSL_FUNC_encoder_settable_ctx_params()\fR.
  260. .SS "Import functions"
  261. .IX Subsection "Import functions"
  262. A provider-native object may be associated with a foreign provider, and may
  263. therefore be unsuitable for direct use with a given ENCODER implementation.
  264. Provided that the foreign provider's implementation to handle the object has
  265. a function to export that object in \fBOSSL_PARAM\fR\|(3) array form, the ENCODER
  266. implementation should be able to import that array and create a suitable
  267. object to be passed to \fBOSSL_FUNC_encoder_encode()\fR's \fIobj_raw\fR.
  268. .PP
  269. \&\fBOSSL_FUNC_encoder_import_object()\fR should import the subset of \fIparams\fR
  270. given with \fIselection\fR to create a provider-native object that can be
  271. passed as \fIobj_raw\fR to \fBOSSL_FUNC_encoder_encode()\fR.
  272. .PP
  273. \&\fBOSSL_FUNC_encoder_free_object()\fR should free the object that was created with
  274. \&\fBOSSL_FUNC_encoder_import_object()\fR.
  275. .SS "Encoding functions"
  276. .IX Subsection "Encoding functions"
  277. \&\fBOSSL_FUNC_encoder_encode()\fR should take a provider-native object (in
  278. \&\fIobj_raw\fR) or an object abstraction (in \fIobj_abstract\fR), and should output
  279. the object in encoded form to the \fBOSSL_CORE_BIO\fR. The \fIselection\fR bits,
  280. if relevant, should determine in greater detail what will be output.
  281. The encoding functions also take an \fBOSSL_PASSPHRASE_CALLBACK\fR\|(3) function
  282. pointer along with a pointer to application data \fIcbarg\fR, which should be
  283. used when a pass phrase prompt is needed.
  284. .SS "Encoder operation parameters"
  285. .IX Subsection "Encoder operation parameters"
  286. Operation parameters currently recognised by built-in encoders are as
  287. follows:
  288. .IP """cipher"" (\fBOSSL_ENCODER_PARAM_CIPHER\fR) <UTF8 string>" 4
  289. .IX Item """cipher"" (OSSL_ENCODER_PARAM_CIPHER) <UTF8 string>"
  290. The name of the encryption cipher to be used when generating encrypted
  291. encoding. This is used when encoding private keys, as well as
  292. other objects that need protection.
  293. .Sp
  294. If this name is invalid for the encoding implementation, the
  295. implementation should refuse to perform the encoding, i.e.
  296. \&\fBOSSL_FUNC_encoder_encode_data()\fR and \fBOSSL_FUNC_encoder_encode_object()\fR
  297. should return an error.
  298. .IP """properties"" (\fBOSSL_ENCODER_PARAM_PROPERTIES\fR) <UTF8 string>" 4
  299. .IX Item """properties"" (OSSL_ENCODER_PARAM_PROPERTIES) <UTF8 string>"
  300. The properties to be queried when trying to fetch the algorithm given
  301. with the "cipher" parameter.
  302. This must be given together with the "cipher" parameter to be
  303. considered valid.
  304. .Sp
  305. The encoding implementation isn't obligated to use this value.
  306. However, it is recommended that implementations that do not handle
  307. property strings return an error on receiving this parameter unless
  308. its value NULL or the empty string.
  309. .IP """save-parameters"" (\fBOSSL_ENCODER_PARAM_SAVE_PARAMETERS\fR) <integer>" 4
  310. .IX Item """save-parameters"" (OSSL_ENCODER_PARAM_SAVE_PARAMETERS) <integer>"
  311. If set to 0 disables saving of key domain parameters. Default is 1.
  312. It currently has an effect only on DSA keys.
  313. .PP
  314. Parameters currently recognised by the built-in pass phrase callback:
  315. .IP """info"" (\fBOSSL_PASSPHRASE_PARAM_INFO\fR) <UTF8 string>" 4
  316. .IX Item """info"" (OSSL_PASSPHRASE_PARAM_INFO) <UTF8 string>"
  317. A string of information that will become part of the pass phrase
  318. prompt. This could be used to give the user information on what kind
  319. of object it's being prompted for.
  320. .SH "RETURN VALUES"
  321. .IX Header "RETURN VALUES"
  322. \&\fBOSSL_FUNC_encoder_newctx()\fR returns a pointer to a context, or NULL on
  323. failure.
  324. .PP
  325. \&\fBOSSL_FUNC_encoder_set_ctx_params()\fR returns 1, unless a recognised
  326. parameter was invalid or caused an error, for which 0 is returned.
  327. .PP
  328. \&\fBOSSL_FUNC_encoder_settable_ctx_params()\fR returns a pointer to an array of
  329. constant \fBOSSL_PARAM\fR\|(3) elements.
  330. .PP
  331. \&\fBOSSL_FUNC_encoder_does_selection()\fR returns 1 if the encoder implementation
  332. supports any of the \fIselection\fR bits, otherwise 0.
  333. .PP
  334. \&\fBOSSL_FUNC_encoder_encode()\fR returns 1 on success, or 0 on failure.
  335. .SH "SEE ALSO"
  336. .IX Header "SEE ALSO"
  337. \&\fBprovider\fR\|(7)
  338. .SH HISTORY
  339. .IX Header "HISTORY"
  340. The ENCODER interface was introduced in OpenSSL 3.0.
  341. .SH COPYRIGHT
  342. .IX Header "COPYRIGHT"
  343. Copyright 2019\-2021 The OpenSSL Project Authors. All Rights Reserved.
  344. .PP
  345. Licensed under the Apache License 2.0 (the "License"). You may not use
  346. this file except in compliance with the License. You can obtain a copy
  347. in the file LICENSE in the source distribution or at
  348. <https://www.openssl.org/source/license.html>.