blob: aa577f07f5c8e4c11defd5cc4737dce7ec1dec2a [file] [log] [blame]
Alex Gaynor2724ff62013-12-20 13:51:42 -08001.. hazmat:: /fernet
Donald Stufftd8f01182013-10-27 16:59:56 -04002
3
Alex Stapletonc5fffd32014-03-18 15:29:00 +00004Symmetric encryption
Donald Stuffte51fb932013-10-27 17:26:17 -04005====================
6
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -06007.. module:: cryptography.hazmat.primitives.ciphers
David Reid1f3d7182013-10-22 16:55:18 -07008
Alex Stapleton092351d2014-03-09 17:44:43 +00009Symmetric encryption is a way to `encrypt`_ or hide the contents of material
10where the sender and receiver both use the same secret key. Note that symmetric
11encryption is **not** sufficient for most applications because it only
12provides secrecy but not authenticity. That means an attacker can't see the
13message but an attacker can create bogus messages and force the application to
14decrypt them.
15
Paul Kehrer006670c2014-05-09 11:12:43 -050016For this reason it is **strongly** recommended to combine encryption with a
Alex Gaynor969f18e2014-05-17 20:07:35 -070017message authentication code, such as :doc:`HMAC </hazmat/primitives/mac/hmac>`,
18in an "encrypt-then-MAC" formulation as `described by Colin Percival`_.
Paul Kehrerafa84f12017-05-27 15:11:24 -050019``cryptography`` includes a recipe named :doc:`/fernet` that does this for you.
20**To minimize the risk of security issues you should evaluate Fernet to see if
21it fits your needs before implementing anything using this module.**
Alex Gaynorf6c47e92013-08-08 07:16:01 -070022
David Reidef0fcf22013-11-06 11:12:45 -080023.. class:: Cipher(algorithm, mode, backend)
Alex Gaynorf6c47e92013-08-08 07:16:01 -070024
Alex Stapleton092351d2014-03-09 17:44:43 +000025 Cipher objects combine an algorithm such as
26 :class:`~cryptography.hazmat.primitives.ciphers.algorithms.AES` with a
27 mode like
Alex Gaynorab5f0112013-11-08 10:34:00 -080028 :class:`~cryptography.hazmat.primitives.ciphers.modes.CBC` or
Alex Stapleton092351d2014-03-09 17:44:43 +000029 :class:`~cryptography.hazmat.primitives.ciphers.modes.CTR`. A simple
30 example of encrypting and then decrypting content with AES is:
Alex Gaynorf6c47e92013-08-08 07:16:01 -070031
Donald Stufft173de982013-08-12 07:34:39 -040032 .. doctest::
Alex Gaynorf6c47e92013-08-08 07:16:01 -070033
Gregory Haynes0f986112014-12-30 09:43:24 -080034 >>> import os
Paul Kehrer051099e2013-11-06 15:53:40 +080035 >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
Alex Gaynorf8796b12013-12-13 20:28:55 -080036 >>> from cryptography.hazmat.backends import default_backend
Alex Gaynorf56444d2013-12-13 15:19:22 -080037 >>> backend = default_backend()
Gregory Haynese261d942015-01-03 09:17:41 -080038 >>> key = os.urandom(32)
Gregory Haynese5917782015-01-03 21:58:25 -080039 >>> iv = os.urandom(16)
Gregory Haynese261d942015-01-03 09:17:41 -080040 >>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend)
Paul Kehrer3e0895c2013-10-21 22:19:29 -050041 >>> encryptor = cipher.encryptor()
42 >>> ct = encryptor.update(b"a secret message") + encryptor.finalize()
43 >>> decryptor = cipher.decryptor()
44 >>> decryptor.update(ct) + decryptor.finalize()
Paul Kehrerf6cf9562013-10-22 10:36:00 -050045 'a secret message'
Alex Gaynorf6c47e92013-08-08 07:16:01 -070046
David Reid663295d2013-11-20 13:55:08 -080047 :param algorithms: A
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -060048 :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -030049 instance such as those described
David Reid663295d2013-11-20 13:55:08 -080050 :ref:`below <symmetric-encryption-algorithms>`.
Paul Kehrer513b7cb2015-02-12 17:31:24 -060051 :param mode: A :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -030052 instance such as those described
David Reid663295d2013-11-20 13:55:08 -080053 :ref:`below <symmetric-encryption-modes>`.
54 :param backend: A
Alex Gaynorf8796b12013-12-13 20:28:55 -080055 :class:`~cryptography.hazmat.backends.interfaces.CipherBackend`
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -030056 instance.
Alex Gaynor0ca7fdb2013-08-08 07:35:26 -070057
Alex Gaynor7a489db2014-03-22 15:09:34 -070058 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised if the
Ayrxf56c54e2014-03-16 14:36:17 +080059 provided ``backend`` does not implement
60 :class:`~cryptography.hazmat.backends.interfaces.CipherBackend`
61
Paul Kehrer5399fd02013-10-21 23:48:25 -050062 .. method:: encryptor()
Alex Gaynor09515f02013-08-08 15:26:55 -070063
David Reid63ba6652013-10-22 14:09:19 -070064 :return: An encrypting
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -060065 :class:`~cryptography.hazmat.primitives.ciphers.CipherContext`
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -030066 instance.
Alex Gaynore62aa402013-08-08 15:23:11 -070067
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070068 If the backend doesn't support the requested combination of ``cipher``
Alex Gaynor7a489db2014-03-22 15:09:34 -070069 and ``mode`` an :class:`~cryptography.exceptions.UnsupportedAlgorithm`
Alex Stapleton092351d2014-03-09 17:44:43 +000070 exception will be raised.
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070071
Paul Kehrer5399fd02013-10-21 23:48:25 -050072 .. method:: decryptor()
73
David Reid63ba6652013-10-22 14:09:19 -070074 :return: A decrypting
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -060075 :class:`~cryptography.hazmat.primitives.ciphers.CipherContext`
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -030076 instance.
Paul Kehrer5399fd02013-10-21 23:48:25 -050077
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070078 If the backend doesn't support the requested combination of ``cipher``
Alex Gaynorfdf63302014-04-29 18:26:11 -070079 and ``mode`` an :class:`~cryptography.exceptions.UnsupportedAlgorithm`
Alex Stapleton092351d2014-03-09 17:44:43 +000080 exception will be raised.
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070081
David Reid663295d2013-11-20 13:55:08 -080082.. _symmetric-encryption-algorithms:
83
Paul Kehrer051099e2013-11-06 15:53:40 +080084Algorithms
85~~~~~~~~~~
Alex Gaynord96d1002013-08-08 07:37:26 -070086
Paul Kehrer051099e2013-11-06 15:53:40 +080087.. currentmodule:: cryptography.hazmat.primitives.ciphers.algorithms
David Reid1f3d7182013-10-22 16:55:18 -070088
89.. class:: AES(key)
Alex Gaynor5ba2dfa2013-08-08 11:04:44 -070090
Alex Gaynor1e3f81f2013-08-08 11:31:43 -070091 AES (Advanced Encryption Standard) is a block cipher standardized by NIST.
Alex Gaynor5ba2dfa2013-08-08 11:04:44 -070092 AES is both fast, and cryptographically strong. It is a good default
93 choice for encryption.
94
Alex Stapleton092351d2014-03-09 17:44:43 +000095 :param bytes key: The secret key. This must be kept secret. Either ``128``,
Paul Kehrer1aac78c2017-10-11 19:49:57 +080096 ``192``, or ``256`` :term:`bits` long.
Alex Gaynor5ba2dfa2013-08-08 11:04:44 -070097
David Reid1f3d7182013-10-22 16:55:18 -070098.. class:: Camellia(key)
Paul Kehrerdff22d42013-09-27 13:43:06 -050099
Alex Stapleton092351d2014-03-09 17:44:43 +0000100 Camellia is a block cipher approved for use by `CRYPTREC`_ and ISO/IEC.
101 It is considered to have comparable security and performance to AES but
Paul Kehrerdff22d42013-09-27 13:43:06 -0500102 is not as widely studied or deployed.
103
Alex Stapleton092351d2014-03-09 17:44:43 +0000104 :param bytes key: The secret key. This must be kept secret. Either ``128``,
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800105 ``192``, or ``256`` :term:`bits` long.
Paul Kehrerdff22d42013-09-27 13:43:06 -0500106
Paul Kehrer62ebb422017-09-28 23:46:49 +0800107.. class:: ChaCha20(key)
108
109 .. versionadded:: 2.1
110
111 .. note::
112
113 In most cases users should use
114 :class:`~cryptography.hazmat.primitives.ciphers.aead.ChaCha20Poly1305`
115 instead of this class. `ChaCha20` alone does not provide integrity
116 so it must be combined with a MAC to be secure.
117 :class:`~cryptography.hazmat.primitives.ciphers.aead.ChaCha20Poly1305`
118 does this for you.
119
120 ChaCha20 is a stream cipher used in several IETF protocols. It is
121 standardized in :rfc:`7539`.
122
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800123 :param bytes key: The secret key. This must be kept secret. ``256``
124 :term:`bits` (32 bytes) in length.
Paul Kehrer62ebb422017-09-28 23:46:49 +0800125
126 :param bytes nonce: Should be unique, a :term:`nonce`. It is
127 critical to never reuse a ``nonce`` with a given key. Any reuse of a
128 nonce with the same key compromises the security of every message
129 encrypted with that key. The nonce does not need to be kept secret
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800130 and may be included with the ciphertext. This must be ``128``
131 :term:`bits` in length.
Paul Kehrer62ebb422017-09-28 23:46:49 +0800132
133 .. note::
134
135 In :rfc:`7539` the nonce is defined as a 96-bit value that is later
136 concatenated with a block counter (encoded as a 32-bit
137 little-endian). If you have a separate nonce and block counter
138 you will need to concatenate it yourself before passing it. For
139 example if you have an initial block counter of 2 and a 96-bit
140 nonce the concatenated nonce would be
141 ``struct.pack("<i", 2) + nonce``.
142
143 .. doctest::
144
145 >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
146 >>> from cryptography.hazmat.backends import default_backend
147 >>> nonce = os.urandom(16)
148 >>> algorithm = algorithms.ChaCha20(key, nonce)
149 >>> cipher = Cipher(algorithm, mode=None, backend=default_backend())
150 >>> encryptor = cipher.encryptor()
151 >>> ct = encryptor.update(b"a secret message")
152 >>> decryptor = cipher.decryptor()
153 >>> decryptor.update(ct)
154 'a secret message'
155
David Reid1f3d7182013-10-22 16:55:18 -0700156.. class:: TripleDES(key)
Alex Gaynoraeb714c2013-09-09 18:06:14 -0700157
Alex Gaynor9316f4c2013-11-15 16:38:42 -0800158 Triple DES (Data Encryption Standard), sometimes referred to as 3DES, is a
159 block cipher standardized by NIST. Triple DES has known crypto-analytic
Alex Gaynor17adce62013-10-16 17:04:40 -0700160 flaws, however none of them currently enable a practical attack.
Alex Chanee9710f2016-09-04 17:40:06 +0100161 Nonetheless, Triple DES is not recommended for new applications because it
Alex Gaynorfbcc5642013-10-22 08:26:00 -0700162 is incredibly slow; old applications should consider moving away from it.
Alex Gaynoraeb714c2013-09-09 18:06:14 -0700163
Alex Stapleton092351d2014-03-09 17:44:43 +0000164 :param bytes key: The secret key. This must be kept secret. Either ``64``,
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800165 ``128``, or ``192`` :term:`bits` long. DES only uses ``56``, ``112``,
166 or ``168`` bits of the key as there is a parity byte in each component
167 of the key. Some writing refers to there being up to three separate
168 keys that are each ``56`` bits long, they can simply be concatenated
169 to produce the full key.
Alex Gaynoraeb714c2013-09-09 18:06:14 -0700170
Paul Kehrerbab0e1a2014-02-09 10:51:59 -0600171.. class:: CAST5(key)
172
Paul Kehrera5011ec2014-02-13 12:33:34 -0600173 .. versionadded:: 0.2
174
Paul Kehrerbab0e1a2014-02-09 10:51:59 -0600175 CAST5 (also known as CAST-128) is a block cipher approved for use in the
176 Canadian government by the `Communications Security Establishment`_. It is
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800177 a variable key length cipher and supports keys from 40-128 :term:`bits` in
178 length.
Paul Kehrerbab0e1a2014-02-09 10:51:59 -0600179
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800180 :param bytes key: The secret key, This must be kept secret. 40 to 128
181 :term:`bits` in length in increments of 8 bits.
Paul Kehrerbab0e1a2014-02-09 10:51:59 -0600182
Paul Kehrer7e914c92014-04-09 09:12:29 -0500183.. class:: SEED(key)
184
185 .. versionadded:: 0.4
186
Alex Stapleton19e97bd2014-05-02 21:57:59 +0100187 SEED is a block cipher developed by the Korea Information Security Agency
188 (KISA). It is defined in :rfc:`4269` and is used broadly throughout South
Paul Kehrer7e914c92014-04-09 09:12:29 -0500189 Korean industry, but rarely found elsewhere.
190
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800191 :param bytes key: The secret key. This must be kept secret. ``128``
192 :term:`bits` in length.
Paul Kehrer7e914c92014-04-09 09:12:29 -0500193
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000194Weak ciphers
Paul Kehrer3446d812013-10-31 17:15:03 -0500195------------
196
197.. warning::
198
199 These ciphers are considered weak for a variety of reasons. New
200 applications should avoid their use and existing applications should
201 strongly consider migrating away.
202
Paul Kehrer5df0abe2013-10-30 16:57:04 -0500203.. class:: Blowfish(key)
204
205 Blowfish is a block cipher developed by Bruce Schneier. It is known to be
206 susceptible to attacks when using weak keys. The author has recommended
Alex Stapleton092351d2014-03-09 17:44:43 +0000207 that users of Blowfish move to newer algorithms such as :class:`AES`.
Paul Kehrer5df0abe2013-10-30 16:57:04 -0500208
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800209 :param bytes key: The secret key. This must be kept secret. 32 to 448
210 :term:`bits` in length in increments of 8 bits.
Paul Kehrer5df0abe2013-10-30 16:57:04 -0500211
Paul Kehrer4da28c32013-11-07 07:50:17 +0800212.. class:: ARC4(key)
213
214 ARC4 (Alleged RC4) is a stream cipher with serious weaknesses in its
215 initial stream output. Its use is strongly discouraged. ARC4 does not use
216 mode constructions.
217
Alex Stapleton092351d2014-03-09 17:44:43 +0000218 :param bytes key: The secret key. This must be kept secret. Either ``40``,
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800219 ``56``, ``64``, ``80``, ``128``, ``192``, or ``256`` :term:`bits` in
220 length.
Paul Kehrer4da28c32013-11-07 07:50:17 +0800221
Paul Kehrer0994c562013-11-10 03:19:14 +0800222 .. doctest::
223
224 >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
Alex Gaynorf8796b12013-12-13 20:28:55 -0800225 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrer0994c562013-11-10 03:19:14 +0800226 >>> algorithm = algorithms.ARC4(key)
Alex Gaynorf56444d2013-12-13 15:19:22 -0800227 >>> cipher = Cipher(algorithm, mode=None, backend=default_backend())
Paul Kehrer0994c562013-11-10 03:19:14 +0800228 >>> encryptor = cipher.encryptor()
229 >>> ct = encryptor.update(b"a secret message")
230 >>> decryptor = cipher.decryptor()
231 >>> decryptor.update(ct)
232 'a secret message'
233
Paul Kehrere5dc1222014-02-20 16:19:32 -0600234.. class:: IDEA(key)
235
236 IDEA (`International Data Encryption Algorithm`_) is a block cipher created
237 in 1991. It is an optional component of the `OpenPGP`_ standard. This cipher
238 is susceptible to attacks when using weak keys. It is recommended that you
239 do not use this cipher for new applications.
240
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800241 :param bytes key: The secret key. This must be kept secret. ``128``
242 :term:`bits` in length.
Paul Kehrere5dc1222014-02-20 16:19:32 -0600243
David Reid30722b92013-11-07 13:03:39 -0800244
245.. _symmetric-encryption-modes:
246
Alex Gaynord96d1002013-08-08 07:37:26 -0700247Modes
248~~~~~
249
Paul Kehrer2129d502015-02-13 12:37:34 -0600250.. module:: cryptography.hazmat.primitives.ciphers.modes
David Reid1f3d7182013-10-22 16:55:18 -0700251
252.. class:: CBC(initialization_vector)
Alex Gaynor48ec9a32013-08-08 11:13:46 -0700253
Alex Stapleton092351d2014-03-09 17:44:43 +0000254 CBC (Cipher Block Chaining) is a mode of operation for block ciphers. It is
Alex Gaynor48ec9a32013-08-08 11:13:46 -0700255 considered cryptographically strong.
256
Paul Kehrerfe2e3c22014-01-07 20:55:20 -0600257 **Padding is required when using this mode.**
258
Alex Gaynor9b6fd8e2014-12-19 10:29:56 -0800259 :param bytes initialization_vector: Must be :doc:`random bytes
260 </random-numbers>`. They do not need to be kept secret and they can be
261 included in a transmitted message. Must be the same number of bytes as
262 the ``block_size`` of the cipher. Each time something is encrypted a
263 new ``initialization_vector`` should be generated. Do not reuse an
264 ``initialization_vector`` with a given ``key``, and particularly do not
265 use a constant ``initialization_vector``.
Alex Gaynor8ed651e2013-11-07 13:24:31 -0800266
267 A good construction looks like:
268
Alex Gaynor989061d2013-12-13 20:22:14 -0800269 .. doctest::
Alex Gaynor8ed651e2013-11-07 13:24:31 -0800270
271 >>> import os
Alex Gaynord83c5902013-12-13 20:43:54 -0800272 >>> from cryptography.hazmat.primitives.ciphers.modes import CBC
Alex Gaynor8ed651e2013-11-07 13:24:31 -0800273 >>> iv = os.urandom(16)
274 >>> mode = CBC(iv)
275
276 While the following is bad and will leak information:
277
Alex Gaynor989061d2013-12-13 20:22:14 -0800278 .. doctest::
Alex Gaynor8ed651e2013-11-07 13:24:31 -0800279
Alex Gaynord83c5902013-12-13 20:43:54 -0800280 >>> from cryptography.hazmat.primitives.ciphers.modes import CBC
Alex Gaynor8ed651e2013-11-07 13:24:31 -0800281 >>> iv = "a" * 16
282 >>> mode = CBC(iv)
Paul Kehrer13f108f2013-09-09 21:41:03 -0500283
Paul Kehrer45064282013-10-17 13:41:53 -0500284
David Reid1f3d7182013-10-22 16:55:18 -0700285.. class:: CTR(nonce)
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500286
Paul Kehrer45064282013-10-17 13:41:53 -0500287 .. warning::
288
289 Counter mode is not recommended for use with block ciphers that have a
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800290 block size of less than 128-:term:`bits`.
Paul Kehrer45064282013-10-17 13:41:53 -0500291
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500292 CTR (Counter) is a mode of operation for block ciphers. It is considered
Alex Gaynord1f02012013-11-01 14:12:35 -0700293 cryptographically strong. It transforms a block cipher into a stream
294 cipher.
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500295
Paul Kehrerfe2e3c22014-01-07 20:55:20 -0600296 **This mode does not require padding.**
297
Eeshan Garg94759002015-05-20 20:35:33 +0530298 :param bytes nonce: Should be unique, a :term:`nonce`. It is
Alex Gaynor9b6fd8e2014-12-19 10:29:56 -0800299 critical to never reuse a ``nonce`` with a given key. Any reuse of a
300 nonce with the same key compromises the security of every message
301 encrypted with that key. Must be the same number of bytes as the
302 ``block_size`` of the cipher with a given key. The nonce does not need
303 to be kept secret and may be included with the ciphertext.
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500304
David Reid1f3d7182013-10-22 16:55:18 -0700305.. class:: OFB(initialization_vector)
Paul Kehrer6f412a02013-09-10 21:30:50 -0500306
307 OFB (Output Feedback) is a mode of operation for block ciphers. It
308 transforms a block cipher into a stream cipher.
309
Paul Kehrerfe2e3c22014-01-07 20:55:20 -0600310 **This mode does not require padding.**
311
Alex Gaynor9b6fd8e2014-12-19 10:29:56 -0800312 :param bytes initialization_vector: Must be :doc:`random bytes
313 </random-numbers>`. They do not need to be kept secret and they can be
314 included in a transmitted message. Must be the same number of bytes as
315 the ``block_size`` of the cipher. Do not reuse an
316 ``initialization_vector`` with a given ``key``.
Paul Kehrer6f412a02013-09-10 21:30:50 -0500317
David Reid1f3d7182013-10-22 16:55:18 -0700318.. class:: CFB(initialization_vector)
Paul Kehrer4223df72013-09-11 09:48:04 -0500319
320 CFB (Cipher Feedback) is a mode of operation for block ciphers. It
321 transforms a block cipher into a stream cipher.
322
Paul Kehrerfe2e3c22014-01-07 20:55:20 -0600323 **This mode does not require padding.**
324
Alex Gaynor9b6fd8e2014-12-19 10:29:56 -0800325 :param bytes initialization_vector: Must be :doc:`random bytes
326 </random-numbers>`. They do not need to be kept secret and they can be
327 included in a transmitted message. Must be the same number of bytes as
328 the ``block_size`` of the cipher. Do not reuse an
329 ``initialization_vector`` with a given ``key``.
Paul Kehrer4223df72013-09-11 09:48:04 -0500330
Paul Kehrer2a947c42014-05-15 17:22:08 -0400331.. class:: CFB8(initialization_vector)
332
333 CFB (Cipher Feedback) is a mode of operation for block ciphers. It
334 transforms a block cipher into a stream cipher. The CFB8 variant uses an
335 8-bit shift register.
336
337 **This mode does not require padding.**
338
Alex Gaynor9b6fd8e2014-12-19 10:29:56 -0800339 :param bytes initialization_vector: Must be :doc:`random bytes
340 </random-numbers>`. They do not need to be kept secret and they can be
341 included in a transmitted message. Must be the same number of bytes as
342 the ``block_size`` of the cipher. Do not reuse an
343 ``initialization_vector`` with a given ``key``.
Paul Kehrer2a947c42014-05-15 17:22:08 -0400344
Alex Gaynorcc5224f2014-06-30 09:25:48 -0700345.. class:: GCM(initialization_vector, tag=None, min_tag_length=16)
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600346
Paul Kehrer5b828b12013-11-29 17:32:08 -0600347 .. danger::
Paul Kehrer26c8c6a2013-11-29 16:24:56 -0600348
Paul Kehrera2173582017-07-17 13:10:14 +0200349 If you are encrypting data that can fit into memory you should strongly
350 consider using
351 :class:`~cryptography.hazmat.primitives.ciphers.aead.AESGCM` instead
352 of this.
353
Alex Stapleton092351d2014-03-09 17:44:43 +0000354 When using this mode you **must** not use the decrypted data until
Philipp Gesang2e84daa2017-05-02 15:28:33 +0200355 the appropriate finalization method
356 (:meth:`~cryptography.hazmat.primitives.ciphers.CipherContext.finalize`
357 or
358 :meth:`~cryptography.hazmat.primitives.ciphers.AEADDecryptionContext.finalize_with_tag`)
Alex Stapleton092351d2014-03-09 17:44:43 +0000359 has been called. GCM provides **no** guarantees of ciphertext integrity
Alex Gaynord4f93832013-12-04 16:31:59 -0600360 until decryption is complete.
Paul Kehrer26c8c6a2013-11-29 16:24:56 -0600361
Paul Kehrer5578c662013-12-03 17:37:42 -0600362 GCM (Galois Counter Mode) is a mode of operation for block ciphers. An
363 AEAD (authenticated encryption with additional data) mode is a type of
Alex Stapleton092351d2014-03-09 17:44:43 +0000364 block cipher mode that simultaneously encrypts the message as well as
365 authenticating it. Additional unencrypted data may also be authenticated.
366 Additional means of verifying integrity such as
Ayrxfa4a6b22014-04-16 23:03:14 +0800367 :doc:`HMAC </hazmat/primitives/mac/hmac>` are not necessary.
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600368
Paul Kehrerfe2e3c22014-01-07 20:55:20 -0600369 **This mode does not require padding.**
370
Eeshan Garg94759002015-05-20 20:35:33 +0530371 :param bytes initialization_vector: Must be unique, a :term:`nonce`.
372 They do not need to be kept secret and they can be included in a
373 transmitted message. NIST `recommends a 96-bit IV length`_ for
374 performance critical situations but it can be up to 2\ :sup:`64` - 1
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800375 :term:`bits`. Do not reuse an ``initialization_vector`` with a given
376 ``key``.
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600377
Paul Kehrerca735042013-12-21 17:31:48 -0600378 .. note::
379
Alex Stapleton092351d2014-03-09 17:44:43 +0000380 Cryptography will generate a 128-bit tag when finalizing encryption.
381 You can shorten a tag by truncating it to the desired length but this
Paul Kehrerfc73e2d2013-12-21 18:41:38 -0600382 is **not recommended** as it lowers the security margins of the
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800383 authentication (`NIST SP-800-38D`_ recommends 96-:term:`bits` or
384 greater). Applications wishing to allow truncation must pass the
Alex Gaynor8f1b8e82014-06-29 20:43:29 -0700385 ``min_tag_length`` parameter.
386
387 .. versionchanged:: 0.5
388
389 The ``min_tag_length`` parameter was added in ``0.5``, previously
Alex Gaynorcc5224f2014-06-30 09:25:48 -0700390 truncation down to ``4`` bytes was always allowed.
Paul Kehrerca735042013-12-21 17:31:48 -0600391
Alex Gaynorfb843aa2014-02-25 11:37:36 -0800392 :param bytes tag: The tag bytes to verify during decryption. When
Philipp Gesang2e84daa2017-05-02 15:28:33 +0200393 encrypting this must be ``None``. When decrypting, it may be ``None``
394 if the tag is supplied on finalization using
395 :meth:`~cryptography.hazmat.primitives.ciphers.AEADDecryptionContext.finalize_with_tag`.
396 Otherwise, the tag is mandatory.
Paul Kehrer67abc862013-11-25 14:29:35 -0600397
Alex Gaynor8f1b8e82014-06-29 20:43:29 -0700398 :param bytes min_tag_length: The minimum length ``tag`` must be. By default
Alex Gaynorcc5224f2014-06-30 09:25:48 -0700399 this is ``16``, meaning tag truncation is not allowed. Allowing tag
400 truncation is strongly discouraged for most applications.
401
402 :raises ValueError: This is raised if ``len(tag) < min_tag_length``.
Alex Gaynor8f1b8e82014-06-29 20:43:29 -0700403
Philipp Gesang2e84daa2017-05-02 15:28:33 +0200404 :raises NotImplementedError: This is raised if the version of the OpenSSL
405 backend used is 1.0.1 or earlier.
406
Alex Gaynor09828cd2016-02-10 15:21:36 -0500407 An example of securely encrypting and decrypting data with ``AES`` in the
408 ``GCM`` mode looks like:
409
David Reidabb72d22014-01-07 16:06:18 -0800410 .. testcode::
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600411
David Reidabb72d22014-01-07 16:06:18 -0800412 import os
413
gdmnbt2a0b8342017-03-24 01:19:20 +0100414 from cryptography.hazmat.backends import default_backend
David Reidabb72d22014-01-07 16:06:18 -0800415 from cryptography.hazmat.primitives.ciphers import (
416 Cipher, algorithms, modes
417 )
418
David Reid78569d62014-01-07 15:42:17 -0800419 def encrypt(key, plaintext, associated_data):
David Reidabb72d22014-01-07 16:06:18 -0800420 # Generate a random 96-bit IV.
David Reid78569d62014-01-07 15:42:17 -0800421 iv = os.urandom(12)
David Reidabb72d22014-01-07 16:06:18 -0800422
Alex Gaynorebb1cb92014-06-10 09:36:39 -0700423 # Construct an AES-GCM Cipher object with the given key and a
Alex Stapleton092351d2014-03-09 17:44:43 +0000424 # randomly generated IV.
David Reidabb72d22014-01-07 16:06:18 -0800425 encryptor = Cipher(
David Reid78569d62014-01-07 15:42:17 -0800426 algorithms.AES(key),
427 modes.GCM(iv),
428 backend=default_backend()
David Reidabb72d22014-01-07 16:06:18 -0800429 ).encryptor()
David Reid78569d62014-01-07 15:42:17 -0800430
David Reidabb72d22014-01-07 16:06:18 -0800431 # associated_data will be authenticated but not encrypted,
432 # it must also be passed in on decryption.
David Reid78569d62014-01-07 15:42:17 -0800433 encryptor.authenticate_additional_data(associated_data)
David Reid78569d62014-01-07 15:42:17 -0800434
David Reidabb72d22014-01-07 16:06:18 -0800435 # Encrypt the plaintext and get the associated ciphertext.
Paul Kehreraf0b9f52014-01-07 19:21:49 -0600436 # GCM does not require padding.
437 ciphertext = encryptor.update(plaintext) + encryptor.finalize()
David Reidabb72d22014-01-07 16:06:18 -0800438
439 return (iv, ciphertext, encryptor.tag)
David Reid78569d62014-01-07 15:42:17 -0800440
441 def decrypt(key, associated_data, iv, ciphertext, tag):
David Reidabb72d22014-01-07 16:06:18 -0800442 # Construct a Cipher object, with the key, iv, and additionally the
443 # GCM tag used for authenticating the message.
444 decryptor = Cipher(
David Reid78569d62014-01-07 15:42:17 -0800445 algorithms.AES(key),
446 modes.GCM(iv, tag),
447 backend=default_backend()
David Reidabb72d22014-01-07 16:06:18 -0800448 ).decryptor()
David Reid78569d62014-01-07 15:42:17 -0800449
David Reidabb72d22014-01-07 16:06:18 -0800450 # We put associated_data back in or the tag will fail to verify
451 # when we finalize the decryptor.
David Reid78569d62014-01-07 15:42:17 -0800452 decryptor.authenticate_additional_data(associated_data)
453
Paul Kehreraf0b9f52014-01-07 19:21:49 -0600454 # Decryption gets us the authenticated plaintext.
455 # If the tag does not match an InvalidTag exception will be raised.
456 return decryptor.update(ciphertext) + decryptor.finalize()
David Reidabb72d22014-01-07 16:06:18 -0800457
458 iv, ciphertext, tag = encrypt(
David Reid78569d62014-01-07 15:42:17 -0800459 key,
David Reidabb72d22014-01-07 16:06:18 -0800460 b"a secret message!",
David Reid78569d62014-01-07 15:42:17 -0800461 b"authenticated but not encrypted payload"
462 )
463
David Reidabb72d22014-01-07 16:06:18 -0800464 print(decrypt(
465 key,
466 b"authenticated but not encrypted payload",
467 iv,
468 ciphertext,
469 tag
470 ))
David Reid78569d62014-01-07 15:42:17 -0800471
472 .. testoutput::
473
David Reidabb72d22014-01-07 16:06:18 -0800474 a secret message!
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600475
Paul Kehrera397d752017-10-02 10:03:20 +0800476.. class:: XTS(tweak)
477
478 .. versionadded:: 2.1
479
480 .. warning::
481
482 XTS mode is meant for disk encryption and should not be used in other
483 contexts. ``cryptography`` only supports XTS mode with
484 :class:`~cryptography.hazmat.primitives.ciphers.algorithms.AES`.
485
486 .. note::
487
488 AES XTS keys are double length. This means that to do AES-128
489 encryption in XTS mode you need a 256-bit key. Similarly, AES-256
490 requires passing a 512-bit key. AES 192 is not supported in XTS mode.
491
492 XTS (XEX-based tweaked-codebook mode with ciphertext stealing) is a mode
493 of operation for the AES block cipher that is used for `disk encryption`_.
494
495 **This mode does not require padding.**
496
497 :param bytes tweak: The tweak is a 16 byte value typically derived from
498 something like the disk sector number. A given ``(tweak, key)`` pair
499 should not be reused, although doing so is less catastrophic than
500 in CTR mode.
501
Paul Kehrer13f108f2013-09-09 21:41:03 -0500502
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000503Insecure modes
Paul Kehrer13f108f2013-09-09 21:41:03 -0500504--------------
505
Alex Gaynorcd413a32013-09-10 18:59:43 -0700506.. warning::
507
508 These modes are insecure. New applications should never make use of them,
509 and existing applications should strongly consider migrating away.
510
511
David Reid1f3d7182013-10-22 16:55:18 -0700512.. class:: ECB()
Paul Kehrer13f108f2013-09-09 21:41:03 -0500513
514 ECB (Electronic Code Book) is the simplest mode of operation for block
Alex Gaynorcd413a32013-09-10 18:59:43 -0700515 ciphers. Each block of data is encrypted in the same way. This means
516 identical plaintext blocks will always result in identical ciphertext
Alex Stapleton092351d2014-03-09 17:44:43 +0000517 blocks, which can leave `significant patterns in the output`_.
Alex Gaynorab5f0112013-11-08 10:34:00 -0800518
Paul Kehrerfe2e3c22014-01-07 20:55:20 -0600519 **Padding is required when using this mode.**
520
Paul Kehrerad6d1642014-01-07 19:10:12 -0600521Interfaces
Paul Kehrere3ff3642017-06-04 11:48:32 -1000522~~~~~~~~~~
Paul Kehrer513b7cb2015-02-12 17:31:24 -0600523
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -0600524.. currentmodule:: cryptography.hazmat.primitives.ciphers
Paul Kehrerad6d1642014-01-07 19:10:12 -0600525
526.. class:: CipherContext
527
528 When calling ``encryptor()`` or ``decryptor()`` on a ``Cipher`` object
Alex Gaynorb4818892014-02-06 10:58:50 -0800529 the result will conform to the ``CipherContext`` interface. You can then
530 call ``update(data)`` with data until you have fed everything into the
531 context. Once that is done call ``finalize()`` to finish the operation and
532 obtain the remainder of the data.
Paul Kehrerad6d1642014-01-07 19:10:12 -0600533
Alex Stapleton092351d2014-03-09 17:44:43 +0000534 Block ciphers require that the plaintext or ciphertext always be a multiple
535 of their block size. Because of that **padding** is sometimes required to
536 make a message the correct size. ``CipherContext`` will not automatically
537 apply any padding; you'll need to add your own. For block ciphers the
538 recommended padding is
Alex Gaynord99fc652014-06-25 10:24:03 -0700539 :class:`~cryptography.hazmat.primitives.padding.PKCS7`. If you are using a
Alex Stapleton092351d2014-03-09 17:44:43 +0000540 stream cipher mode (such as
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600541 :class:`~cryptography.hazmat.primitives.ciphers.modes.CTR`) you don't have
542 to worry about this.
Paul Kehrerad6d1642014-01-07 19:10:12 -0600543
544 .. method:: update(data)
545
546 :param bytes data: The data you wish to pass into the context.
547 :return bytes: Returns the data that was encrypted or decrypted.
548 :raises cryptography.exceptions.AlreadyFinalized: See :meth:`finalize`
549
550 When the ``Cipher`` was constructed in a mode that turns it into a
551 stream cipher (e.g.
Alex Gaynord99fc652014-06-25 10:24:03 -0700552 :class:`~cryptography.hazmat.primitives.ciphers.modes.CTR`), this will
Alex Stapleton092351d2014-03-09 17:44:43 +0000553 return bytes immediately, however in other modes it will return chunks
Paul Kehrerad6d1642014-01-07 19:10:12 -0600554 whose size is determined by the cipher's block size.
555
Paul Kehrer9b34ca92017-02-16 22:20:38 -0600556 .. method:: update_into(data, buf)
557
558 .. versionadded:: 1.8
559
560 .. warning::
561
562 This method allows you to avoid a memory copy by passing a writable
563 buffer and reading the resulting data. You are responsible for
564 correctly sizing the buffer and properly handling the data. This
565 method should only be used when extremely high performance is a
566 requirement and you will be making many small calls to
567 ``update_into``.
568
569 :param bytes data: The data you wish to pass into the context.
570 :param buf: A writable Python buffer that the data will be written
571 into. This buffer should be ``len(data) + n - 1`` bytes where ``n``
572 is the block size (in bytes) of the cipher and mode combination.
573 :return int: Number of bytes written.
574 :raises NotImplementedError: This is raised if the version of ``cffi``
575 used is too old (this can happen on older PyPy releases).
576 :raises ValueError: This is raised if the supplied buffer is too small.
577
578 .. doctest::
579
580 >>> import os
581 >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
582 >>> from cryptography.hazmat.backends import default_backend
583 >>> backend = default_backend()
584 >>> key = os.urandom(32)
585 >>> iv = os.urandom(16)
586 >>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend)
587 >>> encryptor = cipher.encryptor()
588 >>> # the buffer needs to be at least len(data) + n - 1 where n is cipher/mode block size in bytes
589 >>> buf = bytearray(31)
590 >>> len_encrypted = encryptor.update_into(b"a secret message", buf)
591 >>> # get the ciphertext from the buffer reading only the bytes written to it (len_encrypted)
592 >>> ct = bytes(buf[:len_encrypted]) + encryptor.finalize()
593 >>> decryptor = cipher.decryptor()
594 >>> len_decrypted = decryptor.update_into(ct, buf)
595 >>> # get the plaintext from the buffer reading only the bytes written (len_decrypted)
596 >>> bytes(buf[:len_decrypted]) + decryptor.finalize()
597 'a secret message'
598
Paul Kehrerad6d1642014-01-07 19:10:12 -0600599 .. method:: finalize()
600
601 :return bytes: Returns the remainder of the data.
602 :raises ValueError: This is raised when the data provided isn't
Alex Stapleton092351d2014-03-09 17:44:43 +0000603 a multiple of the algorithm's block size.
Paul Kehrerad6d1642014-01-07 19:10:12 -0600604
605 Once ``finalize`` is called this object can no longer be used and
Alex Stapleton092351d2014-03-09 17:44:43 +0000606 :meth:`update` and :meth:`finalize` will raise an
607 :class:`~cryptography.exceptions.AlreadyFinalized` exception.
Paul Kehrerad6d1642014-01-07 19:10:12 -0600608
609.. class:: AEADCipherContext
610
Alex Stapleton092351d2014-03-09 17:44:43 +0000611 When calling ``encryptor`` or ``decryptor`` on a ``Cipher`` object
Paul Kehrerad6d1642014-01-07 19:10:12 -0600612 with an AEAD mode (e.g.
Alex Gaynorb4818892014-02-06 10:58:50 -0800613 :class:`~cryptography.hazmat.primitives.ciphers.modes.GCM`) the result will
614 conform to the ``AEADCipherContext`` and ``CipherContext`` interfaces. If
Philipp Gesang2e84daa2017-05-02 15:28:33 +0200615 it is an encryption or decryption context it will additionally be an
616 ``AEADEncryptionContext`` or ``AEADDecryptionContext`` instance,
617 respectively. ``AEADCipherContext`` contains an additional method
618 :meth:`authenticate_additional_data` for adding additional authenticated
619 but unencrypted data (see note below). You should call this before calls to
620 ``update``. When you are done call ``finalize`` to finish the operation.
Paul Kehrerad6d1642014-01-07 19:10:12 -0600621
622 .. note::
623
624 In AEAD modes all data passed to ``update()`` will be both encrypted
625 and authenticated. Do not pass encrypted data to the
626 ``authenticate_additional_data()`` method. It is meant solely for
627 additional data you may want to authenticate but leave unencrypted.
628
629 .. method:: authenticate_additional_data(data)
630
631 :param bytes data: Any data you wish to authenticate but not encrypt.
632 :raises: :class:`~cryptography.exceptions.AlreadyFinalized`
633
634.. class:: AEADEncryptionContext
635
Alex Stapleton092351d2014-03-09 17:44:43 +0000636 When creating an encryption context using ``encryptor`` on a ``Cipher``
637 object with an AEAD mode such as
638 :class:`~cryptography.hazmat.primitives.ciphers.modes.GCM` an object
639 conforming to both the ``AEADEncryptionContext`` and ``AEADCipherContext``
640 interfaces will be returned. This interface provides one
641 additional attribute ``tag``. ``tag`` can only be obtained after
642 ``finalize`` has been called.
Paul Kehrerad6d1642014-01-07 19:10:12 -0600643
644 .. attribute:: tag
645
646 :return bytes: Returns the tag value as bytes.
647 :raises: :class:`~cryptography.exceptions.NotYetFinalized` if called
Alex Gaynorfb843aa2014-02-25 11:37:36 -0800648 before the context is finalized.
Paul Kehrerad6d1642014-01-07 19:10:12 -0600649
Philipp Gesang2e84daa2017-05-02 15:28:33 +0200650.. class:: AEADDecryptionContext
651
652 .. versionadded:: 1.9
653
654 When creating an encryption context using ``decryptor`` on a ``Cipher``
655 object with an AEAD mode such as
656 :class:`~cryptography.hazmat.primitives.ciphers.modes.GCM` an object
657 conforming to both the ``AEADDecryptionContext`` and ``AEADCipherContext``
658 interfaces will be returned. This interface provides one additional method
659 :meth:`finalize_with_tag` that allows passing the authentication tag for
660 validation after the ciphertext has been decrypted.
661
662 .. method:: finalize_with_tag(tag)
663
Paul Kehrer5fb10212017-05-02 12:04:53 -0500664 .. note::
665
666 This method is not supported when compiled against OpenSSL 1.0.1.
667
Philipp Gesang2e84daa2017-05-02 15:28:33 +0200668 :param bytes tag: The tag bytes to verify after decryption.
669 :return bytes: Returns the remainder of the data.
670 :raises ValueError: This is raised when the data provided isn't
671 a multiple of the algorithm's block size, if ``min_tag_length`` is
672 less than 4, or if ``len(tag) < min_tag_length``.
673 :raises NotImplementedError: This is raised if the version of the
674 OpenSSL backend used is 1.0.1 or earlier.
675
676 If the authentication tag was not already supplied to the constructor
677 of the :class:`~cryptography.hazmat.primitives.ciphers.modes.GCM` mode
678 object, this method must be used instead of
679 :meth:`~cryptography.hazmat.primitives.ciphers.CipherContext.finalize`.
680
Paul Kehrer513b7cb2015-02-12 17:31:24 -0600681.. class:: CipherAlgorithm
682
683 A named symmetric encryption algorithm.
684
685 .. attribute:: name
686
687 :type: str
688
689 The standard name for the mode, for example, "AES", "Camellia", or
690 "Blowfish".
691
692 .. attribute:: key_size
693
694 :type: int
695
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800696 The number of :term:`bits` in the key being used.
Paul Kehrer513b7cb2015-02-12 17:31:24 -0600697
698
699.. class:: BlockCipherAlgorithm
700
701 A block cipher algorithm.
702
703 .. attribute:: block_size
704
705 :type: int
706
Paul Kehrer1aac78c2017-10-11 19:49:57 +0800707 The number of :term:`bits` in a block.
Paul Kehrer513b7cb2015-02-12 17:31:24 -0600708
709Interfaces used by the symmetric cipher modes described in
710:ref:`Symmetric Encryption Modes <symmetric-encryption-modes>`.
711
712.. currentmodule:: cryptography.hazmat.primitives.ciphers.modes
713
714.. class:: Mode
715
716 A named cipher mode.
717
718 .. attribute:: name
719
720 :type: str
721
722 This should be the standard shorthand name for the mode, for example
723 Cipher-Block Chaining mode is "CBC".
724
725 The name may be used by a backend to influence the operation of a
726 cipher in conjunction with the algorithm's name.
727
728 .. method:: validate_for_algorithm(algorithm)
729
Alex Gaynor2c526052015-02-24 10:55:28 -0800730 :param cryptography.hazmat.primitives.ciphers.CipherAlgorithm algorithm:
Paul Kehrer513b7cb2015-02-12 17:31:24 -0600731
732 Checks that the combination of this mode with the provided algorithm
733 meets any necessary invariants. This should raise an exception if they
734 are not met.
735
736 For example, the
737 :class:`~cryptography.hazmat.primitives.ciphers.modes.CBC` mode uses
738 this method to check that the provided initialization vector's length
739 matches the block size of the algorithm.
740
741
742.. class:: ModeWithInitializationVector
743
744 A cipher mode with an initialization vector.
745
746 .. attribute:: initialization_vector
747
748 :type: bytes
749
750 Exact requirements of the initialization are described by the
751 documentation of individual modes.
752
753
754.. class:: ModeWithNonce
755
756 A cipher mode with a nonce.
757
758 .. attribute:: nonce
759
760 :type: bytes
761
762 Exact requirements of the nonce are described by the documentation of
763 individual modes.
764
765
Paul Kehrer4ab60592015-02-13 09:06:48 -0600766.. class:: ModeWithAuthenticationTag
767
768 A cipher mode with an authentication tag.
769
770 .. attribute:: tag
771
772 :type: bytes
773
774 Exact requirements of the tag are described by the documentation of
775 individual modes.
776
Paul Kehrera397d752017-10-02 10:03:20 +0800777
778.. class:: ModeWithTweak
779
780 .. versionadded:: 2.1
781
782 A cipher mode with a tweak.
783
784 .. attribute:: tweak
785
786 :type: bytes
787
788 Exact requirements of the tweak are described by the documentation of
789 individual modes.
790
Paul Kehrera8b1c6e2017-06-04 11:48:24 -1000791Exceptions
792~~~~~~~~~~
793
794.. currentmodule:: cryptography.exceptions
795
796
797.. class:: InvalidTag
798
799 This is raised if an authenticated encryption tag fails to verify during
800 decryption.
801
Paul Kehrer4ab60592015-02-13 09:06:48 -0600802
Alex Gaynorab5f0112013-11-08 10:34:00 -0800803
804.. _`described by Colin Percival`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html
Alex Gaynor20721c92017-09-20 04:39:45 -0400805.. _`recommends a 96-bit IV length`: https://csrc.nist.gov/publications/detail/sp/800-38d/final
Alex Gaynor53e45052017-09-20 09:57:47 -0400806.. _`NIST SP-800-38D`: https://csrc.nist.gov/publications/detail/sp/800-38d/final
Alex Gaynor111aff22015-02-17 14:47:49 -0800807.. _`Communications Security Establishment`: https://www.cse-cst.gc.ca
Alex Gaynor62012302015-02-17 10:49:22 -0800808.. _`encrypt`: https://ssd.eff.org/en/module/what-encryption
Alex Gaynor6422d832016-03-06 21:40:57 -0500809.. _`CRYPTREC`: https://www.cryptrec.go.jp/english/
Alex Gaynor543031a2015-02-16 20:27:35 -0800810.. _`significant patterns in the output`: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_.28ECB.29
Paul Kehrere5dc1222014-02-20 16:19:32 -0600811.. _`International Data Encryption Algorithm`: https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
Alex Gaynore51236d2016-11-06 10:13:35 -0500812.. _`OpenPGP`: http://openpgp.org
Paul Kehrera397d752017-10-02 10:03:20 +0800813.. _`disk encryption`: https://en.wikipedia.org/wiki/Disk_encryption_theory#XTS