mirror of
https://github.com/openhwgroup/cvw
synced 2025-01-24 21:44:29 +00:00
AES64 simplification
This commit is contained in:
parent
64d7f778da
commit
b7f5ce6ed3
@ -51,9 +51,8 @@ module bitmanipalu import cvw::*; #(parameter cvw_t P) (
|
||||
logic [P.XLEN-1:0] ZBKBResult; // ZBKB Result
|
||||
logic [P.XLEN-1:0] ZBKCResult; // ZBKC Result
|
||||
logic [P.XLEN-1:0] ZBKXResult; // ZBKX Result
|
||||
logic [P.XLEN-1:0] ZKNDResult; // ZKND Result
|
||||
logic [P.XLEN-1:0] ZKNEResult; // ZKNE Result
|
||||
logic [P.XLEN-1:0] ZKNHResult; // ZKNH Result
|
||||
logic [P.XLEN-1:0] ZKNResult; // ZKNE or ZKND Result
|
||||
logic [P.XLEN-1:0] MaskB; // BitMask of B
|
||||
logic [P.XLEN-1:0] RevA; // Bit-reversed A
|
||||
logic Mask; // Indicates if it is ZBS instruction
|
||||
@ -114,29 +113,23 @@ module bitmanipalu import cvw::*; #(parameter cvw_t P) (
|
||||
|
||||
// ZKND and ZKNE AES decryption and encryption
|
||||
if (P.XLEN == 32) begin: zknde
|
||||
logic [P.XLEN-1:0] ZKNEResult; // ZKNE Result
|
||||
logic [P.XLEN-1:0] ZKNDResult; // ZKND Result
|
||||
|
||||
if (P.ZKND_SUPPORTED) aes32d aes32d(.bs(Funct7[6:5]), .rs1(ABMU), .rs2(BBMU), .finalround(ZBBSelect[2]), .result(ZKNDResult));
|
||||
if (P.ZKNE_SUPPORTED) aes32e aes32e(.bs(Funct7[6:5]), .rs1(ABMU), .rs2(BBMU), .finalround(ZBBSelect[2]), .result(ZKNEResult));
|
||||
// Select result if both decrypt and encrypt are supported
|
||||
if (P.ZKND_SUPPORTED & P.ZKNE_SUPPORTED)
|
||||
mux2 #(32) zknmux(ZKNDResult, ZKNEResult, ZBBSelect[0], ZKNResult);
|
||||
else if (P.ZKND_SUPPORTED)
|
||||
assign ZKNResult = ZKNDResult;
|
||||
else
|
||||
assign ZKNResult = ZKNEResult;
|
||||
end else
|
||||
if (P.ZKND_SUPPORTED | P.ZKNE_SUPPORTED) begin
|
||||
zkn64 #(P) ZKN64(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNSelect(ZBBSelect[3:0]), .ZKNResult(ZKNDResult));
|
||||
assign ZKNEResult = ZKNDResult;
|
||||
zknde64 #(P) ZKN64(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNSelect(ZBBSelect[3:0]), .ZKNResult);
|
||||
end
|
||||
|
||||
/*
|
||||
// ZKND Unit
|
||||
if (P.ZKND_SUPPORTED) begin: zknd
|
||||
if (P.XLEN == 32) aes32d aes32d(.bs(Funct7[6:5]), .rs1(ABMU), .rs2(BBMU), .finalround(ZBBSelect[2]), .result(ZKNDResult));
|
||||
else zknd64 #(P.XLEN) ZKND64(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNDSelect(ZBBSelect[3:0]), .ZKNDResult);
|
||||
end else assign ZKNDResult = 0;
|
||||
|
||||
// ZKNE Unit
|
||||
if (P.ZKNE_SUPPORTED) begin: zkne
|
||||
if (P.XLEN == 32) aes32e aes32e(.bs(Funct7[6:5]), .rs1(ABMU), .rs2(BBMU), .finalround(ZBBSelect[2]), .result(ZKNEResult));
|
||||
else zkne64 #(P.XLEN) ZKNE64(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNESelect(ZBBSelect[2:0]), .ZKNEResult);
|
||||
end else assign ZKNEResult = 0;
|
||||
|
||||
*/
|
||||
|
||||
// ZKNH Unit
|
||||
if (P.ZKNH_SUPPORTED) begin: zknh
|
||||
if (P.XLEN == 32) zknh32 ZKNH32(.A(ABMU), .B(BBMU), .ZKNHSelect(ZBBSelect), .ZKNHResult(ZKNHResult));
|
||||
@ -154,8 +147,8 @@ module bitmanipalu import cvw::*; #(parameter cvw_t P) (
|
||||
4'b0011: ALUResult = ZBCResult;
|
||||
4'b0100: ALUResult = ZBKBResult;
|
||||
4'b0110: ALUResult = ZBKXResult;
|
||||
4'b0111: ALUResult = ZKNDResult;
|
||||
4'b1000: ALUResult = ZKNEResult;
|
||||
4'b0111: ALUResult = ZKNResult;
|
||||
4'b1000: ALUResult = ZKNResult;
|
||||
4'b1001: ALUResult = ZKNHResult;
|
||||
default: ALUResult = PreALUResult;
|
||||
endcase
|
||||
|
@ -230,8 +230,8 @@ module bmuctrl import cvw::*; #(parameter cvw_t P) (
|
||||
if (P.ZKNE_SUPPORTED) begin //ZKNE
|
||||
if (P.XLEN==32)
|
||||
casez({OpD, Funct7D, Funct3D})
|
||||
17'b0110011_??10001_000: BMUControlsD = `BMUCTRLW'b000_1000_0100_1_0_0_1_0_0_0_0_0; // aes32esi - final round encrypt
|
||||
17'b0110011_??10011_000: BMUControlsD = `BMUCTRLW'b000_1000_0000_1_0_0_1_0_0_0_0_0; // aes32esmi - mid round encrypt
|
||||
17'b0110011_??10001_000: BMUControlsD = `BMUCTRLW'b000_1000_0101_1_0_0_1_0_0_0_0_0; // aes32esi - final round encrypt
|
||||
17'b0110011_??10011_000: BMUControlsD = `BMUCTRLW'b000_1000_0001_1_0_0_1_0_0_0_0_0; // aes32esmi - mid round encrypt
|
||||
endcase
|
||||
else if (P.XLEN==64)
|
||||
casez({OpD, Funct7D, Funct3D})
|
||||
|
@ -1,45 +0,0 @@
|
||||
///////////////////////////////////////////
|
||||
// zknd64.sv
|
||||
//
|
||||
// Written: kelvin.tran@okstate.edu, james.stine@okstate.edu
|
||||
// Created: 27 November 2023
|
||||
// Modified: 31 January 2024
|
||||
//
|
||||
// Purpose: RISC-V ZKND top level unit for 64-bit instructions: RV64 NIST AES Decryption
|
||||
//
|
||||
// A component of the CORE-V-WALLY configurable RISC-V project.
|
||||
// https://github.com/openhwgroup/cvw
|
||||
//
|
||||
// Copyright (C) 2021-24 Harvey Mudd College & Oklahoma State University
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
||||
//
|
||||
// Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file
|
||||
// except in compliance with the License, or, at your option, the Apache License version 2.0. You
|
||||
// may obtain a copy of the License at
|
||||
//
|
||||
// https://solderpad.org/licenses/SHL-2.1/
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, any work distributed under the
|
||||
// License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
// either express or implied. See the License for the specific language governing permissions
|
||||
// and limitations under the License.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
module zknd64 #(parameter WIDTH=32) (
|
||||
input logic [WIDTH-1:0] A, B,
|
||||
input logic [6:0] Funct7,
|
||||
input logic [3:0] round,
|
||||
input logic [3:0] ZKNDSelect,
|
||||
output logic [WIDTH-1:0] ZKNDResult
|
||||
);
|
||||
|
||||
logic [63:0] aes64dRes, aes64imRes, aes64ks1iRes, aes64ks2Res;
|
||||
|
||||
// RV64
|
||||
aes64d aes64d(.rs1(A), .rs2(B), .finalround(ZKNDSelect[2]), .aes64im(ZKNDSelect[3]), .result(aes64dRes)); // decode AES
|
||||
aes64ks1i aes64ks1i(.round, .rs1(A), .result(aes64ks1iRes));
|
||||
aes64ks2 aes64ks2(.rs2(B), .rs1(A), .result(aes64ks2Res));
|
||||
|
||||
mux3 #(WIDTH) zkndmux(aes64dRes, aes64ks1iRes, aes64ks2Res, ZKNDSelect[1:0], ZKNDResult);
|
||||
endmodule
|
@ -1,11 +1,11 @@
|
||||
///////////////////////////////////////////
|
||||
// zkn64.sv
|
||||
// zknde64.sv
|
||||
//
|
||||
// Written: kelvin.tran@okstate.edu, james.stine@okstate.edu
|
||||
// Created: 27 November 2023
|
||||
// Modified: 31 January 2024
|
||||
//
|
||||
// Purpose: NIST AES64 encryption and decryption
|
||||
// Purpose: NIST AES64 decryption and encryption
|
||||
//
|
||||
// A component of the CORE-V-WALLY configurable RISC-V project.
|
||||
// https://github.com/openhwgroup/cvw
|
||||
@ -26,7 +26,7 @@
|
||||
// and limitations under the License.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
module zkn64 import cvw::*; #(parameter cvw_t P) (
|
||||
module zknde64 import cvw::*; #(parameter cvw_t P) (
|
||||
input logic [63:0] A, B,
|
||||
input logic [6:0] Funct7,
|
||||
input logic [3:0] round,
|
@ -1,46 +0,0 @@
|
||||
///////////////////////////////////////////
|
||||
// zkne64.sv
|
||||
//
|
||||
// Written: kelvin.tran@okstate.edu, james.stine@okstate.edu
|
||||
// Created: 21 November 2023
|
||||
// Modified: 31 January 2024
|
||||
//
|
||||
// Purpose: RISC-V ZKNE top level unit for 64-bit instructions: RV64 NIST AES Encryption
|
||||
//
|
||||
// A component of the CORE-V-WALLY configurable RISC-V project.
|
||||
// https://github.com/openhwgroup/cvw
|
||||
//
|
||||
// Copyright (C) 2021-24 Harvey Mudd College & Oklahoma State University
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
||||
//
|
||||
// Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file
|
||||
// except in compliance with the License, or, at your option, the Apache License version 2.0. You
|
||||
// may obtain a copy of the License at
|
||||
//
|
||||
// https://solderpad.org/licenses/SHL-2.1/
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, any work distributed under the
|
||||
// License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
// either express or implied. See the License for the specific language governing permissions
|
||||
// and limitations under the License.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
module zkne64 #(parameter WIDTH=32) (
|
||||
input logic [WIDTH-1:0] A, B,
|
||||
input logic [6:0] Funct7,
|
||||
input logic [3:0] round,
|
||||
input logic [2:0] ZKNESelect,
|
||||
output logic [WIDTH-1:0] ZKNEResult
|
||||
);
|
||||
|
||||
logic [63:0] aes64eRes, aes64ks1iRes, aes64ks2Res;
|
||||
|
||||
// RV64
|
||||
aes64e aes64e(.rs1(A), .rs2(B), .finalround(ZKNESelect[2]), .result(aes64eRes));
|
||||
aes64ks1i aes64ks1i(.round, .rs1(A), .result(aes64ks1iRes));
|
||||
aes64ks2 aes64ks2(.rs2(B), .rs1(A), .result(aes64ks2Res));
|
||||
|
||||
// 010 is a placeholder to match the select of ZKND's AES64KS1I since they share some instruction
|
||||
mux3 #(WIDTH) zknemux(aes64eRes, aes64ks1iRes, aes64ks2Res, ZKNESelect[1:0], ZKNEResult);
|
||||
endmodule
|
Loading…
Reference in New Issue
Block a user