Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/hdl-build.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
**/.pytest_cache/
**/__pycache__/
**/.DS_Store/
nist/
/nist/
**/sim_build/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
46 changes: 23 additions & 23 deletions test/nist/KAT_AES/test_aes_cbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
# Swap CT and IV
pt = aes_cbc(test.ciphertext, test.key, test.plaintext, test.operation)
assert(pt == test.iv)
34 changes: 17 additions & 17 deletions test/nist/KAT_AES/test_aes_ecb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
@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)
33 changes: 17 additions & 16 deletions test/nist/aesmmt/test_aes_cbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
@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)
35 changes: 17 additions & 18 deletions test/nist/aesmmt/test_aes_ecb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
@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)
8 changes: 4 additions & 4 deletions test/scripts/test_rsp_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down