Skip to content

Commit dfd9c25

Browse files
etterlinasahlpa
authored andcommitted
[kmac,rtl] Clean up naming of strobe
The term strobe and mask were used interchangably despite masking has a different meaning in KMAC. Signed-off-by: Pascal Etterli <pascal.etterli@lowrisc.org>
1 parent 8e9a3da commit dfd9c25

5 files changed

Lines changed: 37 additions & 37 deletions

File tree

hw/ip/kmac/data/kmac.hjson

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@
389389
name: "kmac_en"
390390
desc: '''KMAC datapath enable.
391391

392-
If this bit is 1, the incoming message is processed in KMAC
393-
with the secret key.
392+
If this bit is 1, the KMAC mode is active and the secret key is prepended to the incoming message.
394393
'''
395394
tags: [// don't enable kmac and sha data paths - we will do that in functional tests
396395
"excl:CsrNonInitTests:CsrExclWrite",

hw/ip/kmac/doc/registers.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ Other values are reserved.
327327
### CFG_SHADOWED . kmac_en
328328
KMAC datapath enable.
329329

330-
If this bit is 1, the incoming message is processed in KMAC
331-
with the secret key.
330+
If this bit is 1, the KMAC mode is active and the secret key is prepended to the incoming message.
332331

333332
## CMD
334333
KMAC/ SHA3 command register.

hw/ip/kmac/rtl/kmac.sv

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ module kmac
238238
logic [31:0] tlram_wmask_endian;
239239

240240
logic sw_msg_valid;
241-
logic [kmac_pkg::MsgWidth-1:0] sw_msg_data ;
242-
logic [kmac_pkg::MsgWidth-1:0] sw_msg_mask ;
241+
logic [kmac_pkg::MsgWidth-1:0] sw_msg_data;
242+
logic [kmac_pkg::MsgWidth-1:0] sw_msg_strb;
243243
logic sw_msg_ready;
244244

245245
// KeyMgr interface to MSG_FIFO
246246
logic mux2fifo_valid;
247-
logic [kmac_pkg::MsgWidth-1:0] mux2fifo_data ;
248-
logic [kmac_pkg::MsgWidth-1:0] mux2fifo_mask ;
247+
logic [kmac_pkg::MsgWidth-1:0] mux2fifo_data;
248+
logic [kmac_pkg::MsgWidth-1:0] mux2fifo_strb;
249249
logic mux2fifo_ready;
250250

251251
// KMAC to SHA3 core
@@ -1035,10 +1035,10 @@ module kmac
10351035
assign sw_msg_valid = tlram_req & tlram_we ;
10361036
if (MsgWidth == MsgWindowWidth) begin : gen_sw_msg_samewidth
10371037
assign sw_msg_data = tlram_wdata_endian ;
1038-
assign sw_msg_mask = tlram_wmask_endian ;
1038+
assign sw_msg_strb = tlram_wmask_endian ;
10391039
end else begin : gen_sw_msg_diff
10401040
assign sw_msg_data = {{MsgWidth-MsgWindowWidth{1'b0}}, tlram_wdata_endian};
1041-
assign sw_msg_mask = {{MsgWidth-MsgWindowWidth{1'b0}}, tlram_wmask_endian};
1041+
assign sw_msg_strb = {{MsgWidth-MsgWindowWidth{1'b0}}, tlram_wmask_endian};
10421042
end
10431043
assign tlram_gnt = sw_msg_ready ;
10441044

@@ -1067,7 +1067,7 @@ module kmac
10671067
// data from tl_adapter
10681068
.sw_valid_i (sw_msg_valid),
10691069
.sw_data_i (sw_msg_data),
1070-
.sw_mask_i (sw_msg_mask),
1070+
.sw_strb_i (sw_msg_strb),
10711071
.sw_ready_o (sw_msg_ready),
10721072

10731073
// KeyMgr sideloaded key interface
@@ -1085,7 +1085,7 @@ module kmac
10851085
// to MSG_FIFO
10861086
.kmac_valid_o (mux2fifo_valid),
10871087
.kmac_data_o (mux2fifo_data),
1088-
.kmac_mask_o (mux2fifo_mask),
1088+
.kmac_strb_o (mux2fifo_strb),
10891089
.kmac_ready_i (mux2fifo_ready),
10901090

10911091
// to KMAC Core
@@ -1144,7 +1144,7 @@ module kmac
11441144

11451145
.fifo_valid_i (mux2fifo_valid),
11461146
.fifo_data_i (mux2fifo_data),
1147-
.fifo_mask_i (mux2fifo_mask),
1147+
.fifo_strb_i (mux2fifo_strb),
11481148
.fifo_ready_o (mux2fifo_ready),
11491149

11501150
.msg_valid_o (msgfifo_valid),

hw/ip/kmac/rtl/kmac_app.sv

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ module kmac_app
2020
input rst_ni,
2121

2222
// Secret Key from register
23-
input [MaxKeyLen-1:0] reg_key_data_i [Share],
23+
input [MaxKeyLen-1:0] reg_key_data_i[Share],
2424
input key_len_e reg_key_len_i,
2525

2626
// Prefix from register
2727
input [sha3_pkg::NSRegisterSize*8-1:0] reg_prefix_i,
2828

2929
// mode, strength, kmac_en from register
30-
input reg_kmac_en_i,
30+
input logic reg_kmac_en_i,
3131
input sha3_pkg::sha3_mode_e reg_sha3_mode_i,
3232
input sha3_pkg::keccak_strength_e reg_keccak_strength_i,
3333

3434
// Data from Software
3535
input sw_valid_i,
3636
input [MsgWidth-1:0] sw_data_i,
37-
input [MsgWidth-1:0] sw_mask_i,
37+
input [MsgWidth-1:0] sw_strb_i,
3838
output logic sw_ready_o,
3939

4040
// KeyMgr Sideload Key interface
@@ -45,14 +45,15 @@ module kmac_app
4545
output app_rsp_t [NumAppIntf-1:0] app_o,
4646

4747
// to KMAC Core: Secret key
48-
output logic [MaxKeyLen-1:0] key_data_o [Share],
48+
output logic [MaxKeyLen-1:0] key_data_o[Share],
4949
output key_len_e key_len_o,
5050
output logic key_valid_o,
5151

5252
// to MSG_FIFO
5353
output logic kmac_valid_o,
5454
output logic [MsgWidth-1:0] kmac_data_o,
55-
output logic [MsgWidth-1:0] kmac_mask_o,
55+
// This strobe is on bit level for the packer. The FIFO will then convert it again to byte level.
56+
output logic [MsgWidth-1:0] kmac_strb_o,
5657
input kmac_ready_i,
5758

5859
// KMAC Core
@@ -65,19 +66,20 @@ module kmac_app
6566

6667
// STATE from SHA3 Core
6768
input keccak_state_valid_i,
68-
input [sha3_pkg::StateW-1:0] keccak_state_i [Share],
69+
input [sha3_pkg::StateW-1:0] keccak_state_i[Share],
6970

7071
// to STATE TL-window if Application is not active, the incoming state goes to
7172
// register if kdf_en is set, the state value goes to application and the
7273
// output to the register is all zero.
7374
output logic reg_state_valid_o,
74-
output logic [sha3_pkg::StateW-1:0] reg_state_o [Share],
75+
output logic [sha3_pkg::StateW-1:0] reg_state_o[Share],
7576

76-
// Configurations If key_en is set, the logic uses KeyMgr's sideloaded key as
77-
// a secret key rather than register values. This only affects when software
78-
// initiates. If App initiates the hash operation and uses KMAC algorithm, it
79-
// always uses sideloaded key.
80-
input keymgr_key_en_i,
77+
// Controls for SW and CmdApp operations whether to take the key from the KeyMgr sideload
78+
// interface or registers. For KMAC operations initiated by an app interface, we always take the
79+
// sideloaded key.
80+
// If 1, the key for KMAC is taken from the KeyMgr sideload interface.
81+
// If 0, the key is taken from the registers.
82+
input logic keymgr_key_en_i,
8183

8284
// Commands
8385
// Command from software
@@ -166,7 +168,7 @@ module kmac_app
166168
24'h 02_0002 // Key512
167169
};
168170

169-
localparam logic [OutLenW-1:0] EncodedOutLenMask [5] = '{
171+
localparam logic [OutLenW-1:0] EncodedOutLenStrb [5] = '{
170172
24'h 00FFFF, // Key128,
171173
24'h 00FFFF, // Key192
172174
24'h FFFFFF, // Key256
@@ -200,7 +202,7 @@ module kmac_app
200202
logic clr_appid, set_appid;
201203

202204
// Output length
203-
logic [OutLenW-1:0] encoded_outlen, encoded_outlen_mask;
205+
logic [OutLenW-1:0] encoded_outlen, encoded_outlen_strb;
204206

205207
// state output
206208
// Mux selection signal
@@ -600,7 +602,7 @@ module kmac_app
600602

601603
// Encoded output length
602604
assign encoded_outlen = EncodedOutLen[SelDigSize];
603-
assign encoded_outlen_mask = EncodedOutLenMask[SelKeySize];
605+
assign encoded_outlen_strb = EncodedOutLenStrb[SelKeySize];
604606

605607
// Data mux
606608
// This is the main part of the KeyMgr interface logic.
@@ -615,7 +617,7 @@ module kmac_app
615617

616618
kmac_valid_o = 1'b 0;
617619
kmac_data_o = '0;
618-
kmac_mask_o = '0;
620+
kmac_strb_o = '0;
619621

620622
unique case (mux_sel_buf_kmac)
621623
SelApp: begin
@@ -624,7 +626,7 @@ module kmac_app
624626
kmac_data_o = app_i[app_id].data;
625627
// Expand strb to bits. prim_packer inside MSG_FIFO accepts the bit masks
626628
for (int i = 0 ; i < $bits(app_i[app_id].strb) ; i++) begin
627-
kmac_mask_o[8*i+:8] = {8{app_i[app_id].strb[i]}};
629+
kmac_strb_o[8*i+:8] = {8{app_i[app_id].strb[i]}};
628630
end
629631
app_data_ready = kmac_ready_i;
630632
end
@@ -633,20 +635,20 @@ module kmac_app
633635
// Write encoded output length value
634636
kmac_valid_o = 1'b 1; // always write
635637
kmac_data_o = MsgWidth'(encoded_outlen);
636-
kmac_mask_o = MsgWidth'(encoded_outlen_mask);
638+
kmac_strb_o = MsgWidth'(encoded_outlen_strb);
637639
end
638640

639641
SelSw: begin
640642
kmac_valid_o = sw_valid_i;
641643
kmac_data_o = sw_data_i ;
642-
kmac_mask_o = sw_mask_i ;
644+
kmac_strb_o = sw_strb_i ;
643645
sw_ready_o = kmac_ready_i ;
644646
end
645647

646648
default: begin // Incl. SelNone
647649
kmac_valid_o = 1'b 0;
648650
kmac_data_o = '0;
649-
kmac_mask_o = '0;
651+
kmac_strb_o = '0;
650652
end
651653

652654
endcase
@@ -741,7 +743,7 @@ module kmac_app
741743
end
742744
end
743745

744-
// Keccak state --> KeyMgr
746+
// Keccak state --> App interface
745747
always_comb begin
746748
app_digest_done = 1'b 0;
747749
app_digest = '{default:'0};
@@ -764,7 +766,7 @@ module kmac_app
764766
// Prepare merged key if EnMasking is not set.
765767
// Combine share keys into unpacked array for logic below to assign easily.
766768
// SEC_CM: KEY.SIDELOAD
767-
logic [MaxKeyLen-1:0] keymgr_key [Share];
769+
logic [MaxKeyLen-1:0] keymgr_key[Share];
768770
if (EnMasking == 1) begin : g_masked_key
769771
for (genvar i = 0; i < Share; i++) begin : gen_key_pad
770772
assign keymgr_key[i] = {(MaxKeyLen-KeyMgrKeyW)'(0), keymgr_key_i.key[i]};

hw/ip/kmac/rtl/kmac_msgfifo.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module kmac_msgfifo
2727
// from REG or KeyMgr Intf input
2828
input fifo_valid_i,
2929
input [OutWidth-1:0] fifo_data_i,
30-
input [OutWidth-1:0] fifo_mask_i,
30+
input [OutWidth-1:0] fifo_strb_i,
3131
output fifo_ready_o,
3232

3333
// MSG interface
@@ -118,7 +118,7 @@ module kmac_msgfifo
118118

119119
.valid_i (fifo_valid_i),
120120
.data_i (fifo_data_i),
121-
.mask_i (fifo_mask_i),
121+
.mask_i (fifo_strb_i),
122122
.ready_o (fifo_ready_o),
123123

124124
.valid_o (packer_wvalid),

0 commit comments

Comments
 (0)