aboutsummaryrefslogtreecommitdiff
path: root/src/rtl
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2018-09-25 15:08:30 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2018-09-25 15:08:30 +0200
commitaa31953d8789a7349970809955ee3a2f0ab78177 (patch)
treee3da96ab02a7c9c052a0492eae97d2c1664cf935 /src/rtl
parentd3e94a0efeec9b2cbac41eea9a57dc3eaf848b21 (diff)
Added logic to perform status word read operation from the mkm. Adding interfaces and registers to be able to pass mkm status to host. Updated dut instantiation in core testbench to.
Diffstat (limited to 'src/rtl')
-rw-r--r--src/rtl/keywrap.v12
-rw-r--r--src/rtl/keywrap_core.v65
2 files changed, 69 insertions, 8 deletions
diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v
index 829ddd1..cc6f8ac 100644
--- a/src/rtl/keywrap.v
+++ b/src/rtl/keywrap.v
@@ -152,6 +152,9 @@ module keywrap #(parameter ADDR_BITS = 13)
reg [31 : 0] key_reg [0 : 7];
reg key_we;
+ reg [31 : 0] mstatus_reg;
+ reg mstatus_we;
+
reg [31 : 0] api_rd_delay_reg;
reg [31 : 0] api_rd_delay_new;
@@ -218,6 +221,7 @@ module keywrap #(parameter ADDR_BITS = 13)
.key(core_key),
.keylen(keylen_reg),
+ .status(mstatus_reg),
.mkey(core_mkey),
.mstatus(core_mstatus),
@@ -250,6 +254,7 @@ module keywrap #(parameter ADDR_BITS = 13)
mkey_mstatus_reg <= 1'h0;
encdec_reg <= 1'h0;
keylen_reg <= 1'h0;
+ mstatus_reg <= 32'h0;
rlen_reg <= {RLEN_BITS{1'h0}};
valid_reg <= 1'h0;
ready_reg <= 1'h0;
@@ -284,6 +289,9 @@ module keywrap #(parameter ADDR_BITS = 13)
if (a1_we)
a1_reg <= write_data;
+ if (mstatus_we)
+ mstatus_reg <= write_data;
+
if (key_we)
key_reg[address[2 : 0]] <= write_data;
end
@@ -307,6 +315,7 @@ module keywrap #(parameter ADDR_BITS = 13)
core_api_we = 1'h0;
a0_we = 1'h0;
a1_we = 1'h0;
+ mstatus_we = 1'h0;
tmp_read_data = 32'h0;
tmp_error = 1'h0;
api_rd_delay_new = 32'h0;
@@ -342,6 +351,9 @@ module keywrap #(parameter ADDR_BITS = 13)
if (address == {{PAD{1'h0}}, ADDR_A1})
a1_we = 1'h1;
+ if (address == {{PAD{1'h0}}, ADDR_MSTATUS})
+ mstatus_we = 1'h1;
+
if ((address >= {{PAD{1'h0}}, ADDR_KEY0}) &&
(address <= {{PAD{1'h0}}, ADDR_KEY7}))
key_we = 1'h1;
diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v
index 8688e31..00e8391 100644
--- a/src/rtl/keywrap_core.v
+++ b/src/rtl/keywrap_core.v
@@ -61,9 +61,9 @@ module keywrap_core #(parameter MEM_BITS = 11)
output wire valid,
input wire [(MEM_BITS - 2) : 0] rlen,
-
input wire [255 : 0] key,
input wire keylen,
+ input wire [31 : 0] status,
output wire [255 : 0] mkey,
output wire [31 : 0] mstatus,
@@ -95,9 +95,13 @@ module keywrap_core #(parameter MEM_BITS = 11)
localparam CTRL_NEXT_FINALIZE = 6'ha;
localparam CTRL_MKM_RD_START = 6'h10;
- localparam CTRL_MKM_RD_END = 6'h11;
+ localparam CTRL_MKM_RD_WAIT0 = 6'h11;
+ localparam CTRL_MKM_RD_STATUS = 6'h12;
+ localparam CTRL_MKM_RD_END = 6'h13;
+
localparam CTRL_MKM_WR_START = 6'h18;
- localparam CTRL_MKM_WR_END = 6'h19;
+ localparam CTRL_MKM_WR_WAIT0 = 6'h19;
+ localparam CTRL_MKM_WR_END = 6'h1a;
// API for mkm used by the core.
localparam MKM_ADDR_CTRL = 8'h08;
@@ -111,8 +115,8 @@ module keywrap_core #(parameter MEM_BITS = 11)
localparam MKM_ADDR_EMEM_DATA = 8'h20;
// Addresses for storage in the mkm
- localparam MKM_STATUS_WORD = 8'h00;
- localparam MKM_KEY_BASE_WORD = 8'h04;
+ localparam MKM_STATUS_WORD = 16'h00;
+ localparam MKM_KEY_BASE_WORD = 16'h04;
localparam DEFAULT_SCLK_DIV = 16'h0020;
@@ -264,7 +268,7 @@ module keywrap_core #(parameter MEM_BITS = 11)
assign a_result = a_reg;
assign ready = ready_reg;
assign valid = valid_reg;
- assign mkm_status = mkm_status_reg;
+ assign mstatus = mkm_status_reg;
//----------------------------------------------------------------
@@ -637,11 +641,45 @@ module keywrap_core #(parameter MEM_BITS = 11)
CTRL_MKM_RD_START:
begin
- keywrap_core_ctrl_new = CTRL_MKM_RD_END;
+ mkm_init_op = 1'h1;
+ keywrap_core_ctrl_new = CTRL_MKM_RD_WAIT0;
keywrap_core_ctrl_we = 1'h1;
end
+ CTRL_MKM_RD_WAIT0:
+ begin
+ if (mkm_ready)
+ // MKM should have been initialized.
+ if (mkey_mstatus)
+ begin
+ // Read master key from mkm.
+ keywrap_core_ctrl_new = CTRL_MKM_RD_END;
+ keywrap_core_ctrl_we = 1'h1;
+ end
+ else
+ begin
+ // Read master key status from mkm.
+ mkm_read_op = 1'h1;
+ mkm_addr = MKM_STATUS_WORD;
+ keywrap_core_ctrl_new = CTRL_MKM_RD_STATUS;
+ keywrap_core_ctrl_we = 1'h1;
+ end
+ end
+
+
+ CTRL_MKM_RD_STATUS:
+ begin
+ if (mkm_ready)
+ begin
+ // status should have been read.
+ mkm_status_we = 1'h1;
+ keywrap_core_ctrl_new = CTRL_MKM_RD_END;
+ keywrap_core_ctrl_we = 1'h1;
+ end
+ end
+
+
CTRL_MKM_RD_END:
begin
ready_new = 1'h1;
@@ -653,11 +691,22 @@ module keywrap_core #(parameter MEM_BITS = 11)
CTRL_MKM_WR_START:
begin
- keywrap_core_ctrl_new = CTRL_MKM_WR_END;
+ mkm_init_op = 1'h1;
+ keywrap_core_ctrl_new = CTRL_MKM_WR_WAIT0;
keywrap_core_ctrl_we = 1'h1;
end
+ CTRL_MKM_WR_WAIT0:
+ begin
+ if (mkm_ready)
+ begin
+ keywrap_core_ctrl_new = CTRL_MKM_WR_END;
+ keywrap_core_ctrl_we = 1'h1;
+ end
+ end
+
+
CTRL_MKM_WR_END:
begin
ready_new = 1'h1;