purepython-aes 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/.github/workflows/release.yml +0 -18
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/PKG-INFO +1 -1
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/__init__.py +2 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/__init__.py +8 -1
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/__init__.py +2 -2
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/block/__init__.py +2 -1
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/block/_base.py +4 -4
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/block/cbc.py +2 -2
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/block/ecb.py +2 -2
- purepython_aes-0.3.0/src/purepython_aes/aes/modes/block/pcbc.py +35 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/PKG-INFO +1 -1
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/SOURCES.txt +2 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/scm_file_list.json +2 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/scm_version.json +2 -2
- purepython_aes-0.3.0/tests/unit/aes/modes/block/test_pcbc.py +70 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/.github/workflows/pre-commit.yml +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/.gitignore +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/.pre-commit-config.yaml +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/LISENCE.txt +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/README.md +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/pyproject.toml +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/scripts/check-test-marks.sh +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/setup.cfg +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/algorithms/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/algorithms/aes128.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/algorithms/aes192.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/algorithms/aes256.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/core/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/core/aes.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/core/expansion.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/core/operations.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/core/state.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/interface.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/_base.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/operations.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/_base.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/ansix923.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/iso10126.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/iso7816.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/no.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/pkcs7.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/padding/zero.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/const/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/const/aes.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/const/sbox.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/py.typed +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/types/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/types/finite/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/types/finite/aliases.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/dependency_links.txt +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/requires.txt +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/top_level.txt +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/test_initial.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/algorithms/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/algorithms/conftest.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/algorithms/test_aes128.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/algorithms/test_aes192.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/algorithms/test_aes256.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/core/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/core/strategies.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/core/test_aes.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/core/test_expansion.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/core/test_operations.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/core/test_state.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/modes/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/modes/block/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/modes/block/test_cbc.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/modes/block/test_ecb.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/modes/test_operations.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/conftest.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/strategies.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/test_ansix923.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/test_iso10126.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/test_iso7816.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/test_no.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/test_pkcs7.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/padding/test_zero.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/aes/strategies.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/const/__init__.py +0 -0
- {purepython_aes-0.2.0 → purepython_aes-0.3.0}/tests/unit/const/test_sbox.py +0 -0
|
@@ -50,28 +50,10 @@ jobs:
|
|
|
50
50
|
run: python -m pip install --editable ".[dev, test]"
|
|
51
51
|
- name: Run pre-commit hooks
|
|
52
52
|
run: pre-commit run --all-files --show-diff-on-failure
|
|
53
|
-
slow-tests:
|
|
54
|
-
name: Run release-only tests
|
|
55
|
-
needs:
|
|
56
|
-
- validate
|
|
57
|
-
runs-on: ubuntu-latest
|
|
58
|
-
steps:
|
|
59
|
-
- name: Check out tagged commit
|
|
60
|
-
uses: actions/checkout@v4
|
|
61
|
-
- name: Set up Python
|
|
62
|
-
uses: actions/setup-python@v5
|
|
63
|
-
with:
|
|
64
|
-
python-version: "3.10"
|
|
65
|
-
cache: pip
|
|
66
|
-
- name: Install dependencies
|
|
67
|
-
run: python -m pip install --editable ".[dev, test]"
|
|
68
|
-
- name: Run slow tests
|
|
69
|
-
run: python -m pytest -n 8 -m "slow and not quick"
|
|
70
53
|
build:
|
|
71
54
|
name: Build distributions
|
|
72
55
|
needs:
|
|
73
56
|
- pre-commit
|
|
74
|
-
- slow-tests
|
|
75
57
|
runs-on: ubuntu-latest
|
|
76
58
|
steps:
|
|
77
59
|
- name: Check out tagged commit
|
|
@@ -12,6 +12,7 @@ from purepython_aes.aes import (
|
|
|
12
12
|
Iso7816Padding,
|
|
13
13
|
Iso10126Padding,
|
|
14
14
|
NoPadding,
|
|
15
|
+
PcbcMode,
|
|
15
16
|
Pkcs7Padding,
|
|
16
17
|
ZeroPadding,
|
|
17
18
|
)
|
|
@@ -30,6 +31,7 @@ __all__: list[str] = [
|
|
|
30
31
|
'Iso7816Padding',
|
|
31
32
|
'Iso10126Padding',
|
|
32
33
|
'NoPadding',
|
|
34
|
+
'PcbcMode',
|
|
33
35
|
'Pkcs7Padding',
|
|
34
36
|
'ZeroPadding',
|
|
35
37
|
]
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
from purepython_aes.aes.algorithms import Aes128, Aes192, Aes256
|
|
2
2
|
from purepython_aes.aes.interface import Aes
|
|
3
|
-
from purepython_aes.aes.modes import
|
|
3
|
+
from purepython_aes.aes.modes import (
|
|
4
|
+
AesMode,
|
|
5
|
+
BlockCipherMode,
|
|
6
|
+
CbcMode,
|
|
7
|
+
EcbMode,
|
|
8
|
+
PcbcMode,
|
|
9
|
+
)
|
|
4
10
|
from purepython_aes.aes.padding import (
|
|
5
11
|
AnsiX923Padding,
|
|
6
12
|
BasePadding,
|
|
@@ -20,6 +26,7 @@ __all__: list[str] = [
|
|
|
20
26
|
'BlockCipherMode',
|
|
21
27
|
'CbcMode',
|
|
22
28
|
'EcbMode',
|
|
29
|
+
'PcbcMode',
|
|
23
30
|
'AnsiX923Padding',
|
|
24
31
|
'BasePadding',
|
|
25
32
|
'Iso7816Padding',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
from purepython_aes.aes.modes._base import AesMode
|
|
2
|
-
from purepython_aes.aes.modes.block import BlockCipherMode, CbcMode, EcbMode
|
|
2
|
+
from purepython_aes.aes.modes.block import BlockCipherMode, CbcMode, EcbMode, PcbcMode
|
|
3
3
|
|
|
4
|
-
__all__: list[str] = ['AesMode', 'BlockCipherMode', 'CbcMode', 'EcbMode']
|
|
4
|
+
__all__: list[str] = ['AesMode', 'BlockCipherMode', 'CbcMode', 'EcbMode', 'PcbcMode']
|
{purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes/aes/modes/block/__init__.py
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from purepython_aes.aes.modes.block._base import BlockCipherMode
|
|
2
2
|
from purepython_aes.aes.modes.block.cbc import CbcMode
|
|
3
3
|
from purepython_aes.aes.modes.block.ecb import EcbMode
|
|
4
|
+
from purepython_aes.aes.modes.block.pcbc import PcbcMode
|
|
4
5
|
|
|
5
|
-
__all__: list[str] = ['BlockCipherMode', 'CbcMode', 'EcbMode']
|
|
6
|
+
__all__: list[str] = ['BlockCipherMode', 'CbcMode', 'EcbMode', 'PcbcMode']
|
|
@@ -11,13 +11,13 @@ class BlockCipherMode(AesMode, ABC):
|
|
|
11
11
|
padding: BasePadding
|
|
12
12
|
|
|
13
13
|
@abstractmethod
|
|
14
|
-
def
|
|
14
|
+
def __encrypt_blocks__(self, padded_plaintext: bytes) -> bytes:
|
|
15
15
|
"""Encrypt plaintext containing complete blocks."""
|
|
16
16
|
|
|
17
17
|
raise NotImplementedError
|
|
18
18
|
|
|
19
19
|
@abstractmethod
|
|
20
|
-
def
|
|
20
|
+
def __decrypt_blocks__(self, ciphertext: bytes) -> bytes:
|
|
21
21
|
"""Decrypt ciphertext containing complete blocks."""
|
|
22
22
|
|
|
23
23
|
raise NotImplementedError
|
|
@@ -25,11 +25,11 @@ class BlockCipherMode(AesMode, ABC):
|
|
|
25
25
|
def encrypt(self, plaintext: bytes) -> bytes:
|
|
26
26
|
"""Pad and encrypt a byte string."""
|
|
27
27
|
|
|
28
|
-
return self.
|
|
28
|
+
return self.__encrypt_blocks__(self.padding.pad(plaintext))
|
|
29
29
|
|
|
30
30
|
def decrypt(self, ciphertext: bytes) -> bytes:
|
|
31
31
|
"""Decrypt and unpad a byte string."""
|
|
32
32
|
|
|
33
33
|
if len(ciphertext) % AES_BLOCK_SIZE != 0:
|
|
34
34
|
raise ValueError(f'len(ciphertext) % {AES_BLOCK_SIZE} must be 0')
|
|
35
|
-
return self.padding.unpad(self.
|
|
35
|
+
return self.padding.unpad(self.__decrypt_blocks__(ciphertext))
|
|
@@ -12,7 +12,7 @@ from purepython_aes.const import AES_BLOCK_SIZE
|
|
|
12
12
|
class CbcMode(BlockCipherMode):
|
|
13
13
|
"""Cipher Block Chaining mode of operation."""
|
|
14
14
|
|
|
15
|
-
def
|
|
15
|
+
def __encrypt_blocks__(self, padded_plaintext: bytes) -> bytes:
|
|
16
16
|
initialization_vector: bytes = token_bytes(AES_BLOCK_SIZE)
|
|
17
17
|
previous_ciphertext_block: bytes = initialization_vector
|
|
18
18
|
ciphertext_blocks: list[bytes] = [initialization_vector]
|
|
@@ -23,7 +23,7 @@ class CbcMode(BlockCipherMode):
|
|
|
23
23
|
previous_ciphertext_block = ciphertext_block
|
|
24
24
|
return bytes(0).join(ciphertext_blocks)
|
|
25
25
|
|
|
26
|
-
def
|
|
26
|
+
def __decrypt_blocks__(self, ciphertext: bytes) -> bytes:
|
|
27
27
|
initialization_vector, *ciphertext_blocks = split_into_blocks(ciphertext)
|
|
28
28
|
previous_ciphertext_block: bytes = initialization_vector
|
|
29
29
|
plaintext_blocks: list[bytes] = []
|
|
@@ -10,12 +10,12 @@ from purepython_aes.aes.modes.operations import split_into_blocks
|
|
|
10
10
|
class EcbMode(BlockCipherMode):
|
|
11
11
|
"""Electronic Codebook mode of operation."""
|
|
12
12
|
|
|
13
|
-
def
|
|
13
|
+
def __encrypt_blocks__(self, padded_plaintext: bytes) -> bytes:
|
|
14
14
|
return bytes(0).join(
|
|
15
15
|
map(self.algorithm.encrypt_block, split_into_blocks(padded_plaintext))
|
|
16
16
|
)
|
|
17
17
|
|
|
18
|
-
def
|
|
18
|
+
def __decrypt_blocks__(self, ciphertext: bytes) -> bytes:
|
|
19
19
|
return bytes(0).join(
|
|
20
20
|
map(self.algorithm.decrypt_block, split_into_blocks(ciphertext))
|
|
21
21
|
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from secrets import token_bytes
|
|
3
|
+
from typing import final
|
|
4
|
+
|
|
5
|
+
from purepython_aes.aes.modes.block._base import BlockCipherMode
|
|
6
|
+
from purepython_aes.aes.modes.operations import split_into_blocks, xor
|
|
7
|
+
from purepython_aes.const import AES_BLOCK_SIZE
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@final
|
|
11
|
+
@dataclass(slots=True)
|
|
12
|
+
class PcbcMode(BlockCipherMode):
|
|
13
|
+
"""Propagating Cipher Block Chaining mode of operation."""
|
|
14
|
+
|
|
15
|
+
def __encrypt_blocks__(self, padded_plaintext: bytes) -> bytes:
|
|
16
|
+
initialization_vector: bytes = token_bytes(AES_BLOCK_SIZE)
|
|
17
|
+
previous_ciphertext_block: bytes = initialization_vector
|
|
18
|
+
ciphertext_blocks: list[bytes] = [initialization_vector]
|
|
19
|
+
for block in split_into_blocks(padded_plaintext):
|
|
20
|
+
chained_block: bytes = xor(block, previous_ciphertext_block)
|
|
21
|
+
ciphertext_block: bytes = self.algorithm.encrypt_block(chained_block)
|
|
22
|
+
ciphertext_blocks.append(ciphertext_block)
|
|
23
|
+
previous_ciphertext_block = xor(block, ciphertext_block)
|
|
24
|
+
return bytes(0).join(ciphertext_blocks)
|
|
25
|
+
|
|
26
|
+
def __decrypt_blocks__(self, ciphertext: bytes) -> bytes:
|
|
27
|
+
initialization_vector, *ciphertext_blocks = split_into_blocks(ciphertext)
|
|
28
|
+
previous_ciphertext_block: bytes = initialization_vector
|
|
29
|
+
plaintext_blocks: list[bytes] = []
|
|
30
|
+
for block in ciphertext_blocks:
|
|
31
|
+
decrypted_block: bytes = self.algorithm.decrypt_block(block)
|
|
32
|
+
plaintext_block: bytes = xor(decrypted_block, previous_ciphertext_block)
|
|
33
|
+
plaintext_blocks.append(plaintext_block)
|
|
34
|
+
previous_ciphertext_block = xor(block, plaintext_block)
|
|
35
|
+
return bytes(0).join(plaintext_blocks)
|
|
@@ -33,6 +33,7 @@ src/purepython_aes/aes/modes/block/__init__.py
|
|
|
33
33
|
src/purepython_aes/aes/modes/block/_base.py
|
|
34
34
|
src/purepython_aes/aes/modes/block/cbc.py
|
|
35
35
|
src/purepython_aes/aes/modes/block/ecb.py
|
|
36
|
+
src/purepython_aes/aes/modes/block/pcbc.py
|
|
36
37
|
src/purepython_aes/aes/padding/__init__.py
|
|
37
38
|
src/purepython_aes/aes/padding/_base.py
|
|
38
39
|
src/purepython_aes/aes/padding/ansix923.py
|
|
@@ -68,6 +69,7 @@ tests/unit/aes/modes/test_operations.py
|
|
|
68
69
|
tests/unit/aes/modes/block/__init__.py
|
|
69
70
|
tests/unit/aes/modes/block/test_cbc.py
|
|
70
71
|
tests/unit/aes/modes/block/test_ecb.py
|
|
72
|
+
tests/unit/aes/modes/block/test_pcbc.py
|
|
71
73
|
tests/unit/aes/padding/__init__.py
|
|
72
74
|
tests/unit/aes/padding/conftest.py
|
|
73
75
|
tests/unit/aes/padding/strategies.py
|
{purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/scm_file_list.json
RENAMED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"src/purepython_aes/aes/modes/block/_base.py",
|
|
36
36
|
"src/purepython_aes/aes/modes/block/__init__.py",
|
|
37
37
|
"src/purepython_aes/aes/modes/block/cbc.py",
|
|
38
|
+
"src/purepython_aes/aes/modes/block/pcbc.py",
|
|
38
39
|
"src/purepython_aes/aes/modes/block/ecb.py",
|
|
39
40
|
"src/purepython_aes/aes/algorithms/aes128.py",
|
|
40
41
|
"src/purepython_aes/aes/algorithms/__init__.py",
|
|
@@ -65,6 +66,7 @@
|
|
|
65
66
|
"tests/unit/aes/modes/test_operations.py",
|
|
66
67
|
"tests/unit/aes/modes/__init__.py",
|
|
67
68
|
"tests/unit/aes/modes/block/__init__.py",
|
|
69
|
+
"tests/unit/aes/modes/block/test_pcbc.py",
|
|
68
70
|
"tests/unit/aes/modes/block/test_ecb.py",
|
|
69
71
|
"tests/unit/aes/modes/block/test_cbc.py",
|
|
70
72
|
"tests/unit/aes/algorithms/test_aes256.py",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from itertools import product
|
|
2
|
+
|
|
3
|
+
from hypothesis import assume, given
|
|
4
|
+
from hypothesis.strategies import binary
|
|
5
|
+
from pytest import mark
|
|
6
|
+
|
|
7
|
+
from purepython_aes import (
|
|
8
|
+
Aes,
|
|
9
|
+
Aes128,
|
|
10
|
+
Aes192,
|
|
11
|
+
Aes256,
|
|
12
|
+
AnsiX923Padding,
|
|
13
|
+
BasePadding,
|
|
14
|
+
Iso7816Padding,
|
|
15
|
+
Iso10126Padding,
|
|
16
|
+
NoPadding,
|
|
17
|
+
PcbcMode,
|
|
18
|
+
Pkcs7Padding,
|
|
19
|
+
ZeroPadding,
|
|
20
|
+
)
|
|
21
|
+
from tests.unit.aes.strategies import aes256key, aes_blocks
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@mark.quick
|
|
25
|
+
class TestCbcMode:
|
|
26
|
+
@staticmethod
|
|
27
|
+
@mark.parametrize(
|
|
28
|
+
['aes', 'padding'],
|
|
29
|
+
tuple(
|
|
30
|
+
product(
|
|
31
|
+
[Aes128, Aes192, Aes256],
|
|
32
|
+
[AnsiX923Padding, Iso10126Padding, Iso7816Padding, Pkcs7Padding],
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
@given(key=aes256key, data=binary())
|
|
37
|
+
def test_decrypt_inverts_encrypt(
|
|
38
|
+
aes: type[Aes],
|
|
39
|
+
padding: type[BasePadding],
|
|
40
|
+
key: bytes,
|
|
41
|
+
data: bytes,
|
|
42
|
+
) -> None:
|
|
43
|
+
ecb: PcbcMode = PcbcMode(aes(key[:aes.__key_size__]), padding()) # fmt: skip
|
|
44
|
+
assert ecb.decrypt(ecb.encrypt(data)) == data
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
@mark.parametrize(['aes'], [[Aes128], [Aes192], [Aes256]])
|
|
48
|
+
@given(key=aes256key, data=binary())
|
|
49
|
+
def test_decrypt_inverts_encrypt_zero_padding(
|
|
50
|
+
aes: type[Aes],
|
|
51
|
+
key: bytes,
|
|
52
|
+
data: bytes,
|
|
53
|
+
) -> None:
|
|
54
|
+
assume(not data.endswith(bytes(1)))
|
|
55
|
+
ecb: PcbcMode = PcbcMode(
|
|
56
|
+
algorithm=aes(key[:aes.__key_size__]), # fmt: skip
|
|
57
|
+
padding=ZeroPadding(),
|
|
58
|
+
)
|
|
59
|
+
assert ecb.decrypt(ecb.encrypt(data)) == data
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
@mark.parametrize(['aes'], [[Aes128], [Aes192], [Aes256]])
|
|
63
|
+
@given(key=aes256key, data=aes_blocks)
|
|
64
|
+
def test_decrypt_inverts_encrypt_no_padding(
|
|
65
|
+
aes: type[Aes],
|
|
66
|
+
key: bytes,
|
|
67
|
+
data: bytes,
|
|
68
|
+
) -> None:
|
|
69
|
+
ecb: PcbcMode = PcbcMode(aes(key[:aes.__key_size__]), NoPadding()) # fmt: skip
|
|
70
|
+
assert ecb.decrypt(ecb.encrypt(data)) == data
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{purepython_aes-0.2.0 → purepython_aes-0.3.0}/src/purepython_aes.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|