AES simplification

This commit is contained in:
David Harris 2024-03-10 22:37:50 -07:00
parent 9a1fdba077
commit 3d72ccac60
5 changed files with 14 additions and 41 deletions

View File

@ -33,28 +33,13 @@ module aes32dsi(
);
logic [4:0] shamt;
logic [31:0] SboxIn32;
logic [7:0] SboxIn;
logic [7:0] SboxOut;
logic [31:0] so;
logic [31:0] sorotate;
// shamt = bs * 8
assign shamt = {bs, 3'b0};
// Shift rs2 right by shamt and take the lower byte
assign SboxIn32 = (rs2 >> shamt);
assign SboxIn = SboxIn32[7:0];
// Apply inverse sbox to si
aesinvsbox inv_sbox(SboxIn, SboxOut);
// Pad output of inverse substitution box
assign so = {24'h0, SboxOut};
// Rotate the substitution box output left by shamt (bs * 8)
assign sorotate = (so << shamt) | (so >> (32 - shamt));
// Set result to "X(rs1)[31..0] ^ rol32(so, unsigned(shamt));"
assign DataOut = rs1 ^ sorotate;
logic [7:0] SboxIn, SboxOut;
logic [31:0] so, sorotate;
assign shamt = {bs, 3'b0}; // shamt = bs * 8 (convert bytes to bits)
assign SboxIn = rs2[shamt +: 8]; // Shift rs2 right by shamt and take the lower byte
aesinvsbox inv_sbox(SboxIn, SboxOut); // Apply inverse sbox
assign so = {24'h0, SboxOut}; // Pad output of inverse substitution box
assign sorotate = (so << shamt) | (so >> (32 - shamt)); // Rotate the substitution box output left by shamt (bs * 8)
assign DataOut = rs1 ^ sorotate; // Set result to "X(rs1)[31..0] ^ rol32(so, unsigned(shamt));"
endmodule

View File

@ -33,7 +33,6 @@ module aes32dsmi(
);
logic [4:0] shamt;
logic [31:0] SboxIn32;
logic [7:0] SboxIn;
logic [7:0] SboxOut;
logic [31:0] so;
@ -44,8 +43,7 @@ module aes32dsmi(
assign shamt = {bs, 3'b0};
// Shift rs2 right by shamt and take the lower byte
assign SboxIn32 = (rs2 >> shamt);
assign SboxIn = SboxIn32[7:0];
assign SboxIn = rs2[shamt +: 8]; // Shift rs2 right by shamt and take the lower byte
// Apply inverse sbox to si
aesinvsbox inv_sbox(SboxIn, SboxOut);

View File

@ -33,7 +33,6 @@ module aes32esi(
);
logic [4:0] shamt;
logic [31:0] SboxIn32;
logic [7:0] SboxIn;
logic [7:0] SboxOut;
logic [31:0] so;
@ -42,11 +41,7 @@ module aes32esi(
// Shift bs by 3 to get shamt
assign shamt = {bs, 3'b0};
// Shift rs2 right by shamt to get sbox input
assign SboxIn32 = (rs2 >> shamt);
// Take the bottom byte as an input to the substitution box
assign SboxIn = SboxIn32[7:0];
assign SboxIn = rs2[shamt +: 8]; // Shift rs2 right by shamt and take the lower byte
// Substitute
aessbox subbox(SboxIn, SboxOut);

View File

@ -33,7 +33,6 @@ module aes32esmi(
);
logic [4:0] shamt;
logic [31:0] SboxIn32;
logic [7:0] SboxIn;
logic [7:0] SboxOut;
logic [31:0] so;
@ -43,12 +42,8 @@ module aes32esmi(
// Shift bs by 3 to get shamt
assign shamt = {bs, 3'b0};
// Shift rs2 right by shamt to get sbox input
assign SboxIn32 = (rs2 >> shamt);
// Take the bottom byte as an input to the substitution box
assign SboxIn = SboxIn32[7:0];
assign SboxIn = rs2[shamt +: 8]; // Shift rs2 right by shamt and take the lower byte
// Substitute
aessbox sbox(SboxIn, SboxOut);

View File

@ -34,6 +34,6 @@ module aes64ks2(
logic [31:0] w0, w1;
assign w0 = rs1[63:32] ^ rs2[31:0];
assign w1 = rs1[63:32] ^ rs2[31:0] ^ rs2[63:32];
assign w1 = w0 ^ rs2[63:32];
assign rd = {w1, w0};
endmodule