diff --git a/.github/workflows/hdl-build.yaml b/.github/workflows/hdl-build.yaml index 0561321..6697739 100644 --- a/.github/workflows/hdl-build.yaml +++ b/.github/workflows/hdl-build.yaml @@ -1,6 +1,8 @@ name: hdl-build + # Controls when the workflow will run on: + # Triggers the workflow on push or pull request events but only for the $default-branch branch push: branches: @@ -14,8 +16,10 @@ on: permissions: contents: read + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: + # This workflow contains a single job called "build" build: runs-on: macos-latest diff --git a/.gitignore b/.gitignore index a00d614..e41b70d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ **/.pytest_cache/ **/__pycache__/ **/.DS_Store/ -nist/ +/nist/ **/sim_build/ \ No newline at end of file diff --git a/README.md b/README.md index 471dafa..a4a6c17 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # AES The goal of this project is to explore co-simulation of python and systemverilog using AES cores as an example. AES Cores will be created and tested in python followed by systemverilog. Cocotb will be used as a bridge between the python and systemverilog for stimulus and scoreboarding. -![CI](https://github.com/bjohnsonfl/aes/actions/workflows/python-app.yaml/badge.svg?branch=main) +[![python-build](https://github.com/bjohnsonfl/aes/actions/workflows/python-app.yaml/badge.svg)](https://github.com/bjohnsonfl/aes/actions/workflows/python-app.yaml) + +[![hdl-build](https://github.com/bjohnsonfl/aes/actions/workflows/hdl-build.yaml/badge.svg)](https://github.com/bjohnsonfl/aes/actions/workflows/hdl-build.yaml) Docs: - AES Spec diff --git a/test/nist/KAT_AES/test_aes_cbc.py b/test/nist/KAT_AES/test_aes_cbc.py index 089fc3a..4ec5982 100644 --- a/test/nist/KAT_AES/test_aes_cbc.py +++ b/test/nist/KAT_AES/test_aes_cbc.py @@ -5,31 +5,31 @@ from src.python.aes_modes import aes_cbc from scripts.rsp_parser import parse_kat_file -# TODO: Support 192 and 256 -def get_kat_cbc_files(): - return list(Path("nist/KAT_AES").glob("CBC*128.rsp")) +def get_kat_cbc_files(operation): + kat_files = (list(Path("nist/KAT_AES").glob("CBC*.rsp"))) + tests = [] + for file in kat_files: + kat_list = parse_kat_file(file) + for (op, count), test in kat_list.items(): + if op == operation: + tests.append((file, count, test)) + return tests -@pytest.mark.parametrize("kat_files", get_kat_cbc_files(), ids=lambda p: p.name) -def test_kat_aes_cbc_encrypt(kat_files): - kat_list = parse_kat_file(kat_files) - for (op, count), value in kat_list.items(): - if op == "ENCRYPT": - ct = aes_cbc(value.plaintext, value.key, value.iv, op) - assert(ct == value.ciphertext) +@pytest.mark.parametrize(("file, count, test"), get_kat_cbc_files("ENCRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_kat_cbc_files("ENCRYPT")]) +def test_kat_aes_cbc_encrypt(file, count, test): + ct = aes_cbc(test.plaintext, test.key, test.iv, test.operation) + assert(ct == test.ciphertext) - # Swap PT and IV - ct = aes_cbc(value.iv, value.key, value.plaintext, op) - assert(ct == value.ciphertext) + # Swap PT and IV + ct = aes_cbc(test.iv, test.key, test.plaintext, test.operation) + assert(ct == test.ciphertext) -@pytest.mark.parametrize("kat_files", get_kat_cbc_files(), ids=lambda p: p.name) -def test_kat_aes_cbc_decrypt(kat_files): - kat_list = parse_kat_file(kat_files) - for (op, count), value in kat_list.items(): - if op == "DECRYPT": - pt = aes_cbc(value.ciphertext, value.key, value.iv, op) - assert(pt == value.plaintext) +@pytest.mark.parametrize(("file, count, test"), get_kat_cbc_files("DECRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_kat_cbc_files("DECRYPT")]) +def test_kat_aes_cbc_decrypt(file, count, test): + pt = aes_cbc(test.ciphertext, test.key, test.iv, test.operation) + assert(pt == test.plaintext) - # Swap CT and IV - pt = aes_cbc(value.ciphertext, value.key, value.plaintext, op) - assert(pt == value.iv) \ No newline at end of file + # Swap CT and IV + pt = aes_cbc(test.ciphertext, test.key, test.plaintext, test.operation) + assert(pt == test.iv) \ No newline at end of file diff --git a/test/nist/KAT_AES/test_aes_ecb.py b/test/nist/KAT_AES/test_aes_ecb.py index ea3d14e..083a314 100644 --- a/test/nist/KAT_AES/test_aes_ecb.py +++ b/test/nist/KAT_AES/test_aes_ecb.py @@ -4,22 +4,22 @@ from src.python.aes_modes import aes_ecb from scripts.rsp_parser import parse_kat_file -# TODO: Support 192 and 256 -def get_kat_ecb_files(): - return list(Path("nist/KAT_AES").glob("ECB*128.rsp")) +def get_kat_ecb_files(operation): + kat_files = (list(Path("nist/KAT_AES").glob("ECB*.rsp"))) + tests = [] + for file in kat_files: + kat_list = parse_kat_file(file) + for (op, count), test in kat_list.items(): + if op == operation: + tests.append((file, count, test)) + return tests -@pytest.mark.parametrize("kat_files", get_kat_ecb_files(), ids=lambda p: p.name) -def test_kat_aes_ecb_encrypt(kat_files): - kat_list = parse_kat_file(kat_files) - for (op, count), value in kat_list.items(): - if op == "ENCRYPT": - ct = aes_ecb(value.plaintext, value.key, op) - assert(ct == value.ciphertext) +@pytest.mark.parametrize(("file, count, test"), get_kat_ecb_files("ENCRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_kat_ecb_files("ENCRYPT")]) +def test_kat_aes_ecb_encrypt(file, count, test): + ct = aes_ecb(test.plaintext, test.key, test.operation) + assert(ct == test.ciphertext) -@pytest.mark.parametrize("kat_files", get_kat_ecb_files(), ids=lambda p: p.name) -def test_kat_aes_ecb_decrypt(kat_files): - kat_list = parse_kat_file(kat_files) - for (op, count), value in kat_list.items(): - if op == "DECRYPT": - pt = aes_ecb(value.ciphertext, value.key, op) - assert(pt == value.plaintext) \ No newline at end of file +@pytest.mark.parametrize(("file, count, test"), get_kat_ecb_files("DECRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_kat_ecb_files("DECRYPT")]) +def test_kat_aes_ecb_decrypt(file, count, test): + pt = aes_ecb(test.ciphertext, test.key, test.operation) + assert(pt == test.plaintext) \ No newline at end of file diff --git a/test/nist/aesmmt/test_aes_cbc.py b/test/nist/aesmmt/test_aes_cbc.py index 251f03b..33a5aea 100644 --- a/test/nist/aesmmt/test_aes_cbc.py +++ b/test/nist/aesmmt/test_aes_cbc.py @@ -4,21 +4,22 @@ from src.python.aes_modes import aes_cbc from scripts.rsp_parser import parse_kat_file -def get_mmt_cbc_files(): - return list(Path("nist/aesmmt").glob("CBC*.rsp")) +def get_mmt_cbc_files(operation): + mmt_files = (list(Path("nist/aesmmt").glob("CBC*.rsp"))) + tests = [] + for file in mmt_files: + mmt_list = parse_kat_file(file) + for (op, count), test in mmt_list.items(): + if op == operation: + tests.append((file, count, test)) + return tests -@pytest.mark.parametrize("mmt_files", get_mmt_cbc_files(), ids=lambda p: p.name) -def test_mmt_aes_cbc_encrypt(mmt_files): - mmt_list = parse_kat_file(mmt_files) - for (op, count), value in mmt_list.items(): - if op == "ENCRYPT": - ct = aes_cbc(value.plaintext, value.key, value.iv, op) - assert(ct == value.ciphertext) +@pytest.mark.parametrize(("file, count, test"), get_mmt_cbc_files("ENCRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_mmt_cbc_files("ENCRYPT")]) +def test_mmt_aes_cbc_encrypt(file, count, test): + ct = aes_cbc(test.plaintext, test.key, test.iv, test.operation) + assert(ct == test.ciphertext) -@pytest.mark.parametrize("mmt_files", get_mmt_cbc_files(), ids=lambda p: p.name) -def test_mmt_aes_cbc_decrypt(mmt_files): - mmt_list = parse_kat_file(mmt_files) - for (op, count), value in mmt_list.items(): - if op == "DECRYPT": - pt = aes_cbc(value.ciphertext, value.key, value.iv, op) - assert(pt == value.plaintext) \ No newline at end of file +@pytest.mark.parametrize(("file, count, test"), get_mmt_cbc_files("DECRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_mmt_cbc_files("DECRYPT")]) +def test_mmt_aes_cbc_decrypt(file, count, test): + pt = aes_cbc(test.ciphertext, test.key, test.iv, test.operation) + assert(pt == test.plaintext) \ No newline at end of file diff --git a/test/nist/aesmmt/test_aes_ecb.py b/test/nist/aesmmt/test_aes_ecb.py index 1dbde2a..1999d8e 100644 --- a/test/nist/aesmmt/test_aes_ecb.py +++ b/test/nist/aesmmt/test_aes_ecb.py @@ -4,23 +4,22 @@ from src.python.aes_modes import aes_ecb from scripts.rsp_parser import parse_kat_file -def get_mmt_ecb_files(): - return list(Path("nist/aesmmt").glob("ECB*.rsp")) +def get_mmt_ecb_files(operation): + mmt_files = (list(Path("nist/aesmmt").glob("ECB*.rsp"))) + tests = [] + for file in mmt_files: + mmt_list = parse_kat_file(file) + for (op, count), test in mmt_list.items(): + if op == operation: + tests.append((file, count, test)) + return tests -@pytest.mark.parametrize("mmt_files", get_mmt_ecb_files(), ids=lambda p: p.name) -def test_mmt_aes_ecb_encrypt(mmt_files): - mmt_list = parse_kat_file(mmt_files) - for (op, count), value in mmt_list.items(): - if op == "ENCRYPT": - print(f"ENCRYPT: {count}") - ct = aes_ecb(value.plaintext, value.key, op) - assert(ct == value.ciphertext) +@pytest.mark.parametrize(("file, count, test"), get_mmt_ecb_files("ENCRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_mmt_ecb_files("ENCRYPT")]) +def test_mmt_aes_ecb_encrypt(file, count, test): + ct = aes_ecb(test.plaintext, test.key, test.operation) + assert(ct == test.ciphertext) -@pytest.mark.parametrize("mmt_files", get_mmt_ecb_files(), ids=lambda p: p.name) -def test_mmt_aes_ecb_decrypt(mmt_files): - mmt_list = parse_kat_file(mmt_files) - for (op, count), value in mmt_list.items(): - if op == "DECRYPT": - print(f"DECRYPT: {count}") - pt = aes_ecb(value.ciphertext, value.key, op) - assert(pt == value.plaintext) \ No newline at end of file +@pytest.mark.parametrize(("file, count, test"), get_mmt_ecb_files("DECRYPT"), ids=[f'{x[0].stem}_{x[2].operation}_{x[1]}' for x in get_mmt_ecb_files("DECRYPT")]) +def test_mmt_aes_ecb_decrypt(file, count, test): + pt = aes_ecb(test.ciphertext, test.key, test.operation) + assert(pt == test.plaintext) \ No newline at end of file diff --git a/test/scripts/test_rsp_parser.py b/test/scripts/test_rsp_parser.py index 8ebb2f5..e5dd3ed 100644 --- a/test/scripts/test_rsp_parser.py +++ b/test/scripts/test_rsp_parser.py @@ -9,7 +9,7 @@ # KAT Tests ########### def get_kat_ecb_files(): - return list(Path("nist/KAT_AES").glob("ECB*128.rsp")) + return list(Path("nist/KAT_AES").glob("ECB*.rsp")) @pytest.mark.parametrize("kat_files", get_kat_ecb_files(), ids=lambda p: p.name) def test_kat_aes_ecb(kat_files): @@ -18,7 +18,7 @@ def test_kat_aes_ecb(kat_files): aes_ecb(op, value.key, value.iv, value.plaintext, value.ciphertext) def get_kat_cbc_files(): - return list(Path("nist/KAT_AES").glob("CBC*128.rsp")) + return list(Path("nist/KAT_AES").glob("CBC*.rsp")) @pytest.mark.parametrize("kat_files", get_kat_cbc_files(), ids=lambda p: p.name) def test_kat_aes_cbc(kat_files): @@ -31,7 +31,7 @@ def test_kat_aes_cbc(kat_files): ########### def get_mmt_ecb_files(): - return list(Path("nist/aesmmt").glob("ECB*128.rsp")) + return list(Path("nist/aesmmt").glob("ECB*.rsp")) @pytest.mark.parametrize("kat_files", get_mmt_ecb_files(), ids=lambda p: p.name) def test_mmt_aes_ecb(kat_files): @@ -40,7 +40,7 @@ def test_mmt_aes_ecb(kat_files): aes_ecb(op, value.key, value.iv, value.plaintext, value.ciphertext) def get_mmt_cbc_files(): - return list(Path("nist/aesmmt").glob("CBC*128.rsp")) + return list(Path("nist/aesmmt").glob("CBC*.rsp")) @pytest.mark.parametrize("kat_files", get_mmt_cbc_files(), ids=lambda p: p.name) def test_mmt_aes_cbc(kat_files):