xref: /optee_os/core/drivers/crypto/hisilicon/hpre_rsa.h (revision 76d6685e5f3b91d66dc2091b9d61601c050298bb)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2024, HiSilicon Technologies Co., Ltd.
4  */
5 
6 #ifndef __HPRE_RSA_H__
7 #define __HPRE_RSA_H__
8 
9 #include <stdint.h>
10 #include <tee_api_types.h>
11 #include <types_ext.h>
12 
13 #define PKCS_V1_5_MSG_MIN_LEN			11
14 #define PKCS_V1_5_PS_MIN_LEN			8
15 #define PKCS_V1_5_PS_POS			2
16 #define PKCS_V1_5_FIXED_LEN			3
17 #define PKCS_V1_5_PS_DATA			0x5a
18 #define OAEP_MAX_HASH_LEN			64
19 #define OAEP_MAX_DB_LEN				512
20 #define PRIME_QUALITY_FLAG			1024
21 #define HPRE_RSA_CRT_TOTAL_BUF_SIZE(kbytes)	((kbytes) * 6)
22 #define HPRE_RSA_CRT_KEY_BUF_SIZE(kbytes)	((kbytes) >> 10)
23 #define HPRE_RSA_NCRT_TOTAL_BUF_SIZE(kbytes)	((kbytes) * 4)
24 
25 enum pkcs_v1_5_pad_type {
26 	SIGN_PAD = 1,
27 	ENCRYPT_PAD = 2
28 };
29 
30 /*
31  * When the mode is encrypt, the size of the buffer is
32  * HPRE_RSA_NCRT_TOTAL_BUF_SIZE(kbytes) for both crt and ncrt;
33  * when the mode is decrypt, the size of the buffer is
34  * HPRE_RSA_CRT_TOTAL_BUF_SIZE(kbytes) for crt and
35  * HPRE_RSA_NCRT_TOTAL_BUF_SIZE(kbytes) for ncrt.
36  */
37 struct hpre_rsa_msg {
38 	uint8_t *pubkey;
39 	paddr_t pubkey_dma;
40 	uint8_t *prikey;
41 	paddr_t prikey_dma;
42 	uint8_t *in;
43 	paddr_t in_dma;
44 	uint8_t *out;
45 	paddr_t out_dma;
46 	uint32_t alg_type;
47 	uint32_t key_bytes;
48 	bool is_private;    /* True if private key */
49 };
50 
51 #endif
52