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

Crypto Hardware Formatting and Simplification #663

Merged
merged 32 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2c6588d
Timinig optimization for radix 4 division, added missing derived config
davidharrishmc Mar 6, 2024
eb87a4a
UM comments in fdivsqrtotfc
davidharrishmc Mar 6, 2024
93455e8
Added arch64i tests for fp configs
davidharrishmc Mar 11, 2024
39ca709
Merged AES changes
davidharrishmc Mar 11, 2024
34058dd
Crypto formatting cleanup
davidharrishmc Mar 11, 2024
e4724b8
Crypto formatting cleanup
davidharrishmc Mar 11, 2024
ea6846f
Crypto commenting cleanup
davidharrishmc Mar 11, 2024
955c131
Crypto rename inputs and outputs to a and y
davidharrishmc Mar 11, 2024
d0dd308
ZK simplification
davidharrishmc Mar 11, 2024
837abf1
ZK simplifcations
davidharrishmc Mar 11, 2024
2580d37
ZK cleanup, check no LLEN > XLEN without D$, add half and quad float …
davidharrishmc Mar 11, 2024
9a1fdba
Added more Zbkb tests shared with Zbb
davidharrishmc Mar 11, 2024
3d72cca
AES simplification
davidharrishmc Mar 11, 2024
f72e504
Defined rotate module and formatted AES modules more densely
davidharrishmc Mar 11, 2024
f950067
Shared middle and final round aes32 to cut size 50%
davidharrishmc Mar 11, 2024
b53e873
shared hardware for AES 64 decode
davidharrishmc Mar 11, 2024
d22306a
Shared haredware for aes64e
davidharrishmc Mar 11, 2024
7ee3145
Simplified muxing for AES64
davidharrishmc Mar 11, 2024
5257d3d
AES64 cleanup
davidharrishmc Mar 11, 2024
ef89679
Optimized out aes64im hardware; sharing with aes64d
davidharrishmc Mar 11, 2024
87ed778
Starting to merge decrypt and encrypt for AES64
davidharrishmc Mar 11, 2024
7d87c4f
AES64 simplification
davidharrishmc Mar 11, 2024
64d7f77
AES64 simplification
davidharrishmc Mar 11, 2024
b7f5ce6
AES64 simplification
davidharrishmc Mar 11, 2024
39c0d0c
AES64 simplification
davidharrishmc Mar 11, 2024
10d1ff6
Merged ZKNDEResult into a single BMU result mux input
davidharrishmc Mar 11, 2024
a714904
Simplifying AES32 logic
davidharrishmc Mar 11, 2024
8af25a4
AES32 sharing logic
davidharrishmc Mar 11, 2024
096f409
Final cleanup tonight
davidharrishmc Mar 11, 2024
019458a
Shared sbox between aes64ks1i and aes64e
davidharrishmc Mar 11, 2024
dbfe44a
Renamed aes and sha directories
davidharrishmc Mar 11, 2024
7132d30
Simplified ZKNH64
davidharrishmc Mar 11, 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
Prev Previous commit
Next Next commit
Shared sbox between aes64ks1i and aes64e
davidharrishmc committed Mar 11, 2024
commit 019458a63d3b6623c1ea6c72925b5acb840a6e3f
11 changes: 8 additions & 3 deletions src/ieu/aes_instructions/aes64e.sv
Original file line number Diff line number Diff line change
@@ -29,18 +29,23 @@ module aes64e(
input logic [63:0] rs1,
input logic [63:0] rs2,
input logic finalround,
input logic [31:0] Sbox0Out,
output logic [31:0] SboxEIn,
output logic [63:0] result
);

logic [127:0] ShiftRowOut;
logic [63:0] SboxOut, MixcolOut;

// AES shiftrow unit
aesshiftrow srow({rs2,rs1}, ShiftRowOut);

// Apply substitution box to 2 lower words
aessboxword sbox0(ShiftRowOut[31:0], SboxOut[31:0]);
aessboxword sbox1(ShiftRowOut[63:32], SboxOut[63:32]);
// Use the shared sbox in zknde64.sv for the first sbox
assign SboxEIn = ShiftRowOut[31:0];
assign SboxOut[31:0] = Sbox0Out;

aessboxword sbox1(ShiftRowOut[63:32], SboxOut[63:32]); // instantiate second sbox

// Apply mix columns operations
aesmixcolumns mw0(SboxOut[31:0], MixcolOut[31:0]);
15 changes: 10 additions & 5 deletions src/ieu/aes_instructions/aes64ks1i.sv
Original file line number Diff line number Diff line change
@@ -28,20 +28,25 @@
module aes64ks1i(
input logic [3:0] round,
input logic [63:0] rs1,
input logic [31:0] Sbox0Out,
output logic [31:0] SboxKIn,
output logic [63:0] result
);

logic finalround;
logic [7:0] rcon8;
logic [31:0] rcon, rs1Rotate, tmp2, SboxOut;
logic [31:0] rcon, rs1Rotate;

rconlut128 rc(round, rcon8); // Get rcon value from lookup table
assign rcon = {24'b0, rcon8}; // Zero-pad RCON
assign rs1Rotate = {rs1[39:32], rs1[63:40]}; // Get rotated value fo ruse in tmp2
assign finalround = (round == 4'b1010); // round 10 is the last one
assign tmp2 = finalround ? rs1[63:32] : rs1Rotate; // Don't rotate on the last round
aessboxword sbox(tmp2, SboxOut); // Substitute bytes of value obtained for tmp2 using Rijndael sbox
assign result[31:0] = SboxOut ^ rcon;
assign result[63:32] = SboxOut ^ rcon;
assign SboxKIn = finalround ? rs1[63:32] : rs1Rotate; // Don't rotate on the last round

// Share sbox with encryption in zknde64. This module just sends value to shared sbox and gets result back
// send out value as SboxKIn, get back subsittuted result as Sbox0Out

assign result[31:0] = Sbox0Out ^ rcon;
assign result[63:32] = Sbox0Out ^ rcon;
endmodule

9 changes: 7 additions & 2 deletions src/ieu/kmu/zknde64.sv
Original file line number Diff line number Diff line change
@@ -35,14 +35,19 @@ module zknde64 import cvw::*; #(parameter cvw_t P) (
);

logic [63:0] aes64dRes, aes64eRes, aes64ks1iRes, aes64ks2Res;
logic [31:0] SboxEIn, SboxKIn, Sbox0In, Sbox0Out;

if (P.ZKND_SUPPORTED) // ZKND supports aes64ds, aes64dsm, aes64im
aes64d aes64d(.rs1(A), .rs2(B), .finalround(ZKNSelect[2]), .aes64im(ZKNSelect[3]), .result(aes64dRes)); // decode AES
if (P.ZKNE_SUPPORTED) // ZKNE supports aes64es, aes64esm
aes64e aes64e(.rs1(A), .rs2(B), .finalround(ZKNSelect[2]), .result(aes64eRes));
aes64e aes64e(.rs1(A), .rs2(B), .finalround(ZKNSelect[2]), .Sbox0Out, .SboxEIn, .result(aes64eRes));

// One S Box is always needed for aes64ks1i and is also needed for aes64e if that is supported. Put it at the top level to allow sharing
mux2 #(32) sboxmux(SboxEIn, SboxKIn, ZKNSelect[1], Sbox0In);
aessboxword sbox(Sbox0In, Sbox0Out); // Substitute bytes of value obtained for tmp2 using Rijndael sbox

// Both ZKND and ZKNE support aes64ks1i and aes64ks2 instructions
aes64ks1i aes64ks1i(.round, .rs1(A), .result(aes64ks1iRes));
aes64ks1i aes64ks1i(.round, .rs1(A), .Sbox0Out, .SboxKIn, .result(aes64ks1iRes));
aes64ks2 aes64ks2(.rs2(B), .rs1(A), .result(aes64ks2Res));

// Choose among decrypt, encrypt, key schedule 1, key schedule 2 results