1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef _SPU2_H
22#define _SPU2_H
23
24enum spu2_cipher_type {
25 SPU2_CIPHER_TYPE_NONE = 0x0,
26 SPU2_CIPHER_TYPE_AES128 = 0x1,
27 SPU2_CIPHER_TYPE_AES192 = 0x2,
28 SPU2_CIPHER_TYPE_AES256 = 0x3,
29 SPU2_CIPHER_TYPE_DES = 0x4,
30 SPU2_CIPHER_TYPE_3DES = 0x5,
31 SPU2_CIPHER_TYPE_LAST
32};
33
34enum spu2_cipher_mode {
35 SPU2_CIPHER_MODE_ECB = 0x0,
36 SPU2_CIPHER_MODE_CBC = 0x1,
37 SPU2_CIPHER_MODE_CTR = 0x2,
38 SPU2_CIPHER_MODE_CFB = 0x3,
39 SPU2_CIPHER_MODE_OFB = 0x4,
40 SPU2_CIPHER_MODE_XTS = 0x5,
41 SPU2_CIPHER_MODE_CCM = 0x6,
42 SPU2_CIPHER_MODE_GCM = 0x7,
43 SPU2_CIPHER_MODE_LAST
44};
45
46enum spu2_hash_type {
47 SPU2_HASH_TYPE_NONE = 0x0,
48 SPU2_HASH_TYPE_AES128 = 0x1,
49 SPU2_HASH_TYPE_AES192 = 0x2,
50 SPU2_HASH_TYPE_AES256 = 0x3,
51 SPU2_HASH_TYPE_MD5 = 0x6,
52 SPU2_HASH_TYPE_SHA1 = 0x7,
53 SPU2_HASH_TYPE_SHA224 = 0x8,
54 SPU2_HASH_TYPE_SHA256 = 0x9,
55 SPU2_HASH_TYPE_SHA384 = 0xa,
56 SPU2_HASH_TYPE_SHA512 = 0xb,
57 SPU2_HASH_TYPE_SHA512_224 = 0xc,
58 SPU2_HASH_TYPE_SHA512_256 = 0xd,
59 SPU2_HASH_TYPE_SHA3_224 = 0xe,
60 SPU2_HASH_TYPE_SHA3_256 = 0xf,
61 SPU2_HASH_TYPE_SHA3_384 = 0x10,
62 SPU2_HASH_TYPE_SHA3_512 = 0x11,
63 SPU2_HASH_TYPE_LAST
64};
65
66enum spu2_hash_mode {
67 SPU2_HASH_MODE_CMAC = 0x0,
68 SPU2_HASH_MODE_CBC_MAC = 0x1,
69 SPU2_HASH_MODE_XCBC_MAC = 0x2,
70 SPU2_HASH_MODE_HMAC = 0x3,
71 SPU2_HASH_MODE_RABIN = 0x4,
72 SPU2_HASH_MODE_CCM = 0x5,
73 SPU2_HASH_MODE_GCM = 0x6,
74 SPU2_HASH_MODE_RESERVED = 0x7,
75 SPU2_HASH_MODE_LAST
76};
77
78enum spu2_ret_md_opts {
79 SPU2_RET_NO_MD = 0,
80 SPU2_RET_FMD_OMD = 1,
81 SPU2_RET_FMD_ONLY = 2,
82 SPU2_RET_FMD_OMD_IV = 3,
83};
84
85
86struct SPU2_FMD {
87 u64 ctrl0;
88 u64 ctrl1;
89 u64 ctrl2;
90 u64 ctrl3;
91};
92
93#define FMD_SIZE sizeof(struct SPU2_FMD)
94
95
96#define SPU2_REQ_FIXED_LEN FMD_SIZE
97#define SPU2_HEADER_ALLOC_LEN (SPU_REQ_FIXED_LEN + \
98 2 * MAX_KEY_SIZE + 2 * MAX_IV_SIZE)
99
100
101#define SPU2_CIPH_ENCRYPT_EN 0x1
102#define SPU2_CIPH_TYPE 0xF0
103#define SPU2_CIPH_TYPE_SHIFT 4
104#define SPU2_CIPH_MODE 0xF00
105#define SPU2_CIPH_MODE_SHIFT 8
106#define SPU2_CFB_MASK 0x7000
107#define SPU2_CFB_MASK_SHIFT 12
108#define SPU2_PROTO_SEL 0xF00000
109#define SPU2_PROTO_SEL_SHIFT 20
110#define SPU2_HASH_FIRST 0x1000000
111
112
113#define SPU2_CHK_TAG 0x2000000
114#define SPU2_HASH_TYPE 0x1F0000000
115#define SPU2_HASH_TYPE_SHIFT 28
116#define SPU2_HASH_MODE 0xF000000000
117#define SPU2_HASH_MODE_SHIFT 36
118#define SPU2_CIPH_PAD_EN 0x100000000000
119
120
121#define SPU2_CIPH_PAD 0xFF000000000000
122#define SPU2_CIPH_PAD_SHIFT 48
123
124
125#define SPU2_TAG_LOC 0x1
126#define SPU2_HAS_FR_DATA 0x2
127#define SPU2_HAS_AAD1 0x4
128#define SPU2_HAS_NAAD 0x8
129#define SPU2_HAS_AAD2 0x10
130#define SPU2_HAS_ESN 0x20
131#define SPU2_HASH_KEY_LEN 0xFF00
132
133
134#define SPU2_HASH_KEY_LEN_SHIFT 8
135#define SPU2_CIPH_KEY_LEN 0xFF00000
136#define SPU2_CIPH_KEY_LEN_SHIFT 20
137#define SPU2_GENIV 0x10000000
138#define SPU2_HASH_IV 0x20000000
139#define SPU2_RET_IV 0x40000000
140
141
142#define SPU2_RET_IV_LEN 0xF00000000
143
144
145#define SPU2_RET_IV_LEN_SHIFT 32
146#define SPU2_IV_OFFSET 0xF000000000
147#define SPU2_IV_OFFSET_SHIFT 36
148#define SPU2_IV_LEN 0x1F0000000000
149#define SPU2_IV_LEN_SHIFT 40
150#define SPU2_HASH_TAG_LEN 0x7F000000000000
151#define SPU2_HASH_TAG_LEN_SHIFT 48
152#define SPU2_RETURN_MD 0x300000000000000
153#define SPU2_RETURN_MD_SHIFT 56
154#define SPU2_RETURN_FD 0x400000000000000
155#define SPU2_RETURN_AAD1 0x800000000000000
156#define SPU2_RETURN_NAAD 0x1000000000000000
157#define SPU2_RETURN_AAD2 0x2000000000000000
158#define SPU2_RETURN_PAY 0x4000000000000000
159
160
161#define SPU2_AAD1_OFFSET 0xFFF
162#define SPU2_AAD1_LEN 0xFF000
163#define SPU2_AAD1_LEN_SHIFT 12
164#define SPU2_AAD2_OFFSET 0xFFF00000
165#define SPU2_AAD2_OFFSET_SHIFT 20
166#define SPU2_PL_OFFSET 0xFFFFFFFF00000000
167#define SPU2_PL_OFFSET_SHIFT 32
168
169
170#define SPU2_PL_LEN 0xFFFFFFFF
171#define SPU2_TLS_LEN 0xFFFF00000000
172
173
174#define SPU2_TLS_LEN_SHIFT 32
175
176
177
178
179
180#define SPU2_MAX_PAYLOAD SPU2_PL_LEN
181
182
183#define SPU2_INVALID_ICV 1
184
185void spu2_dump_msg_hdr(u8 *buf, unsigned int buf_len);
186u32 spu2_ctx_max_payload(enum spu_cipher_alg cipher_alg,
187 enum spu_cipher_mode cipher_mode,
188 unsigned int blocksize);
189u32 spu2_payload_length(u8 *spu_hdr);
190u16 spu2_response_hdr_len(u16 auth_key_len, u16 enc_key_len, bool is_hash);
191u16 spu2_hash_pad_len(enum hash_alg hash_alg, enum hash_mode hash_mode,
192 u32 chunksize, u16 hash_block_size);
193u32 spu2_gcm_ccm_pad_len(enum spu_cipher_mode cipher_mode,
194 unsigned int data_size);
195u32 spu2_assoc_resp_len(enum spu_cipher_mode cipher_mode,
196 unsigned int assoc_len, unsigned int iv_len,
197 bool is_encrypt);
198u8 spu2_aead_ivlen(enum spu_cipher_mode cipher_mode,
199 u16 iv_len);
200enum hash_type spu2_hash_type(u32 src_sent);
201u32 spu2_digest_size(u32 alg_digest_size, enum hash_alg alg,
202 enum hash_type htype);
203u32 spu2_create_request(u8 *spu_hdr,
204 struct spu_request_opts *req_opts,
205 struct spu_cipher_parms *cipher_parms,
206 struct spu_hash_parms *hash_parms,
207 struct spu_aead_parms *aead_parms,
208 unsigned int data_size);
209u16 spu2_cipher_req_init(u8 *spu_hdr, struct spu_cipher_parms *cipher_parms);
210void spu2_cipher_req_finish(u8 *spu_hdr,
211 u16 spu_req_hdr_len,
212 unsigned int is_inbound,
213 struct spu_cipher_parms *cipher_parms,
214 bool update_key,
215 unsigned int data_size);
216void spu2_request_pad(u8 *pad_start, u32 gcm_padding, u32 hash_pad_len,
217 enum hash_alg auth_alg, enum hash_mode auth_mode,
218 unsigned int total_sent, u32 status_padding);
219u8 spu2_xts_tweak_in_payload(void);
220u8 spu2_tx_status_len(void);
221u8 spu2_rx_status_len(void);
222int spu2_status_process(u8 *statp);
223void spu2_ccm_update_iv(unsigned int digestsize,
224 struct spu_cipher_parms *cipher_parms,
225 unsigned int assoclen, unsigned int chunksize,
226 bool is_encrypt, bool is_esp);
227u32 spu2_wordalign_padlen(u32 data_size);
228#endif
229