Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Versat, crypto software implementations and versat implementations as well. Added tests and they all pass #82

Merged
merged 24 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
374582f
Added Versat, working except contains a bug with first read by CPU of…
zettasticks Dec 20, 2023
368862b
AES256 and SHA working
zettasticks Dec 21, 2023
aed40c2
Merge branch 'master' of github.com:zettasticks/iob-soc-opencryptolinux
zettasticks Jan 22, 2024
daac59b
Merge branch 'master' of github.com:IOBundle/iob-soc-opencryptolinux
zettasticks Feb 2, 2024
7e1ef86
Updated versat
zettasticks Feb 5, 2024
1a46719
Added versat, remade linux with versat, updated submodules to match o…
zettasticks Feb 6, 2024
31589d6
Working in sim-run, only missing testing on FPGA
zettasticks Feb 6, 2024
e721be4
Added initial implementation of McEliece
zettasticks Feb 10, 2024
132e7e8
Save current impl, only giving an error around loop 570
zettasticks Feb 20, 2024
8605d90
Found bug, was cache problem, not good fix but saving what I have
zettasticks Feb 22, 2024
06dff57
Tests working, still need to do a reset + test to make sure everythin…
zettasticks Feb 23, 2024
8de697c
Updated versat
zettasticks Feb 23, 2024
1942780
All crypto tests passing and working on fpga
zettasticks Feb 26, 2024
a68ce5b
Merge remote-tracking branch 'other/master'
zettasticks Feb 26, 2024
9e0ecc1
Reverted some files to match upstream, removed versat tests from sim …
zettasticks Feb 26, 2024
abfc23b
Removed temporary testbench
zettasticks Feb 26, 2024
0d66b79
Update submodules to fix errors given by ghactions
zettasticks Feb 26, 2024
00ed586
Update versat to fix error in tools
zettasticks Feb 26, 2024
1a7ef25
Updated Versat, should fix error on CycloneV
zettasticks Feb 27, 2024
c45d031
Removed lines that where not supposed to get inserted in .mk file
zettasticks Feb 28, 2024
0b5f69d
Simple update on tests to make results easier to check
zettasticks Feb 28, 2024
54cb5be
Adding versat increased compile time so we need to bump up timeout fo…
zettasticks Feb 28, 2024
bb6604b
Added some extra explanation in tests, commit to run checks again
zettasticks Feb 28, 2024
fbe302a
Remove crypto side from sim, default.nix uses common LIB .nix
zettasticks Feb 29, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:

cyclonev:
runs-on: self-hosted
timeout-minutes: 60
timeout-minutes: 90
# run even if previous job failed
if: ${{ !cancelled() }}
# run after indicated job
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
[submodule "submodules/SPI"]
path = submodules/SPI
url = [email protected]:IObundle/iob-spi.git
[submodule "submodules/VERSAT"]
path = submodules/VERSAT
url = [email protected]:IObundle/iob-versat.git
[submodule "submodules/ETHERNET"]
path = submodules/ETHERNET
url = [email protected]:IObundle/iob-eth.git
1 change: 0 additions & 1 deletion default.nix
zettasticks marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

34 changes: 34 additions & 0 deletions default.nix
zettasticks marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ pkgs ? import (builtins.fetchTarball {
# Descriptive name to make the store path easier to identify
name = "nixos-22.11";
# Commit hash for nixos-22.11
url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.11.tar.gz";
# Hash obtained using `nix-prefetch-url --unpack <url>`
sha256 = "11w3wn2yjhaa5pv20gbfbirvjq6i3m7pqrq2msf0g7cv44vijwgw";
}) {}}:
pkgs.mkShell {
name = "iob-shell";
buildInputs = with pkgs; [
bash
gnumake
verilog
verilator
gtkwave
python3
python3Packages.black
python3Packages.parse
python3Packages.numpy
python3Packages.wavedrom
python3Packages.matplotlib
python3Packages.scipy
python3Packages.pyserial
(texlive.combine { inherit (texlive) scheme-medium multirow lipsum catchfile nowidow enumitem placeins xltabular ltablex titlesec makecell datetime fmtcount comment textpos csquotes amsmath cancel listings hyperref biblatex; })
(callPackage ./submodules/IOBSOC/submodules/LIB/scripts/riscv-gnu-toolchain.nix { })
(callPackage ./submodules/VERSAT/versat.nix { })
verible
black
llvmPackages_14.clangUseLLVM
librsvg
libreoffice
];
}
Binary file modified hardware/fpga/quartus/CYCLONEV-GT-DK/fw_jump.bin
Binary file not shown.
Binary file modified hardware/fpga/quartus/CYCLONEV-GT-DK/iob_soc.dtb
Binary file not shown.
7 changes: 4 additions & 3 deletions hardware/fpga/quartus/CYCLONEV-GT-DK/linux_build_macros.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
TIMER0_ADDR f2000000
UART0_ADDR f4000000
ETH0_ADDR f6000000
CLINT0_ADDR f8000000
PLIC0_ADDR fa000000
VERSAT0_ADDR f6000000
ETH0_ADDR f8000000
CLINT0_ADDR fa000000
PLIC0_ADDR fc000000
FREQ 50000000
BAUD 115200
Binary file modified hardware/fpga/vivado/AES-KU040-DB-G/fw_jump.bin
Binary file not shown.
Binary file modified hardware/fpga/vivado/AES-KU040-DB-G/iob_soc.dtb
Binary file not shown.
7 changes: 4 additions & 3 deletions hardware/fpga/vivado/AES-KU040-DB-G/linux_build_macros.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
TIMER0_ADDR f2000000
UART0_ADDR f4000000
ETH0_ADDR f6000000
CLINT0_ADDR f8000000
PLIC0_ADDR fa000000
VERSAT0_ADDR f6000000
ETH0_ADDR f8000000
CLINT0_ADDR fa000000
PLIC0_ADDR fc000000
FREQ 100000000
BAUD 115200
Binary file modified hardware/simulation/fw_jump.bin
Binary file not shown.
Binary file modified hardware/simulation/iob_soc.dtb
Binary file not shown.
7 changes: 4 additions & 3 deletions hardware/simulation/linux_build_macros.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
TIMER0_ADDR f2000000
UART0_ADDR f4000000
ETH0_ADDR f6000000
CLINT0_ADDR f8000000
PLIC0_ADDR fa000000
VERSAT0_ADDR f6000000
ETH0_ADDR f8000000
CLINT0_ADDR fa000000
PLIC0_ADDR fc000000
FREQ 100000000
BAUD 3000000
145 changes: 145 additions & 0 deletions hardware/src/units/xunitF.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
`timescale 1ns / 1ps

module xunitF #(
parameter DELAY_W = 32,
parameter DATA_W = 32
)
(
//control
input clk,
input rst,

input running,
input run,
output done,

//input / output data
input [DATA_W-1:0] in0,
input [DATA_W-1:0] in1,
input [DATA_W-1:0] in2,
input [DATA_W-1:0] in3,
input [DATA_W-1:0] in4,
input [DATA_W-1:0] in5,
input [DATA_W-1:0] in6,
input [DATA_W-1:0] in7,

input [DATA_W-1:0] in8,
input [DATA_W-1:0] in9,

(* versat_latency = 16 *) output [DATA_W-1:0] out0,
(* versat_latency = 16 *) output [DATA_W-1:0] out1,
(* versat_latency = 16 *) output [DATA_W-1:0] out2,
(* versat_latency = 16 *) output [DATA_W-1:0] out3,
(* versat_latency = 16 *) output [DATA_W-1:0] out4,
(* versat_latency = 16 *) output [DATA_W-1:0] out5,
(* versat_latency = 16 *) output [DATA_W-1:0] out6,
(* versat_latency = 16 *) output [DATA_W-1:0] out7,

//configurations
input [DELAY_W-1:0] delay0 // Encodes delay
);

reg [DELAY_W-1:0] delay;
reg [31:0] a,b,c,d,e,f,g,h;

assign out0 = a;
assign out1 = b;
assign out2 = c;
assign out3 = d;
assign out4 = e;
assign out5 = f;
assign out6 = g;
assign out7 = h;

assign done = (delay == 0);

wire [31:0] w = in8;
wire [31:0] k = in9;

function [31:0] ROTR_32(input [31:0] x,input [4:0] c);
begin
ROTR_32 = (((x) >> (c)) | ((x) << (32 - (c))));
end
endfunction

function [31:0] SHR(input [31:0] x,input [4:0] c);
begin
SHR = ((x) >> (c));
end
endfunction

function [31:0] Ch(input [31:0] x,y,z);
begin
Ch = (((x) & (y)) ^ (~(x) & (z)));
end
endfunction

function [31:0] Maj(input [31:0] x,y,z);
begin
Maj = (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)));
end
endfunction

function [31:0] Sigma0_32(input [31:0] x);
begin
Sigma0_32 = (ROTR_32(x, 2) ^ ROTR_32(x,13) ^ ROTR_32(x,22));
end
endfunction

function [31:0] Sigma1_32(input [31:0] x);
begin
Sigma1_32 = (ROTR_32(x, 6) ^ ROTR_32(x,11) ^ ROTR_32(x,25));
end
endfunction

wire [31:0] T1 = h + Sigma1_32(e) + Ch(e,f,g) + k + w;
wire [31:0] T2 = Sigma0_32(a) + Maj(a,b,c);

wire [31:0] T1_init = in7 + Sigma1_32(in4) + Ch(in4,in5,in6) + k + w;
wire [31:0] T2_init = Sigma0_32(in0) + Maj(in0,in1,in2);

reg working;

always @(posedge clk,posedge rst)
begin
if(rst) begin
delay <= 0;
working <= 0;
a <= 0;
b <= 0;
c <= 0;
d <= 0;
e <= 0;
f <= 0;
g <= 0;
h <= 0;
end else if(run) begin
delay <= delay0;
working <= 0;
end else if(!working) begin
if(delay == 0) begin
a <= T1_init + T2_init;
b <= in0;
c <= in1;
d <= in2;
e <= in3 + T1_init;
f <= in4;
g <= in5;
h <= in6;
working <= 1'b1;
end else begin
delay <= delay - 1;
end
end else begin
a <= T1 + T2;
b <= a;
c <= b;
d <= c;
e <= d + T1;
f <= e;
g <= f;
h <= g;
end
end

endmodule
108 changes: 108 additions & 0 deletions hardware/src/units/xunitM.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
`timescale 1ns / 1ps

module xunitM #(
parameter DELAY_W = 32,
parameter DATA_W = 32
)
(
//control
input clk,
input rst,

input running,
input run,
output done,

//input / output data
input [DATA_W-1:0] in0,

(* versat_latency = 17 *) output reg [DATA_W-1:0] out0,

//configurations
input [DELAY_W-1:0] delay0 // Encodes delay
);

assign done = 1'b1;

reg [DELAY_W-1:0] delay;
reg [4:0] latency;
reg [31:0] w[15:0];

// Extract from array to view on gtkwave
wire [31:0] w0 = w[0];
wire [31:0] w1 = w[1];
wire [31:0] w2 = w[2];
wire [31:0] w3 = w[3];
wire [31:0] w4 = w[4];
wire [31:0] w5 = w[5];
wire [31:0] w6 = w[6];
wire [31:0] w7 = w[7];
wire [31:0] w8 = w[8];
wire [31:0] w9 = w[9];
wire [31:0] w10 = w[10];
wire [31:0] w11 = w[11];
wire [31:0] w12 = w[12];
wire [31:0] w13 = w[13];
wire [31:0] w14 = w[14];
wire [31:0] w15 = w[15];

function [31:0] ROTR_32(input [31:0] x,input [4:0] c);
begin
ROTR_32 = (((x) >> (c)) | ((x) << (32 - (c))));
end
endfunction

function [31:0] SHR(input [31:0] x,input [4:0] c);
begin
SHR = ((x) >> (c));
end
endfunction

function [31:0] sigma0_32(input [31:0] x);
begin
sigma0_32 = (ROTR_32(x, 7) ^ ROTR_32(x,18) ^ SHR(x, 3));
end
endfunction

function [31:0] sigma1_32(input [31:0] x);
begin
sigma1_32 = (ROTR_32(x,17) ^ ROTR_32(x,19) ^ SHR(x,10));
end
endfunction

wire [31:0] val = (sigma1_32(w[14]) + (w[9]) + sigma0_32(w[1]) + (w[0]));

integer i;
always @(posedge clk,posedge rst)
begin
if(rst) begin
delay <= 0;
for(i = 0; i < 16; i = i + 1)
w[i] <= 0;
end else if(run) begin
delay <= delay0; // wait delay0 cycles for valid input data
latency <= 5'h11; // cycles from valid input to valid output
end else if (|delay) begin
delay <= delay - 1;
end else begin
if(|latency) begin
latency <= latency - 1;
end

out0 <= w[0];

for(i = 0; i < 15; i = i + 1) begin
w[i] <= w[i+1];
end

if(latency[4:1] != 0) begin // latency > 1
w[15] <= in0;
end else begin
w[15] <= val;
end

out0 <= val;
end
end

endmodule
Loading
Loading