Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
cmomin committed Oct 2, 2024
2 parents 9d34140 + 3b2ae34 commit d6e1fa9
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 56 deletions.
89 changes: 69 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,78 @@ jobs:
steps:
- name: Set up Git repository
uses: actions/checkout@v4
- name: Cache documentation build
uses: actions/cache@v4
with:
key: "doc-pdf-v1-${{ hashFiles('docs/**') }}"
restore-keys: "doc-pdf-v1"
path: docs/build
- name: Touch source to ensure at least 1 build
run: touch docs/SMAesH.tex
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v3
with:
working_directory: docs
root_file: SMAesH.tex
args: -auxdir=build -pdf -file-line-error -halt-on-error -interaction=nonstopmode
- name: Upload PDF file
uses: actions/upload-artifact@v4
with:
name: docs
path: docs/SMAesH.pdf
path: docs/build/SMAesH.pdf

release:
needs: [build_latex]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
sbox:
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
nshares: [2]
env:
NSHARES: "${{ matrix.nshares }}"
steps:
- uses: actions/download-artifact@v3
- name: Check out repository code
uses: actions/checkout@v4
with:
name: docs
path: release
- name: Release
uses: softprops/action-gh-release@v2
submodules: true
- name: Get COMPRESS version
id: compress-version
run: |
echo "cv=$(git -C sboxes-compress/compress show-ref HEAD | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
shell: bash

- run: sudo apt-get install -y yosys
- name: Cache COMPRESS Sbox
uses: actions/cache@v4
with:
body: |
View CHANGELOG.md for full changes.
files: |
release/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

key: "sbox-compress-v1-d${{ matrix.nshares }}-${{ hashFiles('sboxes-compress/canright_aes_sbox_dual.v') }}-${{ steps.compress-version.outputs.cv }}"
path: work/d${{ matrix.nshares }}/sbox
- run: make sbox
- name: Upload COMPRESS sbox
uses: actions/upload-artifact@v4
with:
name: sbox_${{ matrix.nshares }}
path: work/d${{ matrix.nshares }}/sbox/*

functest:
needs: [sbox]
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
nshares: [2]
env:
NSHARES: "${{ matrix.nshares }}"
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
submodules: true
- uses: actions/download-artifact@v4
with:
name: sbox_${{ matrix.nshares }}
path: work/d${{ matrix.nshares }}/sbox
- run: sudo apt-get install -y yosys verilator iverilog
- run: make func-tests
- run: make func-tests

formal_verif_matchi:
runs-on: ubuntu-24.04
Expand All @@ -70,5 +103,21 @@ jobs:
- run: (curl -L https://github.com/simple-crypto/hw-devtools/releases/download/v241002-1/hw-devtools.tar.gz | tar xz; sudo apt install ./hw-devtools/*.deb)
- run: make formal-tests MATCHI_CELLS=${{ github.workspace }}/verif-tools/matchi-0.1.0/matchi_cells MATCHI_BIN=${{ github.workspace }}/verif-tools/matchi



release:
needs: [build_latex, functest]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: docs
path: release
- name: Release
uses: softprops/action-gh-release@v2
with:
body: |
View CHANGELOG.md for full changes.
files: |
release/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 7 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ HDL_DONE = $(DIR_HDL)/.gather
DIR_COMPRESS_ROOT?=./sboxes-compress/compress

##################"
COMPRESS_WORKDIR=$(WORKDIR)/sbox
SBOX_FILE=$(COMPRESS_WORKDIR)/circuits/canright_aes_sbox_dual_d$(NSHARES)_l4/design.v
COMPRESS_WORKDIR=$(WORKDIR)/compress
SBOX_FILE=$(WORKDIR)/sbox/canright_aes_sbox_dual.v

DIR_COMPRESS_GADGETS=$(DIR_COMPRESS_ROOT)/gadget_library
DIR_SMAESH_HDL=hdl/smaesh_hpc
Expand All @@ -43,17 +43,14 @@ $(VE_INSTALLED): $(VE)/pyvenv.cfg
${PYTHON_VE}; python -m pip install -r func_tests/requirements.txt
touch $(VE_INSTALLED)

## Sbox generation with compress
$(SBOX_FILE):
make -C sboxes-compress WORK=$(COMPRESS_WORKDIR) DS=$(NSHARES)
$(SBOX_FILE): sboxes-compress/canright_aes_sbox_dual.v
cd sboxes-compress; SBOX_FILE=$(SBOX_FILE) WORK=$(COMPRESS_WORKDIR) NSHARES=$(NSHARES) ./compress.sh

sbox: $(SBOX_FILE)

## HDL directory building
$(HDL_DONE): $(SBOX_FILE)
$(HDL_DONE): $(SBOX_FILE)
OUT_DIR=${DIR_HDL} ./gather_sources.sh $(DIR_SMAESH_HDL) $(DIR_COMPRESS_GADGETS)/BIN $(DIR_COMPRESS_GADGETS)/MSK
cp $(SBOX_FILE) $(DIR_HDL)/canright_aes_sbox_dual.v
cp $(dir $(SBOX_FILE))/design.vh $(DIR_HDL)
cp $(SBOX_FILE) $(SBOX_FILE)h $(DIR_HDL)
echo "\`define DEFAULTSHARES ${NSHARES}" > $(DIR_HDL)/architecture_default.vh
touch $(HDL_DONE)

Expand All @@ -63,7 +60,7 @@ hdl: $(HDL_DONE)
FUNC_LOG=$(WORKDIR)/functests/simu.log
FUNC_SUCCESS=$(WORKDIR)/functests/success
$(FUNC_LOG): $(VE_INSTALLED) $(HDL_DONE)
mkdir $(dir $(FUNC_LOG))
mkdir -p $(dir $(FUNC_LOG))
$(PYTHON_VE); make -C func_tests NSHARES=$(NSHARES) WORK_CASE=$(WORKDIR)/functests RTL_DIR_HDL=$(DIR_HDL) simu | tee $@

# Mark simulation success (simulation always return a zero exit code).
Expand Down
2 changes: 1 addition & 1 deletion hdl/smaesh_hpc/MSKaes_32bits_core.v
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module MSKaes_32bits_core
rnd_bus0_valid_for_rfrsh
);

`include "design.vh"
`include "canright_aes_sbox_dual.vh"

// IOs Ports
(* matchi_type="control" *)
Expand Down
2 changes: 1 addition & 1 deletion hdl/smaesh_hpc/sbox/gen_sbox.v
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module gen_sbox
);


`include "design.vh"
`include "canright_aes_sbox_dual.vh"

// Inputs ports
input clk;
Expand Down
2 changes: 1 addition & 1 deletion hdl/smaesh_hpc/smaesh_hpc.v
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ output [128*d-1:0] out_shares_data;
output out_valid;
input out_ready;

`include "design.vh"
`include "canright_aes_sbox_dual.vh"

/* =========== Aes core =========== */
wire aes_busy;
Expand Down
2 changes: 1 addition & 1 deletion hdl/tb/tb_MSKaes_32bits_core.v
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ localparam wait_delay = 100*T;
localparam init_delay=Td/2.0;

`include "utils.vh"
`include "design.vh"
`include "canright_aes_sbox_dual.vh"

localparam Td = T/2.0;

Expand Down
36 changes: 15 additions & 21 deletions sboxes-compress/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ WORK ?= work
MODULE_NAME ?= canright_aes_sbox_dual
YOSYS_NETLIST ?= $(WORK)/$(MODULE_NAME).json
CIRCUIT=$(WORK)/$(MODULE_NAME).txt
LATS ?= 4
DS ?= 2 3 4
LAT ?= 4

NSHARES ?= 2

# Python Venv
SHELL=/bin/bash
VE=$(abspath $(WORK)/ve)
VE_INSTALLED=$(VE)/installed
PYTHON_VE=source $(VE)/bin/activate

AREA_REPORT = $(WORK)/$(MODULE_NAME)_area.csv
RES_FILE? = $(WORK)/res/$(MODULE_NAME).v
RES_DIR = $(dir $(RES_FILE))
COMPRESS_FILE=$(WORK)/circuits/canright_aes_sbox_dual_d$(NSHARES)_l$(LAT)/design.v

BEH_SIMU_TB ?= tb_sbox_dual.v
BEH_SIMU_DIR ?= $(WORK)/beh-simu
YOSYS?=yosys

.PHONY: all clean area
.PHONY: all

all: $(AREA_REPORT)
all: $(RES_FILE)

$(VE)/pyvenv.cfg:
mkdir -p work
Expand All @@ -29,28 +31,20 @@ $(VE_INSTALLED): $(VE)/pyvenv.cfg
${PYTHON_VE}; python -m pip install -r compress/requirements.txt
touch $(VE_INSTALLED)

clean:
-rm -r $(WORK) / 2> /dev/null

FILE_IN=canright_aes_sbox_dual.v
$(YOSYS_NETLIST): $(FILE_IN) build-json-yosys.tcl
mkdir -p $(WORK)
FILE_IN=$(FILE_IN) YOSYS_NETLIST=$(YOSYS_NETLIST) yosys -c build-json-yosys.tcl
FILE_IN=$(FILE_IN) YOSYS_NETLIST=$(YOSYS_NETLIST) $(YOSYS) -c build-json-yosys.tcl

$(CIRCUIT): $(VE_INSTALLED) $(YOSYS_NETLIST)
${PYTHON_VE}; python compress/scripts/yosys2compress.py \
--netlist-file $(YOSYS_NETLIST) \
--top canright_aes_sbox_dual \
--compress-file $(CIRCUIT)

$(AREA_REPORT): $(VE_INSTALLED) $(CIRCUIT)
${PYTHON_VE}; make -C compress CIRCUIT="$(abspath $(CIRCUIT))" LATS="$(LATS)" DS="$(DS)" WORK=$(abspath $(WORK)) area

$(BEH_SIMU_DIR):
mkdir -p $(BEH_SIMU_DIR)

beh-simu-umsk: $(BEH_SIMU_DIR)
iverilog tb_sbox_dual.v -y . -o $(BEH_SIMU_DIR)/umsk.out && vvp $(BEH_SIMU_DIR)/umsk.out

$(RES_FILE): $(VE_INSTALLED) $(CIRCUIT)
${PYTHON_VE}; make -C compress CIRCUIT="$(abspath $(CIRCUIT))" LATS="$(LAT)" DS="$(NSHARES)" WORK=$(WORK) $(COMPRESS_FILE)
mkdir -p $(RES_DIR)
cp $(COMPRESS_FILE) $(RES_FILE)
cp $(COMPRESS_FILE)h $(RES_FILE)h

area: $(AREA_REPORT)
2 changes: 1 addition & 1 deletion sboxes-compress/compress
Submodule compress updated 1 files
+5 −3 Makefile
27 changes: 27 additions & 0 deletions sboxes-compress/compress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -e
set -o pipefail
HASH_FILE=$(dirname $SBOX_FILE)/sbox_src_hash

SRC_FILE=./canright_aes_sbox_dual.v

EXPECTED_HASH=$({
echo $NSHARES &
git -C compress show-ref HEAD &
cat $SRC_FILE
} | sha256sum | cut -d ' ' -f 1)

if [ -f $HASH_FILE ] && [ -f $SBOX_FILE ]; then
OLD_HASH=$(cat $HASH_FILE)
else
OLD_HASH="OLDhashinvalid"
fi

if [ "$OLD_HASH" != "$EXPECTED_HASH" ]; then
echo "run compress"
make RES_FILE=$SBOX_FILE
echo $EXPECTED_HASH >$HASH_FILE
else
echo "COMPRESS sbox up-to-date, skipping."
fi

0 comments on commit d6e1fa9

Please sign in to comment.