From 7cb170c19baaae96498a7de1723e834a92357fd2 Mon Sep 17 00:00:00 2001 From: "James E. Stine" Date: Wed, 21 Feb 2024 17:12:50 -0600 Subject: [PATCH] update on aes_instructions --- src/ieu/aes_instructions/aes32esi.sv | 18 ++++++++++++------ src/ieu/aes_instructions/aes32esmi.sv | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/ieu/aes_instructions/aes32esi.sv b/src/ieu/aes_instructions/aes32esi.sv index 2281c6f4e..5ef354291 100644 --- a/src/ieu/aes_instructions/aes32esi.sv +++ b/src/ieu/aes_instructions/aes32esi.sv @@ -39,17 +39,23 @@ module aes32esi(input logic [1:0] bs, logic [31:0] so_rotate; // Shift bs by 3 to get shamt - assign shamt = {bs, 3'b0}; + assign shamt = {bs, 3'b0}; + // Shift rs2 right by shamt to get sbox input - assign sbox_in_32 = (rs2 >> shamt); + assign sbox_in_32 = (rs2 >> shamt); + // Take the bottom byte as an input to the substitution box - assign sbox_in = sbox_in_32[7:0]; + assign sbox_in = sbox_in_32[7:0]; + // Substitute - aes_sbox subbox(.in(sbox_in),.out(sbox_out)); + aes_sbox subbox(.in(sbox_in),.out(sbox_out)); + // Pad sbox output - assign so = {24'h000000,sbox_out}; + assign so = {24'h000000,sbox_out}; + // Rotate so left by shamt - rotate_left rol32(.input_data(so),.shamt(shamt),.rot_data(so_rotate)); + rotate_left rol32(.input_data(so),.shamt(shamt),.rot_data(so_rotate)); + // Set result X(rs1)[31..0] ^ rol32(so, unsigned(shamt)); assign data_out = rs1 ^ so_rotate; diff --git a/src/ieu/aes_instructions/aes32esmi.sv b/src/ieu/aes_instructions/aes32esmi.sv index 382c1da5d..840a7f756 100644 --- a/src/ieu/aes_instructions/aes32esmi.sv +++ b/src/ieu/aes_instructions/aes32esmi.sv @@ -40,19 +40,26 @@ module aes32esmi(input logic [1:0] bs, logic [31:0] mixed_rotate; // Shift bs by 3 to get shamt - assign shamt = {bs, 3'b0}; + assign shamt = {bs, 3'b0}; + // Shift rs2 right by shamt to get sbox input - assign sbox_in_32 = (rs2 >> shamt); + assign sbox_in_32 = (rs2 >> shamt); + // Take the bottom byte as an input to the substitution box - assign sbox_in = sbox_in_32[7:0]; + assign sbox_in = sbox_in_32[7:0]; + // Substitute - aes_sbox sbox(.in(sbox_in),.out(sbox_out)); + aes_sbox sbox(.in(sbox_in),.out(sbox_out)); + // Pad sbox output - assign so = {24'h000000,sbox_out}; + assign so = {24'h000000,sbox_out}; + // Mix Word using aes_mixword component mixword mwd(.word(so),.mixed_word(mixed)); + // Rotate so left by shamt - rotate_left rol32(.input_data(mixed),.shamt(shamt),.rot_data(mixed_rotate)); + rotate_left rol32(.input_data(mixed),.shamt(shamt),.rot_data(mixed_rotate)); + // Set result X(rs1)[31..0] ^ rol32(mixed, unsigned(shamt)); assign data_out = rs1 ^ mixed_rotate;