life_cycle-cipher.pod 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. =pod
  2. =head1 NAME
  3. life_cycle-cipher - The cipher algorithm life-cycle
  4. =head1 DESCRIPTION
  5. All symmetric ciphers (CIPHERs) go through a number of stages in their
  6. life-cycle:
  7. =over 4
  8. =item start
  9. This state represents the CIPHER before it has been allocated. It is the
  10. starting state for any life-cycle transitions.
  11. =item newed
  12. This state represents the CIPHER after it has been allocated.
  13. =item initialised
  14. These states represent the CIPHER when it is set up and capable of processing
  15. input. There are three possible initialised states:
  16. =over 4
  17. =item initialised using EVP_CipherInit
  18. =item initialised for decryption using EVP_DecryptInit
  19. =item initialised for encryption using EVP_EncryptInit
  20. =back
  21. =item updated
  22. These states represent the CIPHER when it is set up and capable of processing
  23. additional input or generating output. The three possible states directly
  24. correspond to those for initialised above. The three different streams should
  25. not be mixed.
  26. =item finaled
  27. This state represents the CIPHER when it has generated output.
  28. =item freed
  29. This state is entered when the CIPHER is freed. It is the terminal state
  30. for all life-cycle transitions.
  31. =back
  32. =head2 State Transition Diagram
  33. The usual life-cycle of a CIPHER is illustrated:
  34. =begin man
  35. +---------------------------+
  36. | |
  37. | start |
  38. | |
  39. +---------------------------+ + - - - - - - - - - - - - - +
  40. | ' any of the initialised '
  41. | EVP_CIPHER_CTX_new ' updated or finaled states '
  42. v ' '
  43. +---------------------------+ + - - - - - - - - - - - - - +
  44. | | |
  45. | newed | | EVP_CIPHER_CTX_reset
  46. | | <----+
  47. +---------------------------+
  48. | | |
  49. +---------+ | +---------+
  50. EVP_DecryptInit | | EVP_CipherInit | EVP_EncryptInit
  51. v v v
  52. +---------------------------+ +---------------------------+ +---------------------------+
  53. | | | | | |
  54. | initialised | | initialised | | initialised |
  55. | for decryption | | | | for encryption |
  56. +---------------------------+ +---------------------------+ +---------------------------+
  57. | | |
  58. | EVP_DecryptUpdate | EVP_CipherUpdate EVP_EncryptUpdate |
  59. | v |
  60. | +---------------------------+ |
  61. | | |--------------------+ |
  62. | | updated | EVP_CipherUpdate | |
  63. | | | <------------------+ |
  64. v +---------------------------+ v
  65. +---------------------------+ | +---------------------------+
  66. | |---------------------+ | | |
  67. | updated | EVP_DecryptUpdate | | | updated |------+
  68. | for decryption | <-------------------+ | | for encryption | |
  69. +---------------------------+ | +---------------------------+ |
  70. | EVP_CipherFinal | | ^ |
  71. +-------+ | +--------+ | |
  72. EVP_DecryptFinal | | | EVP_EncryptFinal +-------------------+
  73. v v v EVP_EncryptUpdate
  74. +---------------------------+
  75. | |-----------------------------+
  76. | finaled | |
  77. | | <---------------------------+
  78. +---------------------------+ EVP_CIPHER_CTX_get_params
  79. | (AEAD encryption)
  80. | EVP_CIPHER_CTX_free
  81. v
  82. +---------------------------+
  83. | |
  84. | freed |
  85. | |
  86. +---------------------------+
  87. =end man
  88. =for html <img src="img/cipher.png">
  89. =head2 Formal State Transitions
  90. This section defines all of the legal state transitions.
  91. This is the canonical list.
  92. =begin man
  93. Function Call ---------------------------------------------- Current State -----------------------------------------------
  94. start newed initialised updated finaled initialised updated initialised updated freed
  95. decryption decryption encryption encryption
  96. EVP_CIPHER_CTX_new newed
  97. EVP_CipherInit initialised initialised initialised initialised initialised initialised initialised initialised
  98. EVP_DecryptInit initialised initialised initialised initialised initialised initialised initialised initialised
  99. decryption decryption decryption decryption decryption decryption decryption decryption
  100. EVP_EncryptInit initialised initialised initialised initialised initialised initialised initialised initialised
  101. encryption encryption encryption encryption encryption encryption encryption encryption
  102. EVP_CipherUpdate updated updated
  103. EVP_DecryptUpdate updated updated
  104. decryption decryption
  105. EVP_EncryptUpdate updated updated
  106. encryption encryption
  107. EVP_CipherFinal finaled
  108. EVP_DecryptFinal finaled
  109. EVP_EncryptFinal finaled
  110. EVP_CIPHER_CTX_free freed freed freed freed freed freed freed freed freed
  111. EVP_CIPHER_CTX_reset newed newed newed newed newed newed newed newed
  112. EVP_CIPHER_CTX_get_params newed initialised updated initialised updated initialised updated
  113. decryption decryption encryption encryption
  114. EVP_CIPHER_CTX_set_params newed initialised updated initialised updated initialised updated
  115. decryption decryption encryption encryption
  116. EVP_CIPHER_CTX_gettable_params newed initialised updated initialised updated initialised updated
  117. decryption decryption encryption encryption
  118. EVP_CIPHER_CTX_settable_params newed initialised updated initialised updated initialised updated
  119. decryption decryption encryption encryption
  120. =end man
  121. =begin html
  122. <table style="border:1px solid; border-collapse:collapse">
  123. <tr><th style="border:1px solid" align="left">Function Call</th>
  124. <th style="border:1px solid" colspan="10">Current State</th></tr>
  125. <tr><th style="border:1px solid"></th>
  126. <th style="border:1px solid" align="center">start</th>
  127. <th style="border:1px solid" align="center">newed</th>
  128. <th style="border:1px solid" align="center">initialised</th>
  129. <th style="border:1px solid" align="center">updated</th>
  130. <th style="border:1px solid" align="center">finaled</th>
  131. <th style="border:1px solid" align="center">initialised<br>decryption</th>
  132. <th style="border:1px solid" align="center">updated<br>decryption</th>
  133. <th style="border:1px solid" align="center">initialised<br>encryption</th>
  134. <th style="border:1px solid" align="center">updated<br>encryption</th>
  135. <th style="border:1px solid" align="center">freed</th></tr>
  136. <tr><th style="border:1px solid" align="left">EVP_CIPHER_CTX_new</th>
  137. <td style="border:1px solid" align="center">newed</td>
  138. <td style="border:1px solid" align="center"></td>
  139. <td style="border:1px solid" align="center"></td>
  140. <td style="border:1px solid" align="center"></td>
  141. <td style="border:1px solid" align="center"></td>
  142. <td style="border:1px solid" align="center"></td>
  143. <td style="border:1px solid" align="center"></td>
  144. <td style="border:1px solid" align="center"></td>
  145. <td style="border:1px solid" align="center"></td>
  146. <td style="border:1px solid" align="center"></td></tr>
  147. <tr><th style="border:1px solid" align="left">EVP_CipherInit</th>
  148. <td style="border:1px solid" align="center"></td>
  149. <td style="border:1px solid" align="center">initialised</td>
  150. <td style="border:1px solid" align="center">initialised</td>
  151. <td style="border:1px solid" align="center">initialised</td>
  152. <td style="border:1px solid" align="center">initialised</td>
  153. <td style="border:1px solid" align="center">initialised</td>
  154. <td style="border:1px solid" align="center">initialised</td>
  155. <td style="border:1px solid" align="center">initialised</td>
  156. <td style="border:1px solid" align="center">initialised</td>
  157. <td style="border:1px solid" align="center"></td></tr>
  158. <tr><th style="border:1px solid" align="left">EVP_DecryptInit</th>
  159. <td style="border:1px solid" align="center"></td>
  160. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  161. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  162. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  163. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  164. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  165. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  166. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  167. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  168. <td style="border:1px solid" align="center"></td></tr>
  169. <tr><th style="border:1px solid" align="left">EVP_EncryptInit</th>
  170. <td style="border:1px solid" align="center"></td>
  171. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  172. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  173. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  174. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  175. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  176. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  177. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  178. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  179. <td style="border:1px solid" align="center"></td></tr>
  180. <tr><th style="border:1px solid" align="left">EVP_CipherUpdate</th>
  181. <td style="border:1px solid" align="center"></td>
  182. <td style="border:1px solid" align="center"></td>
  183. <td style="border:1px solid" align="center">updated</td>
  184. <td style="border:1px solid" align="center">updated</td>
  185. <td style="border:1px solid" align="center"></td>
  186. <td style="border:1px solid" align="center"></td>
  187. <td style="border:1px solid" align="center"></td>
  188. <td style="border:1px solid" align="center"></td>
  189. <td style="border:1px solid" align="center"></td>
  190. <td style="border:1px solid" align="center"></td></tr>
  191. <tr><th style="border:1px solid" align="left">EVP_DecryptUpdate</th>
  192. <td style="border:1px solid" align="center"></td>
  193. <td style="border:1px solid" align="center"></td>
  194. <td style="border:1px solid" align="center"></td>
  195. <td style="border:1px solid" align="center"></td>
  196. <td style="border:1px solid" align="center"></td>
  197. <td style="border:1px solid" align="center">updated<br>decryption</td>
  198. <td style="border:1px solid" align="center">updated<br>decryption</td>
  199. <td style="border:1px solid" align="center"></td>
  200. <td style="border:1px solid" align="center"></td>
  201. <td style="border:1px solid" align="center"></td></tr>
  202. <tr><th style="border:1px solid" align="left">EVP_EncryptUpdate</th>
  203. <td style="border:1px solid" align="center"></td>
  204. <td style="border:1px solid" align="center"></td>
  205. <td style="border:1px solid" align="center"></td>
  206. <td style="border:1px solid" align="center"></td>
  207. <td style="border:1px solid" align="center"></td>
  208. <td style="border:1px solid" align="center"></td>
  209. <td style="border:1px solid" align="center"></td>
  210. <td style="border:1px solid" align="center">updated<br>encryption</td>
  211. <td style="border:1px solid" align="center">updated<br>encryption</td>
  212. <td style="border:1px solid" align="center"></td></tr>
  213. <tr><th style="border:1px solid" align="left">EVP_CipherFinal</th>
  214. <td style="border:1px solid" align="center"></td>
  215. <td style="border:1px solid" align="center"></td>
  216. <td style="border:1px solid" align="center"></td>
  217. <td style="border:1px solid" align="center">finaled</td>
  218. <td style="border:1px solid" align="center"></td>
  219. <td style="border:1px solid" align="center"></td>
  220. <td style="border:1px solid" align="center"></td>
  221. <td style="border:1px solid" align="center"></td>
  222. <td style="border:1px solid" align="center"></td>
  223. <td style="border:1px solid" align="center"></td></tr>
  224. <tr><th style="border:1px solid" align="left">EVP_DecryptFinal</th>
  225. <td style="border:1px solid" align="center"></td>
  226. <td style="border:1px solid" align="center"></td>
  227. <td style="border:1px solid" align="center"></td>
  228. <td style="border:1px solid" align="center"></td>
  229. <td style="border:1px solid" align="center"></td>
  230. <td style="border:1px solid" align="center"></td>
  231. <td style="border:1px solid" align="center">finaled<br>decryption</td>
  232. <td style="border:1px solid" align="center"></td>
  233. <td style="border:1px solid" align="center"></td>
  234. <td style="border:1px solid" align="center"></td></tr>
  235. <tr><th style="border:1px solid" align="left">EVP_EncryptFinal</th>
  236. <td style="border:1px solid" align="center"></td>
  237. <td style="border:1px solid" align="center"></td>
  238. <td style="border:1px solid" align="center"></td>
  239. <td style="border:1px solid" align="center"></td>
  240. <td style="border:1px solid" align="center"></td>
  241. <td style="border:1px solid" align="center"></td>
  242. <td style="border:1px solid" align="center"></td>
  243. <td style="border:1px solid" align="center"></td>
  244. <td style="border:1px solid" align="center">finaled<br>decryption</td>
  245. <td style="border:1px solid" align="center"></td></tr>
  246. <tr><th style="border:1px solid" align="left">EVP_CIPHER_CTX_free</th>
  247. <td style="border:1px solid" align="center">freed</td>
  248. <td style="border:1px solid" align="center">freed</td>
  249. <td style="border:1px solid" align="center">freed</td>
  250. <td style="border:1px solid" align="center">freed</td>
  251. <td style="border:1px solid" align="center">freed</td>
  252. <td style="border:1px solid" align="center">freed</td>
  253. <td style="border:1px solid" align="center">freed</td>
  254. <td style="border:1px solid" align="center">freed</td>
  255. <td style="border:1px solid" align="center">freed</td>
  256. <td style="border:1px solid" align="center"></td></tr>
  257. <tr><th style="border:1px solid" align="left">EVP_CIPHER_CTX_reset</th>
  258. <td style="border:1px solid" align="center"></td>
  259. <td style="border:1px solid" align="center"></td>
  260. <td style="border:1px solid" align="center">newed</td>
  261. <td style="border:1px solid" align="center">newed</td>
  262. <td style="border:1px solid" align="center">newed</td>
  263. <td style="border:1px solid" align="center">newed</td>
  264. <td style="border:1px solid" align="center">newed</td>
  265. <td style="border:1px solid" align="center">newed</td>
  266. <td style="border:1px solid" align="center">newed</td>
  267. <td style="border:1px solid" align="center"></td></tr>
  268. <tr><th style="border:1px solid" align="left">EVP_CIPHER_CTX_get_params</th>
  269. <td style="border:1px solid" align="center"></td>
  270. <td style="border:1px solid" align="center">newed</td>
  271. <td style="border:1px solid" align="center">initialised</td>
  272. <td style="border:1px solid" align="center">updated</td>
  273. <td style="border:1px solid" align="center"></td>
  274. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  275. <td style="border:1px solid" align="center">updated<br>decryption</td>
  276. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  277. <td style="border:1px solid" align="center">updated<br>encryption</td>
  278. <td style="border:1px solid" align="center"></td></tr>
  279. <tr><th style="border:1px solid" align="left">EVP_CIPHER_CTX_set_params</th>
  280. <td style="border:1px solid" align="center"></td>
  281. <td style="border:1px solid" align="center">newed</td>
  282. <td style="border:1px solid" align="center">initialised</td>
  283. <td style="border:1px solid" align="center">updated</td>
  284. <td style="border:1px solid" align="center"></td>
  285. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  286. <td style="border:1px solid" align="center">updated<br>decryption</td>
  287. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  288. <td style="border:1px solid" align="center">updated<br>encryption</td>
  289. <td style="border:1px solid" align="center"></td></tr>
  290. <tr><th style="border:1px solid" align="left">EVP_CIPHER_CTX_gettable_params</th>
  291. <td style="border:1px solid" align="center"></td>
  292. <td style="border:1px solid" align="center">newed</td>
  293. <td style="border:1px solid" align="center">initialised</td>
  294. <td style="border:1px solid" align="center">updated</td>
  295. <td style="border:1px solid" align="center"></td>
  296. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  297. <td style="border:1px solid" align="center">updated<br>decryption</td>
  298. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  299. <td style="border:1px solid" align="center">updated<br>encryption</td>
  300. <td style="border:1px solid" align="center"></td></tr>
  301. <tr><th style="border:1px solid" align="left">EVP_CIPHER_CTX_settable_params</th>
  302. <td style="border:1px solid" align="center"></td>
  303. <td style="border:1px solid" align="center">newed</td>
  304. <td style="border:1px solid" align="center">initialised</td>
  305. <td style="border:1px solid" align="center">updated</td>
  306. <td style="border:1px solid" align="center"></td>
  307. <td style="border:1px solid" align="center">initialised<br>decryption</td>
  308. <td style="border:1px solid" align="center">updated<br>decryption</td>
  309. <td style="border:1px solid" align="center">initialised<br>encryption</td>
  310. <td style="border:1px solid" align="center">updated<br>encryption</td>
  311. <td style="border:1px solid" align="center"></td></tr>
  312. </table>
  313. =end html
  314. =head1 NOTES
  315. At some point the EVP layer will begin enforcing the transitions described
  316. herein.
  317. =head1 SEE ALSO
  318. L<provider-cipher(7)>, L<EVP_EncryptInit(3)>
  319. =head1 COPYRIGHT
  320. Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
  321. Licensed under the Apache License 2.0 (the "License"). You may not use
  322. this file except in compliance with the License. You can obtain a copy
  323. in the file LICENSE in the source distribution or at
  324. L<https://www.openssl.org/source/license.html>.
  325. =cut