provider-cipher.7ossl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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-CIPHER 7ossl"
  58. .TH PROVIDER-CIPHER 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\-cipher \- The cipher library <\-> provider functions
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 2
  68. \& #include <openssl/core_dispatch.h>
  69. \& #include <openssl/core_names.h>
  70. \&
  71. \& /*
  72. \& * None of these are actual functions, but are displayed like this for
  73. \& * the function signatures for functions that are offered as function
  74. \& * pointers in OSSL_DISPATCH arrays.
  75. \& */
  76. \&
  77. \& /* Context management */
  78. \& void *OSSL_FUNC_cipher_newctx(void *provctx);
  79. \& void OSSL_FUNC_cipher_freectx(void *cctx);
  80. \& void *OSSL_FUNC_cipher_dupctx(void *cctx);
  81. \&
  82. \& /* Encryption/decryption */
  83. \& int OSSL_FUNC_cipher_encrypt_init(void *cctx, const unsigned char *key,
  84. \& size_t keylen, const unsigned char *iv,
  85. \& size_t ivlen, const OSSL_PARAM params[]);
  86. \& int OSSL_FUNC_cipher_decrypt_init(void *cctx, const unsigned char *key,
  87. \& size_t keylen, const unsigned char *iv,
  88. \& size_t ivlen, const OSSL_PARAM params[]);
  89. \& int OSSL_FUNC_cipher_update(void *cctx, unsigned char *out, size_t *outl,
  90. \& size_t outsize, const unsigned char *in, size_t inl);
  91. \& int OSSL_FUNC_cipher_final(void *cctx, unsigned char *out, size_t *outl,
  92. \& size_t outsize);
  93. \& int OSSL_FUNC_cipher_cipher(void *cctx, unsigned char *out, size_t *outl,
  94. \& size_t outsize, const unsigned char *in, size_t inl);
  95. \&
  96. \& /* Cipher parameter descriptors */
  97. \& const OSSL_PARAM *OSSL_FUNC_cipher_gettable_params(void *provctx);
  98. \&
  99. \& /* Cipher operation parameter descriptors */
  100. \& const OSSL_PARAM *OSSL_FUNC_cipher_gettable_ctx_params(void *cctx,
  101. \& void *provctx);
  102. \& const OSSL_PARAM *OSSL_FUNC_cipher_settable_ctx_params(void *cctx,
  103. \& void *provctx);
  104. \&
  105. \& /* Cipher parameters */
  106. \& int OSSL_FUNC_cipher_get_params(OSSL_PARAM params[]);
  107. \&
  108. \& /* Cipher operation parameters */
  109. \& int OSSL_FUNC_cipher_get_ctx_params(void *cctx, OSSL_PARAM params[]);
  110. \& int OSSL_FUNC_cipher_set_ctx_params(void *cctx, const OSSL_PARAM params[]);
  111. .Ve
  112. .SH DESCRIPTION
  113. .IX Header "DESCRIPTION"
  114. This documentation is primarily aimed at provider authors. See \fBprovider\fR\|(7)
  115. for further information.
  116. .PP
  117. The CIPHER operation enables providers to implement cipher algorithms and make
  118. them available to applications via the API functions \fBEVP_EncryptInit_ex\fR\|(3),
  119. \&\fBEVP_EncryptUpdate\fR\|(3) and \fBEVP_EncryptFinal\fR\|(3) (as well as the decrypt
  120. equivalents and other related functions).
  121. .PP
  122. All "functions" mentioned here are passed as function pointers between
  123. \&\fIlibcrypto\fR and the provider in \fBOSSL_DISPATCH\fR\|(3) arrays via
  124. \&\fBOSSL_ALGORITHM\fR\|(3) arrays that are returned by the provider's
  125. \&\fBprovider_query_operation()\fR function
  126. (see "Provider Functions" in \fBprovider\-base\fR\|(7)).
  127. .PP
  128. All these "functions" have a corresponding function type definition
  129. named \fBOSSL_FUNC_{name}_fn\fR, and a helper function to retrieve the
  130. function pointer from an \fBOSSL_DISPATCH\fR\|(3) element named
  131. \&\fBOSSL_FUNC_{name}\fR.
  132. For example, the "function" \fBOSSL_FUNC_cipher_newctx()\fR has these:
  133. .PP
  134. .Vb 3
  135. \& typedef void *(OSSL_FUNC_cipher_newctx_fn)(void *provctx);
  136. \& static ossl_inline OSSL_FUNC_cipher_newctx_fn
  137. \& OSSL_FUNC_cipher_newctx(const OSSL_DISPATCH *opf);
  138. .Ve
  139. .PP
  140. \&\fBOSSL_DISPATCH\fR\|(3) arrays are indexed by numbers that are provided as
  141. macros in \fBopenssl\-core_dispatch.h\fR\|(7), as follows:
  142. .PP
  143. .Vb 3
  144. \& OSSL_FUNC_cipher_newctx OSSL_FUNC_CIPHER_NEWCTX
  145. \& OSSL_FUNC_cipher_freectx OSSL_FUNC_CIPHER_FREECTX
  146. \& OSSL_FUNC_cipher_dupctx OSSL_FUNC_CIPHER_DUPCTX
  147. \&
  148. \& OSSL_FUNC_cipher_encrypt_init OSSL_FUNC_CIPHER_ENCRYPT_INIT
  149. \& OSSL_FUNC_cipher_decrypt_init OSSL_FUNC_CIPHER_DECRYPT_INIT
  150. \& OSSL_FUNC_cipher_update OSSL_FUNC_CIPHER_UPDATE
  151. \& OSSL_FUNC_cipher_final OSSL_FUNC_CIPHER_FINAL
  152. \& OSSL_FUNC_cipher_cipher OSSL_FUNC_CIPHER_CIPHER
  153. \&
  154. \& OSSL_FUNC_cipher_get_params OSSL_FUNC_CIPHER_GET_PARAMS
  155. \& OSSL_FUNC_cipher_get_ctx_params OSSL_FUNC_CIPHER_GET_CTX_PARAMS
  156. \& OSSL_FUNC_cipher_set_ctx_params OSSL_FUNC_CIPHER_SET_CTX_PARAMS
  157. \&
  158. \& OSSL_FUNC_cipher_gettable_params OSSL_FUNC_CIPHER_GETTABLE_PARAMS
  159. \& OSSL_FUNC_cipher_gettable_ctx_params OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS
  160. \& OSSL_FUNC_cipher_settable_ctx_params OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS
  161. .Ve
  162. .PP
  163. A cipher algorithm implementation may not implement all of these functions.
  164. In order to be a consistent set of functions there must at least be a complete
  165. set of "encrypt" functions, or a complete set of "decrypt" functions, or a
  166. single "cipher" function.
  167. In all cases both the OSSL_FUNC_cipher_newctx and OSSL_FUNC_cipher_freectx functions must be
  168. present.
  169. All other functions are optional.
  170. .SS "Context Management Functions"
  171. .IX Subsection "Context Management Functions"
  172. \&\fBOSSL_FUNC_cipher_newctx()\fR should create and return a pointer to a provider side
  173. structure for holding context information during a cipher operation.
  174. A pointer to this context will be passed back in a number of the other cipher
  175. operation function calls.
  176. The parameter \fIprovctx\fR is the provider context generated during provider
  177. initialisation (see \fBprovider\fR\|(7)).
  178. .PP
  179. \&\fBOSSL_FUNC_cipher_freectx()\fR is passed a pointer to the provider side cipher context in
  180. the \fIcctx\fR parameter.
  181. This function should free any resources associated with that context.
  182. .PP
  183. \&\fBOSSL_FUNC_cipher_dupctx()\fR should duplicate the provider side cipher context in the
  184. \&\fIcctx\fR parameter and return the duplicate copy.
  185. .SS "Encryption/Decryption Functions"
  186. .IX Subsection "Encryption/Decryption Functions"
  187. \&\fBOSSL_FUNC_cipher_encrypt_init()\fR initialises a cipher operation for encryption given a
  188. newly created provider side cipher context in the \fIcctx\fR parameter.
  189. The key to be used is given in \fIkey\fR which is \fIkeylen\fR bytes long.
  190. The IV to be used is given in \fIiv\fR which is \fIivlen\fR bytes long.
  191. The \fIparams\fR, if not NULL, should be set on the context in a manner similar to
  192. using \fBOSSL_FUNC_cipher_set_ctx_params()\fR.
  193. .PP
  194. \&\fBOSSL_FUNC_cipher_decrypt_init()\fR is the same as \fBOSSL_FUNC_cipher_encrypt_init()\fR except that it
  195. initialises the context for a decryption operation.
  196. .PP
  197. \&\fBOSSL_FUNC_cipher_update()\fR is called to supply data to be encrypted/decrypted as part of
  198. a previously initialised cipher operation.
  199. The \fIcctx\fR parameter contains a pointer to a previously initialised provider
  200. side context.
  201. \&\fBOSSL_FUNC_cipher_update()\fR should encrypt/decrypt \fIinl\fR bytes of data at the location
  202. pointed to by \fIin\fR.
  203. The encrypted data should be stored in \fIout\fR and the amount of data written to
  204. \&\fI*outl\fR which should not exceed \fIoutsize\fR bytes.
  205. \&\fBOSSL_FUNC_cipher_update()\fR may be called multiple times for a single cipher operation.
  206. It is the responsibility of the cipher implementation to handle input lengths
  207. that are not multiples of the block length.
  208. In such cases a cipher implementation will typically cache partial blocks of
  209. input data until a complete block is obtained.
  210. The pointers \fIout\fR and \fIin\fR may point to the same location, in which
  211. case the encryption must be done in-place. If \fIout\fR and \fIin\fR point to different
  212. locations, the requirements of \fBEVP_EncryptUpdate\fR\|(3) and \fBEVP_DecryptUpdate\fR\|(3)
  213. guarantee that the two buffers are disjoint.
  214. Similarly, the requirements of \fBEVP_EncryptUpdate\fR\|(3) and \fBEVP_DecryptUpdate\fR\|(3)
  215. ensure that the buffer pointed to by \fIout\fR contains sufficient room for the
  216. operation being performed.
  217. .PP
  218. \&\fBOSSL_FUNC_cipher_final()\fR completes an encryption or decryption started through previous
  219. \&\fBOSSL_FUNC_cipher_encrypt_init()\fR or \fBOSSL_FUNC_cipher_decrypt_init()\fR, and \fBOSSL_FUNC_cipher_update()\fR
  220. calls.
  221. The \fIcctx\fR parameter contains a pointer to the provider side context.
  222. Any final encryption/decryption output should be written to \fIout\fR and the
  223. amount of data written to \fI*outl\fR which should not exceed \fIoutsize\fR bytes.
  224. The same expectations apply to \fIoutsize\fR as documented for
  225. \&\fBEVP_EncryptFinal\fR\|(3) and \fBEVP_DecryptFinal\fR\|(3).
  226. .PP
  227. \&\fBOSSL_FUNC_cipher_cipher()\fR performs encryption/decryption using the provider side cipher
  228. context in the \fIcctx\fR parameter that should have been previously initialised via
  229. a call to \fBOSSL_FUNC_cipher_encrypt_init()\fR or \fBOSSL_FUNC_cipher_decrypt_init()\fR.
  230. This should call the raw underlying cipher function without any padding.
  231. This will be invoked in the provider as a result of the application calling
  232. \&\fBEVP_Cipher\fR\|(3).
  233. The application is responsible for ensuring that the input is a multiple of the
  234. block length.
  235. The data to be encrypted/decrypted will be in \fIin\fR, and it will be \fIinl\fR bytes
  236. in length.
  237. The output from the encryption/decryption should be stored in \fIout\fR and the
  238. amount of data stored should be put in \fI*outl\fR which should be no more than
  239. \&\fIoutsize\fR bytes.
  240. .SS "Cipher Parameters"
  241. .IX Subsection "Cipher Parameters"
  242. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure used by
  243. these functions.
  244. .PP
  245. \&\fBOSSL_FUNC_cipher_get_params()\fR gets details of the algorithm implementation
  246. and stores them in \fIparams\fR.
  247. .PP
  248. \&\fBOSSL_FUNC_cipher_set_ctx_params()\fR sets cipher operation parameters for the
  249. provider side cipher context \fIcctx\fR to \fIparams\fR.
  250. Any parameter settings are additional to any that were previously set.
  251. Passing NULL for \fIparams\fR should return true.
  252. .PP
  253. \&\fBOSSL_FUNC_cipher_get_ctx_params()\fR gets cipher operation details details from
  254. the given provider side cipher context \fIcctx\fR and stores them in \fIparams\fR.
  255. Passing NULL for \fIparams\fR should return true.
  256. .PP
  257. \&\fBOSSL_FUNC_cipher_gettable_params()\fR, \fBOSSL_FUNC_cipher_gettable_ctx_params()\fR,
  258. and \fBOSSL_FUNC_cipher_settable_ctx_params()\fR all return constant \fBOSSL_PARAM\fR\|(3)
  259. arrays as descriptors of the parameters that \fBOSSL_FUNC_cipher_get_params()\fR,
  260. \&\fBOSSL_FUNC_cipher_get_ctx_params()\fR, and \fBOSSL_FUNC_cipher_set_ctx_params()\fR
  261. can handle, respectively. \fBOSSL_FUNC_cipher_gettable_ctx_params()\fR and
  262. \&\fBOSSL_FUNC_cipher_settable_ctx_params()\fR will return the parameters associated
  263. with the provider side context \fIcctx\fR in its current state if it is
  264. not NULL. Otherwise, they return the parameters associated with the
  265. provider side algorithm \fIprovctx\fR.
  266. .PP
  267. Parameters currently recognised by built-in ciphers are listed in
  268. "PARAMETERS" in \fBEVP_EncryptInit\fR\|(3).
  269. Not all parameters are relevant to, or are understood by all ciphers.
  270. .SH "RETURN VALUES"
  271. .IX Header "RETURN VALUES"
  272. \&\fBOSSL_FUNC_cipher_newctx()\fR and \fBOSSL_FUNC_cipher_dupctx()\fR should return the newly created
  273. provider side cipher context, or NULL on failure.
  274. .PP
  275. \&\fBOSSL_FUNC_cipher_encrypt_init()\fR, \fBOSSL_FUNC_cipher_decrypt_init()\fR, \fBOSSL_FUNC_cipher_update()\fR,
  276. \&\fBOSSL_FUNC_cipher_final()\fR, \fBOSSL_FUNC_cipher_cipher()\fR, \fBOSSL_FUNC_cipher_get_params()\fR,
  277. \&\fBOSSL_FUNC_cipher_get_ctx_params()\fR and \fBOSSL_FUNC_cipher_set_ctx_params()\fR should return 1 for
  278. success or 0 on error.
  279. .PP
  280. \&\fBOSSL_FUNC_cipher_gettable_params()\fR, \fBOSSL_FUNC_cipher_gettable_ctx_params()\fR and
  281. \&\fBOSSL_FUNC_cipher_settable_ctx_params()\fR should return a constant \fBOSSL_PARAM\fR\|(3)
  282. array, or NULL if none is offered.
  283. .SH "SEE ALSO"
  284. .IX Header "SEE ALSO"
  285. \&\fBprovider\fR\|(7), \fBOSSL_PROVIDER\-FIPS\fR\|(7), \fBOSSL_PROVIDER\-default\fR\|(7),
  286. \&\fBOSSL_PROVIDER\-legacy\fR\|(7),
  287. \&\fBEVP_CIPHER\-AES\fR\|(7), \fBEVP_CIPHER\-ARIA\fR\|(7), \fBEVP_CIPHER\-BLOWFISH\fR\|(7),
  288. \&\fBEVP_CIPHER\-CAMELLIA\fR\|(7), \fBEVP_CIPHER\-CAST\fR\|(7), \fBEVP_CIPHER\-CHACHA\fR\|(7),
  289. \&\fBEVP_CIPHER\-DES\fR\|(7), \fBEVP_CIPHER\-IDEA\fR\|(7), \fBEVP_CIPHER\-RC2\fR\|(7),
  290. \&\fBEVP_CIPHER\-RC4\fR\|(7), \fBEVP_CIPHER\-RC5\fR\|(7), \fBEVP_CIPHER\-SEED\fR\|(7),
  291. \&\fBEVP_CIPHER\-SM4\fR\|(7), \fBEVP_CIPHER\-NULL\fR\|(7),
  292. \&\fBlife_cycle\-cipher\fR\|(7), \fBEVP_EncryptInit\fR\|(3)
  293. .SH HISTORY
  294. .IX Header "HISTORY"
  295. The provider CIPHER interface was introduced in OpenSSL 3.0.
  296. .SH COPYRIGHT
  297. .IX Header "COPYRIGHT"
  298. Copyright 2019\-2023 The OpenSSL Project Authors. All Rights Reserved.
  299. .PP
  300. Licensed under the Apache License 2.0 (the "License"). You may not use
  301. this file except in compliance with the License. You can obtain a copy
  302. in the file LICENSE in the source distribution or at
  303. <https://www.openssl.org/source/license.html>.