-
Notifications
You must be signed in to change notification settings - Fork 25
/
sha_padder.sv
13 lines (10 loc) · 921 Bytes
/
sha_padder.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
`define PACK_ARRAY(PK_WIDTH,PK_LEN,PK_SRC,PK_DEST) genvar pk_idx; generate for (pk_idx=0; pk_idx<(PK_LEN); pk_idx=pk_idx+1) begin; assign PK_DEST[((PK_WIDTH)*pk_idx+((PK_WIDTH)-1)):((PK_WIDTH)*pk_idx)] = PK_SRC[pk_idx][((PK_WIDTH)-1):0]; end; endgenerate
`define UNPACK_ARRAY(PK_WIDTH,PK_LEN,PK_DEST,PK_SRC) genvar unpk_idx; generate for (unpk_idx=0; unpk_idx<(PK_LEN); unpk_idx=unpk_idx+1) begin; assign PK_DEST[unpk_idx][((PK_WIDTH)-1):0] = PK_SRC[((PK_WIDTH)*unpk_idx+(PK_WIDTH-1)):((PK_WIDTH)*unpk_idx)]; end; endgenerate
module sha_padder #(parameter MSG_SIZE = 24, // size of full message
parameter PADDED_SIZE = 512)
(input logic [MSG_SIZE-1:0] message,
output logic [PADDED_SIZE-1:0] padded);
localparam zero_width = PADDED_SIZE-MSG_SIZE-1-64;
localparam back_0_width = 64-$bits(MSG_SIZE);
assign padded = {message, 1'b1, {zero_width{1'b0}}, {back_0_width{1'b0}}, MSG_SIZE};
endmodule