SemiDrive SSDK Appication Program Interface PTG3.0
sdrv_crypto_mailbox_common.h
Go to the documentation of this file.
1
9#ifndef SDRV_CRYPTO_MAILBOX_COMMON_H
10#define SDRV_CRYPTO_MAILBOX_COMMON_H
11
12#include <armv7-r/cache.h>
13#include <sdrv_crypto_utility.h>
14#include <stdint.h>
15
17
18#define RETRY_COUNT (20)
19
20#define ROM_VENDER_SM2_PUBKEY_ADDR (0x000)
21#define ROM_FIRMWARE_ADDR (0x000)
22/*if key is from secure port, the max key index(or the number of keys)*/
23#define SKE_MAX_KEY_IDX (9)
24
25#define KEYID_0 (0)
26#define KEYID_1 (1)
27#define KEYID_2 (2)
28#define KEYID_3 (3)
29#define KEYID_4 (4)
30#define KEYID_5 (5)
31#define KEYID_6 (6)
32#define KEYID_7 (7)
33#define KEYID_8 (8)
34#define KEYID_9 (9)
35#define KEYID_MAX SKE_MAX_KEY_IDX
36#define KEYID_HALF_MASK (0x8000)
37
38#define BASIC_MGMT_CMD_BASE (0x00)
39#define GET_DEVICE_INFO (BASIC_MGMT_CMD_BASE + 1)
40#define GET_DEVICE_STATUS (BASIC_MGMT_CMD_BASE + 2)
41#define GENERATE_RAND (BASIC_MGMT_CMD_BASE + 3)
42#define GENERATE_KEY (BASIC_MGMT_CMD_BASE + 4)
43#define SELF_DESTROY (BASIC_MGMT_CMD_BASE + 5)
44#define SEIP_JUMP (BASIC_MGMT_CMD_BASE + 6)
45#define SEIP_DISABLE (BASIC_MGMT_CMD_BASE + 7)
46#define SENSOR_CLK_CFG (BASIC_MGMT_CMD_BASE + 8)
47
48#define MAC_CMD_BASE (0x10)
49#define GENERATE_MAC (MAC_CMD_BASE + 1)
50#define VERIFY_MAC (MAC_CMD_BASE + 2)
51#define GENERATE_AUTH_MAC (MAC_CMD_BASE + 3)
52
53#define SKE_CMD_BASE (0x20)
54#define SKE_ENCRYPT (SKE_CMD_BASE + 1)
55#define SKE_DECRYPT (SKE_CMD_BASE + 2)
56#define SKE_AEAD_ENCRYPT_GCM (SKE_CMD_BASE + 3)
57#define SKE_AEAD_DECRYPT_GCM (SKE_CMD_BASE + 4)
58
59#define SM2_CMD_BASE (0x40)
60#define SM2_GET_Z (SM2_CMD_BASE + 1)
61#define SM2_GET_E (SM2_CMD_BASE + 2)
62#define SM2_GENERATE_KEY (SM2_CMD_BASE + 3)
63#define SM2_GENERATE_SIGNATURE (SM2_CMD_BASE + 4)
64#define SM2_VERIFY_SIGNATURE (SM2_CMD_BASE + 5)
65#define SM2_ENCRYPT (SM2_CMD_BASE + 6)
66#define SM2_DECRYPT (SM2_CMD_BASE + 7)
67#define SM2_EXCHANGE_KEY (SM2_CMD_BASE + 8)
68#define SM2_GET_PUB_KEY (SM2_CMD_BASE + 9)
69
70#define SM9_CMD_BASE (0x50)
71#define SM9_SIGN_GENERATE_MASTER_KEY (SM9_CMD_BASE + 1)
72#define SM9_SIGN_GENERATE_USER_PRIVATE_KEY (SM9_CMD_BASE + 2)
73#define SM9_GENERATE_SIGNATURE (SM9_CMD_BASE + 3)
74#define SM9_VERIFY_SIGNATURE (SM9_CMD_BASE + 4)
75#define SM9_ENC_GENERATE_MASTER_KEY (SM9_CMD_BASE + 5)
76#define SM9_ENC_GENERATE_USER_PRIVATE_KEY (SM9_CMD_BASE + 6)
77#define SM9_WRAP_KEY (SM9_CMD_BASE + 7)
78#define SM9_UNWRAP_KEY (SM9_CMD_BASE + 8)
79#define SM9_ENCRYPT (SM9_CMD_BASE + 9)
80#define SM9_DECRYPT (SM9_CMD_BASE + 10)
81#define SM9_EXCKEY_GENERATE_MASTER_KEY (SM9_CMD_BASE + 11)
82#define SM9_EXCKEY_GENERATE_USER_PRIVATE_KEY (SM9_CMD_BASE + 12)
83#define SM9_EXCKEY_GENERATE_USER_TMP_KEY (SM9_CMD_BASE + 13)
84#define SM9_EXCHANGE_KEY (SM9_CMD_BASE + 14)
85
86#define ECCP_CMD_BASE (0x70)
87#define ECCP_POINT_DOUBLING (ECCP_CMD_BASE + 1)
88#define ECCP_POINT_ADDITION (ECCP_CMD_BASE + 2)
89#define ECCP_POINT_MULTIPLICATION (ECCP_CMD_BASE + 3)
90#define ECCP_POINT_VERIFY (ECCP_CMD_BASE + 4)
91#define ECCP_GENERATE_KEY (ECCP_CMD_BASE + 5)
92#define ECDH_EXCHANGE_KEY (ECCP_CMD_BASE + 6)
93#define ECDSA_GENERATE_SIGNATURE (ECCP_CMD_BASE + 7)
94#define ECDSA_VERIFY_SIGNATURE (ECCP_CMD_BASE + 8)
95
96#define RSA_CMD_BASE (0x80)
97#define RSA_GENERATE_PRIME (RSA_CMD_BASE + 1)
98#define RSA_GENERATE_KEY (RSA_CMD_BASE + 2)
99#define RSA_GENERATE_CRT_KEY (RSA_CMD_BASE + 3)
100#define RSA_ENCRYPT (RSA_CMD_BASE + 4)
101#define RSA_DECRYPT (RSA_CMD_BASE + 5)
102#define RSA_CRT_DECRYPT (RSA_CMD_BASE + 6)
103#define RSA_GENERATE_SIGNATURE (RSA_CMD_BASE + 7)
104#define RSA_CRT_GENERATE_SIGNATURE (RSA_CMD_BASE + 8)
105#define RSA_VERIFY_SIGNATURE (RSA_CMD_BASE + 9)
106
107#define HASH_CMD_BASE (0xA0)
108#define HASH_CALC (HASH_CMD_BASE + 1)
109
110#define CMD_BASIC_MAC_BUFF_LEN 32
111#define CMD_BASIC_TWO_KEY_MAC_BUFF_LEN 64
112
116typedef enum {
129
133typedef enum {
139
143enum {
144 HASH_ALG_SM3 = 0, // 0
151
159
167
172
188
196
204
212
220
224
225};
226
227/* seip error code */
276};
277
286uint32_t send_cmd_and_wait_response(uint32_t cmd[8]);
287
297uint16_t get_big_endian_2byte(void *addr);
298
308uint32_t get_big_endian_4byte(void *addr);
309
318void set_big_endian_2byte_back(uint8_t *addr, uint16_t data);
319
329void set_big_endian_2byte(uint8_t *addr, uint16_t data);
330
339void set_big_endian_4byte_back(uint8_t *addr, uint32_t data);
340
350void set_big_endian_4byte(uint8_t *addr, uint32_t data);
351
361void *get_real_pointer(uint8_t buf[4]);
362
371uint32_t cmd_get_ske_key_bytes(uint8_t crypto_alg_mode_choice);
372
381uint32_t cmd_get_ske_block_bytes(uint8_t crypto_alg_mode_choice);
382
391uint32_t cmd_get_hash_digest_bytes(uint8_t crypto_alg_mode_choice);
392
401uint32_t cmd_get_hash_block_bytes(uint8_t crypto_alg_mode_choice);
402
412uint32_t read_sec_stroge_reg(paddr_t base, uint32_t offset);
413
423void write_sec_stroge_reg(paddr_t base, uint32_t offset, uint32_t data);
424
425#endif
void set_big_endian_4byte(uint8_t *addr, uint32_t data)
set 4 bytes big-endian data.
uint32_t read_sec_stroge_reg(paddr_t base, uint32_t offset)
read secure stroge registers.
uint16_t get_big_endian_2byte(void *addr)
get 2 bytes big-endian data.
ERR_CODE
Definition: sdrv_crypto_mailbox_common.h:228
@ SEIP_ERROR_KEYID1_FAIL
Definition: sdrv_crypto_mailbox_common.h:241
@ SEIP_ERROR_SM2_VERIFY_FAIL
Definition: sdrv_crypto_mailbox_common.h:271
@ SEIP_FW_VER_ERROR
Definition: sdrv_crypto_mailbox_common.h:232
@ SEIP_ERROR_HASH_ALG_INVALID
Definition: sdrv_crypto_mailbox_common.h:256
@ SEIP_ERROR_MODE_INVALID
Definition: sdrv_crypto_mailbox_common.h:235
@ SEIP_ERROR_RSA_GET_KEY_FAIL
Definition: sdrv_crypto_mailbox_common.h:267
@ SEIP_SUCCESS
Definition: sdrv_crypto_mailbox_common.h:229
@ SEIP_ERROR_KEYID_INVALID
Definition: sdrv_crypto_mailbox_common.h:245
@ SEIP_ERROR
Definition: sdrv_crypto_mailbox_common.h:230
@ SEIP_ERROR_SM2_EXCHANGE_FAIL
Definition: sdrv_crypto_mailbox_common.h:274
@ SEIP_ERROR_ECC_GET_KEY_FAIL
Definition: sdrv_crypto_mailbox_common.h:263
@ SEIP_ERROR_ECC_PA_FAIL
Definition: sdrv_crypto_mailbox_common.h:261
@ SEIP_ERROR_ECC_PD_FAIL
Definition: sdrv_crypto_mailbox_common.h:260
@ SEIP_ERROR_KEYID3_FAIL
Definition: sdrv_crypto_mailbox_common.h:243
@ SEIP_ERROR_SM9_FAIL
Definition: sdrv_crypto_mailbox_common.h:275
@ SEIP_ERROR_SM2_ENCRYPT_FAIL
Definition: sdrv_crypto_mailbox_common.h:272
@ SEIP_ERROR_HMAC_FAIL
Definition: sdrv_crypto_mailbox_common.h:258
@ SEIP_ERROR_ECDSA_SIGN_FAIL
Definition: sdrv_crypto_mailbox_common.h:264
@ SEIP_ERROR_SM2_DECRYPT_FAIL
Definition: sdrv_crypto_mailbox_common.h:273
@ SEIP_ERROR_VALUE_INVALID
Definition: sdrv_crypto_mailbox_common.h:236
@ SEIP_ERROR_SM2_GET_KEY_FAIL
Definition: sdrv_crypto_mailbox_common.h:269
@ SEIP_ERROR_KEYID_INVALID2
Definition: sdrv_crypto_mailbox_common.h:246
@ SEIP_ERROR_KEYID2_FAIL
Definition: sdrv_crypto_mailbox_common.h:242
@ SEIP_ERROR_COMPARE_FAIL3
Definition: sdrv_crypto_mailbox_common.h:255
@ SEIP_ERROR_RSA_FAIL
Definition: sdrv_crypto_mailbox_common.h:268
@ SEIP_ERROR_TRNG_FAIL
Definition: sdrv_crypto_mailbox_common.h:251
@ SEIP_ERROR_HASH_FAIL
Definition: sdrv_crypto_mailbox_common.h:257
@ SEIP_ERROR_COMPARE_FAIL
Definition: sdrv_crypto_mailbox_common.h:253
@ SEIP_ERROR_SKE_FAIL
Definition: sdrv_crypto_mailbox_common.h:248
@ SEIP_ERROR_AUTH_KEY_FAIL
Definition: sdrv_crypto_mailbox_common.h:247
@ SEIP_ERROR_GET_PRIME_FAIL
Definition: sdrv_crypto_mailbox_common.h:266
@ SEIP_ERROR_SKE_ALG_INVALID
Definition: sdrv_crypto_mailbox_common.h:249
@ SEIP_SKE_ALARM
Definition: sdrv_crypto_mailbox_common.h:233
@ SEIP_ERROR_COMPARE_FAIL2
Definition: sdrv_crypto_mailbox_common.h:254
@ SEIP_ERROR_KEK_DECRYPT_FAIL
Definition: sdrv_crypto_mailbox_common.h:239
@ SEIP_ERROR_KEYID0_FAIL
Definition: sdrv_crypto_mailbox_common.h:240
@ SEIP_ERROR_NOT_ALIGNED_BY_WORD
Definition: sdrv_crypto_mailbox_common.h:234
@ SEIP_ERROR_SM2_SIGN_FAIL
Definition: sdrv_crypto_mailbox_common.h:270
@ SEIP_ERROR_ECC_CURVE_INVALID
Definition: sdrv_crypto_mailbox_common.h:259
@ SEIP_ERROR_ECDSA_VERIFY_FAIL
Definition: sdrv_crypto_mailbox_common.h:265
@ SEIP_FW_VER_SUCCESS
Definition: sdrv_crypto_mailbox_common.h:231
@ SEIP_ERROR_KEK_ENCRYPT_FAIL
Definition: sdrv_crypto_mailbox_common.h:238
@ SEIP_ERROR_ECC_PM_FAIL
Definition: sdrv_crypto_mailbox_common.h:262
@ SEIP_ERROR_LENGTH_INVALID
Definition: sdrv_crypto_mailbox_common.h:237
@ SEIP_ERROR_BOOTMODE_FAIL
Definition: sdrv_crypto_mailbox_common.h:252
@ SEIP_ERROR_SKE_SET_SEED_FAIL
Definition: sdrv_crypto_mailbox_common.h:250
@ SEIP_ERROR_KEYID_ZERO
Definition: sdrv_crypto_mailbox_common.h:244
uint32_t cmd_get_ske_key_bytes(uint8_t crypto_alg_mode_choice)
get key bytes of SKE algorithm type.
void set_big_endian_2byte_back(uint8_t *addr, uint16_t data)
backup 2 bytes data.
uint32_t get_big_endian_4byte(void *addr)
get 4 bytes big-endian data.
uint32_t cmd_get_ske_block_bytes(uint8_t crypto_alg_mode_choice)
get block bytes of SKE algorithm type.
Crypto_HsmInitReturnType
CRYPTO init return type.
Definition: sdrv_crypto_mailbox_common.h:116
@ CRYPTO_HSM_INIT_OK
Definition: sdrv_crypto_mailbox_common.h:118
@ CRYPTO_HSM_INIT_BOOT_FAIL
Definition: sdrv_crypto_mailbox_common.h:124
@ CRYPTO_HSM_INIT_TYPE_MAX
Definition: sdrv_crypto_mailbox_common.h:127
@ CRYPTO_HSM_INIT_RESET_FAIL
Definition: sdrv_crypto_mailbox_common.h:120
@ CRYPTO_HSM_INIT_PRODUCT_ERROR
Definition: sdrv_crypto_mailbox_common.h:126
@ CRYPTO_HSM_INIT_BOOT_TIMEOUT
Definition: sdrv_crypto_mailbox_common.h:122
uint32_t send_cmd_and_wait_response(uint32_t cmd[8])
Sdrv CRYPTO send cmd.
cmd_key_type_e
CRYPTO key type.
Definition: sdrv_crypto_mailbox_common.h:133
@ CMD_KEY_EXTERNAL_PLAINTEXT
Definition: sdrv_crypto_mailbox_common.h:135
@ CMD_KEY_EXTERNAL_CIPHERTEXT
Definition: sdrv_crypto_mailbox_common.h:136
@ CMD_KEY_MAX
Definition: sdrv_crypto_mailbox_common.h:137
@ CMD_KEY_INTERNAL
Definition: sdrv_crypto_mailbox_common.h:134
void set_big_endian_4byte_back(uint8_t *addr, uint32_t data)
backup 4 bytes data.
@ CBC_MAC_SKE_ALG_TDES_128
Definition: sdrv_crypto_mailbox_common.h:161
@ SKE_ALG_AES_128_CFB
Definition: sdrv_crypto_mailbox_common.h:191
@ SKE_ALG_AES_192_XTS
Definition: sdrv_crypto_mailbox_common.h:202
@ CBC_MAC_SKE_ALG_DES
Definition: sdrv_crypto_mailbox_common.h:160
@ SKE_ALG_AES_128_CTR
Definition: sdrv_crypto_mailbox_common.h:193
@ HMAC_ALG_SHA512
Definition: sdrv_crypto_mailbox_common.h:155
@ SKE_ALG_SM4_GCM
Definition: sdrv_crypto_mailbox_common.h:219
@ SKE_ALG_AES_128_XTS
Definition: sdrv_crypto_mailbox_common.h:194
@ SKE_ALG_SM4_CTR
Definition: sdrv_crypto_mailbox_common.h:217
@ SKE_ALG_TDES_128_ECB
Definition: sdrv_crypto_mailbox_common.h:178
@ SKE_ALG_TDES_192_CBC
Definition: sdrv_crypto_mailbox_common.h:184
@ SKE_ALG_TDES_128_CFB
Definition: sdrv_crypto_mailbox_common.h:180
@ HMAC_ALG_SM3
Definition: sdrv_crypto_mailbox_common.h:152
@ SKE_ALG_AES_192_GCM
Definition: sdrv_crypto_mailbox_common.h:203
@ CMAC_SKE_ALG_AES_256
Definition: sdrv_crypto_mailbox_common.h:170
@ HASH_ALG_SHA512_256
Definition: sdrv_crypto_mailbox_common.h:150
@ PKE_ALG_RSA
Definition: sdrv_crypto_mailbox_common.h:222
@ SKE_ALG_TDES_192_ECB
Definition: sdrv_crypto_mailbox_common.h:183
@ SKE_ALG_AES_192_ECB
Definition: sdrv_crypto_mailbox_common.h:197
@ SKE_ALG_AES_256_CTR
Definition: sdrv_crypto_mailbox_common.h:209
@ CBC_MAC_SKE_ALG_AES_192
Definition: sdrv_crypto_mailbox_common.h:164
@ SKE_ALG_DES_CBC
Definition: sdrv_crypto_mailbox_common.h:174
@ HASH_ALG_SHA224
Definition: sdrv_crypto_mailbox_common.h:148
@ SKE_ALG_AES_192_CTR
Definition: sdrv_crypto_mailbox_common.h:201
@ SKE_ALG_TDES_128_OFB
Definition: sdrv_crypto_mailbox_common.h:181
@ CMAC_SKE_ALG_AES_192
Definition: sdrv_crypto_mailbox_common.h:169
@ PKE_ALG_ECC
Definition: sdrv_crypto_mailbox_common.h:223
@ HASH_ALG_SHA512_224
Definition: sdrv_crypto_mailbox_common.h:149
@ SKE_ALG_DES_CTR
Definition: sdrv_crypto_mailbox_common.h:177
@ SKE_ALG_SM4_ECB
Definition: sdrv_crypto_mailbox_common.h:213
@ HASH_ALG_SHA512
Definition: sdrv_crypto_mailbox_common.h:147
@ SKE_ALG_AES_192_CFB
Definition: sdrv_crypto_mailbox_common.h:199
@ SKE_ALG_TDES_192_CFB
Definition: sdrv_crypto_mailbox_common.h:185
@ SKE_ALG_AES_128_OFB
Definition: sdrv_crypto_mailbox_common.h:192
@ SKE_ALG_AES_192_OFB
Definition: sdrv_crypto_mailbox_common.h:200
@ SKE_ALG_DES_CFB
Definition: sdrv_crypto_mailbox_common.h:175
@ SKE_ALG_AES_256_GCM
Definition: sdrv_crypto_mailbox_common.h:211
@ HASH_ALG_SM3
Definition: sdrv_crypto_mailbox_common.h:144
@ SKE_ALG_DES_OFB
Definition: sdrv_crypto_mailbox_common.h:176
@ SKE_ALG_TDES_128_CBC
Definition: sdrv_crypto_mailbox_common.h:179
@ SKE_ALG_TDES_192_CTR
Definition: sdrv_crypto_mailbox_common.h:187
@ PKE_ALG_SM2
Definition: sdrv_crypto_mailbox_common.h:221
@ SKE_ALG_TDES_128_CTR
Definition: sdrv_crypto_mailbox_common.h:182
@ HMAC_ALG_SHA224
Definition: sdrv_crypto_mailbox_common.h:156
@ HASH_ALG_SHA256
Definition: sdrv_crypto_mailbox_common.h:145
@ SKE_ALG_SM4_XTS
Definition: sdrv_crypto_mailbox_common.h:218
@ HMAC_ALG_SHA512_224
Definition: sdrv_crypto_mailbox_common.h:157
@ SKE_ALG_SM4_CBC
Definition: sdrv_crypto_mailbox_common.h:214
@ SKE_ALG_SM4_CFB
Definition: sdrv_crypto_mailbox_common.h:215
@ SKE_ALG_AES_256_OFB
Definition: sdrv_crypto_mailbox_common.h:208
@ SKE_ALG_TDES_192_OFB
Definition: sdrv_crypto_mailbox_common.h:186
@ HMAC_ALG_SHA256
Definition: sdrv_crypto_mailbox_common.h:153
@ SKE_ALG_AES_192_CBC
Definition: sdrv_crypto_mailbox_common.h:198
@ SKE_ALG_AES_128_GCM
Definition: sdrv_crypto_mailbox_common.h:195
@ SKE_ALG_AES_256_CBC
Definition: sdrv_crypto_mailbox_common.h:206
@ CBC_MAC_SKE_ALG_AES_256
Definition: sdrv_crypto_mailbox_common.h:165
@ SKE_ALG_AES_256_ECB
Definition: sdrv_crypto_mailbox_common.h:205
@ SKE_ALG_AES_256_CFB
Definition: sdrv_crypto_mailbox_common.h:207
@ SKE_ALG_AES_256_XTS
Definition: sdrv_crypto_mailbox_common.h:210
@ CBC_MAC_SKE_ALG_AES_128
Definition: sdrv_crypto_mailbox_common.h:163
@ CMAC_SKE_ALG_AES_128
Definition: sdrv_crypto_mailbox_common.h:168
@ SKE_ALG_AES_128_ECB
Definition: sdrv_crypto_mailbox_common.h:189
@ SKE_ALG_AES_128_CBC
Definition: sdrv_crypto_mailbox_common.h:190
@ SKE_ALG_SM4_OFB
Definition: sdrv_crypto_mailbox_common.h:216
@ HASH_ALG_SHA384
Definition: sdrv_crypto_mailbox_common.h:146
@ CBC_MAC_SKE_ALG_SM4
Definition: sdrv_crypto_mailbox_common.h:166
@ HMAC_ALG_SHA512_256
Definition: sdrv_crypto_mailbox_common.h:158
@ CBC_MAC_SKE_ALG_TDES_192
Definition: sdrv_crypto_mailbox_common.h:162
@ HMAC_ALG_SHA384
Definition: sdrv_crypto_mailbox_common.h:154
@ CMAC_SKE_ALG_SM4
Definition: sdrv_crypto_mailbox_common.h:171
@ SKE_ALG_DES_ECB
Definition: sdrv_crypto_mailbox_common.h:173
void write_sec_stroge_reg(paddr_t base, uint32_t offset, uint32_t data)
write secure stroge registers.
void set_big_endian_2byte(uint8_t *addr, uint16_t data)
set 2 bytes big-endian data.
uint32_t cmd_get_hash_digest_bytes(uint8_t crypto_alg_mode_choice)
get HASH digest bytes.
void * get_real_pointer(uint8_t buf[4])
get the real pointer address.
uint32_t cmd_get_hash_block_bytes(uint8_t crypto_alg_mode_choice)
get HASH block bytes.
crypto utility api