blob: c09b6190b272e2ec8e74ac6c442a049968c1c637 [file] [log] [blame]
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
package kmac_env_pkg;
// dep packages
import uvm_pkg::*;
import top_pkg::*;
import dv_utils_pkg::*;
import dv_lib_pkg::*;
import dv_base_reg_pkg::*;
import tl_agent_pkg::*;
import str_utils_pkg::*;
import test_vectors_pkg::*;
import digestpp_dpi_pkg::*;
import cip_base_pkg::*;
import csr_utils_pkg::*;
import push_pull_agent_pkg::*;
import keymgr_kmac_agent_pkg::*;
import kmac_ral_pkg::*;
import kmac_pkg::*;
import keymgr_pkg::*;
// macro includes
`include "uvm_macros.svh"
`include "dv_macros.svh"
// parameters
// max number of shares in design
parameter int KMAC_NUM_SHARES = 2;
parameter int KMAC_NUM_KEYS_PER_SHARE = 16;
parameter int KMAC_NUM_PREFIX_WORDS = 11;
// share1 of the 1600-bit KMAC state memory
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE0_BASE = 32'h400;
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE0_END = 32'h4C7;
// share2 of the 1600-bit KMAC state memory
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE1_BASE = 32'h500;
parameter bit [TL_AW-1:0] KMAC_STATE_SHARE1_END = 32'h5C7;
// base and end addresses of the KAMC message FIFO.
parameter bit [TL_AW-1:0] KMAC_FIFO_BASE = 32'h800;
parameter bit [TL_AW-1:0] KMAC_FIFO_END = 32'hFFC;
// width and depth of the msgfifo
parameter int KMAC_FIFO_DEPTH = kmac_pkg::MsgFifoDepth;
parameter int KMAC_FIFO_WIDTH = kmac_pkg::MsgWidth;
parameter int KMAC_FIFO_WORDS_PER_ENTRY = KMAC_FIFO_WIDTH / TL_DW;
parameter int KMAC_FIFO_BYTES_PER_ENTRY = KMAC_FIFO_WIDTH / 8;
parameter int KMAC_FIFO_NUM_WORDS = KMAC_FIFO_DEPTH * KMAC_FIFO_WORDS_PER_ENTRY;
parameter int KMAC_FIFO_NUM_BYTES = KMAC_FIFO_NUM_WORDS * 4;
// Represents the max bit-width of some value to be encoded with either
// `right_encode()` or `left_encode()`.
parameter int MAX_ENCODE_WIDTH = 2040;
/////////////////////////////
// Timing Model Parameters //
/////////////////////////////
// Will include information related to both the keccak datapath and the entropy system,
// as both directly relate to how many cycles a given hash operation will take
// Existing parameters:
//
// sha3_pkg::MsgWidth = 64 -> width of internal datapath
//
// sha3_pkg::StateW = 1600 -> represents width of Keccak state
// keccak datapath (lane) size
localparam int W = sha3_pkg::StateW / 25;
// log_2(W)
localparam int L = $clog2(W);
// number of rounds performed by keccak logic
parameter int KECCAK_NUM_ROUNDS = 12 + 2 * L;
parameter int ENTROPY_STORAGE_WIDTH = 320;
parameter int ENTROPY_LFSR_WIDTH = 64;
// After seeding lfsr, internal entropy_storage is filled up in 5 cycles,
// ENTROPY_LFSR_WIDTH bits per cycles
parameter int CYCLES_TO_FILL_ENTROPY = ENTROPY_STORAGE_WIDTH / ENTROPY_LFSR_WIDTH;
// TODO - this assumes entropy_fast_process is disabled, need to support this
//
// 7 cycles total: 5 cycles + 2 cycles (latch/consume entropy)
parameter int SW_ENTROPY_ROUND_CYCLES_NO_FAST = CYCLES_TO_FILL_ENTROPY + 2;
// interrupt types
typedef enum int {
KmacDone = 0,
KmacFifoEmpty = 1,
KmacErr = 2,
KmacNumIntrs = 3
} kmac_intr_e;
// CFG csr bit positions
typedef enum int {
KmacEn = 0,
KmacStrengthLSB = 1,
KmacStrengthMSB = 3,
KmacModeLSB = 4,
KmacModeMSB = 5, KmacMsgEndian = 8,
KmacStateEndian = 9,
KmacSideload = 12,
KmacEntropyModeLSB = 16,
KmacEntropyModeMSB = 17,
KmacFastEntropy = 19,
KmacEntropyReady = 24,
KmacErrProcessed = 25
} kmac_cfg_e;
// STATUS csr bit positions
typedef enum int {
KmacStatusSha3Idle = 0,
KmacStatusSha3Absorb = 1,
KmacStatusSha3Squeeze = 2,
KmacStatusFifoDepthLSB = 8,
KmacStatusFifoDepthMSB = 12,
KmacStatusFifoEmpty = 14,
KmacStatusFifoFull = 15
} kmac_status_e;
typedef virtual pins_if#(1) idle_vif;
typedef virtual kmac_sideload_if sideload_vif;
// Helper functions that returns the KMAC key size in bytes/words/blocks
function automatic int get_key_size_bytes(kmac_pkg::key_len_e len);
case (len)
Key128: return 16;
Key192: return 24;
Key256: return 32;
Key384: return 48;
Key512: return 64;
default: `uvm_fatal("kmac_env_pkg", $sformatf("%0s is an invalid key length", len.name()))
endcase
endfunction
function automatic int get_key_size_words(kmac_pkg::key_len_e len);
return (get_key_size_bytes(len) / 4);
endfunction
function automatic int get_key_size_blocks(kmac_pkg::key_len_e len);
return (get_key_size_words(len) / 2);
endfunction
// package sources
`include "kmac_env_cfg.sv"
`include "kmac_env_cov.sv"
`include "kmac_virtual_sequencer.sv"
`include "kmac_scoreboard.sv"
`include "kmac_env.sv"
`include "kmac_vseq_list.sv"
endpackage