-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add decrepit namespace and put SEED, IDEA, Blowfish, and CAST5 in it (#…
- Loading branch information
1 parent
ea5a5b4
commit 1729ede
Showing
19 changed files
with
630 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
.. hazmat:: | ||
|
||
|
||
Decrepit Symmetric algorithms | ||
============================= | ||
|
||
.. module:: cryptography.hazmat.decrepit.ciphers | ||
|
||
This module contains decrepit symmetric encryption algorithms. These | ||
are algorithms that should not be used unless necessary for backwards | ||
compatibility or interoperability with legacy systems. Their use is | ||
**strongly discouraged**. | ||
|
||
These algorithms require you to use a :class:`~cryptography.hazmat.primitives.ciphers.Cipher` | ||
object along with the appropriate :mod:`~cryptography.hazmat.primitives.ciphers.modes`. | ||
|
||
.. class:: CAST5(key) | ||
|
||
.. versionadded:: 43.0.0 | ||
|
||
CAST5 (also known as CAST-128) is a block cipher approved for use in the | ||
Canadian government by the `Communications Security Establishment`_. It is | ||
a variable key length cipher and supports keys from 40-128 :term:`bits` in | ||
length. | ||
|
||
:param key: The secret key, This must be kept secret. 40 to 128 | ||
:term:`bits` in length in increments of 8 bits. | ||
:type key: :term:`bytes-like` | ||
|
||
.. doctest:: | ||
|
||
>>> import os | ||
>>> from cryptography.hazmat.decrepit.ciphers.algorithms import CAST5 | ||
>>> from cryptography.hazmat.primitives.ciphers import Cipher, modes | ||
>>> key = os.urandom(16) | ||
>>> iv = os.urandom(8) | ||
>>> algorithm = CAST5(key) | ||
>>> cipher = Cipher(algorithm, modes.CBC(iv)) | ||
>>> encryptor = cipher.encryptor() | ||
>>> ct = encryptor.update(b"a secret message") | ||
>>> decryptor = cipher.decryptor() | ||
>>> decryptor.update(ct) | ||
b'a secret message' | ||
|
||
.. class:: SEED(key) | ||
|
||
.. versionadded:: 43.0.0 | ||
|
||
SEED is a block cipher developed by the Korea Information Security Agency | ||
(KISA). It is defined in :rfc:`4269` and is used broadly throughout South | ||
Korean industry, but rarely found elsewhere. | ||
|
||
:param key: The secret key. This must be kept secret. ``128`` | ||
:term:`bits` in length. | ||
:type key: :term:`bytes-like` | ||
|
||
|
||
.. class:: Blowfish(key) | ||
|
||
.. versionadded:: 43.0.0 | ||
|
||
Blowfish is a block cipher developed by Bruce Schneier. It is known to be | ||
susceptible to attacks when using weak keys. The author has recommended | ||
that users of Blowfish move to newer algorithms. | ||
|
||
:param key: The secret key. This must be kept secret. 32 to 448 | ||
:term:`bits` in length in increments of 8 bits. | ||
:type key: :term:`bytes-like` | ||
|
||
.. class:: IDEA(key) | ||
|
||
.. versionadded:: 43.0.0 | ||
|
||
IDEA (`International Data Encryption Algorithm`_) is a block cipher created | ||
in 1991. It is an optional component of the `OpenPGP`_ standard. This cipher | ||
is susceptible to attacks when using weak keys. It is recommended that you | ||
do not use this cipher for new applications. | ||
|
||
:param key: The secret key. This must be kept secret. ``128`` | ||
:term:`bits` in length. | ||
:type key: :term:`bytes-like` | ||
|
||
|
||
|
||
.. _`Communications Security Establishment`: https://www.cse-cst.gc.ca | ||
.. _`International Data Encryption Algorithm`: https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm | ||
.. _`OpenPGP`: https://www.openpgp.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.. hazmat:: | ||
|
||
Decrepit cryptography | ||
===================== | ||
|
||
This module holds old, deprecated, and/or insecure cryptographic | ||
algorithms that may be needed in exceptional cases for backwards | ||
compatibility or interoperability reasons. Unless necessary | ||
their use is **strongly discouraged**. | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
ciphers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This file is dual licensed under the terms of the Apache License, Version | ||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
# for complete details. | ||
|
||
from __future__ import annotations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This file is dual licensed under the terms of the Apache License, Version | ||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
# for complete details. | ||
|
||
from __future__ import annotations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# This file is dual licensed under the terms of the Apache License, Version | ||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
# for complete details. | ||
|
||
from __future__ import annotations | ||
|
||
from cryptography.hazmat.primitives._cipheralgorithm import ( | ||
BlockCipherAlgorithm, | ||
_verify_key_size, | ||
) | ||
|
||
|
||
class Blowfish(BlockCipherAlgorithm): | ||
name = "Blowfish" | ||
block_size = 64 | ||
key_sizes = frozenset(range(32, 449, 8)) | ||
|
||
def __init__(self, key: bytes): | ||
self.key = _verify_key_size(self, key) | ||
|
||
@property | ||
def key_size(self) -> int: | ||
return len(self.key) * 8 | ||
|
||
|
||
class CAST5(BlockCipherAlgorithm): | ||
name = "CAST5" | ||
block_size = 64 | ||
key_sizes = frozenset(range(40, 129, 8)) | ||
|
||
def __init__(self, key: bytes): | ||
self.key = _verify_key_size(self, key) | ||
|
||
@property | ||
def key_size(self) -> int: | ||
return len(self.key) * 8 | ||
|
||
|
||
class SEED(BlockCipherAlgorithm): | ||
name = "SEED" | ||
block_size = 128 | ||
key_sizes = frozenset([128]) | ||
|
||
def __init__(self, key: bytes): | ||
self.key = _verify_key_size(self, key) | ||
|
||
@property | ||
def key_size(self) -> int: | ||
return len(self.key) * 8 | ||
|
||
|
||
class IDEA(BlockCipherAlgorithm): | ||
name = "IDEA" | ||
block_size = 64 | ||
key_sizes = frozenset([128]) | ||
|
||
def __init__(self, key: bytes): | ||
self.key = _verify_key_size(self, key) | ||
|
||
@property | ||
def key_size(self) -> int: | ||
return len(self.key) * 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.