blob: e2cce195ff2dc33ea5cecf26e1cba8ed664a3a0f [file] [log] [blame]
Alex Gaynoraf82d5e2013-10-29 17:07:24 -07001.. hazmat::
Donald Stufftd8f01182013-10-27 16:59:56 -04002
3
Donald Stuffte51fb932013-10-27 17:26:17 -04004Symmetric Encryption
5====================
6
Paul Kehrer051099e2013-11-06 15:53:40 +08007.. currentmodule:: cryptography.hazmat.primitives.ciphers
David Reid1f3d7182013-10-22 16:55:18 -07008
Donald Stufft173de982013-08-12 07:34:39 -04009.. testsetup::
10
11 import binascii
12 key = binascii.unhexlify(b"0" * 32)
13 iv = binascii.unhexlify(b"0" * 32)
14
David Reidef0fcf22013-11-06 11:12:45 -080015 from cryptography.hazmat.bindings import default_backend
16 backend = default_backend()
17
Donald Stufft173de982013-08-12 07:34:39 -040018
Alex Gaynorf6c47e92013-08-08 07:16:01 -070019Symmetric encryption is a way to encrypt (hide the plaintext value) material
Alex Gaynorb317c7a2013-11-15 16:45:52 -080020where the sender and receiver both use the same key. Note that symmetric
Alex Gaynorab5f0112013-11-08 10:34:00 -080021encryption is **not** sufficient for most applications, because it only
22provides secrecy (an attacker can't see the message) but not authenticity (an
23attacker can create bogus messages and force the application to decrypt them).
Alex Gaynor9316f4c2013-11-15 16:38:42 -080024For this reason it is *strongly* recommended to combine encryption with a
Alex Gaynorab5f0112013-11-08 10:34:00 -080025message authentication code, such as :doc:`HMAC </hazmat/primitives/hmac>`, in
26an "encrypt-then-MAC" formulation as `described by Colin Percival`_.
Alex Gaynorf6c47e92013-08-08 07:16:01 -070027
David Reidef0fcf22013-11-06 11:12:45 -080028.. class:: Cipher(algorithm, mode, backend)
Alex Gaynorf6c47e92013-08-08 07:16:01 -070029
Alex Gaynorab5f0112013-11-08 10:34:00 -080030 Cipher objects combine an algorithm (such as
31 :class:`~cryptography.hazmat.primitives.ciphers.algorithms.AES`) with a
32 mode (such as
33 :class:`~cryptography.hazmat.primitives.ciphers.modes.CBC` or
34 :class:`~cryptography.hazmat.primitives.ciphers.modes.CTR`). A simple
35 example of encrypting (and then decrypting) content with AES is:
Alex Gaynorf6c47e92013-08-08 07:16:01 -070036
Donald Stufft173de982013-08-12 07:34:39 -040037 .. doctest::
Alex Gaynorf6c47e92013-08-08 07:16:01 -070038
Paul Kehrer051099e2013-11-06 15:53:40 +080039 >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
David Reid63fa19a2013-11-20 10:49:13 -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
48 :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm`
49 provider such as those described
50 :ref:`below <symmetric-encryption-algorithms>`.
51 :param mode: A :class:`~cryptography.hazmat.primitives.interfaces.Mode`
52 provider such as those described
53 :ref:`below <symmetric-encryption-modes>`.
54 :param backend: A
55 :class:`~cryptography.hazmat.bindings.interfaces.CipherBackend`
56 provider.
Alex Gaynor0ca7fdb2013-08-08 07:35:26 -070057
Paul Kehrer5399fd02013-10-21 23:48:25 -050058 .. method:: encryptor()
Alex Gaynor09515f02013-08-08 15:26:55 -070059
David Reid63ba6652013-10-22 14:09:19 -070060 :return: An encrypting
Donald Stufftf04317a2013-10-27 16:44:30 -040061 :class:`~cryptography.hazmat.primitives.interfaces.CipherContext`
David Reid63ba6652013-10-22 14:09:19 -070062 provider.
Alex Gaynore62aa402013-08-08 15:23:11 -070063
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070064 If the backend doesn't support the requested combination of ``cipher``
Alex Gaynor3949f112013-11-02 16:57:10 -070065 and ``mode`` an :class:`cryptography.exceptions.UnsupportedAlgorithm`
66 will be raised.
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070067
Paul Kehrer5399fd02013-10-21 23:48:25 -050068 .. method:: decryptor()
69
David Reid63ba6652013-10-22 14:09:19 -070070 :return: A decrypting
Donald Stufftf04317a2013-10-27 16:44:30 -040071 :class:`~cryptography.hazmat.primitives.interfaces.CipherContext`
David Reid63ba6652013-10-22 14:09:19 -070072 provider.
Paul Kehrer5399fd02013-10-21 23:48:25 -050073
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070074 If the backend doesn't support the requested combination of ``cipher``
Alex Gaynor3949f112013-11-02 16:57:10 -070075 and ``mode`` an :class:`cryptography.exceptions.UnsupportedAlgorithm`
76 will be raised.
Alex Gaynorf1a3fc02013-11-02 14:03:34 -070077
78
Donald Stufftf04317a2013-10-27 16:44:30 -040079.. currentmodule:: cryptography.hazmat.primitives.interfaces
David Reid1f3d7182013-10-22 16:55:18 -070080
Alex Gaynorb2d5efd2013-10-29 11:15:30 -070081.. class:: CipherContext
Paul Kehrer5399fd02013-10-21 23:48:25 -050082
Paul Kehrer051099e2013-11-06 15:53:40 +080083 When calling ``encryptor()`` or ``decryptor()`` on a ``Cipher`` object
Alex Gaynorb2d5efd2013-10-29 11:15:30 -070084 you will receive a return object conforming to the ``CipherContext``
85 interface. You can then call ``update(data)`` with data until you have fed
86 everything into the context. Once that is done call ``finalize()`` to
87 finish the operation and obtain the remainder of the data.
Paul Kehrer5399fd02013-10-21 23:48:25 -050088
Alex Gaynor797dd832013-11-22 13:08:58 -080089 Block ciphers require that plaintext or ciphertext always be a multiple of
90 their block size, because of that **padding** is often required to make a
91 message the correct size. ``CipherContext`` will not automatically apply
Alex Gaynor1a278a82013-11-27 13:40:45 -060092 any padding; you'll need to add your own. For block ciphers the recommended
Alex Gaynor797dd832013-11-22 13:08:58 -080093 padding is :class:`cryptography.hazmat.primitives.padding.PKCS7`. If you
94 are using a stream cipher mode (such as
95 :class:`cryptography.hazmat.primitives.modes.CTR`) you don't have to worry
96 about this.
97
Paul Kehrer5399fd02013-10-21 23:48:25 -050098 .. method:: update(data)
99
Alex Gaynorb2d5efd2013-10-29 11:15:30 -0700100 :param bytes data: The data you wish to pass into the context.
Paul Kehrer5399fd02013-10-21 23:48:25 -0500101 :return bytes: Returns the data that was encrypted or decrypted.
Alex Gaynor34511c62013-11-13 13:30:30 -0800102 :raises cryptography.exceptions.AlreadyFinalized: See :meth:`finalize`
Alex Gaynore62aa402013-08-08 15:23:11 -0700103
Paul Kehrer051099e2013-11-06 15:53:40 +0800104 When the ``Cipher`` was constructed in a mode that turns it into a
Alex Gaynorfc09a7c2013-11-01 14:43:02 -0700105 stream cipher (e.g.
Paul Kehrer051099e2013-11-06 15:53:40 +0800106 :class:`cryptography.hazmat.primitives.ciphers.modes.CTR`), this will
Alex Gaynorbf2de742013-11-01 14:48:19 -0700107 return bytes immediately, however in other modes it will return chunks,
108 whose size is determined by the cipher's block size.
Alex Gaynord1f02012013-11-01 14:12:35 -0700109
Alex Gaynore62aa402013-08-08 15:23:11 -0700110 .. method:: finalize()
111
Paul Kehrer5399fd02013-10-21 23:48:25 -0500112 :return bytes: Returns the remainder of the data.
Alex Gaynorbae899a2013-11-22 16:54:55 -0800113 :raises ValueError: This is raised when the data provided isn't
114 correctly padded to be a multiple of the
115 algorithm's block size.
Alex Gaynord96d1002013-08-08 07:37:26 -0700116
Alex Gaynor34511c62013-11-13 13:30:30 -0800117 Once ``finalize`` is called this object can no longer be used and
Alex Gaynor9b70ba32013-11-13 13:49:43 -0800118 :meth:`update` and :meth:`finalize` will raise
Alex Gaynor34511c62013-11-13 13:30:30 -0800119 :class:`~cryptography.exceptions.AlreadyFinalized`.
120
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600121.. class:: AEADCipherContext
122
123 When calling ``encryptor()`` or ``decryptor()`` on a ``Cipher`` object
124 with an AEAD mode you will receive a return object conforming to the
Paul Kehrer5b828b12013-11-29 17:32:08 -0600125 ``AEADCipherContext`` interface (in addition to the ``CipherContext``
Paul Kehrercd28a7c2013-12-03 18:17:57 -0600126 interface). If it is an encryption context it will additionally be an
127 ``AEADEncryptionContext`` interface. ``AEADCipherContext`` contains an
128 additional method ``authenticate_additional_data`` for adding additional
129 authenticated but unencrypted data. You should call this before calls to
130 ``update``. When you are done call ``finalize()`` to finish the operation.
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600131
Paul Kehrerbc31fb22013-11-24 11:03:53 -0600132 .. method:: authenticate_additional_data(data)
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600133
134 :param bytes data: The data you wish to authenticate but not encrypt.
135 :raises: :class:`~cryptography.exceptions.AlreadyFinalized`
136
Paul Kehrer5b828b12013-11-29 17:32:08 -0600137.. class:: AEADEncryptionContext
138
139 When creating an encryption context using ``encryptor()`` on a ``Cipher``
140 object with an AEAD mode you will receive a return object conforming to the
141 ``AEADEncryptionContext`` interface (as well as ``AEADCipherContext``).
142 This interface provides one additional attribute ``tag``. ``tag`` can only
143 be obtained after ``finalize()``.
144
Paul Kehrer65c4e0a2013-11-21 11:20:56 -0600145 .. attribute:: tag
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600146
147 :return bytes: Returns the tag value as bytes.
Paul Kehrer6331daa2013-11-22 13:42:02 -0600148 :raises: :class:`~cryptography.exceptions.NotYetFinalized` if called
149 before the context is finalized.
Paul Kehrer5b828b12013-11-29 17:32:08 -0600150
David Reid663295d2013-11-20 13:55:08 -0800151.. _symmetric-encryption-algorithms:
152
Paul Kehrer051099e2013-11-06 15:53:40 +0800153Algorithms
154~~~~~~~~~~
Alex Gaynord96d1002013-08-08 07:37:26 -0700155
Paul Kehrer051099e2013-11-06 15:53:40 +0800156.. currentmodule:: cryptography.hazmat.primitives.ciphers.algorithms
David Reid1f3d7182013-10-22 16:55:18 -0700157
158.. class:: AES(key)
Alex Gaynor5ba2dfa2013-08-08 11:04:44 -0700159
Alex Gaynor1e3f81f2013-08-08 11:31:43 -0700160 AES (Advanced Encryption Standard) is a block cipher standardized by NIST.
Alex Gaynor5ba2dfa2013-08-08 11:04:44 -0700161 AES is both fast, and cryptographically strong. It is a good default
162 choice for encryption.
163
164 :param bytes key: The secret key, either ``128``, ``192``, or ``256`` bits.
Alex Gaynor48ec9a32013-08-08 11:13:46 -0700165 This must be kept secret.
Alex Gaynor5ba2dfa2013-08-08 11:04:44 -0700166
David Reid1f3d7182013-10-22 16:55:18 -0700167.. class:: Camellia(key)
Paul Kehrerdff22d42013-09-27 13:43:06 -0500168
169 Camellia is a block cipher approved for use by CRYPTREC and ISO/IEC.
170 It is considered to have comparable security and performance to AES, but
171 is not as widely studied or deployed.
172
173 :param bytes key: The secret key, either ``128``, ``192``, or ``256`` bits.
174 This must be kept secret.
175
Alex Gaynord96d1002013-08-08 07:37:26 -0700176
David Reid1f3d7182013-10-22 16:55:18 -0700177.. class:: TripleDES(key)
Alex Gaynoraeb714c2013-09-09 18:06:14 -0700178
Alex Gaynor9316f4c2013-11-15 16:38:42 -0800179 Triple DES (Data Encryption Standard), sometimes referred to as 3DES, is a
180 block cipher standardized by NIST. Triple DES has known crypto-analytic
Alex Gaynor17adce62013-10-16 17:04:40 -0700181 flaws, however none of them currently enable a practical attack.
Alex Gaynor9316f4c2013-11-15 16:38:42 -0800182 Nonetheless, Triples DES is not recommended for new applications because it
Alex Gaynorfbcc5642013-10-22 08:26:00 -0700183 is incredibly slow; old applications should consider moving away from it.
Alex Gaynoraeb714c2013-09-09 18:06:14 -0700184
185 :param bytes key: The secret key, either ``64``, ``128``, or ``192`` bits
186 (note that DES functionally uses ``56``, ``112``, or
187 ``168`` bits of the key, there is a parity byte in each
188 component of the key), in some materials these are
189 referred to as being up to three separate keys (each
190 ``56`` bits long), they can simply be concatenated to
191 produce the full key. This must be kept secret.
192
Paul Kehrer6022d452013-10-30 17:03:54 -0500193.. class:: CAST5(key)
194
195 CAST5 (also known as CAST-128) is a block cipher approved for use in the
196 Canadian government by their Communications Security Establishment. It is a
197 variable key length cipher and supports keys from 40-128 bits in length.
198
199 :param bytes key: The secret key, 40-128 bits in length (in increments of
200 8). This must be kept secret.
201
Paul Kehrer3446d812013-10-31 17:15:03 -0500202Weak Ciphers
203------------
204
205.. warning::
206
207 These ciphers are considered weak for a variety of reasons. New
208 applications should avoid their use and existing applications should
209 strongly consider migrating away.
210
Paul Kehrer5df0abe2013-10-30 16:57:04 -0500211.. class:: Blowfish(key)
212
213 Blowfish is a block cipher developed by Bruce Schneier. It is known to be
214 susceptible to attacks when using weak keys. The author has recommended
Alex Gaynorab5f0112013-11-08 10:34:00 -0800215 that users of Blowfish move to newer algorithms, such as :class:`AES`.
Paul Kehrer5df0abe2013-10-30 16:57:04 -0500216
217 :param bytes key: The secret key, 32-448 bits in length (in increments of
218 8). This must be kept secret.
219
Paul Kehrer4da28c32013-11-07 07:50:17 +0800220.. class:: ARC4(key)
221
222 ARC4 (Alleged RC4) is a stream cipher with serious weaknesses in its
223 initial stream output. Its use is strongly discouraged. ARC4 does not use
224 mode constructions.
225
226 :param bytes key: The secret key, ``40``, ``56``, ``64``, ``80``, ``128``,
227 ``192``, or ``256`` bits in length. This must be kept
228 secret.
229
Paul Kehrer0994c562013-11-10 03:19:14 +0800230 .. doctest::
231
232 >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
233 >>> algorithm = algorithms.ARC4(key)
David Reid63fa19a2013-11-20 10:49:13 -0800234 >>> cipher = Cipher(algorithm, mode=None, backend=backend)
Paul Kehrer0994c562013-11-10 03:19:14 +0800235 >>> encryptor = cipher.encryptor()
236 >>> ct = encryptor.update(b"a secret message")
237 >>> decryptor = cipher.decryptor()
238 >>> decryptor.update(ct)
239 'a secret message'
240
David Reid30722b92013-11-07 13:03:39 -0800241
242.. _symmetric-encryption-modes:
243
Alex Gaynord96d1002013-08-08 07:37:26 -0700244Modes
245~~~~~
246
Paul Kehrer051099e2013-11-06 15:53:40 +0800247.. currentmodule:: cryptography.hazmat.primitives.ciphers.modes
David Reid1f3d7182013-10-22 16:55:18 -0700248
249.. class:: CBC(initialization_vector)
Alex Gaynor48ec9a32013-08-08 11:13:46 -0700250
251 CBC (Cipher block chaining) is a mode of operation for block ciphers. It is
252 considered cryptographically strong.
253
254 :param bytes initialization_vector: Must be random bytes. They do not need
255 to be kept secret (they can be included
Alex Gaynor2dc2b862013-08-08 11:58:04 -0700256 in a transmitted message). Must be the
257 same number of bytes as the
Alex Gaynor8ed651e2013-11-07 13:24:31 -0800258 ``block_size`` of the cipher. Each time
Alex Gaynor9de452d2013-11-07 13:28:23 -0800259 something is encrypted a new
Alex Gaynor8ed651e2013-11-07 13:24:31 -0800260 ``initialization_vector`` should be
261 generated. Do not reuse an
262 ``initialization_vector`` with
263 a given ``key``, and particularly do
264 not use a constant
265 ``initialization_vector``.
266
267 A good construction looks like:
268
269 .. code-block:: pycon
270
271 >>> import os
272 >>> iv = os.urandom(16)
273 >>> mode = CBC(iv)
274
275 While the following is bad and will leak information:
276
277 .. code-block:: pycon
278
279 >>> iv = "a" * 16
280 >>> mode = CBC(iv)
Paul Kehrer13f108f2013-09-09 21:41:03 -0500281
Paul Kehrer45064282013-10-17 13:41:53 -0500282
David Reid1f3d7182013-10-22 16:55:18 -0700283.. class:: CTR(nonce)
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500284
Paul Kehrer45064282013-10-17 13:41:53 -0500285 .. warning::
286
287 Counter mode is not recommended for use with block ciphers that have a
288 block size of less than 128-bits.
289
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500290 CTR (Counter) is a mode of operation for block ciphers. It is considered
Alex Gaynord1f02012013-11-01 14:12:35 -0700291 cryptographically strong. It transforms a block cipher into a stream
292 cipher.
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500293
Paul Kehrer89b3dd32013-10-17 14:02:45 -0500294 :param bytes nonce: Should be random bytes. It is critical to never reuse a
295 ``nonce`` with a given key. Any reuse of a nonce
296 with the same key compromises the security of every
297 message encrypted with that key. Must be the same
298 number of bytes as the ``block_size`` of the cipher
299 with a given key. The nonce does not need to be kept
300 secret and may be included alongside the ciphertext.
Paul Kehrerd0ec60e2013-10-16 08:46:50 -0500301
David Reid1f3d7182013-10-22 16:55:18 -0700302.. class:: OFB(initialization_vector)
Paul Kehrer6f412a02013-09-10 21:30:50 -0500303
304 OFB (Output Feedback) is a mode of operation for block ciphers. It
305 transforms a block cipher into a stream cipher.
306
David Reidf1a39bd2013-09-11 16:28:42 -0700307 :param bytes initialization_vector: Must be random bytes. They do not need
308 to be kept secret (they can be included
309 in a transmitted message). Must be the
310 same number of bytes as the
311 ``block_size`` of the cipher. Do not
312 reuse an ``initialization_vector`` with
313 a given ``key``.
Paul Kehrer6f412a02013-09-10 21:30:50 -0500314
David Reid1f3d7182013-10-22 16:55:18 -0700315.. class:: CFB(initialization_vector)
Paul Kehrer4223df72013-09-11 09:48:04 -0500316
317 CFB (Cipher Feedback) is a mode of operation for block ciphers. It
318 transforms a block cipher into a stream cipher.
319
320 :param bytes initialization_vector: Must be random bytes. They do not need
321 to be kept secret (they can be included
322 in a transmitted message). Must be the
323 same number of bytes as the
324 ``block_size`` of the cipher. Do not
325 reuse an ``initialization_vector`` with
326 a given ``key``.
327
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600328.. class:: GCM(initialization_vector, tag=None)
329
Paul Kehrer5b828b12013-11-29 17:32:08 -0600330 .. danger::
Paul Kehrer26c8c6a2013-11-29 16:24:56 -0600331
Alex Gaynord4f93832013-12-04 16:31:59 -0600332 When using this mode you MUST not use the decrypted data until
Alex Gaynor0d23e942013-12-04 17:28:24 -0600333 :meth:`~cryptography.hazmat.primitives.interfaces.CipherContext.finalize`
Alex Gaynord4f93832013-12-04 16:31:59 -0600334 has been called. GCM provides NO guarantees of ciphertext integrity
335 until decryption is complete.
Paul Kehrer26c8c6a2013-11-29 16:24:56 -0600336
Paul Kehrer5578c662013-12-03 17:37:42 -0600337 GCM (Galois Counter Mode) is a mode of operation for block ciphers. An
338 AEAD (authenticated encryption with additional data) mode is a type of
339 block cipher mode that encrypts the message as well as authenticating it
340 (and optionally additional data that is not encrypted) simultaneously.
341 Additional means of verifying integrity (like
Paul Kehrer2631c2b2013-11-24 10:20:50 -0600342 :doc:`HMAC </hazmat/primitives/hmac>`) are not necessary.
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600343
344 :param bytes initialization_vector: Must be random bytes. They do not need
345 to be kept secret (they can be included
Paul Kehrer67284372013-12-03 18:58:14 -0600346 in a transmitted message). NIST
347 `recommends 96-bit IV length`_ for
348 performance critical situations, but it
349 can be up to 2\ :sup:`64` - 1 bits.
350 Do not reuse an ``initialization_vector``
351 with a given ``key``.
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600352
Paul Kehrer67abc862013-11-25 14:29:35 -0600353 :param bytes tag: The tag bytes to verify during decryption. Must be provided
354 for decryption, but is ignored when encrypting.
355
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600356 .. doctest::
357
358 >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
Paul Kehrere0b5bb12013-11-29 16:35:04 -0600359 >>> cipher = Cipher(algorithms.AES(key), modes.GCM(iv), backend)
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600360 >>> encryptor = cipher.encryptor()
Paul Kehrerbc31fb22013-11-24 11:03:53 -0600361 >>> encryptor.authenticate_additional_data(b"authenticated but not encrypted payload")
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600362 >>> ct = encryptor.update(b"a secret message") + encryptor.finalize()
363 >>> tag = encryptor.tag
Paul Kehrere0b5bb12013-11-29 16:35:04 -0600364 >>> cipher = Cipher(algorithms.AES(key), modes.GCM(iv, tag), backend)
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600365 >>> decryptor = cipher.decryptor()
Paul Kehrerbc31fb22013-11-24 11:03:53 -0600366 >>> decryptor.authenticate_additional_data(b"authenticated but not encrypted payload")
Paul Kehrer22e80cb2013-11-20 21:27:00 -0600367 >>> decryptor.update(ct) + decryptor.finalize()
368 'a secret message'
369
Paul Kehrer13f108f2013-09-09 21:41:03 -0500370
371Insecure Modes
372--------------
373
Alex Gaynorcd413a32013-09-10 18:59:43 -0700374.. warning::
375
376 These modes are insecure. New applications should never make use of them,
377 and existing applications should strongly consider migrating away.
378
379
David Reid1f3d7182013-10-22 16:55:18 -0700380.. class:: ECB()
Paul Kehrer13f108f2013-09-09 21:41:03 -0500381
382 ECB (Electronic Code Book) is the simplest mode of operation for block
Alex Gaynorcd413a32013-09-10 18:59:43 -0700383 ciphers. Each block of data is encrypted in the same way. This means
384 identical plaintext blocks will always result in identical ciphertext
385 blocks, and thus result in information leakage
Alex Gaynorab5f0112013-11-08 10:34:00 -0800386
387
388.. _`described by Colin Percival`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html
Paul Kehrer67284372013-12-03 18:58:14 -0600389.. _`recommends 96-bit IV length`: http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf