xref: /optee_os/core/drivers/crypto/hisilicon/sec_authenc.h (revision 5d5d7d0b1c038a6836be9f0b38585f5aa6a4dd01)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /* Copyright (c) 2022-2024 HiSilicon Limited. */
3 
4 #ifndef __SEC_AUTHENC_H__
5 #define __SEC_AUTHENC_H__
6 
7 #include <stdbool.h>
8 #include <stdint.h>
9 
10 #include "hisi_qm.h"
11 
12 #define SEC_MAX_AEAD_LENGTH		16777199
13 #define SEC_MIN_AEAD_LENGTH		4
14 #define SEC_TAG_ERR			0x2
15 #define SEC_MIN_GCM_TAG_LEN		8
16 #define SEC_MIN_CCM_TAG_LEN		4
17 #define SEC_MAX_TAG_LEN			16
18 #define SEC_CIPHER_THEN_DIGEST		0
19 #define SEC_DIGEST_THEN_CIPHER		1
20 
21 #define MAX_GCM_AAD_SIZE		65535
22 #define MAX_CCM_AAD_SIZE		65279
23 #define GCM_IV_SIZE			12
24 #define MAX_CCM_NONCE_SIZE		12
25 #define MIN_CCM_NONCE_SIZE		7
26 #define TAG_ALIGN			2
27 #define MAX_KEY_SIZE			32
28 #define MAX_IV_SIZE			16
29 #define NONCE_OFFSET			1
30 #define IV_LAST_BYTE1			15
31 #define IV_LAST_BYTE2			14
32 #define IV_LAST_BYTE3			13
33 #define IV_CTR_INIT			1
34 #define IV_CL_CAL_NUM			14
35 #define IV_CM_CAL_NUM			2
36 #define IV_CL_MASK			0x7
37 #define IV_FLAGS_OFFSET			0x6
38 #define IV_CM_OFFSET			0x3
39 #define IV_LAST_BYTE_MASK		0xFF
40 #define IV_BYTE_OFFSET			0x8
41 #define AAD_NOT_NULL			1
42 
43 struct authenc_ctx {
44 	struct hisi_qp *qp;
45 	bool encrypt;
46 	uint8_t civ[MAX_IV_SIZE];
47 	uint8_t aiv[MAX_IV_SIZE];
48 	uint8_t key[MAX_KEY_SIZE];
49 	uint8_t tag[SEC_MAX_TAG_LEN];
50 	struct drvcrypt_buf aad;
51 	struct drvcrypt_buf src;
52 	struct drvcrypt_buf dst;
53 
54 	uint8_t algo;
55 	uint8_t mode;
56 	uint32_t result;
57 	bool is_hw_supported;
58 	struct crypto_authenc_ctx *ae_soft_ctx;
59 	size_t src_offset;
60 	size_t payload_len;
61 	size_t key_len;
62 	size_t civ_len;
63 	size_t tag_len;
64 	uint8_t c_key_len;
65 
66 	/* aead dma */
67 	paddr_t key_dma;
68 	paddr_t civ_dma;
69 	paddr_t aiv_dma;
70 	paddr_t src_dma;
71 	paddr_t dst_dma;
72 	paddr_t tag_dma;
73 };
74 #endif /* __SEC_AUTHENC_H__ */
75