Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * AMCC SoC PPC4xx Crypto Driver
  4 *
  5 * Copyright (c) 2008 Applied Micro Circuits Corporation.
  6 * All rights reserved. James Hsiao <jhsiao@amcc.com>
  7 *
 
 
 
 
 
 
 
 
 
 
  8 * This file defines the security context
  9 * associate format.
 10 */
 11
 12#ifndef __CRYPTO4XX_SA_H__
 13#define __CRYPTO4XX_SA_H__
 14
 15#define AES_IV_SIZE				16
 16
 17/*
 18 * Contents of Dynamic Security Association (SA) with all possible fields
 19 */
 20union dynamic_sa_contents {
 21	struct {
 22		u32 arc4_state_ptr:1;
 23		u32 arc4_ij_ptr:1;
 24		u32 state_ptr:1;
 25		u32 iv3:1;
 26		u32 iv2:1;
 27		u32 iv1:1;
 28		u32 iv0:1;
 29		u32 seq_num_mask3:1;
 30		u32 seq_num_mask2:1;
 31		u32 seq_num_mask1:1;
 32		u32 seq_num_mask0:1;
 33		u32 seq_num1:1;
 34		u32 seq_num0:1;
 35		u32 spi:1;
 36		u32 outer_size:5;
 37		u32 inner_size:5;
 38		u32 key_size:4;
 39		u32 cmd_size:4;
 40	} bf;
 41	u32 w;
 42} __attribute__((packed));
 43
 44#define DIR_OUTBOUND				0
 45#define DIR_INBOUND				1
 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
 58
 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
 65
 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
 73
 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
 81#define SA_SAVE_IV				1
 82#define SA_HEADER_PROC				1
 83#define SA_NO_HEADER_PROC			0
 84
 85union sa_command_0 {
 86	struct {
 87		u32 scatter:1;
 88		u32 gather:1;
 89		u32 save_hash_state:1;
 90		u32 save_iv:1;
 91		u32 load_hash_state:2;
 92		u32 load_iv:2;
 93		u32 digest_len:4;
 94		u32 hdr_proc:1;
 95		u32 extend_pad:1;
 96		u32 stream_cipher_pad:1;
 97		u32 rsv:1;
 98		u32 hash_alg:4;
 99		u32 cipher_alg:4;
100		u32 pad_type:2;
101		u32 op_group:2;
102		u32 dir:1;
103		u32 opcode:3;
104	} bf;
105	u32 w;
106} __attribute__((packed));
107
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
113
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
119
120#define SA_AES_KEY_LEN_128			2
121#define SA_AES_KEY_LEN_192			3
122#define SA_AES_KEY_LEN_256			4
123
124#define SA_REV2					1
125/*
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.
129 */
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
144
145union sa_command_1 {
146	struct {
147		u32 crypto_mode31:1;
148		u32 save_arc4_state:1;
149		u32 arc4_stateful:1;
150		u32 key_len:5;
151		u32 hash_crypto_offset:8;
152		u32 sa_rev:2;
153		u32 byte_offset:1;
154		u32 hmac_muting:1;
155		u32 feedback_mode:2;
156		u32 crypto_mode9_8:2;
157		u32 extended_seq_num:1;
158		u32 seq_num_mask:1;
159		u32 mutable_bit_proc:1;
160		u32 ip_version:1;
161		u32 copy_pad:1;
162		u32 copy_payload:1;
163		u32 copy_hdr:1;
164		u32 rsv1:1;
165	} bf;
166	u32 w;
167} __attribute__((packed));
168
169struct 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));
174
175/*
176 * State Record for Security Association (SA)
177 */
178struct  sa_state_record {
179	__le32 save_iv[4];
180	__le32 save_hash_byte_cnt[2];
181	union {
182		u32 save_digest[16]; /* for MD5/SHA */
183		__le32 save_digest_le32[16]; /* GHASH / CBC */
184	};
185} __attribute__((packed));
186
187/*
188 * Security Association (SA) for AES128
189 *
190 */
191struct dynamic_sa_aes128 {
192	struct dynamic_sa_ctl	ctrl;
193	__le32 key[4];
194	__le32 iv[4]; /* for CBC, OFC, and CFB mode */
195	u32 state_ptr;
196	u32 reserved;
197} __attribute__((packed));
198
199#define SA_AES128_LEN		(sizeof(struct dynamic_sa_aes128)/4)
200#define SA_AES128_CONTENTS	0x3e000042
201
202/*
203 * Security Association (SA) for AES192
204 */
205struct dynamic_sa_aes192 {
206	struct dynamic_sa_ctl ctrl;
207	__le32 key[6];
208	__le32 iv[4]; /* for CBC, OFC, and CFB mode */
209	u32 state_ptr;
210	u32 reserved;
211} __attribute__((packed));
212
213#define SA_AES192_LEN		(sizeof(struct dynamic_sa_aes192)/4)
214#define SA_AES192_CONTENTS	0x3e000062
215
216/*
217 * Security Association (SA) for AES256
218 */
219struct dynamic_sa_aes256 {
220	struct dynamic_sa_ctl ctrl;
221	__le32 key[8];
222	__le32 iv[4]; /* for CBC, OFC, and CFB mode */
223	u32 state_ptr;
224	u32 reserved;
225} __attribute__((packed));
226
227#define SA_AES256_LEN		(sizeof(struct dynamic_sa_aes256)/4)
228#define SA_AES256_CONTENTS	0x3e000082
229#define SA_AES_CONTENTS		0x3e000002
230
231/*
232 * Security Association (SA) for AES128 CCM
233 */
234struct dynamic_sa_aes128_ccm {
235	struct dynamic_sa_ctl ctrl;
236	__le32 key[4];
237	__le32 iv[4];
238	u32 state_ptr;
239	u32 reserved;
240} __packed;
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
244
245/*
246 * Security Association (SA) for AES128_GCM
247 */
248struct dynamic_sa_aes128_gcm {
249	struct dynamic_sa_ctl ctrl;
250	__le32 key[4];
251	__le32 inner_digest[4];
252	__le32 iv[4];
253	u32 state_ptr;
254	u32 reserved;
255} __packed;
256
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
260
261/*
262 * Security Association (SA) for HASH160: HMAC-SHA1
263 */
264struct dynamic_sa_hash160 {
265	struct dynamic_sa_ctl ctrl;
266	__le32 inner_digest[5];
267	__le32 outer_digest[5];
268	u32 state_ptr;
269	u32 reserved;
270} __attribute__((packed));
271#define SA_HASH160_LEN		(sizeof(struct dynamic_sa_hash160)/4)
272#define SA_HASH160_CONTENTS     0x2000a502
273
274static inline u32
275get_dynamic_sa_offset_state_ptr_field(struct dynamic_sa_ctl *cts)
276{
277	u32 offset;
278
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;
293
294	return sizeof(struct dynamic_sa_ctl) + offset * 4;
295}
296
297static inline __le32 *get_dynamic_sa_key_field(struct dynamic_sa_ctl *cts)
298{
299	return (__le32 *) ((unsigned long)cts + sizeof(struct dynamic_sa_ctl));
300}
301
302static inline __le32 *get_dynamic_sa_inner_digest(struct dynamic_sa_ctl *cts)
303{
304	return (__le32 *) ((unsigned long)cts +
305		sizeof(struct dynamic_sa_ctl) +
306		cts->sa_contents.bf.key_size * 4);
307}
308
309#endif
v4.17
  1/**
 
  2 * AMCC SoC PPC4xx Crypto Driver
  3 *
  4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
  5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
  6 *
  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.
 11 *
 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.
 16 *
 17 * This file defines the security context
 18 * associate format.
 19 */
 20
 21#ifndef __CRYPTO4XX_SA_H__
 22#define __CRYPTO4XX_SA_H__
 23
 24#define AES_IV_SIZE				16
 25
 26/**
 27 * Contents of Dynamic Security Association (SA) with all possible fields
 28 */
 29union dynamic_sa_contents {
 30	struct {
 31		u32 arc4_state_ptr:1;
 32		u32 arc4_ij_ptr:1;
 33		u32 state_ptr:1;
 34		u32 iv3:1;
 35		u32 iv2:1;
 36		u32 iv1:1;
 37		u32 iv0:1;
 38		u32 seq_num_mask3:1;
 39		u32 seq_num_mask2:1;
 40		u32 seq_num_mask1:1;
 41		u32 seq_num_mask0:1;
 42		u32 seq_num1:1;
 43		u32 seq_num0:1;
 44		u32 spi:1;
 45		u32 outer_size:5;
 46		u32 inner_size:5;
 47		u32 key_size:4;
 48		u32 cmd_size:4;
 49	} bf;
 50	u32 w;
 51} __attribute__((packed));
 52
 53#define DIR_OUTBOUND				0
 54#define DIR_INBOUND				1
 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
 67
 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
 74
 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
 82
 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
 90#define SA_SAVE_IV				1
 91#define SA_HEADER_PROC				1
 92#define SA_NO_HEADER_PROC			0
 93
 94union sa_command_0 {
 95	struct {
 96		u32 scatter:1;
 97		u32 gather:1;
 98		u32 save_hash_state:1;
 99		u32 save_iv:1;
100		u32 load_hash_state:2;
101		u32 load_iv:2;
102		u32 digest_len:4;
103		u32 hdr_proc:1;
104		u32 extend_pad:1;
105		u32 stream_cipher_pad:1;
106		u32 rsv:1;
107		u32 hash_alg:4;
108		u32 cipher_alg:4;
109		u32 pad_type:2;
110		u32 op_group:2;
111		u32 dir:1;
112		u32 opcode:3;
113	} bf;
114	u32 w;
115} __attribute__((packed));
116
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
122
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
128
129#define SA_AES_KEY_LEN_128			2
130#define SA_AES_KEY_LEN_192			3
131#define SA_AES_KEY_LEN_256			4
132
133#define SA_REV2					1
134/**
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.
138 */
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
153
154union sa_command_1 {
155	struct {
156		u32 crypto_mode31:1;
157		u32 save_arc4_state:1;
158		u32 arc4_stateful:1;
159		u32 key_len:5;
160		u32 hash_crypto_offset:8;
161		u32 sa_rev:2;
162		u32 byte_offset:1;
163		u32 hmac_muting:1;
164		u32 feedback_mode:2;
165		u32 crypto_mode9_8:2;
166		u32 extended_seq_num:1;
167		u32 seq_num_mask:1;
168		u32 mutable_bit_proc:1;
169		u32 ip_version:1;
170		u32 copy_pad:1;
171		u32 copy_payload:1;
172		u32 copy_hdr:1;
173		u32 rsv1:1;
174	} bf;
175	u32 w;
176} __attribute__((packed));
177
178struct 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));
183
184/**
185 * State Record for Security Association (SA)
186 */
187struct  sa_state_record {
188	__le32 save_iv[4];
189	__le32 save_hash_byte_cnt[2];
190	union {
191		u32 save_digest[16]; /* for MD5/SHA */
192		__le32 save_digest_le32[16]; /* GHASH / CBC */
193	};
194} __attribute__((packed));
195
196/**
197 * Security Association (SA) for AES128
198 *
199 */
200struct dynamic_sa_aes128 {
201	struct dynamic_sa_ctl	ctrl;
202	__le32 key[4];
203	__le32 iv[4]; /* for CBC, OFC, and CFB mode */
204	u32 state_ptr;
205	u32 reserved;
206} __attribute__((packed));
207
208#define SA_AES128_LEN		(sizeof(struct dynamic_sa_aes128)/4)
209#define SA_AES128_CONTENTS	0x3e000042
210
211/*
212 * Security Association (SA) for AES192
213 */
214struct dynamic_sa_aes192 {
215	struct dynamic_sa_ctl ctrl;
216	__le32 key[6];
217	__le32 iv[4]; /* for CBC, OFC, and CFB mode */
218	u32 state_ptr;
219	u32 reserved;
220} __attribute__((packed));
221
222#define SA_AES192_LEN		(sizeof(struct dynamic_sa_aes192)/4)
223#define SA_AES192_CONTENTS	0x3e000062
224
225/**
226 * Security Association (SA) for AES256
227 */
228struct dynamic_sa_aes256 {
229	struct dynamic_sa_ctl ctrl;
230	__le32 key[8];
231	__le32 iv[4]; /* for CBC, OFC, and CFB mode */
232	u32 state_ptr;
233	u32 reserved;
234} __attribute__((packed));
235
236#define SA_AES256_LEN		(sizeof(struct dynamic_sa_aes256)/4)
237#define SA_AES256_CONTENTS	0x3e000082
238#define SA_AES_CONTENTS		0x3e000002
239
240/**
241 * Security Association (SA) for AES128 CCM
242 */
243struct dynamic_sa_aes128_ccm {
244	struct dynamic_sa_ctl ctrl;
245	__le32 key[4];
246	__le32 iv[4];
247	u32 state_ptr;
248	u32 reserved;
249} __packed;
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
253
254/**
255 * Security Association (SA) for AES128_GCM
256 */
257struct dynamic_sa_aes128_gcm {
258	struct dynamic_sa_ctl ctrl;
259	__le32 key[4];
260	__le32 inner_digest[4];
261	__le32 iv[4];
262	u32 state_ptr;
263	u32 reserved;
264} __packed;
265
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
269
270/**
271 * Security Association (SA) for HASH160: HMAC-SHA1
272 */
273struct dynamic_sa_hash160 {
274	struct dynamic_sa_ctl ctrl;
275	__le32 inner_digest[5];
276	__le32 outer_digest[5];
277	u32 state_ptr;
278	u32 reserved;
279} __attribute__((packed));
280#define SA_HASH160_LEN		(sizeof(struct dynamic_sa_hash160)/4)
281#define SA_HASH160_CONTENTS     0x2000a502
282
283static inline u32
284get_dynamic_sa_offset_state_ptr_field(struct dynamic_sa_ctl *cts)
285{
286	u32 offset;
287
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;
302
303	return sizeof(struct dynamic_sa_ctl) + offset * 4;
304}
305
306static inline __le32 *get_dynamic_sa_key_field(struct dynamic_sa_ctl *cts)
307{
308	return (__le32 *) ((unsigned long)cts + sizeof(struct dynamic_sa_ctl));
309}
310
311static inline __le32 *get_dynamic_sa_inner_digest(struct dynamic_sa_ctl *cts)
312{
313	return (__le32 *) ((unsigned long)cts +
314		sizeof(struct dynamic_sa_ctl) +
315		cts->sa_contents.bf.key_size * 4);
316}
317
318#endif