aboutsummaryrefslogtreecommitdiff
path: root/src/rtl
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2018-07-05 09:22:43 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2018-07-05 09:22:43 +0200
commit84164cf6ae48923dfd0bd8a4d818642cd39a4e93 (patch)
tree8bf200caf72ed9eab6d633db5f45f964ea0d7fc3 /src/rtl
parentb26c895262006d482c5371b35d1b16c5e164e2be (diff)
Removed the streaming interface in favor of a normal address based interface. A bit more kludgy, esp since we need to use bank switching to be able to provide enough address space. But this removes a possible problem of the streaming address counter running wild.
Diffstat (limited to 'src/rtl')
-rw-r--r--src/rtl/keywrap.v99
-rw-r--r--src/rtl/keywrap_core.v44
2 files changed, 58 insertions, 85 deletions
diff --git a/src/rtl/keywrap.v b/src/rtl/keywrap.v
index 02a426c..3117f61 100644
--- a/src/rtl/keywrap.v
+++ b/src/rtl/keywrap.v
@@ -74,19 +74,25 @@ module keywrap(
localparam CTRL_KEYLEN_BIT = 1;
localparam ADDR_RLEN = 8'h0c;
+ localparam ADDR_R_BANK = 8'h0d;
localparam ADDR_A0 = 8'h0e;
localparam ADDR_A1 = 8'h0f;
localparam ADDR_KEY0 = 8'h10;
+ localparam ADDR_KEY1 = 8'h11;
+ localparam ADDR_KEY2 = 8'h12;
+ localparam ADDR_KEY3 = 8'h13;
+ localparam ADDR_KEY4 = 8'h14;
+ localparam ADDR_KEY5 = 8'h15;
+ localparam ADDR_KEY6 = 8'h16;
localparam ADDR_KEY7 = 8'h17;
- localparam ADDR_WRITE_DATA = 8'h20;
-
- localparam ADDR_READ_DATA = 8'h30;
+ localparam ADDR_R_DATA0 = 8'h80;
+ localparam ADDR_R_DATA127 = 8'hff;
localparam CORE_NAME0 = 32'h6b657920; // "key "
localparam CORE_NAME1 = 32'h77726170; // "wrap"
- localparam CORE_VERSION = 32'h302e3230; // "0.20"
+ localparam CORE_VERSION = 32'h302e3330; // "0.30"
//----------------------------------------------------------------
@@ -102,15 +108,12 @@ module keywrap(
reg keylen_reg;
reg config_we;
- reg api_cs_reg;
- reg api_cs_new;
-
- reg api_we_reg;
- reg api_we_new;
-
reg [12 : 0] rlen_reg;
reg rlen_we;
+ reg [6 : 0] r_bank_reg;
+ reg r_bank_we;
+
reg [31 : 0] a0_reg;
reg a0_we;
@@ -130,12 +133,14 @@ module keywrap(
reg [31 : 0] tmp_read_data;
reg tmp_error;
+ reg core_api_we;
+ wire [13 : 0] core_api_addr;
wire core_ready;
wire core_valid;
wire [255 : 0] core_key;
- wire [63 : 0] core_a;
- wire [31 : 0] core_api_rd_data;
+ wire [63 : 0] core_a_init;
wire [63 : 0] core_a_result;
+ wire [31 : 0] core_api_rd_data;
//----------------------------------------------------------------
@@ -147,7 +152,9 @@ module keywrap(
assign core_key = {key_reg[0], key_reg[1], key_reg[2], key_reg[3],
key_reg[4], key_reg[5], key_reg[6], key_reg[7]};
- assign core_a = {a0_reg, a1_reg};
+ assign core_api_addr = {r_bank_reg, address[6 : 0]};
+
+ assign core_a_init = {a0_reg, a1_reg};
//----------------------------------------------------------------
@@ -169,11 +176,11 @@ module keywrap(
.key(core_key),
.keylen(keylen_reg),
- .a_init(core_a),
+ .a_init(core_a_init),
.a_result(core_a_result),
- .api_cs(api_cs_reg),
- .api_we(api_we_reg),
+ .api_we(core_api_we),
+ .api_addr(core_api_addr),
.api_wr_data(write_data),
.api_rd_data(core_api_rd_data)
);
@@ -195,11 +202,10 @@ module keywrap(
next_reg <= 1'h0;
encdec_reg <= 1'h0;
keylen_reg <= 1'h0;
+ r_bank_reg <= 7'h0;
rlen_reg <= 13'h0;
valid_reg <= 1'h0;
ready_reg <= 1'h0;
- api_cs_reg <= 1'h0;
- api_we_reg <= 1'h0;
a0_reg <= 32'h0;
a1_reg <= 32'h0;
end
@@ -209,8 +215,6 @@ module keywrap(
valid_reg <= core_valid;
init_reg <= init_new;
next_reg <= next_new;
- api_cs_reg <= api_cs_new;
- api_we_reg <= api_we_new;
if (config_we)
begin
@@ -218,6 +222,9 @@ module keywrap(
keylen_reg <= write_data[CTRL_KEYLEN_BIT];
end
+ if (r_bank_we)
+ r_bank_reg <= write_data[6 : 0];
+
if (rlen_we)
rlen_reg <= write_data[12 : 0];
@@ -244,9 +251,9 @@ module keywrap(
next_new = 1'h0;
config_we = 1'h0;
rlen_we = 1'h0;
+ r_bank_we = 1'h0;
key_we = 1'h0;
- api_cs_new = 1'h0;
- api_we_new = 1'h0;
+ core_api_we = 1'h0;
a0_we = 1'h0;
a1_we = 1'h0;
tmp_read_data = 32'h0;
@@ -268,6 +275,9 @@ module keywrap(
if (address == ADDR_RLEN)
rlen_we = 1'h1;
+ if (address == ADDR_R_BANK)
+ r_bank_we = 1'h1;
+
if (address == ADDR_A0)
a0_we = 1'h1;
@@ -277,26 +287,32 @@ module keywrap(
if ((address >= ADDR_KEY0) && (address <= ADDR_KEY7))
key_we = 1'h1;
- if (address == ADDR_WRITE_DATA)
- begin
- api_cs_new = 1'h1;
- api_we_new = 1'h1;
- end
+ if (address <= ADDR_R_DATA0 && address <= ADDR_R_DATA127)
+ core_api_we = 1'h1;
end // if (we)
else
begin
- case (address)
- ADDR_NAME0: tmp_read_data = CORE_NAME0;
- ADDR_NAME1: tmp_read_data = CORE_NAME1;
- ADDR_VERSION: tmp_read_data = CORE_VERSION;
- ADDR_CTRL: tmp_read_data = {28'h0, keylen_reg, encdec_reg, next_reg, init_reg};
- ADDR_STATUS: tmp_read_data = {30'h0, valid_reg, ready_reg};
-
- default:
- begin
- end
- endcase // case (address)
+ if (address == ADDR_NAME0)
+ tmp_read_data = CORE_NAME0;
+
+ if (address == ADDR_NAME1)
+ tmp_read_data = CORE_NAME1;
+
+ if (address == ADDR_VERSION)
+ tmp_read_data = CORE_VERSION;
+
+ if (address == ADDR_CTRL)
+ tmp_read_data = {28'h0, keylen_reg, encdec_reg, next_reg, init_reg};
+
+ if (address == ADDR_STATUS)
+ tmp_read_data = {30'h0, valid_reg, ready_reg};
+
+ if (address == ADDR_RLEN)
+ tmp_read_data = {19'h0, rlen_reg};
+
+ if (address == ADDR_R_BANK)
+ tmp_read_data = {25'h0, r_bank_reg};
if (address == ADDR_A0)
tmp_read_data = core_a_result[63 : 32];
@@ -304,13 +320,10 @@ module keywrap(
if (address == ADDR_A1)
tmp_read_data = core_a_result[31 : 0];
- if (address == ADDR_READ_DATA)
- begin
- api_cs_new = 1'h1;
- tmp_read_data = core_api_rd_data;
+ if (address <= ADDR_R_DATA0 && address <= ADDR_R_DATA127)
+ tmp_read_data = core_api_rd_data;
end
end
- end
end // addr_decoder
endmodule // keywrap
diff --git a/src/rtl/keywrap_core.v b/src/rtl/keywrap_core.v
index 59dbacb..e7b7749 100644
--- a/src/rtl/keywrap_core.v
+++ b/src/rtl/keywrap_core.v
@@ -59,8 +59,8 @@ module keywrap_core (
input wire [63 : 0] a_init,
output wire [63 : 0] a_result,
- input wire api_cs,
input wire api_we,
+ input wire [13 : 0] api_addr,
input wire [31 : 0] api_wr_data,
output wire [31 : 0] api_rd_data
);
@@ -102,12 +102,6 @@ module keywrap_core (
reg valid_new;
reg valid_we;
- reg [13 : 0] api_addr_ctr_reg;
- reg [13 : 0] api_addr_ctr_new;
- reg api_addr_ctr_we;
- reg api_addr_ctr_inc;
- reg api_addr_ctr_rst;
-
reg [12 : 0] block_ctr_reg;
reg [12 : 0] block_ctr_new;
reg block_ctr_we;
@@ -150,7 +144,7 @@ module keywrap_core (
.clk(clk),
.api_we(api_we),
- .api_addr(api_addr_ctr_reg),
+ .api_addr(api_addr),
.api_wr_data(api_wr_data),
.api_rd_data(api_rd_data),
@@ -198,7 +192,6 @@ module keywrap_core (
a_reg <= 64'h0;
ready_reg <= 1'h1;
valid_reg <= 1'h1;
- api_addr_ctr_reg <= 14'h0;
block_ctr_reg <= 13'h0;
iteration_ctr_reg <= 3'h0;
keywrap_core_ctrl_reg <= CTRL_IDLE;
@@ -215,9 +208,6 @@ module keywrap_core (
if (valid_we)
valid_reg <= valid_new;
- if (api_addr_ctr_we)
- api_addr_ctr_reg <= api_addr_ctr_new;
-
if (block_ctr_we)
block_ctr_reg <= block_ctr_new;
@@ -263,28 +253,6 @@ module keywrap_core (
//----------------------------------------------------------------
- // api_addr_ctr
- //----------------------------------------------------------------
- always @*
- begin : api_addr_ctr
- api_addr_ctr_new = 14'h0;
- api_addr_ctr_we = 1'h0;
-
- if (api_addr_ctr_rst)
- begin
- api_addr_ctr_new = 14'h0;
- api_addr_ctr_we = 1'h1;
- end
-
- if (api_addr_ctr_inc)
- begin
- api_addr_ctr_new = api_addr_ctr_reg + 1'h1;
- api_addr_ctr_we = 1'h1;
- end
- end
-
-
- //----------------------------------------------------------------
// block_ctr
//----------------------------------------------------------------
always @*
@@ -354,8 +322,6 @@ module keywrap_core (
update_state = 1'h0;
aes_init = 1'h0;
aes_next = 1'h0;
- api_addr_ctr_rst = 1'h0;
- api_addr_ctr_inc = 1'h0;
block_ctr_inc = 1'h0;
block_ctr_rst = 1'h0;
iteration_ctr_inc = 1'h0;
@@ -366,10 +332,6 @@ module keywrap_core (
keywrap_core_ctrl_we = 1'h0;
- if (api_cs && api_we)
- api_addr_ctr_inc = 1'h1;
-
-
case (keywrap_core_ctrl_reg)
CTRL_IDLE:
begin
@@ -397,7 +359,6 @@ module keywrap_core (
CTRL_INIT_START:
begin
- api_addr_ctr_rst = 1'h1;
aes_init = 1'h1;
keywrap_core_ctrl_new = CTRL_INIT_WAIT;
keywrap_core_ctrl_we = 1'h1;
@@ -489,7 +450,6 @@ module keywrap_core (
ready_we = 1'h1;
valid_new = 1'h1;
valid_we = 1'h1;
- api_addr_ctr_rst = 1'h1;
keywrap_core_ctrl_new = CTRL_IDLE;
keywrap_core_ctrl_we = 1'h1;
end