2 * AMCC SoC PPC4xx Crypto Driver
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * This file defines the security context
21 #ifndef __CRYPTO4XX_SA_H__
22 #define __CRYPTO4XX_SA_H__
24 #define AES_IV_SIZE 16
27 * Contents of Dynamic Security Association (SA) with all possible fields
29 union dynamic_sa_contents
{
51 } __attribute__((packed
));
53 #define DIR_OUTBOUND 0
55 #define SA_OP_GROUP_BASIC 0
56 #define SA_OPCODE_ENCRYPT 0
57 #define SA_OPCODE_DECRYPT 0
58 #define SA_OPCODE_ENCRYPT_HASH 1
59 #define SA_OPCODE_HASH_DECRYPT 1
60 #define SA_OPCODE_HASH 3
61 #define SA_CIPHER_ALG_DES 0
62 #define SA_CIPHER_ALG_3DES 1
63 #define SA_CIPHER_ALG_ARC4 2
64 #define SA_CIPHER_ALG_AES 3
65 #define SA_CIPHER_ALG_KASUMI 4
66 #define SA_CIPHER_ALG_NULL 15
68 #define SA_HASH_ALG_MD5 0
69 #define SA_HASH_ALG_SHA1 1
70 #define SA_HASH_ALG_GHASH 12
71 #define SA_HASH_ALG_CBC_MAC 14
72 #define SA_HASH_ALG_NULL 15
73 #define SA_HASH_ALG_SHA1_DIGEST_SIZE 20
75 #define SA_LOAD_HASH_FROM_SA 0
76 #define SA_LOAD_HASH_FROM_STATE 2
77 #define SA_NOT_LOAD_HASH 3
78 #define SA_LOAD_IV_FROM_SA 0
79 #define SA_LOAD_IV_FROM_INPUT 1
80 #define SA_LOAD_IV_FROM_STATE 2
81 #define SA_LOAD_IV_GEN_IV 3
83 #define SA_PAD_TYPE_CONSTANT 2
84 #define SA_PAD_TYPE_ZERO 3
85 #define SA_PAD_TYPE_TLS 5
86 #define SA_PAD_TYPE_DTLS 5
87 #define SA_NOT_SAVE_HASH 0
88 #define SA_SAVE_HASH 1
89 #define SA_NOT_SAVE_IV 0
91 #define SA_HEADER_PROC 1
92 #define SA_NO_HEADER_PROC 0
98 u32 save_hash_state
:1;
100 u32 load_hash_state
:2;
105 u32 stream_cipher_pad
:1;
115 } __attribute__((packed
));
117 #define CRYPTO_MODE_ECB 0
118 #define CRYPTO_MODE_CBC 1
119 #define CRYPTO_MODE_OFB 2
120 #define CRYPTO_MODE_CFB 3
121 #define CRYPTO_MODE_CTR 4
123 #define CRYPTO_FEEDBACK_MODE_NO_FB 0
124 #define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0
125 #define CRYPTO_FEEDBACK_MODE_8BIT_CFB 1
126 #define CRYPTO_FEEDBACK_MODE_1BIT_CFB 2
127 #define CRYPTO_FEEDBACK_MODE_128BIT_CFB 3
129 #define SA_AES_KEY_LEN_128 2
130 #define SA_AES_KEY_LEN_192 3
131 #define SA_AES_KEY_LEN_256 4
135 * The follow defines bits sa_command_1
136 * In Basic hash mode this bit define simple hash or hmac.
137 * In IPsec mode, this bit define muting control.
139 #define SA_HASH_MODE_HASH 0
140 #define SA_HASH_MODE_HMAC 1
141 #define SA_MC_ENABLE 0
142 #define SA_MC_DISABLE 1
143 #define SA_NOT_COPY_HDR 0
144 #define SA_COPY_HDR 1
145 #define SA_NOT_COPY_PAD 0
146 #define SA_COPY_PAD 1
147 #define SA_NOT_COPY_PAYLOAD 0
148 #define SA_COPY_PAYLOAD 1
149 #define SA_EXTENDED_SN_OFF 0
150 #define SA_EXTENDED_SN_ON 1
151 #define SA_SEQ_MASK_OFF 0
152 #define SA_SEQ_MASK_ON 1
157 u32 save_arc4_state
:1;
160 u32 hash_crypto_offset
:8;
165 u32 crypto_mode9_8
:2;
166 u32 extended_seq_num
:1;
168 u32 mutable_bit_proc
:1;
176 } __attribute__((packed
));
178 struct dynamic_sa_ctl
{
179 union dynamic_sa_contents sa_contents
;
180 union sa_command_0 sa_command_0
;
181 union sa_command_1 sa_command_1
;
182 } __attribute__((packed
));
185 * State Record for Security Association (SA)
187 struct sa_state_record
{
189 __le32 save_hash_byte_cnt
[2];
191 u32 save_digest
[16]; /* for MD5/SHA */
192 __le32 save_digest_le32
[16]; /* GHASH / CBC */
194 } __attribute__((packed
));
197 * Security Association (SA) for AES128
200 struct dynamic_sa_aes128
{
201 struct dynamic_sa_ctl ctrl
;
203 __le32 iv
[4]; /* for CBC, OFC, and CFB mode */
206 } __attribute__((packed
));
208 #define SA_AES128_LEN (sizeof(struct dynamic_sa_aes128)/4)
209 #define SA_AES128_CONTENTS 0x3e000042
212 * Security Association (SA) for AES192
214 struct dynamic_sa_aes192
{
215 struct dynamic_sa_ctl ctrl
;
217 __le32 iv
[4]; /* for CBC, OFC, and CFB mode */
220 } __attribute__((packed
));
222 #define SA_AES192_LEN (sizeof(struct dynamic_sa_aes192)/4)
223 #define SA_AES192_CONTENTS 0x3e000062
226 * Security Association (SA) for AES256
228 struct dynamic_sa_aes256
{
229 struct dynamic_sa_ctl ctrl
;
231 __le32 iv
[4]; /* for CBC, OFC, and CFB mode */
234 } __attribute__((packed
));
236 #define SA_AES256_LEN (sizeof(struct dynamic_sa_aes256)/4)
237 #define SA_AES256_CONTENTS 0x3e000082
238 #define SA_AES_CONTENTS 0x3e000002
241 * Security Association (SA) for AES128 CCM
243 struct dynamic_sa_aes128_ccm
{
244 struct dynamic_sa_ctl ctrl
;
250 #define SA_AES128_CCM_LEN (sizeof(struct dynamic_sa_aes128_ccm)/4)
251 #define SA_AES128_CCM_CONTENTS 0x3e000042
252 #define SA_AES_CCM_CONTENTS 0x3e000002
255 * Security Association (SA) for AES128_GCM
257 struct dynamic_sa_aes128_gcm
{
258 struct dynamic_sa_ctl ctrl
;
260 __le32 inner_digest
[4];
266 #define SA_AES128_GCM_LEN (sizeof(struct dynamic_sa_aes128_gcm)/4)
267 #define SA_AES128_GCM_CONTENTS 0x3e000442
268 #define SA_AES_GCM_CONTENTS 0x3e000402
271 * Security Association (SA) for HASH160: HMAC-SHA1
273 struct dynamic_sa_hash160
{
274 struct dynamic_sa_ctl ctrl
;
275 __le32 inner_digest
[5];
276 __le32 outer_digest
[5];
279 } __attribute__((packed
));
280 #define SA_HASH160_LEN (sizeof(struct dynamic_sa_hash160)/4)
281 #define SA_HASH160_CONTENTS 0x2000a502
284 get_dynamic_sa_offset_state_ptr_field(struct dynamic_sa_ctl
*cts
)
288 offset
= cts
->sa_contents
.bf
.key_size
289 + cts
->sa_contents
.bf
.inner_size
290 + cts
->sa_contents
.bf
.outer_size
291 + cts
->sa_contents
.bf
.spi
292 + cts
->sa_contents
.bf
.seq_num0
293 + cts
->sa_contents
.bf
.seq_num1
294 + cts
->sa_contents
.bf
.seq_num_mask0
295 + cts
->sa_contents
.bf
.seq_num_mask1
296 + cts
->sa_contents
.bf
.seq_num_mask2
297 + cts
->sa_contents
.bf
.seq_num_mask3
298 + cts
->sa_contents
.bf
.iv0
299 + cts
->sa_contents
.bf
.iv1
300 + cts
->sa_contents
.bf
.iv2
301 + cts
->sa_contents
.bf
.iv3
;
303 return sizeof(struct dynamic_sa_ctl
) + offset
* 4;
306 static inline __le32
*get_dynamic_sa_key_field(struct dynamic_sa_ctl
*cts
)
308 return (__le32
*) ((unsigned long)cts
+ sizeof(struct dynamic_sa_ctl
));
311 static inline __le32
*get_dynamic_sa_inner_digest(struct dynamic_sa_ctl
*cts
)
313 return (__le32
*) ((unsigned long)cts
+
314 sizeof(struct dynamic_sa_ctl
) +
315 cts
->sa_contents
.bf
.key_size
* 4);