SemiDrive SSDK Appication Program Interface PTG3.0
sm9.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 *
4 *Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
5 *Software License Agreement
6 *
7 ******************************************************************************
8 */
9#ifndef SM9_H
10#define SM9_H
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include <pke.h>
17#include <trng.h>
18
19#define SM9_MAX_ID_BYTE_LEN (1 << 13)
20#define SM9_MAX_MSG_BYTE_LEN (0xFFFFFF9F)
21#define SM9_MAX_ENC_K2_BYTE_LEN (0x40)
22#define SM9_POINT_NOT_COMPRESSED (0x04)
23
24/*SM9 error code*/
36};
37
38/*SM9 encryption type choice*/
39typedef enum {
43
44/*available when choose SM9_ENC_KDF_BLOCK_CIPHER*/
45typedef enum {
50
51/*SM9 key exchange role*/
53
55 uint8_t Ppub_s[128]);
56
57uint32_t sm9_sign_gen_mastKeyPair(uint8_t ks[32], uint8_t Ppub_s[128]);
58
59uint32_t sm9_sign_gen_userPriKey(const uint8_t *IDA, uint32_t IDA_byteLen,
60 uint8_t hid, uint8_t ks[32], uint8_t dsA[64]);
61
62uint32_t sm9_sign(const uint8_t *M, uint32_t MByteLen,
63 const uint8_t Ppub_s[128], const uint8_t dsA[64],
64 uint8_t r[32], uint8_t h[32], uint8_t S[65]);
65
66uint32_t sm9_verify(const uint8_t *M, uint32_t MByteLen, const uint8_t *IDA,
67 uint32_t IDA_byteLen, uint8_t hid,
68 const uint8_t Ppub_s[128], const uint8_t h[32],
69 const uint8_t S[65]);
70
72 uint8_t Ppub_e[64]);
73
74uint32_t sm9_enc_gen_mastKeyPair(uint8_t ke[32], uint8_t Ppub_e[64]);
75
76uint32_t sm9_enc_gen_userPriKey(const uint8_t *IDB, uint32_t IDB_byteLen,
77 uint8_t hid, uint8_t ke[32], uint8_t deB[128]);
78
79uint32_t sm9_wrap_key(const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid,
80 const uint8_t Ppub_e[64], uint8_t r[32], uint8_t C[64],
81 uint32_t KByteLen, uint8_t *K);
82
83uint32_t sm9_unwrap_key(const uint8_t *IDB, uint32_t IDB_byteLen,
84 const uint8_t deB[128], const uint8_t C[64],
85 uint32_t KByteLen, uint8_t *K);
86
87uint32_t sm9_enc(const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid,
88 const uint8_t *M, uint32_t MByteLen, const uint8_t Ppub_e[64],
89 uint8_t r[32], sm9_enc_type_e enc_type,
90 sm9_enc_padding_e padding_type, uint32_t K2ByteLen, uint8_t *C,
91 uint32_t *CByteLen);
92
93uint32_t sm9_dec(const uint8_t *IDB, uint32_t IDB_byteLen, const uint8_t *C,
94 uint32_t CByteLen, const uint8_t deB[128],
95 sm9_enc_type_e enc_type, sm9_enc_padding_e padding_type,
96 uint32_t K2ByteLen, uint8_t *M, uint32_t *MByteLen);
97
99 uint8_t Ppub_e[64]);
100
101uint32_t sm9_exckey_gen_mastKeyPair(uint8_t ke[32], uint8_t Ppub_e[64]);
102
103uint32_t sm9_exckey_gen_userPriKey(const uint8_t *IDA, uint32_t IDA_byteLen,
104 uint8_t hid, uint8_t ke[32],
105 uint8_t deA[128]);
106
108 const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid,
109 const uint8_t Ppub_e[64], uint8_t rA[32], uint8_t RA[64]);
110
111uint32_t sm9_exckey_gen_tmpKeyPair(const uint8_t *IDB, uint32_t IDB_byteLen,
112 uint8_t hid, const uint8_t Ppub_e[64],
113 uint8_t rA[32], uint8_t RA[64]);
114
115uint32_t sm9_exchangekey(sm9_exchange_role_e role, const uint8_t *IDA,
116 uint32_t IDA_byteLen, const uint8_t *IDB,
117 uint32_t IDB_byteLen, const uint8_t Ppub_e[64],
118 const uint8_t deA[128], const uint8_t rA[32],
119 const uint8_t RA[64], const uint8_t RB[64],
120 uint32_t kByteLen, uint8_t *KA, uint8_t S1[32],
121 uint8_t SA[32]);
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif
Semidrive CRYPTO pke header file.
uint32_t sm9_sign_gen_mastPubKey_from_mastPriKey(uint8_t ks[32], uint8_t Ppub_s[128])
sm9_enc_type_e
Definition: sm9.h:39
@ SM9_ENC_KDF_BLOCK_CIPHER
Definition: sm9.h:41
@ SM9_ENC_KDF_STREAM_CIPHER
Definition: sm9.h:40
uint32_t sm9_exckey_gen_mastPubKey_from_mastPriKey(uint8_t ke[32], uint8_t Ppub_e[64])
uint32_t sm9_exchangekey(sm9_exchange_role_e role, const uint8_t *IDA, uint32_t IDA_byteLen, const uint8_t *IDB, uint32_t IDB_byteLen, const uint8_t Ppub_e[64], const uint8_t deA[128], const uint8_t rA[32], const uint8_t RA[64], const uint8_t RB[64], uint32_t kByteLen, uint8_t *KA, uint8_t S1[32], uint8_t SA[32])
uint32_t sm9_dec(const uint8_t *IDB, uint32_t IDB_byteLen, const uint8_t *C, uint32_t CByteLen, const uint8_t deB[128], sm9_enc_type_e enc_type, sm9_enc_padding_e padding_type, uint32_t K2ByteLen, uint8_t *M, uint32_t *MByteLen)
sm9_exchange_role_e
Definition: sm9.h:52
@ SM9_ROLE_SPONSOR
Definition: sm9.h:52
@ SM9_ROLE_RESPONSOR
Definition: sm9.h:52
uint32_t sm9_exckey_gen_tmpKeyPair(const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid, const uint8_t Ppub_e[64], uint8_t rA[32], uint8_t RA[64])
uint32_t sm9_enc_gen_mastKeyPair(uint8_t ke[32], uint8_t Ppub_e[64])
uint32_t sm9_sign_gen_mastKeyPair(uint8_t ks[32], uint8_t Ppub_s[128])
uint32_t sm9_enc_gen_mastPubKey_from_mastPriKey(uint8_t ke[32], uint8_t Ppub_e[64])
uint32_t sm9_exckey_gen_tmpPubKey_from_tmpPriKey(const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid, const uint8_t Ppub_e[64], uint8_t rA[32], uint8_t RA[64])
uint32_t sm9_enc_gen_userPriKey(const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid, uint8_t ke[32], uint8_t deB[128])
SM9_RET_CODE
Definition: sm9.h:25
@ SM9_IN_OUT_SAME_BUFFER
Definition: sm9.h:34
@ SM9_INPUT_INVALID
Definition: sm9.h:30
@ SM9_EXCHANGE_ROLE_INVALID
Definition: sm9.h:29
@ SM9_INTEGER_TOO_BIG
Definition: sm9.h:32
@ SM9_BUFFER_NULL
Definition: sm9.h:27
@ SM9_VERIFY_FAILED
Definition: sm9.h:33
@ SM9_SUCCESS
Definition: sm9.h:26
@ SM9_ZERO_ALL
Definition: sm9.h:31
@ SM9_NOT_ON_CURVE
Definition: sm9.h:28
@ SM9_DECRY_VERIFY_FAILED
Definition: sm9.h:35
uint32_t sm9_enc(const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid, const uint8_t *M, uint32_t MByteLen, const uint8_t Ppub_e[64], uint8_t r[32], sm9_enc_type_e enc_type, sm9_enc_padding_e padding_type, uint32_t K2ByteLen, uint8_t *C, uint32_t *CByteLen)
sm9_enc_padding_e
Definition: sm9.h:45
@ SM9_ENC_PKCS7_PADDING
Definition: sm9.h:47
@ SM9_ENC_MAX_PADDING
Definition: sm9.h:48
@ SM9_ENC_NO_PADDING
Definition: sm9.h:46
uint32_t sm9_exckey_gen_mastKeyPair(uint8_t ke[32], uint8_t Ppub_e[64])
uint32_t sm9_wrap_key(const uint8_t *IDB, uint32_t IDB_byteLen, uint8_t hid, const uint8_t Ppub_e[64], uint8_t r[32], uint8_t C[64], uint32_t KByteLen, uint8_t *K)
uint32_t sm9_sign_gen_userPriKey(const uint8_t *IDA, uint32_t IDA_byteLen, uint8_t hid, uint8_t ks[32], uint8_t dsA[64])
uint32_t sm9_exckey_gen_userPriKey(const uint8_t *IDA, uint32_t IDA_byteLen, uint8_t hid, uint8_t ke[32], uint8_t deA[128])
uint32_t sm9_unwrap_key(const uint8_t *IDB, uint32_t IDB_byteLen, const uint8_t deB[128], const uint8_t C[64], uint32_t KByteLen, uint8_t *K)
uint32_t sm9_sign(const uint8_t *M, uint32_t MByteLen, const uint8_t Ppub_s[128], const uint8_t dsA[64], uint8_t r[32], uint8_t h[32], uint8_t S[65])
uint32_t sm9_verify(const uint8_t *M, uint32_t MByteLen, const uint8_t *IDA, uint32_t IDA_byteLen, uint8_t hid, const uint8_t Ppub_s[128], const uint8_t h[32], const uint8_t S[65])
Semidrive CRYPTO trng header file.