WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
crypto_common_def.h
浏览该文件的文档.
1
9#ifndef CRYPTO_COMMON_DEF_H
10#define CRYPTO_COMMON_DEF_H
11
12#define MS_TO_US 1000
13
14#define CRYPTO_BITS_IN_BYTE 8
15
16#define CRYPTO_AES_IV_SIZE 16
17#define CRYPTO_AES_IV_SIZE_IN_WORD 4
18#define CRYPTO_WORD_WIDTH 4
19#define CRYPTO_IV_LEN_IN_BYTES 16
20
21#define CRYPTO_128_KEY_LEN 16
22#define CRYPTO_192_KEY_LEN 24
23#define CRYPTO_256_KEY_LEN 32
24
25#define CRYPTO_AES_MAX_TAG_SIZE 16
26#define CRYPTO_AES_CCM_N_LEN_IN_BYTES 16
27
28#define CRYPTO_AES_BLOCK_SIZE_IN_BYTES 16
29
30#define CRYPTO_BIT_3 3
31#define CRYPTO_BIT_6 6
32
33#define CRYPTO_AES_CCM_NQ_LEN 14
34#define CRYPTO_SYMC_CCM_Q_LEN_2B 2
35#define CRYPTO_SYMC_CCM_Q_LEN_3B 3
36#define CRYPTO_SYMC_CCM_Q_LEN_4B 4
37
38#define HASH_SHA1_BLOCK_SIZE 64
39#define HASH_SHA224_BLOCK_SIZE 64
40#define HASH_SHA256_BLOCK_SIZE 64
41#define HASH_SHA384_BLOCK_SIZE 128
42#define HASH_SHA512_BLOCK_SIZE 128
43#define HASH_SM3_BLOCK_SIZE 64
44
45#define HASH_SHA1_RESULT_SIZE 20
46#define HASH_SHA224_RESULT_SIZE 28
47#define HASH_SHA256_RESULT_SIZE 32
48#define HASH_SHA384_RESULT_SIZE 48
49#define HASH_SHA512_RESULT_SIZE 64
50#define HASH_SM3_RESULT_SIZE 32
51
52#define CRYPTO_GCM_SPECIAL_IV_BYTES 12
53#define CRYPTO_AES_MAX_TAG_LEN 16
54
55#define CRYPTO_CENC_IV_LEN 8
56
57#define CRYPTO_TYPE_ENCRYPT 0x0
58#define CRYPTO_TYPE_DECRYPT 0x1
59#define CRYPTO_TYPE_DMA 0x2
60
61#define CRYPTO_RSA_1024_LEN 128
62#define CRYPTO_RSA_2048_LEN 256
63#define CRYPTO_RSA_3072_LEN 384
64#define CRYPTO_RSA_4096_LEN 512
65
66/* Memory Limit. */
67#define CRYPTO_MAX_AAD_SIZE (4 * 1024)
68#define CRYPTO_MAX_CRYPTO_SIZE (4 * 1024)
69
70/* PBKDF2 Limits. */
71#define CRYPTO_PBKDF2_PASS_MAX_LENGTH 1024
72#define CRYPTO_PBKDF2_SALT_MAX_LENGTH 1024
73#define CRYPTO_PBKDF2_OUT_MAX_LENGTH 1024
74#define CRYPTO_PBKDF2_MAX_COUNT 100000
75
76/* Hash Limits. */
77#define CRYPTO_HASH_KEY_MAX_LENGTH 128
78#define CRYPTO_HASH_MIN_LEN 32
79#define CRYPTO_HASH_MAX_LEN 64
80
81/* CENC Limits. */
82#define CRYPTO_SYMC_CENC_SUBSAMPLE_MAX_SIZE 200
83
84/* SYMC Limits. */
85#define CRYPTO_SYMC_MULTI_PACK_MAX_SIZE 200
86#define CRYPTO_SYMC_AAD_MAX_SIZE (4 * 1024)
87
88/* PKE Limits. */
89#define CRYPTO_PKE_ECC_KEY_MIN_SIZE 32
90#define CRYPTO_PKE_ECC_KEY_MAX_SIZE 72
91#define CRYPTO_PKE_RSA_KEY_MIN_SIZE 256
92#define CRYPTO_PKE_RSA_KEY_MAX_SIZE 512
93
94/* TRNG Limits. */
95#define CRYPTO_MULTI_RANDOM_MAX_LENGTH 1024
96
97/* HKDF Limits. */
98#define HKDF_EXPAND_INFO_MAX_LENGTH 1024
99
100#define CRYPTO_PKE_MSG_MIN_SIZE 1
101#define CRYPTO_PKE_MSG_MAX_SIZE (10 * 1024)
102#define CRYPTO_PKE_SM2_ID_MIN_SIZE 1
103#define CRYPTO_PKE_SM2_ID_MAX_SIZE 1024
104#define CRYPTO_PKE_SM2_PLAIN_TEXT_MIN_SIZE 1
105#define CRYPTO_PKE_SM2_PLAIN_TEXT_MAX_SIZE 1024
106#define CRYPTO_PKE_RSA_LABLE_MAX_SIZE 1024
107
108/*
109 * Handle Process
110 * Kapi Handle consists of the following parts:
111 *|<---- Reserved(15-bit) --->|<- Soft alg flag(1-bit) ->|<---- Module ID(8-bit) ---->|<---- Context Idx(8-bit)---->|
112 */
113#define crypto_set_soft_alg_flag(handle) ((handle) | 0x10000)
114#define crypto_check_soft_alg_flag(handle) (((handle) >> 16) & 0x1)
115#define crypto_get_soft_channel_id(handle) ((handle) & 0xff)
116
117#define kapi_get_module_id(kapi_handle) (((kapi_handle) >> 8) & 0xff)
118#define kapi_get_ctx_idx(kapi_handle) ((kapi_handle) & 0xff)
119#define synthesize_kapi_handle(module_id, ctx_id) (((module_id) << 8) | (ctx_id))
120
121/*
122 *|<---- Reserved(8-bit) --->|<- keyslot_type(8-bit) ->|<---- Module ID(8-bit) ---->|<---- Context Idx(8-bit)---->|
123 * keyslot_type: 0 - MCIPHER, 1 - HMAC
124 */
125#define crypto_keyslot_compat_handle(keyslot_type, idx) \
126 (((keyslot_type) << 16) | ((KAPI_KEYSLOT_MODULE_ID) << 8) | (idx))
127#define crypto_keyslot_compat_hmac_handle(idx) crypto_keyslot_compat_handle(1, idx)
128#define crypto_keyslot_compat_mcipher_handle(idx) crypto_keyslot_compat_handle(0, idx)
129#define crypto_keyslot_is_hmac(handle) ((((handle) >> 16) & 0xff) == 0x1)
130#define crypto_keyslot_is_mcipher(handle) ((((handle) >> 16) & 0xff) == 0)
131#define crypto_keyslot_get_idx(handle) ((handle) & 0xff)
132#define crypto_keyslot_get_module_id(handle) (((handle) >> 8) & 0xff)
133
134#endif