diff --git a/src/ieu/bmu/bitmanipalu.sv b/src/ieu/bmu/bitmanipalu.sv index dde42d5d4..244a5b446 100644 --- a/src/ieu/bmu/bitmanipalu.sv +++ b/src/ieu/bmu/bitmanipalu.sv @@ -112,24 +112,10 @@ module bitmanipalu import cvw::*; #(parameter cvw_t P) ( end else assign ZBKXResult = 0; // 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], ZKNDEResult); - else if (P.ZKND_SUPPORTED) - assign ZKNDEResult = ZKNDResult; - else - assign ZKNDEResult = ZKNEResult; - end else - if (P.ZKND_SUPPORTED | P.ZKNE_SUPPORTED) begin - zknde64 #(P) ZKN64(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNSelect(ZBBSelect[3:0]), .ZKNDEResult); - end - + if (P.ZKND_SUPPORTED | P.ZKNE_SUPPORTED) + if (P.XLEN == 32) zknde32 #(P) ZKN32(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNSelect(ZBBSelect[3:0]), .ZKNDEResult); + else zknde64 #(P) ZKN64(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNSelect(ZBBSelect[3:0]), .ZKNDEResult); + // ZKNH Unit if (P.ZKNH_SUPPORTED) begin: zknh if (P.XLEN == 32) zknh32 ZKNH32(.A(ABMU), .B(BBMU), .ZKNHSelect(ZBBSelect), .ZKNHResult(ZKNHResult)); diff --git a/src/ieu/kmu/zknde32.sv b/src/ieu/kmu/zknde32.sv new file mode 100644 index 000000000..32eed01ac --- /dev/null +++ b/src/ieu/kmu/zknde32.sv @@ -0,0 +1,49 @@ +/////////////////////////////////////////// +// zknde32.sv +// +// Written: kelvin.tran@okstate.edu, james.stine@okstate.edu +// Created: 27 November 2023 +// Modified: 31 January 2024 +// +// Purpose: NIST AES64 decryption and 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 zknde32 import cvw::*; #(parameter cvw_t P) ( + input logic [31:0] A, B, + input logic [6:0] Funct7, + input logic [3:0] round, + input logic [3:0] ZKNSelect, + output logic [31:0] ZKNDEResult +); + + logic [31:0] ZKNEResult, ZKNDResult; + + if (P.ZKND_SUPPORTED) aes32d aes32d(.bs(Funct7[6:5]), .rs1(A), .rs2(B), .finalround(ZKNSelect[2]), .result(ZKNDResult)); + if (P.ZKNE_SUPPORTED) aes32e aes32e(.bs(Funct7[6:5]), .rs1(A), .rs2(B), .finalround(ZKNSelect[2]), .result(ZKNEResult)); + + // Mux result if both decrypt and encrypt are supported; otherwise, choose the only result + if (P.ZKND_SUPPORTED & P.ZKNE_SUPPORTED) + mux2 #(32) zknmux(ZKNDResult, ZKNEResult, ZKNSelect[0], ZKNDEResult); + else if (P.ZKND_SUPPORTED) + assign ZKNDEResult = ZKNDResult; + else + assign ZKNDEResult = ZKNEResult; +endmodule