diff options
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r-- | tests/test_utils.py | 364 |
1 files changed, 179 insertions, 185 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 73394a51..28e7407b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -56,21 +56,19 @@ def test_load_nist_vectors_encrypt(): PLAINTEXT = 9798c4640bad75c7c3227db910174e72 """).splitlines() - assert load_nist_vectors(vector_data, "ENCRYPT", - ["key", "iv", "plaintext", "ciphertext"], - ) == [ - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"f34481ec3cc627bacd5dc3fb08f273e6", - b"0336763e966d92595a567cc9ce537f5e", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"9798c4640bad75c7c3227db910174e72", - b"a9a1631bf4996954ebc093957b234589", - ), + assert load_nist_vectors(vector_data, "ENCRYPT") == [ + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6", + "ciphertext": b"0336763e966d92595a567cc9ce537f5e", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"9798c4640bad75c7c3227db910174e72", + "ciphertext": b"a9a1631bf4996954ebc093957b234589", + }, ] @@ -112,72 +110,69 @@ def test_load_nist_vectors_decrypt(): PLAINTEXT = 9798c4640bad75c7c3227db910174e72 """).splitlines() - assert load_nist_vectors(vector_data, "DECRYPT", - ["key", "iv", "ciphertext", "plaintext"], - ) == [ - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"0336763e966d92595a567cc9ce537f5e", - b"f34481ec3cc627bacd5dc3fb08f273e6", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"a9a1631bf4996954ebc093957b234589", - b"9798c4640bad75c7c3227db910174e72", - ), + assert load_nist_vectors(vector_data, "DECRYPT") == [ + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6", + "ciphertext": b"0336763e966d92595a567cc9ce537f5e", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"9798c4640bad75c7c3227db910174e72", + "ciphertext": b"a9a1631bf4996954ebc093957b234589", + }, ] def test_load_nist_vectors_from_file_encrypt(): assert load_nist_vectors_from_file( "AES/KAT/CBCGFSbox128.rsp", - "ENCRYPT", - ["key", "iv", "plaintext", "ciphertext"], + "ENCRYPT" ) == [ - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"f34481ec3cc627bacd5dc3fb08f273e6", - b"0336763e966d92595a567cc9ce537f5e", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"9798c4640bad75c7c3227db910174e72", - b"a9a1631bf4996954ebc093957b234589", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"96ab5c2ff612d9dfaae8c31f30c42168", - b"ff4f8391a6a40ca5b25d23bedd44a597", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"6a118a874519e64e9963798a503f1d35", - b"dc43be40be0e53712f7e2bf5ca707209", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"cb9fceec81286ca3e989bd979b0cb284", - b"92beedab1895a94faa69b632e5cc47ce", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"b26aeb1874e47ca8358ff22378f09144", - b"459264f4798f6a78bacb89c15ed3d601", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"58c8e00b2631686d54eab84b91f0aca1", - b"08a4e2efec8a8e3312ca7460b9040bbf", - ), + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6", + "ciphertext": b"0336763e966d92595a567cc9ce537f5e", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"9798c4640bad75c7c3227db910174e72", + "ciphertext": b"a9a1631bf4996954ebc093957b234589", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"96ab5c2ff612d9dfaae8c31f30c42168", + "ciphertext": b"ff4f8391a6a40ca5b25d23bedd44a597", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"6a118a874519e64e9963798a503f1d35", + "ciphertext": b"dc43be40be0e53712f7e2bf5ca707209", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"cb9fceec81286ca3e989bd979b0cb284", + "ciphertext": b"92beedab1895a94faa69b632e5cc47ce", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"b26aeb1874e47ca8358ff22378f09144", + "ciphertext": b"459264f4798f6a78bacb89c15ed3d601", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"58c8e00b2631686d54eab84b91f0aca1", + "ciphertext": b"08a4e2efec8a8e3312ca7460b9040bbf", + }, ] @@ -185,50 +180,49 @@ def test_load_nist_vectors_from_file_decrypt(): assert load_nist_vectors_from_file( "AES/KAT/CBCGFSbox128.rsp", "DECRYPT", - ["key", "iv", "ciphertext", "plaintext"], ) == [ - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"0336763e966d92595a567cc9ce537f5e", - b"f34481ec3cc627bacd5dc3fb08f273e6", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"a9a1631bf4996954ebc093957b234589", - b"9798c4640bad75c7c3227db910174e72", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"ff4f8391a6a40ca5b25d23bedd44a597", - b"96ab5c2ff612d9dfaae8c31f30c42168", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"dc43be40be0e53712f7e2bf5ca707209", - b"6a118a874519e64e9963798a503f1d35", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"92beedab1895a94faa69b632e5cc47ce", - b"cb9fceec81286ca3e989bd979b0cb284", - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"459264f4798f6a78bacb89c15ed3d601", - b"b26aeb1874e47ca8358ff22378f09144" - ), - ( - b"00000000000000000000000000000000", - b"00000000000000000000000000000000", - b"08a4e2efec8a8e3312ca7460b9040bbf", - b"58c8e00b2631686d54eab84b91f0aca1" - ), + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6", + "ciphertext": b"0336763e966d92595a567cc9ce537f5e", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"9798c4640bad75c7c3227db910174e72", + "ciphertext": b"a9a1631bf4996954ebc093957b234589", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"96ab5c2ff612d9dfaae8c31f30c42168", + "ciphertext": b"ff4f8391a6a40ca5b25d23bedd44a597", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"6a118a874519e64e9963798a503f1d35", + "ciphertext": b"dc43be40be0e53712f7e2bf5ca707209", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"cb9fceec81286ca3e989bd979b0cb284", + "ciphertext": b"92beedab1895a94faa69b632e5cc47ce", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"b26aeb1874e47ca8358ff22378f09144", + "ciphertext": b"459264f4798f6a78bacb89c15ed3d601", + }, + { + "key": b"00000000000000000000000000000000", + "iv": b"00000000000000000000000000000000", + "plaintext": b"58c8e00b2631686d54eab84b91f0aca1", + "ciphertext": b"08a4e2efec8a8e3312ca7460b9040bbf", + }, ] @@ -254,21 +248,21 @@ def test_load_cryptrec_vectors(): """).splitlines() assert load_cryptrec_vectors(vector_data) == [ - ( - b"00000000000000000000000000000000", - b"80000000000000000000000000000000", - b"07923A39EB0A817D1C4D87BDB82D1F1C", - ), - ( - b"00000000000000000000000000000000", - b"40000000000000000000000000000000", - b"48CD6419809672D2349260D89A08D3D3", - ), - ( - b"10000000000000000000000000000000", - b"80000000000000000000000000000000", - b"07923A39EB0A817D1C4D87BDB82D1F1C", - ), + { + "key": b"00000000000000000000000000000000", + "plaintext": b"80000000000000000000000000000000", + "ciphertext": b"07923A39EB0A817D1C4D87BDB82D1F1C", + }, + { + "key": b"00000000000000000000000000000000", + "plaintext": b"40000000000000000000000000000000", + "ciphertext": b"48CD6419809672D2349260D89A08D3D3", + }, + { + "key": b"10000000000000000000000000000000", + "plaintext": b"80000000000000000000000000000000", + "ciphertext": b"07923A39EB0A817D1C4D87BDB82D1F1C", + }, ] @@ -277,11 +271,11 @@ def test_load_cryptrec_vectors_from_file_encrypt(): "Camellia/NTT/camellia-128-ecb.txt" ) assert test_set[0] == ( - ( - b"00000000000000000000000000000000", - b"80000000000000000000000000000000", - b"07923A39EB0A817D1C4D87BDB82D1F1C", - ) + { + "key": b"00000000000000000000000000000000", + "plaintext": b"80000000000000000000000000000000", + "ciphertext": b"07923A39EB0A817D1C4D87BDB82D1F1C", + } ) assert len(test_set) == 1280 @@ -310,30 +304,30 @@ def test_load_openssl_vectors(): ).splitlines() assert load_openssl_vectors(vector_data) == [ - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"000102030405060708090A0B0C0D0E0F", - b"6BC1BEE22E409F96E93D7E117393172A", - b"14F7646187817EB586599146B82BD719", - ), - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"14F7646187817EB586599146B82BD719", - b"AE2D8A571E03AC9C9EB76FAC45AF8E51", - b"A53D28BB82DF741103EA4F921A44880B", - ), - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"000102030405060708090A0B0C0D0E0F", - b"6BC1BEE22E409F96E93D7E117393172A", - b"14F7646187817EB586599146B82BD719", - ), - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"14F7646187817EB586599146B82BD719", - b"AE2D8A571E03AC9C9EB76FAC45AF8E51", - b"A53D28BB82DF741103EA4F921A44880B", - ), + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"000102030405060708090A0B0C0D0E0F", + "plaintext": b"6BC1BEE22E409F96E93D7E117393172A", + "ciphertext": b"14F7646187817EB586599146B82BD719", + }, + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"14F7646187817EB586599146B82BD719", + "plaintext": b"AE2D8A571E03AC9C9EB76FAC45AF8E51", + "ciphertext": b"A53D28BB82DF741103EA4F921A44880B", + }, + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"000102030405060708090A0B0C0D0E0F", + "plaintext": b"6BC1BEE22E409F96E93D7E117393172A", + "ciphertext": b"14F7646187817EB586599146B82BD719", + }, + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"14F7646187817EB586599146B82BD719", + "plaintext": b"AE2D8A571E03AC9C9EB76FAC45AF8E51", + "ciphertext": b"A53D28BB82DF741103EA4F921A44880B", + }, ] @@ -341,28 +335,28 @@ def test_load_openssl_vectors_from_file(): test_list = load_openssl_vectors_from_file("Camellia/camellia-ofb.txt") assert len(test_list) == 24 assert test_list[:4] == [ - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"000102030405060708090A0B0C0D0E0F", - b"6BC1BEE22E409F96E93D7E117393172A", - b"14F7646187817EB586599146B82BD719", - ), - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"50FE67CC996D32B6DA0937E99BAFEC60", - b"AE2D8A571E03AC9C9EB76FAC45AF8E51", - b"25623DB569CA51E01482649977E28D84", - ), - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"D9A4DADA0892239F6B8B3D7680E15674", - b"30C81C46A35CE411E5FBC1191A0A52EF", - b"C776634A60729DC657D12B9FCA801E98", - ), - ( - b"2B7E151628AED2A6ABF7158809CF4F3C", - b"A78819583F0308E7A6BF36B1386ABF23", - b"F69F2445DF4F9B17AD2B417BE66C3710", - b"D776379BE0E50825E681DA1A4C980E8E", - ), + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"000102030405060708090A0B0C0D0E0F", + "plaintext": b"6BC1BEE22E409F96E93D7E117393172A", + "ciphertext": b"14F7646187817EB586599146B82BD719", + }, + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"50FE67CC996D32B6DA0937E99BAFEC60", + "plaintext": b"AE2D8A571E03AC9C9EB76FAC45AF8E51", + "ciphertext": b"25623DB569CA51E01482649977E28D84", + }, + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"D9A4DADA0892239F6B8B3D7680E15674", + "plaintext": b"30C81C46A35CE411E5FBC1191A0A52EF", + "ciphertext": b"C776634A60729DC657D12B9FCA801E98", + }, + { + "key": b"2B7E151628AED2A6ABF7158809CF4F3C", + "iv": b"A78819583F0308E7A6BF36B1386ABF23", + "plaintext": b"F69F2445DF4F9B17AD2B417BE66C3710", + "ciphertext": b"D776379BE0E50825E681DA1A4C980E8E", + }, ] |