1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * AMCC SoC PPC4xx Crypto Driver
5 * Copyright (c) 2008 Applied Micro Circuits Corporation.
6 * All rights reserved. James Hsiao <jhsiao@amcc.com>
8 * This file defines the security context
12 #ifndef __CRYPTO4XX_SA_H__
13 #define __CRYPTO4XX_SA_H__
15 #define AES_IV_SIZE 16
18 * Contents of Dynamic Security Association (SA) with all possible fields
20 union dynamic_sa_contents
{
42 } __attribute__((packed
));
44 #define DIR_OUTBOUND 0
46 #define SA_OP_GROUP_BASIC 0
47 #define SA_OPCODE_ENCRYPT 0
48 #define SA_OPCODE_DECRYPT 0
49 #define SA_OPCODE_ENCRYPT_HASH 1
50 #define SA_OPCODE_HASH_DECRYPT 1
51 #define SA_OPCODE_HASH 3
52 #define SA_CIPHER_ALG_DES 0
53 #define SA_CIPHER_ALG_3DES 1
54 #define SA_CIPHER_ALG_ARC4 2
55 #define SA_CIPHER_ALG_AES 3
56 #define SA_CIPHER_ALG_KASUMI 4
57 #define SA_CIPHER_ALG_NULL 15
59 #define SA_HASH_ALG_MD5 0
60 #define SA_HASH_ALG_SHA1 1
61 #define SA_HASH_ALG_GHASH 12
62 #define SA_HASH_ALG_CBC_MAC 14
63 #define SA_HASH_ALG_NULL 15
64 #define SA_HASH_ALG_SHA1_DIGEST_SIZE 20
66 #define SA_LOAD_HASH_FROM_SA 0
67 #define SA_LOAD_HASH_FROM_STATE 2
68 #define SA_NOT_LOAD_HASH 3
69 #define SA_LOAD_IV_FROM_SA 0
70 #define SA_LOAD_IV_FROM_INPUT 1
71 #define SA_LOAD_IV_FROM_STATE 2
72 #define SA_LOAD_IV_GEN_IV 3
74 #define SA_PAD_TYPE_CONSTANT 2
75 #define SA_PAD_TYPE_ZERO 3
76 #define SA_PAD_TYPE_TLS 5
77 #define SA_PAD_TYPE_DTLS 5
78 #define SA_NOT_SAVE_HASH 0
79 #define SA_SAVE_HASH 1
80 #define SA_NOT_SAVE_IV 0
82 #define SA_HEADER_PROC 1
83 #define SA_NO_HEADER_PROC 0
89 u32 save_hash_state
:1;
91 u32 load_hash_state
:2;
96 u32 stream_cipher_pad
:1;
106 } __attribute__((packed
));
108 #define CRYPTO_MODE_ECB 0
109 #define CRYPTO_MODE_CBC 1
110 #define CRYPTO_MODE_OFB 2
111 #define CRYPTO_MODE_CFB 3
112 #define CRYPTO_MODE_CTR 4
114 #define CRYPTO_FEEDBACK_MODE_NO_FB 0
115 #define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0
116 #define CRYPTO_FEEDBACK_MODE_8BIT_CFB 1
117 #define CRYPTO_FEEDBACK_MODE_1BIT_CFB 2
118 #define CRYPTO_FEEDBACK_MODE_128BIT_CFB 3
120 #define SA_AES_KEY_LEN_128 2
121 #define SA_AES_KEY_LEN_192 3
122 #define SA_AES_KEY_LEN_256 4
126 * The follow defines bits sa_command_1
127 * In Basic hash mode this bit define simple hash or hmac.
128 * In IPsec mode, this bit define muting control.
130 #define SA_HASH_MODE_HASH 0
131 #define SA_HASH_MODE_HMAC 1
132 #define SA_MC_ENABLE 0
133 #define SA_MC_DISABLE 1
134 #define SA_NOT_COPY_HDR 0
135 #define SA_COPY_HDR 1
136 #define SA_NOT_COPY_PAD 0
137 #define SA_COPY_PAD 1
138 #define SA_NOT_COPY_PAYLOAD 0
139 #define SA_COPY_PAYLOAD 1
140 #define SA_EXTENDED_SN_OFF 0
141 #define SA_EXTENDED_SN_ON 1
142 #define SA_SEQ_MASK_OFF 0
143 #define SA_SEQ_MASK_ON 1
148 u32 save_arc4_state
:1;
151 u32 hash_crypto_offset
:8;
156 u32 crypto_mode9_8
:2;
157 u32 extended_seq_num
:1;
159 u32 mutable_bit_proc
:1;
167 } __attribute__((packed
));
169 struct dynamic_sa_ctl
{
170 union dynamic_sa_contents sa_contents
;
171 union sa_command_0 sa_command_0
;
172 union sa_command_1 sa_command_1
;
173 } __attribute__((packed
));
176 * State Record for Security Association (SA)
178 struct sa_state_record
{
180 __le32 save_hash_byte_cnt
[2];
182 u32 save_digest
[16]; /* for MD5/SHA */
183 __le32 save_digest_le32
[16]; /* GHASH / CBC */
185 } __attribute__((packed
));
188 * Security Association (SA) for AES128
191 struct dynamic_sa_aes128
{
192 struct dynamic_sa_ctl ctrl
;
194 __le32 iv
[4]; /* for CBC, OFC, and CFB mode */
197 } __attribute__((packed
));
199 #define SA_AES128_LEN (sizeof(struct dynamic_sa_aes128)/4)
200 #define SA_AES128_CONTENTS 0x3e000042
203 * Security Association (SA) for AES192
205 struct dynamic_sa_aes192
{
206 struct dynamic_sa_ctl ctrl
;
208 __le32 iv
[4]; /* for CBC, OFC, and CFB mode */
211 } __attribute__((packed
));
213 #define SA_AES192_LEN (sizeof(struct dynamic_sa_aes192)/4)
214 #define SA_AES192_CONTENTS 0x3e000062
217 * Security Association (SA) for AES256
219 struct dynamic_sa_aes256
{
220 struct dynamic_sa_ctl ctrl
;
222 __le32 iv
[4]; /* for CBC, OFC, and CFB mode */
225 } __attribute__((packed
));
227 #define SA_AES256_LEN (sizeof(struct dynamic_sa_aes256)/4)
228 #define SA_AES256_CONTENTS 0x3e000082
229 #define SA_AES_CONTENTS 0x3e000002
232 * Security Association (SA) for AES128 CCM
234 struct dynamic_sa_aes128_ccm
{
235 struct dynamic_sa_ctl ctrl
;
241 #define SA_AES128_CCM_LEN (sizeof(struct dynamic_sa_aes128_ccm)/4)
242 #define SA_AES128_CCM_CONTENTS 0x3e000042
243 #define SA_AES_CCM_CONTENTS 0x3e000002
246 * Security Association (SA) for AES128_GCM
248 struct dynamic_sa_aes128_gcm
{
249 struct dynamic_sa_ctl ctrl
;
251 __le32 inner_digest
[4];
257 #define SA_AES128_GCM_LEN (sizeof(struct dynamic_sa_aes128_gcm)/4)
258 #define SA_AES128_GCM_CONTENTS 0x3e000442
259 #define SA_AES_GCM_CONTENTS 0x3e000402
262 * Security Association (SA) for HASH160: HMAC-SHA1
264 struct dynamic_sa_hash160
{
265 struct dynamic_sa_ctl ctrl
;
266 __le32 inner_digest
[5];
267 __le32 outer_digest
[5];
270 } __attribute__((packed
));
271 #define SA_HASH160_LEN (sizeof(struct dynamic_sa_hash160)/4)
272 #define SA_HASH160_CONTENTS 0x2000a502
275 get_dynamic_sa_offset_state_ptr_field(struct dynamic_sa_ctl
*cts
)
279 offset
= cts
->sa_contents
.bf
.key_size
280 + cts
->sa_contents
.bf
.inner_size
281 + cts
->sa_contents
.bf
.outer_size
282 + cts
->sa_contents
.bf
.spi
283 + cts
->sa_contents
.bf
.seq_num0
284 + cts
->sa_contents
.bf
.seq_num1
285 + cts
->sa_contents
.bf
.seq_num_mask0
286 + cts
->sa_contents
.bf
.seq_num_mask1
287 + cts
->sa_contents
.bf
.seq_num_mask2
288 + cts
->sa_contents
.bf
.seq_num_mask3
289 + cts
->sa_contents
.bf
.iv0
290 + cts
->sa_contents
.bf
.iv1
291 + cts
->sa_contents
.bf
.iv2
292 + cts
->sa_contents
.bf
.iv3
;
294 return sizeof(struct dynamic_sa_ctl
) + offset
* 4;
297 static inline __le32
*get_dynamic_sa_key_field(struct dynamic_sa_ctl
*cts
)
299 return (__le32
*) ((unsigned long)cts
+ sizeof(struct dynamic_sa_ctl
));
302 static inline __le32
*get_dynamic_sa_inner_digest(struct dynamic_sa_ctl
*cts
)
304 return (__le32
*) ((unsigned long)cts
+
305 sizeof(struct dynamic_sa_ctl
) +
306 cts
->sa_contents
.bf
.key_size
* 4);