EVP_EncryptInit.3ossl 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  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 "EVP_ENCRYPTINIT 3ossl"
  58. .TH EVP_ENCRYPTINIT 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. EVP_CIPHER_fetch,
  65. EVP_CIPHER_up_ref,
  66. EVP_CIPHER_free,
  67. EVP_CIPHER_CTX_new,
  68. EVP_CIPHER_CTX_reset,
  69. EVP_CIPHER_CTX_free,
  70. EVP_CIPHER_CTX_dup,
  71. EVP_CIPHER_CTX_copy,
  72. EVP_EncryptInit_ex,
  73. EVP_EncryptInit_ex2,
  74. EVP_EncryptUpdate,
  75. EVP_EncryptFinal_ex,
  76. EVP_DecryptInit_ex,
  77. EVP_DecryptInit_ex2,
  78. EVP_DecryptUpdate,
  79. EVP_DecryptFinal_ex,
  80. EVP_CipherInit_ex,
  81. EVP_CipherInit_ex2,
  82. EVP_CipherUpdate,
  83. EVP_CipherFinal_ex,
  84. EVP_CIPHER_CTX_set_key_length,
  85. EVP_CIPHER_CTX_ctrl,
  86. EVP_EncryptInit,
  87. EVP_EncryptFinal,
  88. EVP_DecryptInit,
  89. EVP_DecryptFinal,
  90. EVP_CipherInit,
  91. EVP_CipherFinal,
  92. EVP_Cipher,
  93. EVP_get_cipherbyname,
  94. EVP_get_cipherbynid,
  95. EVP_get_cipherbyobj,
  96. EVP_CIPHER_is_a,
  97. EVP_CIPHER_get0_name,
  98. EVP_CIPHER_get0_description,
  99. EVP_CIPHER_names_do_all,
  100. EVP_CIPHER_get0_provider,
  101. EVP_CIPHER_get_nid,
  102. EVP_CIPHER_get_params,
  103. EVP_CIPHER_gettable_params,
  104. EVP_CIPHER_get_block_size,
  105. EVP_CIPHER_get_key_length,
  106. EVP_CIPHER_get_iv_length,
  107. EVP_CIPHER_get_flags,
  108. EVP_CIPHER_get_mode,
  109. EVP_CIPHER_get_type,
  110. EVP_CIPHER_CTX_cipher,
  111. EVP_CIPHER_CTX_get0_cipher,
  112. EVP_CIPHER_CTX_get1_cipher,
  113. EVP_CIPHER_CTX_get0_name,
  114. EVP_CIPHER_CTX_get_nid,
  115. EVP_CIPHER_CTX_get_params,
  116. EVP_CIPHER_gettable_ctx_params,
  117. EVP_CIPHER_CTX_gettable_params,
  118. EVP_CIPHER_CTX_set_params,
  119. EVP_CIPHER_settable_ctx_params,
  120. EVP_CIPHER_CTX_settable_params,
  121. EVP_CIPHER_CTX_get_block_size,
  122. EVP_CIPHER_CTX_get_key_length,
  123. EVP_CIPHER_CTX_get_iv_length,
  124. EVP_CIPHER_CTX_get_tag_length,
  125. EVP_CIPHER_CTX_get_app_data,
  126. EVP_CIPHER_CTX_set_app_data,
  127. EVP_CIPHER_CTX_flags,
  128. EVP_CIPHER_CTX_set_flags,
  129. EVP_CIPHER_CTX_clear_flags,
  130. EVP_CIPHER_CTX_test_flags,
  131. EVP_CIPHER_CTX_get_type,
  132. EVP_CIPHER_CTX_get_mode,
  133. EVP_CIPHER_CTX_get_num,
  134. EVP_CIPHER_CTX_set_num,
  135. EVP_CIPHER_CTX_is_encrypting,
  136. EVP_CIPHER_param_to_asn1,
  137. EVP_CIPHER_asn1_to_param,
  138. EVP_CIPHER_CTX_set_padding,
  139. EVP_enc_null,
  140. EVP_CIPHER_do_all_provided,
  141. EVP_CIPHER_nid,
  142. EVP_CIPHER_name,
  143. EVP_CIPHER_block_size,
  144. EVP_CIPHER_key_length,
  145. EVP_CIPHER_iv_length,
  146. EVP_CIPHER_flags,
  147. EVP_CIPHER_mode,
  148. EVP_CIPHER_type,
  149. EVP_CIPHER_CTX_encrypting,
  150. EVP_CIPHER_CTX_nid,
  151. EVP_CIPHER_CTX_block_size,
  152. EVP_CIPHER_CTX_key_length,
  153. EVP_CIPHER_CTX_iv_length,
  154. EVP_CIPHER_CTX_tag_length,
  155. EVP_CIPHER_CTX_num,
  156. EVP_CIPHER_CTX_type,
  157. EVP_CIPHER_CTX_mode
  158. \&\- EVP cipher routines
  159. .SH SYNOPSIS
  160. .IX Header "SYNOPSIS"
  161. .Vb 1
  162. \& #include <openssl/evp.h>
  163. \&
  164. \& EVP_CIPHER *EVP_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
  165. \& const char *properties);
  166. \& int EVP_CIPHER_up_ref(EVP_CIPHER *cipher);
  167. \& void EVP_CIPHER_free(EVP_CIPHER *cipher);
  168. \& EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void);
  169. \& int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx);
  170. \& void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx);
  171. \& EVP_CIPHER_CTX *EVP_CIPHER_CTX_dup(const EVP_CIPHER_CTX *in);
  172. \& int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in);
  173. \&
  174. \& int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  175. \& ENGINE *impl, const unsigned char *key, const unsigned char *iv);
  176. \& int EVP_EncryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  177. \& const unsigned char *key, const unsigned char *iv,
  178. \& const OSSL_PARAM params[]);
  179. \& int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
  180. \& int *outl, const unsigned char *in, int inl);
  181. \& int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
  182. \&
  183. \& int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  184. \& ENGINE *impl, const unsigned char *key, const unsigned char *iv);
  185. \& int EVP_DecryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  186. \& const unsigned char *key, const unsigned char *iv,
  187. \& const OSSL_PARAM params[]);
  188. \& int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
  189. \& int *outl, const unsigned char *in, int inl);
  190. \& int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
  191. \&
  192. \& int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  193. \& ENGINE *impl, const unsigned char *key, const unsigned char *iv, int enc);
  194. \& int EVP_CipherInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  195. \& const unsigned char *key, const unsigned char *iv,
  196. \& int enc, const OSSL_PARAM params[]);
  197. \& int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
  198. \& int *outl, const unsigned char *in, int inl);
  199. \& int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
  200. \&
  201. \& int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  202. \& const unsigned char *key, const unsigned char *iv);
  203. \& int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
  204. \&
  205. \& int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  206. \& const unsigned char *key, const unsigned char *iv);
  207. \& int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
  208. \&
  209. \& int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
  210. \& const unsigned char *key, const unsigned char *iv, int enc);
  211. \& int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
  212. \&
  213. \& int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
  214. \& const unsigned char *in, unsigned int inl);
  215. \&
  216. \& int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *x, int padding);
  217. \& int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
  218. \& int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int cmd, int p1, void *p2);
  219. \& int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);
  220. \& void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags);
  221. \& void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags);
  222. \& int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags);
  223. \&
  224. \& const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
  225. \& const EVP_CIPHER *EVP_get_cipherbynid(int nid);
  226. \& const EVP_CIPHER *EVP_get_cipherbyobj(const ASN1_OBJECT *a);
  227. \&
  228. \& int EVP_CIPHER_get_nid(const EVP_CIPHER *e);
  229. \& int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name);
  230. \& int EVP_CIPHER_names_do_all(const EVP_CIPHER *cipher,
  231. \& void (*fn)(const char *name, void *data),
  232. \& void *data);
  233. \& const char *EVP_CIPHER_get0_name(const EVP_CIPHER *cipher);
  234. \& const char *EVP_CIPHER_get0_description(const EVP_CIPHER *cipher);
  235. \& const OSSL_PROVIDER *EVP_CIPHER_get0_provider(const EVP_CIPHER *cipher);
  236. \& int EVP_CIPHER_get_block_size(const EVP_CIPHER *e);
  237. \& int EVP_CIPHER_get_key_length(const EVP_CIPHER *e);
  238. \& int EVP_CIPHER_get_iv_length(const EVP_CIPHER *e);
  239. \& unsigned long EVP_CIPHER_get_flags(const EVP_CIPHER *e);
  240. \& unsigned long EVP_CIPHER_get_mode(const EVP_CIPHER *e);
  241. \& int EVP_CIPHER_get_type(const EVP_CIPHER *cipher);
  242. \&
  243. \& const EVP_CIPHER *EVP_CIPHER_CTX_get0_cipher(const EVP_CIPHER_CTX *ctx);
  244. \& EVP_CIPHER *EVP_CIPHER_CTX_get1_cipher(const EVP_CIPHER_CTX *ctx);
  245. \& int EVP_CIPHER_CTX_get_nid(const EVP_CIPHER_CTX *ctx);
  246. \& const char *EVP_CIPHER_CTX_get0_name(const EVP_CIPHER_CTX *ctx);
  247. \&
  248. \& int EVP_CIPHER_get_params(EVP_CIPHER *cipher, OSSL_PARAM params[]);
  249. \& int EVP_CIPHER_CTX_set_params(EVP_CIPHER_CTX *ctx, const OSSL_PARAM params[]);
  250. \& int EVP_CIPHER_CTX_get_params(EVP_CIPHER_CTX *ctx, OSSL_PARAM params[]);
  251. \& const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher);
  252. \& const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher);
  253. \& const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher);
  254. \& const OSSL_PARAM *EVP_CIPHER_CTX_settable_params(EVP_CIPHER_CTX *ctx);
  255. \& const OSSL_PARAM *EVP_CIPHER_CTX_gettable_params(EVP_CIPHER_CTX *ctx);
  256. \& int EVP_CIPHER_CTX_get_block_size(const EVP_CIPHER_CTX *ctx);
  257. \& int EVP_CIPHER_CTX_get_key_length(const EVP_CIPHER_CTX *ctx);
  258. \& int EVP_CIPHER_CTX_get_iv_length(const EVP_CIPHER_CTX *ctx);
  259. \& int EVP_CIPHER_CTX_get_tag_length(const EVP_CIPHER_CTX *ctx);
  260. \& void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx);
  261. \& void EVP_CIPHER_CTX_set_app_data(const EVP_CIPHER_CTX *ctx, void *data);
  262. \& int EVP_CIPHER_CTX_get_type(const EVP_CIPHER_CTX *ctx);
  263. \& int EVP_CIPHER_CTX_get_mode(const EVP_CIPHER_CTX *ctx);
  264. \& int EVP_CIPHER_CTX_get_num(const EVP_CIPHER_CTX *ctx);
  265. \& int EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num);
  266. \& int EVP_CIPHER_CTX_is_encrypting(const EVP_CIPHER_CTX *ctx);
  267. \&
  268. \& int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
  269. \& int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
  270. \&
  271. \& void EVP_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx,
  272. \& void (*fn)(EVP_CIPHER *cipher, void *arg),
  273. \& void *arg);
  274. \&
  275. \& #define EVP_CIPHER_nid EVP_CIPHER_get_nid
  276. \& #define EVP_CIPHER_name EVP_CIPHER_get0_name
  277. \& #define EVP_CIPHER_block_size EVP_CIPHER_get_block_size
  278. \& #define EVP_CIPHER_key_length EVP_CIPHER_get_key_length
  279. \& #define EVP_CIPHER_iv_length EVP_CIPHER_get_iv_length
  280. \& #define EVP_CIPHER_flags EVP_CIPHER_get_flags
  281. \& #define EVP_CIPHER_mode EVP_CIPHER_get_mode
  282. \& #define EVP_CIPHER_type EVP_CIPHER_get_type
  283. \& #define EVP_CIPHER_CTX_encrypting EVP_CIPHER_CTX_is_encrypting
  284. \& #define EVP_CIPHER_CTX_nid EVP_CIPHER_CTX_get_nid
  285. \& #define EVP_CIPHER_CTX_block_size EVP_CIPHER_CTX_get_block_size
  286. \& #define EVP_CIPHER_CTX_key_length EVP_CIPHER_CTX_get_key_length
  287. \& #define EVP_CIPHER_CTX_iv_length EVP_CIPHER_CTX_get_iv_length
  288. \& #define EVP_CIPHER_CTX_tag_length EVP_CIPHER_CTX_get_tag_length
  289. \& #define EVP_CIPHER_CTX_num EVP_CIPHER_CTX_get_num
  290. \& #define EVP_CIPHER_CTX_type EVP_CIPHER_CTX_get_type
  291. \& #define EVP_CIPHER_CTX_mode EVP_CIPHER_CTX_get_mode
  292. .Ve
  293. .PP
  294. The following function has been deprecated since OpenSSL 3.0, and can be
  295. hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
  296. see \fBopenssl_user_macros\fR\|(7):
  297. .PP
  298. .Vb 1
  299. \& const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx);
  300. .Ve
  301. .PP
  302. The following function has been deprecated since OpenSSL 1.1.0, and can be
  303. hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
  304. see \fBopenssl_user_macros\fR\|(7):
  305. .PP
  306. .Vb 1
  307. \& int EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx);
  308. .Ve
  309. .SH DESCRIPTION
  310. .IX Header "DESCRIPTION"
  311. The EVP cipher routines are a high-level interface to certain
  312. symmetric ciphers.
  313. .PP
  314. The \fBEVP_CIPHER\fR type is a structure for cipher method implementation.
  315. .IP \fBEVP_CIPHER_fetch()\fR 4
  316. .IX Item "EVP_CIPHER_fetch()"
  317. Fetches the cipher implementation for the given \fIalgorithm\fR from any provider
  318. offering it, within the criteria given by the \fIproperties\fR.
  319. See "ALGORITHM FETCHING" in \fBcrypto\fR\|(7) for further information.
  320. .Sp
  321. The returned value must eventually be freed with \fBEVP_CIPHER_free()\fR.
  322. .Sp
  323. Fetched \fBEVP_CIPHER\fR structures are reference counted.
  324. .IP \fBEVP_CIPHER_up_ref()\fR 4
  325. .IX Item "EVP_CIPHER_up_ref()"
  326. Increments the reference count for an \fBEVP_CIPHER\fR structure.
  327. .IP \fBEVP_CIPHER_free()\fR 4
  328. .IX Item "EVP_CIPHER_free()"
  329. Decrements the reference count for the fetched \fBEVP_CIPHER\fR structure.
  330. If the reference count drops to 0 then the structure is freed.
  331. If the argument is NULL, nothing is done.
  332. .IP \fBEVP_CIPHER_CTX_new()\fR 4
  333. .IX Item "EVP_CIPHER_CTX_new()"
  334. Allocates and returns a cipher context.
  335. .IP \fBEVP_CIPHER_CTX_free()\fR 4
  336. .IX Item "EVP_CIPHER_CTX_free()"
  337. Clears all information from a cipher context and frees any allocated memory
  338. associated with it, including \fIctx\fR itself. This function should be called
  339. after all operations using a cipher are complete so sensitive information does
  340. not remain in memory. If the argument is NULL, nothing is done.
  341. .IP \fBEVP_CIPHER_CTX_dup()\fR 4
  342. .IX Item "EVP_CIPHER_CTX_dup()"
  343. Can be used to duplicate the cipher state from \fIin\fR. This is useful
  344. to avoid multiple \fBEVP_CIPHER_fetch()\fR calls or if large amounts of data are to be
  345. fed which only differ in the last few bytes.
  346. .IP \fBEVP_CIPHER_CTX_copy()\fR 4
  347. .IX Item "EVP_CIPHER_CTX_copy()"
  348. Can be used to copy the cipher state from \fIin\fR to \fIout\fR.
  349. .IP \fBEVP_CIPHER_CTX_ctrl()\fR 4
  350. .IX Item "EVP_CIPHER_CTX_ctrl()"
  351. \&\fIThis is a legacy method.\fR \fBEVP_CIPHER_CTX_set_params()\fR and
  352. \&\fBEVP_CIPHER_CTX_get_params()\fR is the mechanism that should be used to set and get
  353. parameters that are used by providers.
  354. .Sp
  355. Performs cipher-specific control actions on context \fIctx\fR. The control command
  356. is indicated in \fIcmd\fR and any additional arguments in \fIp1\fR and \fIp2\fR.
  357. \&\fBEVP_CIPHER_CTX_ctrl()\fR must be called after \fBEVP_CipherInit_ex2()\fR. Other restrictions
  358. may apply depending on the control type and cipher implementation.
  359. .Sp
  360. If this function happens to be used with a fetched \fBEVP_CIPHER\fR, it will
  361. translate the controls that are known to OpenSSL into \fBOSSL_PARAM\fR\|(3)
  362. parameters with keys defined by OpenSSL and call \fBEVP_CIPHER_CTX_get_params()\fR or
  363. \&\fBEVP_CIPHER_CTX_set_params()\fR as is appropriate for each control command.
  364. .Sp
  365. See "CONTROLS" below for more information, including what translations are
  366. being done.
  367. .IP \fBEVP_CIPHER_get_params()\fR 4
  368. .IX Item "EVP_CIPHER_get_params()"
  369. Retrieves the requested list of algorithm \fIparams\fR from a CIPHER \fIcipher\fR.
  370. See "PARAMETERS" below for more information.
  371. .IP \fBEVP_CIPHER_CTX_get_params()\fR 4
  372. .IX Item "EVP_CIPHER_CTX_get_params()"
  373. Retrieves the requested list of \fIparams\fR from CIPHER context \fIctx\fR.
  374. See "PARAMETERS" below for more information.
  375. .IP \fBEVP_CIPHER_CTX_set_params()\fR 4
  376. .IX Item "EVP_CIPHER_CTX_set_params()"
  377. Sets the list of \fIparams\fR into a CIPHER context \fIctx\fR.
  378. See "PARAMETERS" below for more information.
  379. .IP \fBEVP_CIPHER_gettable_params()\fR 4
  380. .IX Item "EVP_CIPHER_gettable_params()"
  381. Get a constant \fBOSSL_PARAM\fR\|(3) array that describes the retrievable parameters
  382. that can be used with \fBEVP_CIPHER_get_params()\fR.
  383. .IP "\fBEVP_CIPHER_gettable_ctx_params()\fR and \fBEVP_CIPHER_CTX_gettable_params()\fR" 4
  384. .IX Item "EVP_CIPHER_gettable_ctx_params() and EVP_CIPHER_CTX_gettable_params()"
  385. Get a constant \fBOSSL_PARAM\fR\|(3) array that describes the retrievable parameters
  386. that can be used with \fBEVP_CIPHER_CTX_get_params()\fR.
  387. \&\fBEVP_CIPHER_gettable_ctx_params()\fR returns the parameters that can be retrieved
  388. from the algorithm, whereas \fBEVP_CIPHER_CTX_gettable_params()\fR returns the
  389. parameters that can be retrieved in the context's current state.
  390. .IP "\fBEVP_CIPHER_settable_ctx_params()\fR and \fBEVP_CIPHER_CTX_settable_params()\fR" 4
  391. .IX Item "EVP_CIPHER_settable_ctx_params() and EVP_CIPHER_CTX_settable_params()"
  392. Get a constant \fBOSSL_PARAM\fR\|(3) array that describes the settable parameters
  393. that can be used with \fBEVP_CIPHER_CTX_set_params()\fR.
  394. \&\fBEVP_CIPHER_settable_ctx_params()\fR returns the parameters that can be set from the
  395. algorithm, whereas \fBEVP_CIPHER_CTX_settable_params()\fR returns the parameters that
  396. can be set in the context's current state.
  397. .IP \fBEVP_EncryptInit_ex2()\fR 4
  398. .IX Item "EVP_EncryptInit_ex2()"
  399. Sets up cipher context \fIctx\fR for encryption with cipher \fItype\fR. \fItype\fR is
  400. typically supplied by calling \fBEVP_CIPHER_fetch()\fR. \fItype\fR may also be set
  401. using legacy functions such as \fBEVP_aes_256_cbc()\fR, but this is not recommended
  402. for new applications. \fIkey\fR is the symmetric key to use and \fIiv\fR is the IV to
  403. use (if necessary), the actual number of bytes used for the key and IV depends
  404. on the cipher. The parameters \fIparams\fR will be set on the context after
  405. initialisation. It is possible to set all parameters to NULL except \fItype\fR in
  406. an initial call and supply the remaining parameters in subsequent calls, all of
  407. which have \fItype\fR set to NULL. This is done when the default cipher parameters
  408. are not appropriate.
  409. For \fBEVP_CIPH_GCM_MODE\fR the IV will be generated internally if it is not
  410. specified.
  411. .IP \fBEVP_EncryptInit_ex()\fR 4
  412. .IX Item "EVP_EncryptInit_ex()"
  413. This legacy function is similar to \fBEVP_EncryptInit_ex2()\fR when \fIimpl\fR is NULL.
  414. The implementation of the \fItype\fR from the \fIimpl\fR engine will be used if it
  415. exists.
  416. .IP \fBEVP_EncryptUpdate()\fR 4
  417. .IX Item "EVP_EncryptUpdate()"
  418. Encrypts \fIinl\fR bytes from the buffer \fIin\fR and writes the encrypted version to
  419. \&\fIout\fR. The pointers \fIout\fR and \fIin\fR may point to the same location, in which
  420. case the encryption will be done in-place. However, in-place encryption is
  421. guaranteed to work only if the encryption context (\fIctx\fR) has processed data in
  422. multiples of the block size. If the context contains an incomplete data block
  423. from previous operations, in-place encryption will fail.
  424. .Sp
  425. If \fIout\fR and \fIin\fR point to different locations, the two buffers must be
  426. disjoint, otherwise the operation might fail or the outcome might be undefined.
  427. .Sp
  428. This function can be called multiple times to encrypt successive blocks
  429. of data. The amount of data written depends on the block alignment of the
  430. encrypted data.
  431. For most ciphers and modes, the amount of data written can be anything
  432. from zero bytes to (inl + cipher_block_size \- 1) bytes.
  433. For wrap cipher modes, the amount of data written can be anything
  434. from zero bytes to (inl + cipher_block_size) bytes.
  435. For stream ciphers, the amount of data written can be anything from zero
  436. bytes to inl bytes.
  437. Thus, the buffer pointed to by \fIout\fR must contain sufficient room for the
  438. operation being performed.
  439. The actual number of bytes written is placed in \fIoutl\fR.
  440. .Sp
  441. If padding is enabled (the default) then \fBEVP_EncryptFinal_ex()\fR encrypts
  442. the "final" data, that is any data that remains in a partial block.
  443. It uses standard block padding (aka PKCS padding) as described in
  444. the NOTES section, below. The encrypted
  445. final data is written to \fIout\fR which should have sufficient space for
  446. one cipher block. The number of bytes written is placed in \fIoutl\fR. After
  447. this function is called the encryption operation is finished and no further
  448. calls to \fBEVP_EncryptUpdate()\fR should be made.
  449. .Sp
  450. If padding is disabled then \fBEVP_EncryptFinal_ex()\fR will not encrypt any more
  451. data and it will return an error if any data remains in a partial block:
  452. that is if the total data length is not a multiple of the block size.
  453. .IP "\fBEVP_DecryptInit_ex2()\fR, \fBEVP_DecryptInit_ex()\fR, \fBEVP_DecryptUpdate()\fR and \fBEVP_DecryptFinal_ex()\fR" 4
  454. .IX Item "EVP_DecryptInit_ex2(), EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex()"
  455. These functions are the corresponding decryption operations.
  456. \&\fBEVP_DecryptFinal()\fR will return an error code if padding is enabled and the
  457. final block is not correctly formatted. The parameters and restrictions are
  458. identical to the encryption operations except that if padding is enabled the
  459. decrypted data buffer \fIout\fR passed to \fBEVP_DecryptUpdate()\fR should have
  460. sufficient room for (\fIinl\fR + cipher_block_size) bytes unless the cipher block
  461. size is 1 in which case \fIinl\fR bytes is sufficient.
  462. .IP "\fBEVP_CipherInit_ex2()\fR, \fBEVP_CipherInit_ex()\fR, \fBEVP_CipherUpdate()\fR and \fBEVP_CipherFinal_ex()\fR" 4
  463. .IX Item "EVP_CipherInit_ex2(), EVP_CipherInit_ex(), EVP_CipherUpdate() and EVP_CipherFinal_ex()"
  464. These functions can be used for decryption or encryption. The operation
  465. performed depends on the value of the \fIenc\fR parameter. It should be set to 1
  466. for encryption, 0 for decryption and \-1 to leave the value unchanged
  467. (the actual value of 'enc' being supplied in a previous call).
  468. .IP \fBEVP_CIPHER_CTX_reset()\fR 4
  469. .IX Item "EVP_CIPHER_CTX_reset()"
  470. Clears all information from a cipher context and free up any allocated memory
  471. associated with it, except the \fIctx\fR itself. This function should be called
  472. anytime \fIctx\fR is reused by another
  473. \&\fBEVP_CipherInit()\fR / \fBEVP_CipherUpdate()\fR / \fBEVP_CipherFinal()\fR series of calls.
  474. .IP "\fBEVP_EncryptInit()\fR, \fBEVP_DecryptInit()\fR and \fBEVP_CipherInit()\fR" 4
  475. .IX Item "EVP_EncryptInit(), EVP_DecryptInit() and EVP_CipherInit()"
  476. Behave in a similar way to \fBEVP_EncryptInit_ex()\fR, \fBEVP_DecryptInit_ex()\fR and
  477. \&\fBEVP_CipherInit_ex()\fR except if the \fItype\fR is not a fetched cipher they use the
  478. default implementation of the \fItype\fR.
  479. .IP "\fBEVP_EncryptFinal()\fR, \fBEVP_DecryptFinal()\fR and \fBEVP_CipherFinal()\fR" 4
  480. .IX Item "EVP_EncryptFinal(), EVP_DecryptFinal() and EVP_CipherFinal()"
  481. Identical to \fBEVP_EncryptFinal_ex()\fR, \fBEVP_DecryptFinal_ex()\fR and
  482. \&\fBEVP_CipherFinal_ex()\fR. In previous releases they also cleaned up
  483. the \fIctx\fR, but this is no longer done and \fBEVP_CIPHER_CTX_cleanup()\fR
  484. must be called to free any context resources.
  485. .IP \fBEVP_Cipher()\fR 4
  486. .IX Item "EVP_Cipher()"
  487. Encrypts or decrypts a maximum \fIinl\fR amount of bytes from \fIin\fR and leaves the
  488. result in \fIout\fR.
  489. .Sp
  490. For legacy ciphers \- If the cipher doesn't have the flag
  491. \&\fBEVP_CIPH_FLAG_CUSTOM_CIPHER\fR set, then \fIinl\fR must be a multiple of
  492. \&\fBEVP_CIPHER_get_block_size()\fR. If it isn't, the result is undefined. If the cipher
  493. has that flag set, then \fIinl\fR can be any size.
  494. .Sp
  495. Due to the constraints of the API contract of this function it shouldn't be used
  496. in applications, please consider using \fBEVP_CipherUpdate()\fR and
  497. \&\fBEVP_CipherFinal_ex()\fR instead.
  498. .IP "\fBEVP_get_cipherbyname()\fR, \fBEVP_get_cipherbynid()\fR and \fBEVP_get_cipherbyobj()\fR" 4
  499. .IX Item "EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()"
  500. Returns an \fBEVP_CIPHER\fR structure when passed a cipher name, a cipher \fBNID\fR or
  501. an \fBASN1_OBJECT\fR structure respectively.
  502. .Sp
  503. \&\fBEVP_get_cipherbyname()\fR will return NULL for algorithms such as "AES\-128\-SIV",
  504. "AES\-128\-CBC\-CTS" and "CAMELLIA\-128\-CBC\-CTS" which were previously only
  505. accessible via low level interfaces.
  506. .Sp
  507. The \fBEVP_get_cipherbyname()\fR function is present for backwards compatibility with
  508. OpenSSL prior to version 3 and is different to the \fBEVP_CIPHER_fetch()\fR function
  509. since it does not attempt to "fetch" an implementation of the cipher.
  510. Additionally, it only knows about ciphers that are built-in to OpenSSL and have
  511. an associated NID. Similarly \fBEVP_get_cipherbynid()\fR and \fBEVP_get_cipherbyobj()\fR
  512. also return objects without an associated implementation.
  513. .Sp
  514. When the cipher objects returned by these functions are used (such as in a call
  515. to \fBEVP_EncryptInit_ex()\fR) an implementation of the cipher will be implicitly
  516. fetched from the loaded providers. This fetch could fail if no suitable
  517. implementation is available. Use \fBEVP_CIPHER_fetch()\fR instead to explicitly fetch
  518. the algorithm and an associated implementation from a provider.
  519. .Sp
  520. See "ALGORITHM FETCHING" in \fBcrypto\fR\|(7) for more information about fetching.
  521. .Sp
  522. The cipher objects returned from these functions do not need to be freed with
  523. \&\fBEVP_CIPHER_free()\fR.
  524. .IP "\fBEVP_CIPHER_get_nid()\fR and \fBEVP_CIPHER_CTX_get_nid()\fR" 4
  525. .IX Item "EVP_CIPHER_get_nid() and EVP_CIPHER_CTX_get_nid()"
  526. Return the NID of a cipher when passed an \fBEVP_CIPHER\fR or \fBEVP_CIPHER_CTX\fR
  527. structure. The actual NID value is an internal value which may not have a
  528. corresponding OBJECT IDENTIFIER. NID_undef is returned in the event that the
  529. nid is unknown or if the cipher has not been properly initialized via a call to
  530. \&\fBEVP_CipherInit\fR.
  531. .IP "\fBEVP_CIPHER_CTX_set_flags()\fR, \fBEVP_CIPHER_CTX_clear_flags()\fR and \fBEVP_CIPHER_CTX_test_flags()\fR" 4
  532. .IX Item "EVP_CIPHER_CTX_set_flags(), EVP_CIPHER_CTX_clear_flags() and EVP_CIPHER_CTX_test_flags()"
  533. Sets, clears and tests \fIctx\fR flags. See "FLAGS" below for more information.
  534. .Sp
  535. For provided ciphers \fBEVP_CIPHER_CTX_set_flags()\fR should be called only after the
  536. fetched cipher has been assigned to the \fIctx\fR. It is recommended to use
  537. "PARAMETERS" instead.
  538. .IP \fBEVP_CIPHER_CTX_set_padding()\fR 4
  539. .IX Item "EVP_CIPHER_CTX_set_padding()"
  540. Enables or disables padding. This function should be called after the context
  541. is set up for encryption or decryption with \fBEVP_EncryptInit_ex2()\fR,
  542. \&\fBEVP_DecryptInit_ex2()\fR or \fBEVP_CipherInit_ex2()\fR. By default encryption operations
  543. are padded using standard block padding and the padding is checked and removed
  544. when decrypting. If the \fIpad\fR parameter is zero then no padding is
  545. performed, the total amount of data encrypted or decrypted must then
  546. be a multiple of the block size or an error will occur.
  547. .IP "\fBEVP_CIPHER_get_key_length()\fR and \fBEVP_CIPHER_CTX_get_key_length()\fR" 4
  548. .IX Item "EVP_CIPHER_get_key_length() and EVP_CIPHER_CTX_get_key_length()"
  549. Return the key length of a cipher when passed an \fBEVP_CIPHER\fR or
  550. \&\fBEVP_CIPHER_CTX\fR structure. The constant \fBEVP_MAX_KEY_LENGTH\fR is the maximum
  551. key length for all ciphers. Note: although \fBEVP_CIPHER_get_key_length()\fR is fixed for
  552. a given cipher, the value of \fBEVP_CIPHER_CTX_get_key_length()\fR may be different for
  553. variable key length ciphers.
  554. .IP \fBEVP_CIPHER_CTX_set_key_length()\fR 4
  555. .IX Item "EVP_CIPHER_CTX_set_key_length()"
  556. Sets the key length of the cipher context.
  557. If the cipher is a fixed length cipher then attempting to set the key
  558. length to any value other than the fixed value is an error.
  559. .IP "\fBEVP_CIPHER_get_iv_length()\fR and \fBEVP_CIPHER_CTX_get_iv_length()\fR" 4
  560. .IX Item "EVP_CIPHER_get_iv_length() and EVP_CIPHER_CTX_get_iv_length()"
  561. Return the IV length of a cipher when passed an \fBEVP_CIPHER\fR or
  562. \&\fBEVP_CIPHER_CTX\fR. It will return zero if the cipher does not use an IV, if
  563. the cipher has not yet been initialized within the \fBEVP_CIPHER_CTX\fR, or if the
  564. passed cipher is NULL. The constant \fBEVP_MAX_IV_LENGTH\fR is the maximum IV
  565. length for all ciphers.
  566. .IP \fBEVP_CIPHER_CTX_get_tag_length()\fR 4
  567. .IX Item "EVP_CIPHER_CTX_get_tag_length()"
  568. Returns the tag length of an AEAD cipher when passed a \fBEVP_CIPHER_CTX\fR. It will
  569. return zero if the cipher does not support a tag. It returns a default value if
  570. the tag length has not been set.
  571. .IP "\fBEVP_CIPHER_get_block_size()\fR and \fBEVP_CIPHER_CTX_get_block_size()\fR" 4
  572. .IX Item "EVP_CIPHER_get_block_size() and EVP_CIPHER_CTX_get_block_size()"
  573. Return the block size of a cipher when passed an \fBEVP_CIPHER\fR or
  574. \&\fBEVP_CIPHER_CTX\fR structure. The constant \fBEVP_MAX_BLOCK_LENGTH\fR is also the
  575. maximum block length for all ciphers. A value of 0 is returned if the cipher
  576. has not been properly initialized with a call to \fBEVP_CipherInit\fR.
  577. .IP "\fBEVP_CIPHER_get_type()\fR and \fBEVP_CIPHER_CTX_get_type()\fR" 4
  578. .IX Item "EVP_CIPHER_get_type() and EVP_CIPHER_CTX_get_type()"
  579. Return the type of the passed cipher or context. This "type" is the actual NID
  580. of the cipher OBJECT IDENTIFIER and as such it ignores the cipher parameters
  581. (40 bit RC2 and 128 bit RC2 have the same NID). If the cipher does not have an
  582. object identifier or does not have ASN1 support this function will return
  583. \&\fBNID_undef\fR.
  584. .IP \fBEVP_CIPHER_is_a()\fR 4
  585. .IX Item "EVP_CIPHER_is_a()"
  586. Returns 1 if \fIcipher\fR is an implementation of an algorithm that's identifiable
  587. with \fIname\fR, otherwise 0. If \fIcipher\fR is a legacy cipher (it's the return
  588. value from the likes of \fBEVP_aes128()\fR rather than the result of an
  589. \&\fBEVP_CIPHER_fetch()\fR), only cipher names registered with the default library
  590. context (see \fBOSSL_LIB_CTX\fR\|(3)) will be considered.
  591. .IP "\fBEVP_CIPHER_get0_name()\fR and \fBEVP_CIPHER_CTX_get0_name()\fR" 4
  592. .IX Item "EVP_CIPHER_get0_name() and EVP_CIPHER_CTX_get0_name()"
  593. Return the name of the passed cipher or context. For fetched ciphers with
  594. multiple names, only one of them is returned. See also \fBEVP_CIPHER_names_do_all()\fR.
  595. .IP \fBEVP_CIPHER_names_do_all()\fR 4
  596. .IX Item "EVP_CIPHER_names_do_all()"
  597. Traverses all names for the \fIcipher\fR, and calls \fIfn\fR with each name and
  598. \&\fIdata\fR. This is only useful with fetched \fBEVP_CIPHER\fRs.
  599. .IP \fBEVP_CIPHER_get0_description()\fR 4
  600. .IX Item "EVP_CIPHER_get0_description()"
  601. Returns a description of the cipher, meant for display and human consumption.
  602. The description is at the discretion of the cipher implementation.
  603. .IP \fBEVP_CIPHER_get0_provider()\fR 4
  604. .IX Item "EVP_CIPHER_get0_provider()"
  605. Returns an \fBOSSL_PROVIDER\fR pointer to the provider that implements the given
  606. \&\fBEVP_CIPHER\fR.
  607. .IP \fBEVP_CIPHER_CTX_get0_cipher()\fR 4
  608. .IX Item "EVP_CIPHER_CTX_get0_cipher()"
  609. Returns the \fBEVP_CIPHER\fR structure when passed an \fBEVP_CIPHER_CTX\fR structure.
  610. \&\fBEVP_CIPHER_CTX_get1_cipher()\fR is the same except the ownership is passed to
  611. the caller. Both functions return NULL on error.
  612. .IP "\fBEVP_CIPHER_get_mode()\fR and \fBEVP_CIPHER_CTX_get_mode()\fR" 4
  613. .IX Item "EVP_CIPHER_get_mode() and EVP_CIPHER_CTX_get_mode()"
  614. Return the block cipher mode:
  615. EVP_CIPH_ECB_MODE, EVP_CIPH_CBC_MODE, EVP_CIPH_CFB_MODE, EVP_CIPH_OFB_MODE,
  616. EVP_CIPH_CTR_MODE, EVP_CIPH_GCM_MODE, EVP_CIPH_CCM_MODE, EVP_CIPH_XTS_MODE,
  617. EVP_CIPH_WRAP_MODE, EVP_CIPH_OCB_MODE or EVP_CIPH_SIV_MODE.
  618. If the cipher is a stream cipher then EVP_CIPH_STREAM_CIPHER is returned.
  619. .IP \fBEVP_CIPHER_get_flags()\fR 4
  620. .IX Item "EVP_CIPHER_get_flags()"
  621. Returns any flags associated with the cipher. See "FLAGS"
  622. for a list of currently defined flags.
  623. .IP "\fBEVP_CIPHER_CTX_get_num()\fR and \fBEVP_CIPHER_CTX_set_num()\fR" 4
  624. .IX Item "EVP_CIPHER_CTX_get_num() and EVP_CIPHER_CTX_set_num()"
  625. Gets or sets the cipher specific "num" parameter for the associated \fIctx\fR.
  626. Built-in ciphers typically use this to track how much of the current underlying block
  627. has been "used" already.
  628. .IP \fBEVP_CIPHER_CTX_is_encrypting()\fR 4
  629. .IX Item "EVP_CIPHER_CTX_is_encrypting()"
  630. Reports whether the \fIctx\fR is being used for encryption or decryption.
  631. .IP \fBEVP_CIPHER_CTX_flags()\fR 4
  632. .IX Item "EVP_CIPHER_CTX_flags()"
  633. A deprecated macro calling \f(CW\*(C`EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(ctx))\*(C'\fR.
  634. Do not use.
  635. .IP \fBEVP_CIPHER_param_to_asn1()\fR 4
  636. .IX Item "EVP_CIPHER_param_to_asn1()"
  637. Sets the AlgorithmIdentifier "parameter" based on the passed cipher. This will
  638. typically include any parameters and an IV. The cipher IV (if any) must be set
  639. when this call is made. This call should be made before the cipher is actually
  640. "used" (before any \fBEVP_EncryptUpdate()\fR, \fBEVP_DecryptUpdate()\fR calls for example).
  641. This function may fail if the cipher does not have any ASN1 support, or if an
  642. uninitialized cipher is passed to it.
  643. .IP \fBEVP_CIPHER_asn1_to_param()\fR 4
  644. .IX Item "EVP_CIPHER_asn1_to_param()"
  645. Sets the cipher parameters based on an ASN1 AlgorithmIdentifier "parameter".
  646. The precise effect depends on the cipher. In the case of \fBRC2\fR, for example,
  647. it will set the IV and effective key length.
  648. This function should be called after the base cipher type is set but before
  649. the key is set. For example \fBEVP_CipherInit()\fR will be called with the IV and
  650. key set to NULL, \fBEVP_CIPHER_asn1_to_param()\fR will be called and finally
  651. \&\fBEVP_CipherInit()\fR again with all parameters except the key set to NULL. It is
  652. possible for this function to fail if the cipher does not have any ASN1 support
  653. or the parameters cannot be set (for example the RC2 effective key length
  654. is not supported.
  655. .IP \fBEVP_CIPHER_CTX_rand_key()\fR 4
  656. .IX Item "EVP_CIPHER_CTX_rand_key()"
  657. Generates a random key of the appropriate length based on the cipher context.
  658. The \fBEVP_CIPHER\fR can provide its own random key generation routine to support
  659. keys of a specific form. \fIkey\fR must point to a buffer at least as big as the
  660. value returned by \fBEVP_CIPHER_CTX_get_key_length()\fR.
  661. .IP \fBEVP_CIPHER_do_all_provided()\fR 4
  662. .IX Item "EVP_CIPHER_do_all_provided()"
  663. Traverses all ciphers implemented by all activated providers in the given
  664. library context \fIlibctx\fR, and for each of the implementations, calls the given
  665. function \fIfn\fR with the implementation method and the given \fIarg\fR as argument.
  666. .SH PARAMETERS
  667. .IX Header "PARAMETERS"
  668. See \fBOSSL_PARAM\fR\|(3) for information about passing parameters.
  669. .SS "Gettable EVP_CIPHER parameters"
  670. .IX Subsection "Gettable EVP_CIPHER parameters"
  671. When \fBEVP_CIPHER_fetch()\fR is called it internally calls \fBEVP_CIPHER_get_params()\fR
  672. and caches the results.
  673. .PP
  674. \&\fBEVP_CIPHER_get_params()\fR can be used with the following \fBOSSL_PARAM\fR\|(3) keys:
  675. .IP """mode"" (\fBOSSL_CIPHER_PARAM_MODE\fR) <unsigned integer>" 4
  676. .IX Item """mode"" (OSSL_CIPHER_PARAM_MODE) <unsigned integer>"
  677. Gets the mode for the associated cipher algorithm \fIcipher\fR.
  678. See "\fBEVP_CIPHER_get_mode()\fR and \fBEVP_CIPHER_CTX_get_mode()\fR" for a list of valid modes.
  679. Use \fBEVP_CIPHER_get_mode()\fR to retrieve the cached value.
  680. .IP """keylen"" (\fBOSSL_CIPHER_PARAM_KEYLEN\fR) <unsigned integer>" 4
  681. .IX Item """keylen"" (OSSL_CIPHER_PARAM_KEYLEN) <unsigned integer>"
  682. Gets the key length for the associated cipher algorithm \fIcipher\fR.
  683. Use \fBEVP_CIPHER_get_key_length()\fR to retrieve the cached value.
  684. .IP """ivlen"" (\fBOSSL_CIPHER_PARAM_IVLEN\fR) <unsigned integer>" 4
  685. .IX Item """ivlen"" (OSSL_CIPHER_PARAM_IVLEN) <unsigned integer>"
  686. Gets the IV length for the associated cipher algorithm \fIcipher\fR.
  687. Use \fBEVP_CIPHER_get_iv_length()\fR to retrieve the cached value.
  688. .IP """blocksize"" (\fBOSSL_CIPHER_PARAM_BLOCK_SIZE\fR) <unsigned integer>" 4
  689. .IX Item """blocksize"" (OSSL_CIPHER_PARAM_BLOCK_SIZE) <unsigned integer>"
  690. Gets the block size for the associated cipher algorithm \fIcipher\fR.
  691. The block size should be 1 for stream ciphers.
  692. Note that the block size for a cipher may be different to the block size for
  693. the underlying encryption/decryption primitive.
  694. For example AES in CTR mode has a block size of 1 (because it operates like a
  695. stream cipher), even though AES has a block size of 16.
  696. Use \fBEVP_CIPHER_get_block_size()\fR to retrieve the cached value.
  697. .IP """aead"" (\fBOSSL_CIPHER_PARAM_AEAD\fR) <integer>" 4
  698. .IX Item """aead"" (OSSL_CIPHER_PARAM_AEAD) <integer>"
  699. Gets 1 if this is an AEAD cipher algorithm, otherwise it gets 0.
  700. Use (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) to retrieve the
  701. cached value.
  702. .IP """custom-iv"" (\fBOSSL_CIPHER_PARAM_CUSTOM_IV\fR) <integer>" 4
  703. .IX Item """custom-iv"" (OSSL_CIPHER_PARAM_CUSTOM_IV) <integer>"
  704. Gets 1 if the cipher algorithm \fIcipher\fR has a custom IV, otherwise it gets 0.
  705. Storing and initializing the IV is left entirely to the implementation, if a
  706. custom IV is used.
  707. Use (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_CUSTOM_IV) to retrieve the
  708. cached value.
  709. .IP """cts"" (\fBOSSL_CIPHER_PARAM_CTS\fR) <integer>" 4
  710. .IX Item """cts"" (OSSL_CIPHER_PARAM_CTS) <integer>"
  711. Gets 1 if the cipher algorithm \fIcipher\fR uses ciphertext stealing,
  712. otherwise it gets 0.
  713. This is currently used to indicate that the cipher is a one shot that only
  714. allows a single call to \fBEVP_CipherUpdate()\fR.
  715. Use (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_CTS) to retrieve the
  716. cached value.
  717. .IP """tls-multi"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK\fR) <integer>" 4
  718. .IX Item """tls-multi"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK) <integer>"
  719. Gets 1 if the cipher algorithm \fIcipher\fR supports interleaving of crypto blocks,
  720. otherwise it gets 0. The interleaving is an optimization only applicable to certain
  721. TLS ciphers.
  722. Use (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK) to retrieve the
  723. cached value.
  724. .IP """has-randkey"" (\fBOSSL_CIPHER_PARAM_HAS_RANDKEY\fR) <integer>" 4
  725. .IX Item """has-randkey"" (OSSL_CIPHER_PARAM_HAS_RANDKEY) <integer>"
  726. Gets 1 if the cipher algorithm \fIcipher\fR supports the gettable EVP_CIPHER_CTX
  727. parameter \fBOSSL_CIPHER_PARAM_RANDOM_KEY\fR. Only DES and 3DES set this to 1,
  728. all other OpenSSL ciphers return 0.
  729. .IP """decrypt-only"" (\fBOSSL_CIPHER_PARAM_DECRYPT_ONLY) <integer\fR" 4
  730. .IX Item """decrypt-only"" (OSSL_CIPHER_PARAM_DECRYPT_ONLY) <integer"
  731. Gets 1 if the cipher algorithm \fIcipher\fR implementation supports only
  732. the decryption operation such as the 3DES ciphers in the fips provider.
  733. Otherwise gets 0 or the parameter might not be present at all.
  734. .SS "Gettable and Settable EVP_CIPHER_CTX parameters"
  735. .IX Subsection "Gettable and Settable EVP_CIPHER_CTX parameters"
  736. The following \fBOSSL_PARAM\fR\|(3) keys can be used with both \fBEVP_CIPHER_CTX_get_params()\fR
  737. and \fBEVP_CIPHER_CTX_set_params()\fR.
  738. .IP """padding"" (\fBOSSL_CIPHER_PARAM_PADDING\fR) <unsigned integer>" 4
  739. .IX Item """padding"" (OSSL_CIPHER_PARAM_PADDING) <unsigned integer>"
  740. Gets or sets the padding mode for the cipher context \fIctx\fR.
  741. Padding is enabled if the value is 1, and disabled if the value is 0.
  742. See also \fBEVP_CIPHER_CTX_set_padding()\fR.
  743. .IP """num"" (\fBOSSL_CIPHER_PARAM_NUM\fR) <unsigned integer>" 4
  744. .IX Item """num"" (OSSL_CIPHER_PARAM_NUM) <unsigned integer>"
  745. Gets or sets the cipher specific "num" parameter for the cipher context \fIctx\fR.
  746. Built-in ciphers typically use this to track how much of the current underlying
  747. block has been "used" already.
  748. See also \fBEVP_CIPHER_CTX_get_num()\fR and \fBEVP_CIPHER_CTX_set_num()\fR.
  749. .IP """keylen"" (\fBOSSL_CIPHER_PARAM_KEYLEN\fR) <unsigned integer>" 4
  750. .IX Item """keylen"" (OSSL_CIPHER_PARAM_KEYLEN) <unsigned integer>"
  751. Gets or sets the key length for the cipher context \fIctx\fR.
  752. The length of the "keylen" parameter should not exceed that of a \fBsize_t\fR.
  753. See also \fBEVP_CIPHER_CTX_get_key_length()\fR and \fBEVP_CIPHER_CTX_set_key_length()\fR.
  754. .IP """tag"" (\fBOSSL_CIPHER_PARAM_AEAD_TAG\fR) <octet string>" 4
  755. .IX Item """tag"" (OSSL_CIPHER_PARAM_AEAD_TAG) <octet string>"
  756. Gets or sets the AEAD tag for the associated cipher context \fIctx\fR.
  757. See "AEAD Interface" in \fBEVP_EncryptInit\fR\|(3).
  758. .IP """keybits"" (\fBOSSL_CIPHER_PARAM_RC2_KEYBITS\fR) <unsigned integer>" 4
  759. .IX Item """keybits"" (OSSL_CIPHER_PARAM_RC2_KEYBITS) <unsigned integer>"
  760. Gets or sets the effective keybits used for a RC2 cipher.
  761. The length of the "keybits" parameter should not exceed that of a \fBsize_t\fR.
  762. .IP """rounds"" (\fBOSSL_CIPHER_PARAM_ROUNDS\fR) <unsigned integer>" 4
  763. .IX Item """rounds"" (OSSL_CIPHER_PARAM_ROUNDS) <unsigned integer>"
  764. Gets or sets the number of rounds to be used for a cipher.
  765. This is used by the RC5 cipher.
  766. .IP """algorithm-id"" (\fBOSSL_CIPHER_PARAM_ALGORITHM_ID\fR) <octet string>" 4
  767. .IX Item """algorithm-id"" (OSSL_CIPHER_PARAM_ALGORITHM_ID) <octet string>"
  768. Used to get the DER encoded AlgorithmIdentifier from the cipher
  769. implementation. Functions like \fBEVP_PKEY_CTX_get_algor\fR\|(3) use this
  770. parameter.
  771. .IP """algorithm-id-params"" (\fBOSSL_CIPHER_PARAM_ALGORITHM_ID_PARAMS\fR) <octet string>" 4
  772. .IX Item """algorithm-id-params"" (OSSL_CIPHER_PARAM_ALGORITHM_ID_PARAMS) <octet string>"
  773. Used to pass the DER encoded AlgorithmIdentifier parameter to or from
  774. the cipher implementation.
  775. Functions like \fBEVP_CIPHER_CTX_set_algor_params\fR\|(3) and
  776. \&\fBEVP_CIPHER_CTX_get_algor_params\fR\|(3) use this parameter.
  777. .IP """alg_id_params"" (\fBOSSL_CIPHER_PARAM_ALGORITHM_ID_PARAMS_OLD\fR) <octet string>" 4
  778. .IX Item """alg_id_params"" (OSSL_CIPHER_PARAM_ALGORITHM_ID_PARAMS_OLD) <octet string>"
  779. An deprecated alias for "algorithm-id-params", only used by
  780. \&\fBEVP_CIPHER_param_to_asn1\fR\|(3) and \fBEVP_CIPHER_asn1_to_param\fR\|(3).
  781. .IP """cts_mode"" (\fBOSSL_CIPHER_PARAM_CTS_MODE\fR) <UTF8 string>" 4
  782. .IX Item """cts_mode"" (OSSL_CIPHER_PARAM_CTS_MODE) <UTF8 string>"
  783. Gets or sets the cipher text stealing mode. For all modes the output size is the
  784. same as the input size. The input length must be greater than or equal to the
  785. block size. (The block size for AES and CAMELLIA is 16 bytes).
  786. .Sp
  787. Valid values for the mode are:
  788. .RS 4
  789. .IP """CS1""" 4
  790. .IX Item """CS1"""
  791. The NIST variant of cipher text stealing.
  792. For input lengths that are multiples of the block size it is equivalent to
  793. using a "AES-XXX-CBC" or "CAMELLIA-XXX-CBC" cipher otherwise the second last
  794. cipher text block is a partial block.
  795. .IP """CS2""" 4
  796. .IX Item """CS2"""
  797. For input lengths that are multiples of the block size it is equivalent to
  798. using a "AES-XXX-CBC" or "CAMELLIA-XXX-CBC" cipher, otherwise it is the same as
  799. "CS3" mode.
  800. .IP """CS3""" 4
  801. .IX Item """CS3"""
  802. The Kerberos5 variant of cipher text stealing which always swaps the last
  803. cipher text block with the previous block (which may be a partial or full block
  804. depending on the input length). If the input length is exactly one full block
  805. then this is equivalent to using a "AES-XXX-CBC" or "CAMELLIA-XXX-CBC" cipher.
  806. .RE
  807. .RS 4
  808. .Sp
  809. The default is "CS1".
  810. This is only supported for "AES\-128\-CBC\-CTS", "AES\-192\-CBC\-CTS", "AES\-256\-CBC\-CTS",
  811. "CAMELLIA\-128\-CBC\-CTS", "CAMELLIA\-192\-CBC\-CTS" and "CAMELLIA\-256\-CBC\-CTS".
  812. .RE
  813. .IP """tls1multi_interleave"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE\fR) <unsigned integer>" 4
  814. .IX Item """tls1multi_interleave"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE) <unsigned integer>"
  815. Sets or gets the number of records being sent in one go for a tls1 multiblock
  816. cipher operation (either 4 or 8 records).
  817. .SS "Gettable EVP_CIPHER_CTX parameters"
  818. .IX Subsection "Gettable EVP_CIPHER_CTX parameters"
  819. The following \fBOSSL_PARAM\fR\|(3) keys can be used with \fBEVP_CIPHER_CTX_get_params()\fR:
  820. .IP """ivlen"" (\fBOSSL_CIPHER_PARAM_IVLEN\fR and <\fBOSSL_CIPHER_PARAM_AEAD_IVLEN\fR) <unsigned integer>" 4
  821. .IX Item """ivlen"" (OSSL_CIPHER_PARAM_IVLEN and <OSSL_CIPHER_PARAM_AEAD_IVLEN) <unsigned integer>"
  822. Gets the IV length for the cipher context \fIctx\fR.
  823. The length of the "ivlen" parameter should not exceed that of a \fBsize_t\fR.
  824. See also \fBEVP_CIPHER_CTX_get_iv_length()\fR.
  825. .IP """iv"" (\fBOSSL_CIPHER_PARAM_IV\fR) <octet string OR octet ptr>" 4
  826. .IX Item """iv"" (OSSL_CIPHER_PARAM_IV) <octet string OR octet ptr>"
  827. Gets the IV used to initialize the associated cipher context \fIctx\fR.
  828. See also \fBEVP_CIPHER_CTX_get_original_iv()\fR.
  829. .IP """updated-iv"" (\fBOSSL_CIPHER_PARAM_UPDATED_IV\fR) <octet string OR octet ptr>" 4
  830. .IX Item """updated-iv"" (OSSL_CIPHER_PARAM_UPDATED_IV) <octet string OR octet ptr>"
  831. Gets the updated pseudo-IV state for the associated cipher context, e.g.,
  832. the previous ciphertext block for CBC mode or the iteratively encrypted IV
  833. value for OFB mode. Note that octet pointer access is deprecated and is
  834. provided only for backwards compatibility with historical libcrypto APIs.
  835. See also \fBEVP_CIPHER_CTX_get_updated_iv()\fR.
  836. .IP """randkey"" (\fBOSSL_CIPHER_PARAM_RANDOM_KEY\fR) <octet string>" 4
  837. .IX Item """randkey"" (OSSL_CIPHER_PARAM_RANDOM_KEY) <octet string>"
  838. Gets an implementation specific randomly generated key for the associated
  839. cipher context \fIctx\fR. This is currently only supported by DES and 3DES (which set
  840. the key to odd parity).
  841. .IP """taglen"" (\fBOSSL_CIPHER_PARAM_AEAD_TAGLEN\fR) <unsigned integer>" 4
  842. .IX Item """taglen"" (OSSL_CIPHER_PARAM_AEAD_TAGLEN) <unsigned integer>"
  843. Gets the tag length to be used for an AEAD cipher for the associated cipher
  844. context \fIctx\fR. It gets a default value if it has not been set.
  845. The length of the "taglen" parameter should not exceed that of a \fBsize_t\fR.
  846. See also \fBEVP_CIPHER_CTX_get_tag_length()\fR.
  847. .IP """tlsaadpad"" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD\fR) <unsigned integer>" 4
  848. .IX Item """tlsaadpad"" (OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD) <unsigned integer>"
  849. Gets the length of the tag that will be added to a TLS record for the AEAD
  850. tag for the associated cipher context \fIctx\fR.
  851. The length of the "tlsaadpad" parameter should not exceed that of a \fBsize_t\fR.
  852. .IP """tlsivgen"" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_GET_IV_GEN\fR) <octet string>" 4
  853. .IX Item """tlsivgen"" (OSSL_CIPHER_PARAM_AEAD_TLS1_GET_IV_GEN) <octet string>"
  854. Gets the invocation field generated for encryption.
  855. Can only be called after "tlsivfixed" is set.
  856. This is only used for GCM mode.
  857. .IP """tls1multi_enclen"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_LEN\fR) <unsigned integer>" 4
  858. .IX Item """tls1multi_enclen"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_LEN) <unsigned integer>"
  859. Get the total length of the record returned from the "tls1multi_enc" operation.
  860. .IP """tls1multi_maxbufsz"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE\fR) <unsigned integer>" 4
  861. .IX Item """tls1multi_maxbufsz"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE) <unsigned integer>"
  862. Gets the maximum record length for a TLS1 multiblock cipher operation.
  863. The length of the "tls1multi_maxbufsz" parameter should not exceed that of a \fBsize_t\fR.
  864. .IP """tls1multi_aadpacklen"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD_PACKLEN\fR) <unsigned integer>" 4
  865. .IX Item """tls1multi_aadpacklen"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD_PACKLEN) <unsigned integer>"
  866. Gets the result of running the "tls1multi_aad" operation.
  867. .IP """tls-mac"" (\fBOSSL_CIPHER_PARAM_TLS_MAC\fR) <octet ptr>" 4
  868. .IX Item """tls-mac"" (OSSL_CIPHER_PARAM_TLS_MAC) <octet ptr>"
  869. Used to pass the TLS MAC data.
  870. .IP """fips-indicator"" (\fBOSSL_CIPHER_PARAM_FIPS_APPROVED_INDICATOR\fR) <integer>" 4
  871. .IX Item """fips-indicator"" (OSSL_CIPHER_PARAM_FIPS_APPROVED_INDICATOR) <integer>"
  872. This option is used by the OpenSSL FIPS provider.
  873. .Sp
  874. A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
  875. This may be used after calling a cipher final operation such as
  876. \&\fBEVP_EncryptFinal_ex()\fR. It may return 0 if the "encrypt-check" option is set to 0.
  877. .IP """iv-generated"" (\fBOSSL_CIPHER_PARAM_AEAD_IV_GENERATED\fR) <unsigned integer>" 4
  878. .IX Item """iv-generated"" (OSSL_CIPHER_PARAM_AEAD_IV_GENERATED) <unsigned integer>"
  879. An indicator that returns 1 if an IV was generated internally during encryption,
  880. or O otherwise.
  881. This may be used by GCM ciphers after calling a cipher final operation such
  882. as \fBEVP_EncryptFinal_ex()\fR.
  883. GCM should generate an IV internally if the IV is not specified during a
  884. cipher initialisation call such as \fBEVP_CipherInit_ex()\fR.
  885. See FIPS 140\-3 IG C.H for information related to IV requirements.
  886. .SS "Settable EVP_CIPHER_CTX parameters"
  887. .IX Subsection "Settable EVP_CIPHER_CTX parameters"
  888. The following \fBOSSL_PARAM\fR\|(3) keys can be used with \fBEVP_CIPHER_CTX_set_params()\fR:
  889. .IP """mackey"" (\fBOSSL_CIPHER_PARAM_AEAD_MAC_KEY\fR) <octet string>" 4
  890. .IX Item """mackey"" (OSSL_CIPHER_PARAM_AEAD_MAC_KEY) <octet string>"
  891. Sets the MAC key used by composite AEAD ciphers such as AES\-CBC\-HMAC\-SHA256.
  892. .IP """speed"" (\fBOSSL_CIPHER_PARAM_SPEED\fR) <unsigned integer>" 4
  893. .IX Item """speed"" (OSSL_CIPHER_PARAM_SPEED) <unsigned integer>"
  894. Sets the speed option for the associated cipher context. This is only supported
  895. by AES SIV ciphers which disallow multiple operations by default.
  896. Setting "speed" to 1 allows another encrypt or decrypt operation to be
  897. performed. This is used for performance testing.
  898. .IP """use-bits"" (\fBOSSL_CIPHER_PARAM_USE_BITS\fR) <unsigned integer>" 4
  899. .IX Item """use-bits"" (OSSL_CIPHER_PARAM_USE_BITS) <unsigned integer>"
  900. Determines if the input length \fIinl\fR passed to \fBEVP_EncryptUpdate()\fR,
  901. \&\fBEVP_DecryptUpdate()\fR and \fBEVP_CipherUpdate()\fR is the number of bits or number of bytes.
  902. Setting "use-bits" to 1 uses bits. The default is in bytes.
  903. This is only used for \fBCFB1\fR ciphers.
  904. .Sp
  905. This can be set using EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS).
  906. .IP """tls-version"" (\fBOSSL_CIPHER_PARAM_TLS_VERSION\fR) <integer>" 4
  907. .IX Item """tls-version"" (OSSL_CIPHER_PARAM_TLS_VERSION) <integer>"
  908. Sets the TLS version.
  909. .IP """tls-mac-size"" (\fBOSSL_CIPHER_PARAM_TLS_MAC_SIZE\fR) <unsigned integer>" 4
  910. .IX Item """tls-mac-size"" (OSSL_CIPHER_PARAM_TLS_MAC_SIZE) <unsigned integer>"
  911. Set the TLS MAC size.
  912. .IP """tlsaad"" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_AAD\fR) <octet string>" 4
  913. .IX Item """tlsaad"" (OSSL_CIPHER_PARAM_AEAD_TLS1_AAD) <octet string>"
  914. Sets TLSv1.2 AAD information for the associated cipher context \fIctx\fR.
  915. TLSv1.2 AAD information is always 13 bytes in length and is as defined for the
  916. "additional_data" field described in section 6.2.3.3 of RFC5246.
  917. .IP """tlsivfixed"" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED\fR) <octet string>" 4
  918. .IX Item """tlsivfixed"" (OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED) <octet string>"
  919. Sets the fixed portion of an IV for an AEAD cipher used in a TLS record
  920. encryption/ decryption for the associated cipher context.
  921. TLS record encryption/decryption always occurs "in place" so that the input and
  922. output buffers are always the same memory location.
  923. AEAD IVs in TLSv1.2 consist of an implicit "fixed" part and an explicit part
  924. that varies with every record.
  925. Setting a TLS fixed IV changes a cipher to encrypt/decrypt TLS records.
  926. TLS records are encrypted/decrypted using a single OSSL_FUNC_cipher_cipher call per
  927. record.
  928. For a record decryption the first bytes of the input buffer will be the explicit
  929. part of the IV and the final bytes of the input buffer will be the AEAD tag.
  930. The length of the explicit part of the IV and the tag length will depend on the
  931. cipher in use and will be defined in the RFC for the relevant ciphersuite.
  932. In order to allow for "in place" decryption the plaintext output should be
  933. written to the same location in the output buffer that the ciphertext payload
  934. was read from, i.e. immediately after the explicit IV.
  935. .Sp
  936. When encrypting a record the first bytes of the input buffer should be empty to
  937. allow space for the explicit IV, as will the final bytes where the tag will
  938. be written.
  939. The length of the input buffer will include the length of the explicit IV, the
  940. payload, and the tag bytes.
  941. The cipher implementation should generate the explicit IV and write it to the
  942. beginning of the output buffer, do "in place" encryption of the payload and
  943. write that to the output buffer, and finally add the tag onto the end of the
  944. output buffer.
  945. .Sp
  946. Whether encrypting or decrypting the value written to \fI*outl\fR in the
  947. OSSL_FUNC_cipher_cipher call should be the length of the payload excluding the explicit
  948. IV length and the tag length.
  949. .IP """tlsivinv"" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_SET_IV_INV\fR) <octet string>" 4
  950. .IX Item """tlsivinv"" (OSSL_CIPHER_PARAM_AEAD_TLS1_SET_IV_INV) <octet string>"
  951. Sets the invocation field used for decryption.
  952. Can only be called after "tlsivfixed" is set.
  953. This is only used for GCM mode.
  954. .IP """tls1multi_enc"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC\fR) <octet string>" 4
  955. .IX Item """tls1multi_enc"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC) <octet string>"
  956. Triggers a multiblock TLS1 encrypt operation for a TLS1 aware cipher that
  957. supports sending 4 or 8 records in one go.
  958. The cipher performs both the MAC and encrypt stages and constructs the record
  959. headers itself.
  960. "tls1multi_enc" supplies the output buffer for the encrypt operation,
  961. "tls1multi_encin" & "tls1multi_interleave" must also be set in order to supply
  962. values to the encrypt operation.
  963. .IP """tls1multi_encin"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN\fR) <octet string>" 4
  964. .IX Item """tls1multi_encin"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN) <octet string>"
  965. Supplies the data to encrypt for a TLS1 multiblock cipher operation.
  966. .IP """tls1multi_maxsndfrag"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_SEND_FRAGMENT\fR) <unsigned integer>" 4
  967. .IX Item """tls1multi_maxsndfrag"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_SEND_FRAGMENT) <unsigned integer>"
  968. Sets the maximum send fragment size for a TLS1 multiblock cipher operation.
  969. It must be set before using "tls1multi_maxbufsz".
  970. The length of the "tls1multi_maxsndfrag" parameter should not exceed that of a \fBsize_t\fR.
  971. .IP """tls1multi_aad"" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD\fR) <octet string>" 4
  972. .IX Item """tls1multi_aad"" (OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD) <octet string>"
  973. Sets the authenticated additional data used by a TLS1 multiblock cipher operation.
  974. The supplied data consists of 13 bytes of record data containing:
  975. Bytes 0\-7: The sequence number of the first record
  976. Byte 8: The record type
  977. Byte 9\-10: The protocol version
  978. Byte 11\-12: Input length (Always 0)
  979. .Sp
  980. "tls1multi_interleave" must also be set for this operation.
  981. .IP """xts_standard"" (\fBOSSL_CIPHER_PARAM_XTS_STANDARD\fR) <UTF8 string>" 4
  982. .IX Item """xts_standard"" (OSSL_CIPHER_PARAM_XTS_STANDARD) <UTF8 string>"
  983. Sets the XTS standard to use with SM4\-XTS algorithm. XTS mode has two
  984. implementations, one is standardized in IEEE Std. 1619\-2007 and has
  985. been widely used (e.g., XTS AES), the other is proposed recently
  986. (GB/T 17964\-2021 implemented in May 2022) and is currently only used
  987. in SM4.
  988. .Sp
  989. The main difference between them is the multiplication by the
  990. primitive element α to calculate the tweak values. The IEEE
  991. Std 1619\-2007 noted that the multiplication "is a left shift of each
  992. byte by one bit with carry propagating from one byte to the next
  993. one", which means that in each byte, the leftmost bit is the most
  994. significant bit. But in GB/T 17964\-2021, the rightmost bit is the
  995. most significant bit, thus the multiplication becomes a right shift
  996. of each byte by one bit with carry propagating from one byte to the
  997. next one.
  998. .Sp
  999. Valid values for the mode are:
  1000. .RS 4
  1001. .IP """GB""" 4
  1002. .IX Item """GB"""
  1003. The GB/T 17964\-2021 variant of SM4\-XTS algorithm.
  1004. .IP """IEEE""" 4
  1005. .IX Item """IEEE"""
  1006. The IEEE Std. 1619\-2007 variant of SM4\-XTS algorithm.
  1007. .RE
  1008. .RS 4
  1009. .Sp
  1010. The default value is "GB".
  1011. .RE
  1012. .IP """encrypt-check"" (\fBOSSL_CIPHER_PARAM_FIPS_ENCRYPT_CHECK\fR) <integer>" 4
  1013. .IX Item """encrypt-check"" (OSSL_CIPHER_PARAM_FIPS_ENCRYPT_CHECK) <integer>"
  1014. This option is used by the OpenSSL FIPS provider.
  1015. .Sp
  1016. If required this parameter should be set early via an cipher encrypt init
  1017. function such as \fBEVP_EncryptInit_ex2()\fR.
  1018. The default value of 1 causes an error when an encryption operation is triggered.
  1019. Setting this to 0 will ignore the error and set the approved "fips-indicator" to
  1020. 0.
  1021. This option breaks FIPS compliance if it causes the approved "fips-indicator"
  1022. to return 0.
  1023. .SH CONTROLS
  1024. .IX Header "CONTROLS"
  1025. The Mappings from \fBEVP_CIPHER_CTX_ctrl()\fR identifiers to PARAMETERS are listed
  1026. in the following section. See the "PARAMETERS" section for more details.
  1027. .PP
  1028. \&\fBEVP_CIPHER_CTX_ctrl()\fR can be used to send the following standard controls:
  1029. .IP "EVP_CTRL_AEAD_SET_IVLEN and EVP_CTRL_GET_IVLEN" 4
  1030. .IX Item "EVP_CTRL_AEAD_SET_IVLEN and EVP_CTRL_GET_IVLEN"
  1031. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR and
  1032. \&\fBEVP_CIPHER_CTX_get_params()\fR get called with an \fBOSSL_PARAM\fR\|(3) item with the
  1033. key "ivlen" (\fBOSSL_CIPHER_PARAM_IVLEN\fR).
  1034. .IP EVP_CTRL_AEAD_SET_IV_FIXED 4
  1035. .IX Item "EVP_CTRL_AEAD_SET_IV_FIXED"
  1036. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1037. with an \fBOSSL_PARAM\fR\|(3) item with the key "tlsivfixed"
  1038. (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED\fR).
  1039. .IP EVP_CTRL_AEAD_SET_MAC_KEY 4
  1040. .IX Item "EVP_CTRL_AEAD_SET_MAC_KEY"
  1041. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1042. with an \fBOSSL_PARAM\fR\|(3) item with the key "mackey"
  1043. (\fBOSSL_CIPHER_PARAM_AEAD_MAC_KEY\fR).
  1044. .IP "EVP_CTRL_AEAD_SET_TAG and EVP_CTRL_AEAD_GET_TAG" 4
  1045. .IX Item "EVP_CTRL_AEAD_SET_TAG and EVP_CTRL_AEAD_GET_TAG"
  1046. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR and
  1047. \&\fBEVP_CIPHER_CTX_get_params()\fR get called with an \fBOSSL_PARAM\fR\|(3) item with the
  1048. key "tag" (\fBOSSL_CIPHER_PARAM_AEAD_TAG\fR).
  1049. .IP EVP_CTRL_CCM_SET_L 4
  1050. .IX Item "EVP_CTRL_CCM_SET_L"
  1051. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1052. with an \fBOSSL_PARAM\fR\|(3) item with the key "ivlen" (\fBOSSL_CIPHER_PARAM_IVLEN\fR)
  1053. with a value of (15 \- L)
  1054. .IP EVP_CTRL_COPY 4
  1055. .IX Item "EVP_CTRL_COPY"
  1056. There is no OSSL_PARAM mapping for this. Use \fBEVP_CIPHER_CTX_copy()\fR instead.
  1057. .IP EVP_CTRL_GCM_SET_IV_INV 4
  1058. .IX Item "EVP_CTRL_GCM_SET_IV_INV"
  1059. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1060. with an \fBOSSL_PARAM\fR\|(3) item with the key "tlsivinv"
  1061. (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_SET_IV_INV\fR).
  1062. .IP EVP_CTRL_RAND_KEY 4
  1063. .IX Item "EVP_CTRL_RAND_KEY"
  1064. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1065. with an \fBOSSL_PARAM\fR\|(3) item with the key "randkey"
  1066. (\fBOSSL_CIPHER_PARAM_RANDOM_KEY\fR).
  1067. .IP EVP_CTRL_SET_KEY_LENGTH 4
  1068. .IX Item "EVP_CTRL_SET_KEY_LENGTH"
  1069. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1070. with an \fBOSSL_PARAM\fR\|(3) item with the key "keylen" (\fBOSSL_CIPHER_PARAM_KEYLEN\fR).
  1071. .IP "EVP_CTRL_SET_RC2_KEY_BITS and EVP_CTRL_GET_RC2_KEY_BITS" 4
  1072. .IX Item "EVP_CTRL_SET_RC2_KEY_BITS and EVP_CTRL_GET_RC2_KEY_BITS"
  1073. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR and
  1074. \&\fBEVP_CIPHER_CTX_get_params()\fR get called with an \fBOSSL_PARAM\fR\|(3) item with the
  1075. key "keybits" (\fBOSSL_CIPHER_PARAM_RC2_KEYBITS\fR).
  1076. .IP "EVP_CTRL_SET_RC5_ROUNDS and EVP_CTRL_GET_RC5_ROUNDS" 4
  1077. .IX Item "EVP_CTRL_SET_RC5_ROUNDS and EVP_CTRL_GET_RC5_ROUNDS"
  1078. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR and
  1079. \&\fBEVP_CIPHER_CTX_get_params()\fR get called with an \fBOSSL_PARAM\fR\|(3) item with the
  1080. key "rounds" (\fBOSSL_CIPHER_PARAM_ROUNDS\fR).
  1081. .IP EVP_CTRL_SET_SPEED 4
  1082. .IX Item "EVP_CTRL_SET_SPEED"
  1083. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1084. with an \fBOSSL_PARAM\fR\|(3) item with the key "speed" (\fBOSSL_CIPHER_PARAM_SPEED\fR).
  1085. .IP EVP_CTRL_GCM_IV_GEN 4
  1086. .IX Item "EVP_CTRL_GCM_IV_GEN"
  1087. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_get_params()\fR gets called
  1088. with an \fBOSSL_PARAM\fR\|(3) item with the key
  1089. "tlsivgen" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_GET_IV_GEN\fR).
  1090. .IP EVP_CTRL_AEAD_TLS1_AAD 4
  1091. .IX Item "EVP_CTRL_AEAD_TLS1_AAD"
  1092. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR get called
  1093. with an \fBOSSL_PARAM\fR\|(3) item with the key
  1094. "tlsaad" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_AAD\fR)
  1095. followed by \fBEVP_CIPHER_CTX_get_params()\fR with a key of
  1096. "tlsaadpad" (\fBOSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD\fR).
  1097. .IP EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE 4
  1098. .IX Item "EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE"
  1099. When used with a fetched \fBEVP_CIPHER\fR,
  1100. \&\fBEVP_CIPHER_CTX_set_params()\fR gets called with an \fBOSSL_PARAM\fR\|(3) item with the
  1101. key OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_SEND_FRAGMENT
  1102. followed by \fBEVP_CIPHER_CTX_get_params()\fR with a key of
  1103. "tls1multi_maxbufsz" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE\fR).
  1104. .IP EVP_CTRL_TLS1_1_MULTIBLOCK_AAD 4
  1105. .IX Item "EVP_CTRL_TLS1_1_MULTIBLOCK_AAD"
  1106. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1107. with \fBOSSL_PARAM\fR\|(3) items with the keys
  1108. "tls1multi_aad" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD\fR) and
  1109. "tls1multi_interleave" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE\fR)
  1110. followed by \fBEVP_CIPHER_CTX_get_params()\fR with keys of
  1111. "tls1multi_aadpacklen" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD_PACKLEN\fR) and
  1112. "tls1multi_interleave" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE\fR).
  1113. .IP EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT 4
  1114. .IX Item "EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT"
  1115. When used with a fetched \fBEVP_CIPHER\fR, \fBEVP_CIPHER_CTX_set_params()\fR gets called
  1116. with \fBOSSL_PARAM\fR\|(3) items with the keys
  1117. "tls1multi_enc" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC\fR),
  1118. "tls1multi_encin" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN\fR) and
  1119. "tls1multi_interleave" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE\fR),
  1120. followed by \fBEVP_CIPHER_CTX_get_params()\fR with a key of
  1121. "tls1multi_enclen" (\fBOSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_LEN\fR).
  1122. .SH FLAGS
  1123. .IX Header "FLAGS"
  1124. \&\fBEVP_CIPHER_CTX_set_flags()\fR, \fBEVP_CIPHER_CTX_clear_flags()\fR and \fBEVP_CIPHER_CTX_test_flags()\fR.
  1125. can be used to manipulate and test these \fBEVP_CIPHER_CTX\fR flags:
  1126. .IP EVP_CIPH_NO_PADDING 4
  1127. .IX Item "EVP_CIPH_NO_PADDING"
  1128. Used by \fBEVP_CIPHER_CTX_set_padding()\fR.
  1129. .Sp
  1130. See also "Gettable and Settable EVP_CIPHER_CTX parameters" "padding"
  1131. .IP EVP_CIPH_FLAG_LENGTH_BITS 4
  1132. .IX Item "EVP_CIPH_FLAG_LENGTH_BITS"
  1133. See "Settable EVP_CIPHER_CTX parameters" "use-bits".
  1134. .IP EVP_CIPHER_CTX_FLAG_WRAP_ALLOW 4
  1135. .IX Item "EVP_CIPHER_CTX_FLAG_WRAP_ALLOW"
  1136. Used for Legacy purposes only. This flag needed to be set to indicate the
  1137. cipher handled wrapping.
  1138. .PP
  1139. \&\fBEVP_CIPHER_flags()\fR uses the following flags that
  1140. have mappings to "Gettable EVP_CIPHER parameters":
  1141. .IP EVP_CIPH_FLAG_AEAD_CIPHER 4
  1142. .IX Item "EVP_CIPH_FLAG_AEAD_CIPHER"
  1143. See "Gettable EVP_CIPHER parameters" "aead".
  1144. .IP EVP_CIPH_CUSTOM_IV 4
  1145. .IX Item "EVP_CIPH_CUSTOM_IV"
  1146. See "Gettable EVP_CIPHER parameters" "custom-iv".
  1147. .IP EVP_CIPH_FLAG_CTS 4
  1148. .IX Item "EVP_CIPH_FLAG_CTS"
  1149. See "Gettable EVP_CIPHER parameters" "cts".
  1150. .IP EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK; 4
  1151. .IX Item "EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK;"
  1152. See "Gettable EVP_CIPHER parameters" "tls-multi".
  1153. .IP EVP_CIPH_RAND_KEY 4
  1154. .IX Item "EVP_CIPH_RAND_KEY"
  1155. See "Gettable EVP_CIPHER parameters" "has-randkey".
  1156. .PP
  1157. \&\fBEVP_CIPHER_flags()\fR uses the following flags for legacy purposes only:
  1158. .IP EVP_CIPH_VARIABLE_LENGTH 4
  1159. .IX Item "EVP_CIPH_VARIABLE_LENGTH"
  1160. .PD 0
  1161. .IP EVP_CIPH_FLAG_CUSTOM_CIPHER 4
  1162. .IX Item "EVP_CIPH_FLAG_CUSTOM_CIPHER"
  1163. .IP EVP_CIPH_ALWAYS_CALL_INIT 4
  1164. .IX Item "EVP_CIPH_ALWAYS_CALL_INIT"
  1165. .IP EVP_CIPH_CTRL_INIT 4
  1166. .IX Item "EVP_CIPH_CTRL_INIT"
  1167. .IP EVP_CIPH_CUSTOM_KEY_LENGTH 4
  1168. .IX Item "EVP_CIPH_CUSTOM_KEY_LENGTH"
  1169. .IP EVP_CIPH_CUSTOM_COPY 4
  1170. .IX Item "EVP_CIPH_CUSTOM_COPY"
  1171. .IP EVP_CIPH_FLAG_DEFAULT_ASN1 4
  1172. .IX Item "EVP_CIPH_FLAG_DEFAULT_ASN1"
  1173. .PD
  1174. See \fBEVP_CIPHER_meth_set_flags\fR\|(3) for further information related to the above
  1175. flags.
  1176. .SH "RETURN VALUES"
  1177. .IX Header "RETURN VALUES"
  1178. \&\fBEVP_CIPHER_fetch()\fR returns a pointer to a \fBEVP_CIPHER\fR for success
  1179. and \fBNULL\fR for failure.
  1180. .PP
  1181. \&\fBEVP_CIPHER_up_ref()\fR returns 1 for success or 0 otherwise.
  1182. .PP
  1183. \&\fBEVP_CIPHER_CTX_new()\fR returns a pointer to a newly created
  1184. \&\fBEVP_CIPHER_CTX\fR for success and \fBNULL\fR for failure.
  1185. .PP
  1186. \&\fBEVP_CIPHER_CTX_dup()\fR returns a new EVP_CIPHER_CTX if successful or NULL on failure.
  1187. .PP
  1188. \&\fBEVP_CIPHER_CTX_copy()\fR returns 1 if successful or 0 for failure.
  1189. .PP
  1190. \&\fBEVP_EncryptInit_ex2()\fR, \fBEVP_EncryptUpdate()\fR and \fBEVP_EncryptFinal_ex()\fR
  1191. return 1 for success and 0 for failure.
  1192. .PP
  1193. \&\fBEVP_DecryptInit_ex2()\fR and \fBEVP_DecryptUpdate()\fR return 1 for success and 0 for failure.
  1194. \&\fBEVP_DecryptFinal_ex()\fR returns 0 if the decrypt failed or 1 for success.
  1195. .PP
  1196. \&\fBEVP_CipherInit_ex2()\fR and \fBEVP_CipherUpdate()\fR return 1 for success and 0 for failure.
  1197. \&\fBEVP_CipherFinal_ex()\fR returns 0 for a decryption failure or 1 for success.
  1198. .PP
  1199. \&\fBEVP_Cipher()\fR returns 1 on success and <= 0 on failure, if the flag
  1200. \&\fBEVP_CIPH_FLAG_CUSTOM_CIPHER\fR is not set for the cipher, or if the cipher has
  1201. not been initialized via a call to \fBEVP_CipherInit_ex2\fR.
  1202. \&\fBEVP_Cipher()\fR returns the number of bytes written to \fIout\fR for encryption / decryption, or
  1203. the number of bytes authenticated in a call specifying AAD for an AEAD cipher, if the flag
  1204. \&\fBEVP_CIPH_FLAG_CUSTOM_CIPHER\fR is set for the cipher.
  1205. .PP
  1206. \&\fBEVP_CIPHER_CTX_reset()\fR returns 1 for success and 0 for failure.
  1207. .PP
  1208. \&\fBEVP_get_cipherbyname()\fR, \fBEVP_get_cipherbynid()\fR and \fBEVP_get_cipherbyobj()\fR
  1209. return an \fBEVP_CIPHER\fR structure or NULL on error.
  1210. .PP
  1211. \&\fBEVP_CIPHER_get_nid()\fR and \fBEVP_CIPHER_CTX_get_nid()\fR return a NID.
  1212. .PP
  1213. \&\fBEVP_CIPHER_get_block_size()\fR and \fBEVP_CIPHER_CTX_get_block_size()\fR return the
  1214. block size, or 0 on error.
  1215. .PP
  1216. \&\fBEVP_CIPHER_get_key_length()\fR and \fBEVP_CIPHER_CTX_get_key_length()\fR return the key
  1217. length.
  1218. .PP
  1219. \&\fBEVP_CIPHER_CTX_set_padding()\fR always returns 1.
  1220. .PP
  1221. \&\fBEVP_CIPHER_get_iv_length()\fR and \fBEVP_CIPHER_CTX_get_iv_length()\fR return the IV
  1222. length, zero if the cipher does not use an IV and a negative value on error.
  1223. .PP
  1224. \&\fBEVP_CIPHER_CTX_get_tag_length()\fR return the tag length or zero if the cipher
  1225. does not use a tag.
  1226. .PP
  1227. \&\fBEVP_CIPHER_get_type()\fR and \fBEVP_CIPHER_CTX_get_type()\fR return the NID of the
  1228. cipher's OBJECT IDENTIFIER or NID_undef if it has no defined
  1229. OBJECT IDENTIFIER.
  1230. .PP
  1231. \&\fBEVP_CIPHER_CTX_cipher()\fR returns an \fBEVP_CIPHER\fR structure.
  1232. .PP
  1233. \&\fBEVP_CIPHER_CTX_get_num()\fR returns a nonnegative num value or
  1234. \&\fBEVP_CTRL_RET_UNSUPPORTED\fR if the implementation does not support the call
  1235. or on any other error.
  1236. .PP
  1237. \&\fBEVP_CIPHER_CTX_set_num()\fR returns 1 on success and 0 if the implementation
  1238. does not support the call or on any other error.
  1239. .PP
  1240. \&\fBEVP_CIPHER_CTX_is_encrypting()\fR returns 1 if the \fIctx\fR is set up for encryption
  1241. 0 otherwise.
  1242. .PP
  1243. \&\fBEVP_CIPHER_param_to_asn1()\fR and \fBEVP_CIPHER_asn1_to_param()\fR return greater
  1244. than zero for success and zero or a negative number on failure.
  1245. .PP
  1246. \&\fBEVP_CIPHER_CTX_rand_key()\fR returns 1 for success and zero or a negative number
  1247. for failure.
  1248. .PP
  1249. \&\fBEVP_CIPHER_names_do_all()\fR returns 1 if the callback was called for all names.
  1250. A return value of 0 means that the callback was not called for any names.
  1251. .SH "CIPHER LISTING"
  1252. .IX Header "CIPHER LISTING"
  1253. All algorithms have a fixed key length unless otherwise stated.
  1254. .PP
  1255. Refer to "SEE ALSO" for the full list of ciphers available through the EVP
  1256. interface.
  1257. .IP \fBEVP_enc_null()\fR 4
  1258. .IX Item "EVP_enc_null()"
  1259. Null cipher: does nothing.
  1260. .SH "AEAD INTERFACE"
  1261. .IX Header "AEAD INTERFACE"
  1262. The EVP interface for Authenticated Encryption with Associated Data (AEAD)
  1263. modes are subtly altered and several additional \fIctrl\fR operations are supported
  1264. depending on the mode specified.
  1265. .PP
  1266. To specify additional authenticated data (AAD), a call to \fBEVP_CipherUpdate()\fR,
  1267. \&\fBEVP_EncryptUpdate()\fR or \fBEVP_DecryptUpdate()\fR should be made with the output
  1268. parameter \fIout\fR set to \fBNULL\fR. In this case, on success, the parameter
  1269. \&\fIoutl\fR is set to the number of bytes authenticated.
  1270. .PP
  1271. When decrypting, the return value of \fBEVP_DecryptFinal()\fR or \fBEVP_CipherFinal()\fR
  1272. indicates whether the operation was successful. If it does not indicate success,
  1273. the authentication operation has failed and any output data \fBMUST NOT\fR be used
  1274. as it is corrupted.
  1275. .PP
  1276. Please note that the number of authenticated bytes returned by
  1277. \&\fBEVP_CipherUpdate()\fR depends on the cipher used. Stream ciphers, such as ChaCha20
  1278. or ciphers in GCM mode, can handle 1 byte at a time, resulting in an effective
  1279. "block" size of 1. Conversely, ciphers in OCB mode must process data one block
  1280. at a time, and the block size is returned.
  1281. .PP
  1282. Regardless of the returned size, it is safe to pass unpadded data to an
  1283. \&\fBEVP_CipherUpdate()\fR call in a single operation.
  1284. .SS "GCM and OCB Modes"
  1285. .IX Subsection "GCM and OCB Modes"
  1286. The following \fIctrl\fRs are supported in GCM and OCB modes.
  1287. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, ivlen, NULL)" 4
  1288. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, ivlen, NULL)"
  1289. Sets the IV length. This call can only be made before specifying an IV. If
  1290. not called a default IV length is used.
  1291. .Sp
  1292. For GCM AES and OCB AES the default is 12 (i.e. 96 bits). For OCB mode the
  1293. maximum is 15.
  1294. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag)" 4
  1295. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag)"
  1296. Writes \f(CW\*(C`taglen\*(C'\fR bytes of the tag value to the buffer indicated by \f(CW\*(C`tag\*(C'\fR.
  1297. This call can only be made when encrypting data and \fBafter\fR all data has been
  1298. processed (e.g. after an \fBEVP_EncryptFinal()\fR call).
  1299. .Sp
  1300. For OCB, \f(CW\*(C`taglen\*(C'\fR must either be 16 or the value previously set via
  1301. \&\fBEVP_CTRL_AEAD_SET_TAG\fR.
  1302. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag)" 4
  1303. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag)"
  1304. When decrypting, this call sets the expected tag to \f(CW\*(C`taglen\*(C'\fR bytes from \f(CW\*(C`tag\*(C'\fR.
  1305. \&\f(CW\*(C`taglen\*(C'\fR must be between 1 and 16 inclusive.
  1306. The tag must be set prior to any call to \fBEVP_DecryptFinal()\fR or
  1307. \&\fBEVP_DecryptFinal_ex()\fR.
  1308. .Sp
  1309. For GCM, this call is only valid when decrypting data.
  1310. .Sp
  1311. For OCB, this call is valid when decrypting data to set the expected tag,
  1312. and when encrypting to set the desired tag length.
  1313. .Sp
  1314. In OCB mode, calling this with \f(CW\*(C`tag\*(C'\fR set to \f(CW\*(C`NULL\*(C'\fR sets the tag length.
  1315. The tag length can only be set before specifying an IV. If this is not called
  1316. prior to setting the IV, then a default tag length is used.
  1317. .Sp
  1318. For OCB AES, the default tag length is 16 (i.e. 128 bits). It is also the
  1319. maximum tag length for OCB.
  1320. .SS "CCM Mode"
  1321. .IX Subsection "CCM Mode"
  1322. The EVP interface for CCM mode is similar to that of the GCM mode but with a
  1323. few additional requirements and different \fIctrl\fR values.
  1324. .PP
  1325. For CCM mode, the total plaintext or ciphertext length \fBMUST\fR be passed to
  1326. \&\fBEVP_CipherUpdate()\fR, \fBEVP_EncryptUpdate()\fR or \fBEVP_DecryptUpdate()\fR with the output
  1327. and input parameters (\fIin\fR and \fIout\fR) set to \fBNULL\fR and the length passed in
  1328. the \fIinl\fR parameter.
  1329. .PP
  1330. The following \fIctrl\fRs are supported in CCM mode.
  1331. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag)" 4
  1332. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag)"
  1333. This call is made to set the expected \fBCCM\fR tag value when decrypting or
  1334. the length of the tag (with the \f(CW\*(C`tag\*(C'\fR parameter set to NULL) when encrypting.
  1335. The tag length is often referred to as \fBM\fR. If not set a default value is
  1336. used (12 for AES). When decrypting, the tag needs to be set before passing
  1337. in data to be decrypted, but as in GCM and OCB mode, it can be set after
  1338. passing additional authenticated data (see "AEAD INTERFACE").
  1339. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_L, ivlen, NULL)" 4
  1340. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_L, ivlen, NULL)"
  1341. Sets the CCM \fBL\fR value. If not set a default is used (8 for AES).
  1342. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, ivlen, NULL)" 4
  1343. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, ivlen, NULL)"
  1344. Sets the CCM nonce (IV) length. This call can only be made before specifying a
  1345. nonce value. The nonce length is given by \fB15 \- L\fR so it is 7 by default for
  1346. AES.
  1347. .SS "SIV Mode"
  1348. .IX Subsection "SIV Mode"
  1349. Both the AES-SIV and AES-GCM-SIV ciphers fall under this mode.
  1350. .PP
  1351. For SIV mode ciphers the behaviour of the EVP interface is subtly
  1352. altered and several additional ctrl operations are supported.
  1353. .PP
  1354. To specify any additional authenticated data (AAD) and/or a Nonce, a call to
  1355. \&\fBEVP_CipherUpdate()\fR, \fBEVP_EncryptUpdate()\fR or \fBEVP_DecryptUpdate()\fR should be made
  1356. with the output parameter \fIout\fR set to \fBNULL\fR.
  1357. .PP
  1358. RFC5297 states that the Nonce is the last piece of AAD before the actual
  1359. encrypt/decrypt takes place. The API does not differentiate the Nonce from
  1360. other AAD.
  1361. .PP
  1362. When decrypting the return value of \fBEVP_DecryptFinal()\fR or \fBEVP_CipherFinal()\fR
  1363. indicates if the operation was successful. If it does not indicate success
  1364. the authentication operation has failed and any output data \fBMUST NOT\fR
  1365. be used as it is corrupted.
  1366. .PP
  1367. The API does not store the SIV (Synthetic Initialization Vector) in
  1368. the cipher text. Instead, it is stored as the tag within the EVP_CIPHER_CTX.
  1369. The SIV must be retrieved from the context after encryption, and set into
  1370. the context before decryption.
  1371. .PP
  1372. This differs from RFC5297 in that the cipher output from encryption, and
  1373. the cipher input to decryption, does not contain the SIV. This also means
  1374. that the plain text and cipher text lengths are identical.
  1375. .PP
  1376. The following ctrls are supported in SIV mode, and are used to get and set
  1377. the Synthetic Initialization Vector:
  1378. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag);" 4
  1379. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag);"
  1380. Writes \fItaglen\fR bytes of the tag value (the Synthetic Initialization Vector)
  1381. to the buffer indicated by \fItag\fR. This call can only be made when encrypting
  1382. data and \fBafter\fR all data has been processed (e.g. after an \fBEVP_EncryptFinal()\fR
  1383. call). For SIV mode the taglen must be 16.
  1384. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag);" 4
  1385. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag);"
  1386. Sets the expected tag (the Synthetic Initialization Vector) to \fItaglen\fR
  1387. bytes from \fItag\fR. This call is only legal when decrypting data and must be
  1388. made \fBbefore\fR any data is processed (e.g. before any \fBEVP_DecryptUpdate()\fR
  1389. calls). For SIV mode the taglen must be 16.
  1390. .PP
  1391. SIV mode makes two passes over the input data, thus, only one call to
  1392. \&\fBEVP_CipherUpdate()\fR, \fBEVP_EncryptUpdate()\fR or \fBEVP_DecryptUpdate()\fR should be made
  1393. with \fIout\fR set to a non\-\fBNULL\fR value. A call to \fBEVP_DecryptFinal()\fR or
  1394. \&\fBEVP_CipherFinal()\fR is not required, but will indicate if the update
  1395. operation succeeded.
  1396. .SS ChaCha20\-Poly1305
  1397. .IX Subsection "ChaCha20-Poly1305"
  1398. The following \fIctrl\fRs are supported for the ChaCha20\-Poly1305 AEAD algorithm.
  1399. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, ivlen, NULL)" 4
  1400. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, ivlen, NULL)"
  1401. Sets the nonce length. This call is now redundant since the only valid value
  1402. is the default length of 12 (i.e. 96 bits).
  1403. Prior to OpenSSL 3.0 a nonce of less than 12 bytes could be used to automatically
  1404. pad the iv with leading 0 bytes to make it 12 bytes in length.
  1405. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag)" 4
  1406. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag)"
  1407. Writes \f(CW\*(C`taglen\*(C'\fR bytes of the tag value to the buffer indicated by \f(CW\*(C`tag\*(C'\fR.
  1408. This call can only be made when encrypting data and \fBafter\fR all data has been
  1409. processed (e.g. after an \fBEVP_EncryptFinal()\fR call).
  1410. .Sp
  1411. \&\f(CW\*(C`taglen\*(C'\fR specified here must be 16 (\fBPOLY1305_BLOCK_SIZE\fR, i.e. 128\-bits) or
  1412. less.
  1413. .IP "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag)" 4
  1414. .IX Item "EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, taglen, tag)"
  1415. Sets the expected tag to \f(CW\*(C`taglen\*(C'\fR bytes from \f(CW\*(C`tag\*(C'\fR.
  1416. The tag length can only be set before specifying an IV.
  1417. \&\f(CW\*(C`taglen\*(C'\fR must be between 1 and 16 (\fBPOLY1305_BLOCK_SIZE\fR) inclusive.
  1418. This call is only valid when decrypting data.
  1419. .SH NOTES
  1420. .IX Header "NOTES"
  1421. Where possible the \fBEVP\fR interface to symmetric ciphers should be used in
  1422. preference to the low-level interfaces. This is because the code then becomes
  1423. transparent to the cipher used and much more flexible. Additionally, the
  1424. \&\fBEVP\fR interface will ensure the use of platform specific cryptographic
  1425. acceleration such as AES-NI (the low-level interfaces do not provide the
  1426. guarantee).
  1427. .PP
  1428. PKCS padding works by adding \fBn\fR padding bytes of value \fBn\fR to make the total
  1429. length of the encrypted data a multiple of the block size. Padding is always
  1430. added so if the data is already a multiple of the block size \fBn\fR will equal
  1431. the block size. For example if the block size is 8 and 11 bytes are to be
  1432. encrypted then 5 padding bytes of value 5 will be added.
  1433. .PP
  1434. When decrypting the final block is checked to see if it has the correct form.
  1435. .PP
  1436. Although the decryption operation can produce an error if padding is enabled,
  1437. it is not a strong test that the input data or key is correct. A random block
  1438. has better than 1 in 256 chance of being of the correct format and problems with
  1439. the input data earlier on will not produce a final decrypt error.
  1440. .PP
  1441. If padding is disabled then the decryption operation will always succeed if
  1442. the total amount of data decrypted is a multiple of the block size.
  1443. .PP
  1444. The functions \fBEVP_EncryptInit()\fR, \fBEVP_EncryptInit_ex()\fR,
  1445. \&\fBEVP_EncryptFinal()\fR, \fBEVP_DecryptInit()\fR, \fBEVP_DecryptInit_ex()\fR,
  1446. \&\fBEVP_CipherInit()\fR, \fBEVP_CipherInit_ex()\fR and \fBEVP_CipherFinal()\fR are obsolete
  1447. but are retained for compatibility with existing code. New code should
  1448. use \fBEVP_EncryptInit_ex2()\fR, \fBEVP_EncryptFinal_ex()\fR, \fBEVP_DecryptInit_ex2()\fR,
  1449. \&\fBEVP_DecryptFinal_ex()\fR, \fBEVP_CipherInit_ex2()\fR and \fBEVP_CipherFinal_ex()\fR
  1450. because they can reuse an existing context without allocating and freeing
  1451. it up on each call.
  1452. .PP
  1453. There are some differences between functions \fBEVP_CipherInit()\fR and
  1454. \&\fBEVP_CipherInit_ex()\fR, significant in some circumstances. \fBEVP_CipherInit()\fR fills
  1455. the passed context object with zeros. As a consequence, \fBEVP_CipherInit()\fR does
  1456. not allow step-by-step initialization of the ctx when the \fIkey\fR and \fIiv\fR are
  1457. passed in separate calls. It also means that the flags set for the CTX are
  1458. removed, and it is especially important for the
  1459. \&\fBEVP_CIPHER_CTX_FLAG_WRAP_ALLOW\fR flag treated specially in
  1460. \&\fBEVP_CipherInit_ex()\fR.
  1461. .PP
  1462. Ignoring failure returns of the \fBEVP_CIPHER_CTX\fR initialization functions can
  1463. lead to subsequent undefined behavior when calling the functions that update or
  1464. finalize the context. The only valid calls on the \fBEVP_CIPHER_CTX\fR when
  1465. initialization fails are calls that attempt another initialization of the
  1466. context or release the context.
  1467. .PP
  1468. \&\fBEVP_get_cipherbynid()\fR, and \fBEVP_get_cipherbyobj()\fR are implemented as macros.
  1469. .SH BUGS
  1470. .IX Header "BUGS"
  1471. \&\fBEVP_MAX_KEY_LENGTH\fR and \fBEVP_MAX_IV_LENGTH\fR only refer to the internal
  1472. ciphers with default key lengths. If custom ciphers exceed these values the
  1473. results are unpredictable. This is because it has become standard practice to
  1474. define a generic key as a fixed unsigned char array containing
  1475. \&\fBEVP_MAX_KEY_LENGTH\fR bytes.
  1476. .PP
  1477. The ASN1 code is incomplete (and sometimes inaccurate) it has only been tested
  1478. for certain common S/MIME ciphers (RC2, DES, triple DES) in CBC mode.
  1479. .SH EXAMPLES
  1480. .IX Header "EXAMPLES"
  1481. Encrypt a string using IDEA:
  1482. .PP
  1483. .Vb 10
  1484. \& int do_crypt(char *outfile)
  1485. \& {
  1486. \& unsigned char outbuf[1024];
  1487. \& int outlen, tmplen;
  1488. \& /*
  1489. \& * Bogus key and IV: we\*(Aqd normally set these from
  1490. \& * another source.
  1491. \& */
  1492. \& unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
  1493. \& unsigned char iv[] = {1,2,3,4,5,6,7,8};
  1494. \& char intext[] = "Some Crypto Text";
  1495. \& EVP_CIPHER_CTX *ctx;
  1496. \& FILE *out;
  1497. \&
  1498. \& ctx = EVP_CIPHER_CTX_new();
  1499. \& if (!EVP_EncryptInit_ex2(ctx, EVP_idea_cbc(), key, iv, NULL)) {
  1500. \& /* Error */
  1501. \& EVP_CIPHER_CTX_free(ctx);
  1502. \& return 0;
  1503. \& }
  1504. \&
  1505. \& if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, intext, strlen(intext))) {
  1506. \& /* Error */
  1507. \& EVP_CIPHER_CTX_free(ctx);
  1508. \& return 0;
  1509. \& }
  1510. \& /*
  1511. \& * Buffer passed to EVP_EncryptFinal() must be after data just
  1512. \& * encrypted to avoid overwriting it.
  1513. \& */
  1514. \& if (!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen)) {
  1515. \& /* Error */
  1516. \& EVP_CIPHER_CTX_free(ctx);
  1517. \& return 0;
  1518. \& }
  1519. \& outlen += tmplen;
  1520. \& EVP_CIPHER_CTX_free(ctx);
  1521. \& /*
  1522. \& * Need binary mode for fopen because encrypted data is
  1523. \& * binary data. Also cannot use strlen() on it because
  1524. \& * it won\*(Aqt be NUL terminated and may contain embedded
  1525. \& * NULs.
  1526. \& */
  1527. \& out = fopen(outfile, "wb");
  1528. \& if (out == NULL) {
  1529. \& /* Error */
  1530. \& return 0;
  1531. \& }
  1532. \& fwrite(outbuf, 1, outlen, out);
  1533. \& fclose(out);
  1534. \& return 1;
  1535. \& }
  1536. .Ve
  1537. .PP
  1538. The ciphertext from the above example can be decrypted using the \fBopenssl\fR
  1539. utility with the command line (shown on two lines for clarity):
  1540. .PP
  1541. .Vb 2
  1542. \& openssl idea \-d \e
  1543. \& \-K 000102030405060708090A0B0C0D0E0F \-iv 0102030405060708 <filename
  1544. .Ve
  1545. .PP
  1546. General encryption and decryption function example using FILE I/O and AES128
  1547. with a 128\-bit key:
  1548. .PP
  1549. .Vb 12
  1550. \& int do_crypt(FILE *in, FILE *out, int do_encrypt)
  1551. \& {
  1552. \& /* Allow enough space in output buffer for additional block */
  1553. \& unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];
  1554. \& int inlen, outlen;
  1555. \& EVP_CIPHER_CTX *ctx;
  1556. \& /*
  1557. \& * Bogus key and IV: we\*(Aqd normally set these from
  1558. \& * another source.
  1559. \& */
  1560. \& unsigned char key[] = "0123456789abcdeF";
  1561. \& unsigned char iv[] = "1234567887654321";
  1562. \&
  1563. \& /* Don\*(Aqt set key or IV right away; we want to check lengths */
  1564. \& ctx = EVP_CIPHER_CTX_new();
  1565. \& if (!EVP_CipherInit_ex2(ctx, EVP_aes_128_cbc(), NULL, NULL,
  1566. \& do_encrypt, NULL)) {
  1567. \& /* Error */
  1568. \& EVP_CIPHER_CTX_free(ctx);
  1569. \& return 0;
  1570. \& }
  1571. \& OPENSSL_assert(EVP_CIPHER_CTX_get_key_length(ctx) == 16);
  1572. \& OPENSSL_assert(EVP_CIPHER_CTX_get_iv_length(ctx) == 16);
  1573. \&
  1574. \& /* Now we can set key and IV */
  1575. \& if (!EVP_CipherInit_ex2(ctx, NULL, key, iv, do_encrypt, NULL)) {
  1576. \& /* Error */
  1577. \& EVP_CIPHER_CTX_free(ctx);
  1578. \& return 0;
  1579. \& }
  1580. \&
  1581. \& for (;;) {
  1582. \& inlen = fread(inbuf, 1, 1024, in);
  1583. \& if (inlen <= 0)
  1584. \& break;
  1585. \& if (!EVP_CipherUpdate(ctx, outbuf, &outlen, inbuf, inlen)) {
  1586. \& /* Error */
  1587. \& EVP_CIPHER_CTX_free(ctx);
  1588. \& return 0;
  1589. \& }
  1590. \& fwrite(outbuf, 1, outlen, out);
  1591. \& }
  1592. \& if (!EVP_CipherFinal_ex(ctx, outbuf, &outlen)) {
  1593. \& /* Error */
  1594. \& EVP_CIPHER_CTX_free(ctx);
  1595. \& return 0;
  1596. \& }
  1597. \& fwrite(outbuf, 1, outlen, out);
  1598. \&
  1599. \& EVP_CIPHER_CTX_free(ctx);
  1600. \& return 1;
  1601. \& }
  1602. .Ve
  1603. .PP
  1604. Encryption using AES-CBC with a 256\-bit key with "CS1" ciphertext stealing.
  1605. .PP
  1606. .Vb 10
  1607. \& int encrypt(const unsigned char *key, const unsigned char *iv,
  1608. \& const unsigned char *msg, size_t msg_len, unsigned char *out)
  1609. \& {
  1610. \& /*
  1611. \& * This assumes that key size is 32 bytes and the iv is 16 bytes.
  1612. \& * For ciphertext stealing mode the length of the ciphertext "out" will be
  1613. \& * the same size as the plaintext size "msg_len".
  1614. \& * The "msg_len" can be any size >= 16.
  1615. \& */
  1616. \& int ret = 0, encrypt = 1, outlen, len;
  1617. \& EVP_CIPHER_CTX *ctx = NULL;
  1618. \& EVP_CIPHER *cipher = NULL;
  1619. \& OSSL_PARAM params[2];
  1620. \&
  1621. \& ctx = EVP_CIPHER_CTX_new();
  1622. \& cipher = EVP_CIPHER_fetch(NULL, "AES\-256\-CBC\-CTS", NULL);
  1623. \& if (ctx == NULL || cipher == NULL)
  1624. \& goto err;
  1625. \&
  1626. \& /*
  1627. \& * The default is "CS1" so this is not really needed,
  1628. \& * but would be needed to set either "CS2" or "CS3".
  1629. \& */
  1630. \& params[0] = OSSL_PARAM_construct_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE,
  1631. \& "CS1", 0);
  1632. \& params[1] = OSSL_PARAM_construct_end();
  1633. \&
  1634. \& if (!EVP_CipherInit_ex2(ctx, cipher, key, iv, encrypt, params))
  1635. \& goto err;
  1636. \&
  1637. \& /* NOTE: CTS mode does not support multiple calls to EVP_CipherUpdate() */
  1638. \& if (!EVP_CipherUpdate(ctx, out, &outlen, msg, msg_len))
  1639. \& goto err;
  1640. \& if (!EVP_CipherFinal_ex(ctx, out + outlen, &len))
  1641. \& goto err;
  1642. \& ret = 1;
  1643. \& err:
  1644. \& EVP_CIPHER_free(cipher);
  1645. \& EVP_CIPHER_CTX_free(ctx);
  1646. \& return ret;
  1647. \& }
  1648. .Ve
  1649. .SH "SEE ALSO"
  1650. .IX Header "SEE ALSO"
  1651. \&\fBevp\fR\|(7),
  1652. \&\fBproperty\fR\|(7),
  1653. "ALGORITHM FETCHING" in \fBcrypto\fR\|(7),
  1654. \&\fBprovider\-cipher\fR\|(7),
  1655. \&\fBlife_cycle\-cipher\fR\|(7)
  1656. .PP
  1657. Supported ciphers are listed in:
  1658. .PP
  1659. \&\fBEVP_aes_128_gcm\fR\|(3),
  1660. \&\fBEVP_aria_128_gcm\fR\|(3),
  1661. \&\fBEVP_bf_cbc\fR\|(3),
  1662. \&\fBEVP_camellia_128_ecb\fR\|(3),
  1663. \&\fBEVP_cast5_cbc\fR\|(3),
  1664. \&\fBEVP_chacha20\fR\|(3),
  1665. \&\fBEVP_des_cbc\fR\|(3),
  1666. \&\fBEVP_desx_cbc\fR\|(3),
  1667. \&\fBEVP_idea_cbc\fR\|(3),
  1668. \&\fBEVP_rc2_cbc\fR\|(3),
  1669. \&\fBEVP_rc4\fR\|(3),
  1670. \&\fBEVP_rc5_32_12_16_cbc\fR\|(3),
  1671. \&\fBEVP_seed_cbc\fR\|(3),
  1672. \&\fBEVP_sm4_cbc\fR\|(3),
  1673. .SH HISTORY
  1674. .IX Header "HISTORY"
  1675. Support for OCB mode was added in OpenSSL 1.1.0.
  1676. .PP
  1677. \&\fBEVP_CIPHER_CTX\fR was made opaque in OpenSSL 1.1.0. As a result,
  1678. \&\fBEVP_CIPHER_CTX_reset()\fR appeared and \fBEVP_CIPHER_CTX_cleanup()\fR
  1679. disappeared. \fBEVP_CIPHER_CTX_init()\fR remains as an alias for
  1680. \&\fBEVP_CIPHER_CTX_reset()\fR.
  1681. .PP
  1682. The \fBEVP_CIPHER_CTX_cipher()\fR function was deprecated in OpenSSL 3.0; use
  1683. \&\fBEVP_CIPHER_CTX_get0_cipher()\fR instead.
  1684. .PP
  1685. The \fBEVP_EncryptInit_ex2()\fR, \fBEVP_DecryptInit_ex2()\fR, \fBEVP_CipherInit_ex2()\fR,
  1686. \&\fBEVP_CIPHER_fetch()\fR, \fBEVP_CIPHER_free()\fR, \fBEVP_CIPHER_up_ref()\fR,
  1687. \&\fBEVP_CIPHER_CTX_get0_cipher()\fR, \fBEVP_CIPHER_CTX_get1_cipher()\fR,
  1688. \&\fBEVP_CIPHER_get_params()\fR, \fBEVP_CIPHER_CTX_set_params()\fR,
  1689. \&\fBEVP_CIPHER_CTX_get_params()\fR, \fBEVP_CIPHER_gettable_params()\fR,
  1690. \&\fBEVP_CIPHER_settable_ctx_params()\fR, \fBEVP_CIPHER_gettable_ctx_params()\fR,
  1691. \&\fBEVP_CIPHER_CTX_settable_params()\fR and \fBEVP_CIPHER_CTX_gettable_params()\fR
  1692. functions were added in 3.0.
  1693. .PP
  1694. The \fBEVP_CIPHER_nid()\fR, \fBEVP_CIPHER_name()\fR, \fBEVP_CIPHER_block_size()\fR,
  1695. \&\fBEVP_CIPHER_key_length()\fR, \fBEVP_CIPHER_iv_length()\fR, \fBEVP_CIPHER_flags()\fR,
  1696. \&\fBEVP_CIPHER_mode()\fR, \fBEVP_CIPHER_type()\fR, \fBEVP_CIPHER_CTX_nid()\fR,
  1697. \&\fBEVP_CIPHER_CTX_block_size()\fR, \fBEVP_CIPHER_CTX_key_length()\fR,
  1698. \&\fBEVP_CIPHER_CTX_iv_length()\fR, \fBEVP_CIPHER_CTX_tag_length()\fR,
  1699. \&\fBEVP_CIPHER_CTX_num()\fR, \fBEVP_CIPHER_CTX_type()\fR, and \fBEVP_CIPHER_CTX_mode()\fR
  1700. functions were renamed to include \f(CW\*(C`get\*(C'\fR or \f(CW\*(C`get0\*(C'\fR in their names in
  1701. OpenSSL 3.0, respectively. The old names are kept as non-deprecated
  1702. alias macros.
  1703. .PP
  1704. The \fBEVP_CIPHER_CTX_encrypting()\fR function was renamed to
  1705. \&\fBEVP_CIPHER_CTX_is_encrypting()\fR in OpenSSL 3.0. The old name is kept as
  1706. non-deprecated alias macro.
  1707. .PP
  1708. The \fBEVP_CIPHER_CTX_flags()\fR macro was deprecated in OpenSSL 1.1.0.
  1709. .PP
  1710. \&\fBEVP_CIPHER_CTX_dup()\fR was added in OpenSSL 3.2.
  1711. .SH COPYRIGHT
  1712. .IX Header "COPYRIGHT"
  1713. Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved.
  1714. .PP
  1715. Licensed under the Apache License 2.0 (the "License"). You may not use
  1716. this file except in compliance with the License. You can obtain a copy
  1717. in the file LICENSE in the source distribution or at
  1718. <https://www.openssl.org/source/license.html>.