From 87ed778763df95192063795287a735cb9f73f4a3 Mon Sep 17 00:00:00 2001 From: David Harris Date: Mon, 11 Mar 2024 00:45:38 -0700 Subject: [PATCH] Starting to merge decrypt and encrypt for AES64 --- src/ieu/bmu/bitmanipalu.sv | 10 ++++++++++ src/ieu/kmu/zkn64.sv | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/ieu/kmu/zkn64.sv diff --git a/src/ieu/bmu/bitmanipalu.sv b/src/ieu/bmu/bitmanipalu.sv index 39563b346..3d07dc498 100644 --- a/src/ieu/bmu/bitmanipalu.sv +++ b/src/ieu/bmu/bitmanipalu.sv @@ -112,6 +112,14 @@ module bitmanipalu import cvw::*; #(parameter cvw_t P) ( zbkx #(P.XLEN) ZBKX(.A(ABMU), .B(BBMU), .ZBKXSelect(ZBBSelect[2:0]), .ZBKXResult); end else assign ZBKXResult = 0; + // ZKND and ZKNE AES decryption and encryption + if (P.XLEN == 32) begin: zknde + 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)); + end else + if (P.ZKND_SUPPORTED | P.ZKNE_SUPPORTED) zkn64 ZKND64(.A(ABMU), .B(BBMU), .Funct7, .round(Rs2E[3:0]), .ZKNSelect(ZBBSelect[3:0]), .ZKNDResult, .ZKNEResult); // *** simplify to only one output + +/* // 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)); @@ -124,6 +132,8 @@ module bitmanipalu import cvw::*; #(parameter cvw_t P) ( 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)); diff --git a/src/ieu/kmu/zkn64.sv b/src/ieu/kmu/zkn64.sv new file mode 100644 index 000000000..1960bbaa8 --- /dev/null +++ b/src/ieu/kmu/zkn64.sv @@ -0,0 +1,39 @@ +/////////////////////////////////////////// +// zkn64.sv +// +// Written: kelvin.tran@okstate.edu, james.stine@okstate.edu +// Created: 27 November 2023 +// Modified: 31 January 2024 +// +// Purpose: NIST AES64 encryption and 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 zkn64 ( + input logic [63:0] A, B, + input logic [6:0] Funct7, + input logic [3:0] round, + input logic [3:0] ZKNSelect, + output logic [63:0] ZKNDResult, ZKNEResult +); + + zknd64 #(64) ZKND64(.A, .B, .Funct7, .round, .ZKNDSelect(ZKNSelect[3:0]), .ZKNDResult); // *** strip out parameter unneded + zkne64 #(64) ZKNE64(.A, .B, .Funct7, .round, .ZKNESelect(ZKNSelect[2:0]), .ZKNEResult); +endmodule