Made the load NIST vectors test utility use bytes correctly

This commit is contained in:
Alex Gaynor 2013-08-10 15:23:38 -04:00
parent 34c7a91c08
commit f312a5c1c9
2 changed files with 109 additions and 59 deletions

View file

@ -1,3 +1,16 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import textwrap
from .utils import load_nist_vectors, load_nist_vectors_from_file
@ -45,16 +58,16 @@ def test_load_nist_vectors_encrypt():
["key", "iv", "plaintext", "ciphertext"],
) == [
(
"00000000000000000000000000000000",
"00000000000000000000000000000000",
"f34481ec3cc627bacd5dc3fb08f273e6",
"0336763e966d92595a567cc9ce537f5e",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"f34481ec3cc627bacd5dc3fb08f273e6",
b"0336763e966d92595a567cc9ce537f5e",
),
(
"00000000000000000000000000000000",
"00000000000000000000000000000000",
"9798c4640bad75c7c3227db910174e72",
"a9a1631bf4996954ebc093957b234589",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"9798c4640bad75c7c3227db910174e72",
b"a9a1631bf4996954ebc093957b234589",
),
]
@ -101,93 +114,117 @@ def test_load_nist_vectors_decrypt():
["key", "iv", "ciphertext", "plaintext"],
) == [
(
"00000000000000000000000000000000",
"00000000000000000000000000000000",
"0336763e966d92595a567cc9ce537f5e",
"f34481ec3cc627bacd5dc3fb08f273e6",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"0336763e966d92595a567cc9ce537f5e",
b"f34481ec3cc627bacd5dc3fb08f273e6",
),
(
"00000000000000000000000000000000",
"00000000000000000000000000000000",
"a9a1631bf4996954ebc093957b234589",
"9798c4640bad75c7c3227db910174e72",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"a9a1631bf4996954ebc093957b234589",
b"9798c4640bad75c7c3227db910174e72",
),
]
def test_load_nist_vectors_from_file_encrypt():
assert load_nist_vectors_from_file(
"AES/KAT/CBCGFSbox256.rsp",
"AES/KAT/CBCGFSbox128.rsp",
"ENCRYPT",
["key", "iv", "plaintext", "ciphertext"],
) == [
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"014730f80ac625fe84f026c60bfd547d",
"5c9d844ed46f9885085e5d6a4f94c7d7",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"f34481ec3cc627bacd5dc3fb08f273e6",
b"0336763e966d92595a567cc9ce537f5e",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"0b24af36193ce4665f2825d7b4749c98",
"a9ff75bd7cf6613d3731c77c3b6d0c04",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"9798c4640bad75c7c3227db910174e72",
b"a9a1631bf4996954ebc093957b234589",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"761c1fe41a18acf20d241650611d90f1",
"623a52fcea5d443e48d9181ab32c7421",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"96ab5c2ff612d9dfaae8c31f30c42168",
b"ff4f8391a6a40ca5b25d23bedd44a597",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"8a560769d605868ad80d819bdba03771",
"38f2c7ae10612415d27ca190d27da8b4",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"6a118a874519e64e9963798a503f1d35",
b"dc43be40be0e53712f7e2bf5ca707209",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"91fbef2d15a97816060bee1feaa49afe",
"1bc704f1bce135ceb810341b216d7abe",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"cb9fceec81286ca3e989bd979b0cb284",
b"92beedab1895a94faa69b632e5cc47ce",
),
(
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"b26aeb1874e47ca8358ff22378f09144",
b"459264f4798f6a78bacb89c15ed3d601",
),
(
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"58c8e00b2631686d54eab84b91f0aca1",
b"08a4e2efec8a8e3312ca7460b9040bbf",
),
]
def test_load_nist_vectors_from_file_decypt():
assert load_nist_vectors_from_file(
"AES/KAT/CBCGFSbox256.rsp",
"AES/KAT/CBCGFSbox128.rsp",
"DECRYPT",
["key", "iv", "ciphertext", "plaintext"],
) == [
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"5c9d844ed46f9885085e5d6a4f94c7d7",
"014730f80ac625fe84f026c60bfd547d",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"0336763e966d92595a567cc9ce537f5e",
b"f34481ec3cc627bacd5dc3fb08f273e6",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"a9ff75bd7cf6613d3731c77c3b6d0c04",
"0b24af36193ce4665f2825d7b4749c98",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"a9a1631bf4996954ebc093957b234589",
b"9798c4640bad75c7c3227db910174e72",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"623a52fcea5d443e48d9181ab32c7421",
"761c1fe41a18acf20d241650611d90f1",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"ff4f8391a6a40ca5b25d23bedd44a597",
b"96ab5c2ff612d9dfaae8c31f30c42168",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"38f2c7ae10612415d27ca190d27da8b4",
"8a560769d605868ad80d819bdba03771",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"dc43be40be0e53712f7e2bf5ca707209",
b"6a118a874519e64e9963798a503f1d35",
),
(
"0000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000",
"1bc704f1bce135ceb810341b216d7abe",
"91fbef2d15a97816060bee1feaa49afe",
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"92beedab1895a94faa69b632e5cc47ce",
b"cb9fceec81286ca3e989bd979b0cb284",
),
(
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"459264f4798f6a78bacb89c15ed3d601",
b"b26aeb1874e47ca8358ff22378f09144"
),
(
b"00000000000000000000000000000000",
b"00000000000000000000000000000000",
b"08a4e2efec8a8e3312ca7460b9040bbf",
b"58c8e00b2631686d54eab84b91f0aca1"
),
]

View file

@ -1,3 +1,16 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os.path
@ -35,7 +48,7 @@ def load_nist_vectors(vector_data, op, fields):
# We want to test only for a particular operation
return [
tuple(vector[1][f] for f in fields)
tuple(vector[1][f].encode("ascii") for f in fields)
for vector in sorted(data[op].items(), key=lambda v: v[0])
]