../src/lowrisc_ip_aes_0.6/rtl/aes_sbox.sv Cov: 36.1%
1: // Copyright lowRISC contributors.
2: // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3: // SPDX-License-Identifier: Apache-2.0
4: //
5: // AES SBox
6:
7: module aes_sbox #(
8: parameter SBoxImpl = "lut"
9: ) (
10: input aes_pkg::ciph_op_e op_i,
11: input logic [7:0] data_i,
12: output logic [7:0] data_o
13: );
14:
15: if (SBoxImpl == "lut") begin : gen_sbox_lut
16: aes_sbox_lut aes_sbox (
17: .op_i,
18: .data_i,
19: .data_o
20: );
21: end else if (SBoxImpl == "canright") begin : gen_sbox_canright
22: aes_sbox_canright aes_sbox (
23: .op_i,
24: .data_i,
25: .data_o
26: );
27: end else begin : gen_sbox_masked
28: // TODO: Use non-constant masks + remove corresponding comment in aes.sv.
29: // See https://github.com/lowRISC/opentitan/issues/1005
30: logic [7:0] in_data_m, out_data_m;
31: logic [7:0] in_mask, out_mask;
32: assign in_mask = 8'hAA;
33: assign out_mask = 8'h55;
34:
35: // Mask input data
36: assign in_data_m = data_i ^ in_mask;
37: if (SBoxImpl == "canright_masked_noreuse") begin : gen_sbox_canright_masked_noreuse
38: aes_sbox_canright_masked_noreuse aes_sbox (
39: .op_i,
40: .data_i ( in_data_m ),
41: .in_mask_i ( in_mask ),
42: .out_mask_i ( out_mask ),
43: .data_o ( out_data_m )
44: );
45: end else if (SBoxImpl == "canright_masked") begin : gen_sbox_canright_masked
46: aes_sbox_canright_masked aes_sbox (
47: .op_i,
48: .data_i ( in_data_m ),
49: .in_mask_i ( in_mask ),
50: .out_mask_i ( out_mask ),
51: .data_o ( out_data_m )
52: );
53: end
54: // Unmask output data
55: assign data_o = out_data_m ^ out_mask;
56: end
57:
58: endmodule
59: