• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the License); you may
5  *  not use this file except in compliance with the License.
6  *
7  *  http://www.apache.org/licenses/LICENSE-2.0
8  */
9 
10 /*
11  * this header file is based on the standard GM/T 0006-2012
12  * Cryptographic Application Identifier Criterion Specification
13  */
14 
15 #ifndef SDFUTIL_SGD_H
16 #define SDFUTIL_SGD_H
17 
18 
19 #include <stdint.h>
20 
21 
22 /* block cipher modes */
23 #define SGD_ECB			0x01
24 #define SGD_CBC			0x02
25 #define SGD_CFB			0x04
26 #define SGD_OFB			0x08
27 #define SGD_MAC			0x10
28 
29 /* stream cipher modes */
30 #define SGD_EEA3		0x01
31 #define SGD_EIA3		0x02
32 
33 /* ciphers */
34 #define SGD_SM1			0x00000100
35 #define SGD_SSF33		0x00000200
36 #define SGD_SM4			0x00000400
37 #define SGD_ZUC			0x00000800
38 
39 /* ciphers with modes */
40 #define SGD_SM1_ECB		(SGD_SM1|SGD_ECB)
41 #define SGD_SM1_CBC		(SGD_SM1|SGD_CBC)
42 #define SGD_SM1_CFB		(SGD_SM1|SGD_CFB)
43 #define SGD_SM1_OFB		(SGD_SM1|SGD_OFB)
44 #define SGD_SM1_MAC		(SGD_SM1|SGD_MAC)
45 #define SGD_SSF33_ECB		(SGD_SSF33|SGD_ECB)
46 #define SGD_SSF33_CBC		(SGD_SSF33|SGD_CBC)
47 #define SGD_SSF33_CFB		(SGD_SSF33|SGD_CFB)
48 #define SGD_SSF33_OFB		(SGD_SSF33|SGD_OFB)
49 #define SGD_SSF33_MAC		(SGD_SSF33|SGD_MAC)
50 #define SGD_SM4_ECB		(SGD_SM4|SGD_ECB)
51 #define SGD_SM4_CBC		(SGD_SM4|SGD_CBC)
52 #define SGD_SM4_CFB		(SGD_SM4|SGD_CFB)
53 #define SGD_SM4_OFB		(SGD_SM4|SGD_OFB)
54 #define SGD_SM4_MAC		(SGD_SM4|SGD_MAC)
55 #define SGD_ZUC_EEA3		(SGD_ZUC|SGD_EEA3)
56 #define SGD_ZUC_EIA3		(SGD_ZUC|SGD_EIA3)
57 
58 /* public key usage */
59 #define SGD_PK_SIGN		0x0100 // FIXME: correct?
60 #define SGD_PK_DH		0x0200 // FIXME: correct?
61 #define SGD_PK_ENC		0x0400 // FIXME: correct?
62 
63 /* public key types */
64 #define SGD_RSA			0x00010000
65 #define SGD_RSA_SIGN		(SGD_RSA|SGD_PK_SIGN) // FIXME: correct?
66 #define SGD_RSA_ENC		(SGD_RSA|SGD_PK_ENC) // FIXME: correct?
67 #define SGD_SM2			0x00020100
68 #define SGD_SM2_1		0x00020200
69 #define SGD_SM2_2		0x00020400
70 #define SGD_SM2_3		0x00020800
71 
72 /* hash */
73 #define SGD_SM3			0x00000001
74 #define SGD_SHA1		0x00000002
75 #define SGD_SHA256		0x00000004
76 #define SGD_HASH_FROM		0x00000008
77 #define SGD_HASH_TO		0x000000FF
78 
79 /* signatue schemes */
80 #define SGD_SM3_RSA		(SGD_SM3|SGD_RSA)
81 #define SGD_SHA1_RSA		(SGD_SHA1|SGD_RSA)
82 #define SGD_SHA256_RSA		(SGD_SHA256|SGD_RSA)
83 #define SGD_SM3_SM2		(SGD_SM3|SGD_SM2)
84 #define SGD_SIG_FROM		0x00040000
85 #define SGD_SIG_TO		0x800000FF
86 
87 /* data types */
88 typedef char			SGD_CHAR;
89 typedef char			SGD_INT8;
90 typedef int16_t			SGD_INT16;
91 typedef int32_t			SGD_INT32;
92 typedef int64_t			SGD_INT64;
93 typedef unsigned char		SGD_UCHAR;
94 typedef uint8_t			SGD_UINT8;
95 typedef uint16_t		SGD_UINT16;
96 typedef uint32_t		SGD_UINT32;
97 typedef uint64_t		SGD_UINT64;
98 typedef uint32_t		SGD_RV;
99 typedef void *			SGD_OBJ;
100 typedef int32_t			SGD_BOOL;
101 
102 #define SGD_TRUE		0x00000001
103 #define SGD_FALSE		0x00000000
104 
105 #define SGD_KEY_INDEX		0x00000101
106 #define SGD_SECRET_KEY		0x00000102
107 #define SGD_PUBLIC_KEY_SIGN	0x00000103
108 #define SGD_PUBLIC_KEY_ENCRYPT	0x00000104
109 #define SGD_PRIVATE_KEY_SIGN	0x00000105
110 #define SGD_PRIVATE_KEY_ENCRYPT	0x00000106
111 #define SGD_KEY_COMPONENT	0x00000107
112 #define SGD_PASSWORD		0x00000108
113 #define SGD_PUBLIC_KEY_CERT	0x00000109
114 #define SGD_ATTRIBUTE_CERT	0x1000010A
115 #define SGD_SIGNATURE_DATA	0x10000111
116 #define SGD_ENVELOPE_DATA	0x10000112
117 #define SGD_RANDOM_DATA		0x10000113
118 #define SGD_PLAIN_DATA		0x10000114
119 #define SGD_CIPHER_DATA		0x10000115
120 #define SGD_DIGEST_DATA		0x10000116
121 #define SGD_USER_DATA		0x10000117
122 
123 /* certificate */
124 #define SGD_CERT_VERSION			0x00000001
125 #define SGD_CERT_SERIAL				0x00000002
126 #define SGD_CERT_ISSUER				0x00000005
127 #define SGD_CERT_VALID_TIME			0x00000006
128 #define SGD_CERT_SUBJECT			0x00000007
129 #define SGD_CERT_DER_PUBLIC_KEY			0x00000008
130 #define SGD_CERT_DER_EXTENSIONS			0x00000009
131 #define SGD_EXT_AUTHORITYKEYIDENTIFIER_INFO	0x00000011
132 #define SGD_EXT_SUBJECTKEYIDENTIFIER_INFO	0x00000012
133 #define SGD_EXT_KEYUSAGE_INFO			0x00000013
134 #define SGD_EXT_PRIVATEKEYUSAGEPERIOD_INFO	0x00000014
135 #define SGD_EXT_CERTIFICATEPOLICIES_INFO	0x00000015
136 #define SGD_EXT_POLICYMAPPINGS_INFO		0x00000016
137 #define SGD_EXT_BASICCONSTRAINTS_INFO		0x00000017
138 #define SGD_EXT_POLICYCONSTRAINTS_INFO		0x00000018
139 #define SGD_EXT_EXTKEYUSAGE_INFO		0x00000019
140 #define SGD_EXT_CRLDISTRIBUTIONPOINTS_INFO	0x0000001A
141 #define SGD_EXT_NETSCAPE_CERT_TYPE_INFO		0x0000001B
142 #define SGD_EXT_SELFDEFINED_EXTENSION_INFO	0x0000001C
143 #define SGD_CERT_ISSUER_CN			0x00000021
144 #define SGD_CERT_ISSUER_O			0x00000022
145 #define SGD_CERT_ISSUER_OU			0x00000023
146 #define SGD_CERT_SUBJECT_CN			0x00000031
147 #define SGD_CERT_SUBJECT_O			0x00000032
148 #define SGD_CERT_SUBJECT_OU			0x00000033
149 #define SGD_CERT_SUBJECT_EMAIL			0x00000034
150 #define SGD_CERT_NOTBEFORE_TIME			0x00000035
151 #define SGD_CERT_NOTAFTER_TIME			0x00000036
152 
153 /* timestamp info */
154 #define SGD_TIME_OF_STAMP		0x00000201
155 #define SGD_CN_OF_TSSIGNER		0x00000202 /* Common Name of TS Signer */
156 #define SGD_ORININAL_DATA		0x00000203
157 #define SGD_CERT_OF_TSSSERVER		0x00000204
158 #define SGD_GERTCHAIN_OF_TSSERVER	0x00000205
159 #define SGD_SOURCE_OF_TIME		0x00000206
160 #define SGD_TIME_PRECISION		0x00000207
161 #define SGD_RESPONSE_TYPE		0x00000208
162 #define SGD_SUBJECT_COUNTRY_OF_TSSIGNER	0x00000209
163 #define SGD_SUBJECT_ORGNIZATION_OF_TSSIGNER 0x0000020A
164 #define SGD_SUJECT_CITY_OF_TSSIGNER	0x0000020B
165 #define SGD_SUBJECT_EMAIL_OF_TSSIGNER	0x0000020C
166 
167 /* single sign-on */
168 #define SGD_SP_ID			0x00000001
169 #define SGD_SP_USER_ID			0x00000002
170 #define SGD_IDP_ID			0x00000003
171 #define SGD_IDP_USER_ID			0x00000004
172 
173 /* data encoding */
174 #define SGD_ENCODING_RAW		0x00000000
175 #define SGD_ENCODING_DER		0x01000000
176 #define SGD_ENCODING_BASE64		0x02000000
177 #define SGD_ENCODING_PEM		0x03000000
178 #define SGD_ENCODING_TXT		0x04000000
179 
180 /* APIs */
181 #define SGD_PROTOCOL_CSP		1 /* Microsoft CryptoAPI */
182 #define SGD_PROTOCOL_PKCS11		2 /* PKCS#11 */
183 #define SGD_PROTOCOL_SDS		3 /* SDF API */
184 #define SGD_PROTOCOL_UKEY		4 /* SKF API */
185 #define SGD_PROTOCOL_CNG		5 /* Microsoft CryptoAPI Next Gen */
186 #define SGD_PROTOCOL_GCS		6 /* */
187 
188 /* certificate validation */
189 #define SGD_CRL_VERIFY			1
190 #define SGD_OCSP_VEIFY			2
191 
192 /* role */
193 #define SGD_ROLE_SUPER_MANAGER		0x00000001
194 #define SGD_ROLE_MANAGER		0x00000002
195 #define SGD_ROLE_AUDIT_MANAGER		0x00000003
196 #define SGD_ROLE_AUDITOR		0x00000004
197 #define SGD_ROLE_OPERATOR		0x00000005
198 #define SGD_ROLE_USER			0x00000006
199 
200 /* user operations */
201 #define SGD_OPERATION_SIGNIN		0x00000001
202 #define SGD_OPERATION_SIGNOUT		0x00000002
203 #define SGD_OPERATION_CREATE		0x00000003
204 #define SGD_OPERATION_DELETE		0x00000004
205 #define SGD_OPERATION_MODIFY		0x00000005
206 #define SGD_OPERATION_CHG_PWD		0x00000006
207 #define SGD_OPERATION_AUTHORIZATION	0x00000007
208 
209 /* user operation results */
210 #define SGD_OPERATION_SUCCESS		0x00000000
211 
212 /* key types */
213 #define SGD_MAIN_KEY			0x00000101
214 #define SGD_DEVICE_KEYS			0x00000102
215 #define SGD_USER_KEYS			0x00000103
216 #define SGD_KEY				0x00000104
217 #define SGD_SESSION_KEY			0x00000105
218 #define SGD_PRIKEY_PASSWD		0x00000106
219 #define SGD_COMPARTITION_KEY		0x00000107
220 
221 /* key operations */
222 #define SGD_KEY_GENERATION		0x00000101
223 #define SGD_KEY_DISPENSE		0x00000102
224 #define SGD_KEY_IMPORT			0x00000103
225 #define SGD_KEY_EXPORT			0x00000104
226 #define SGD_KEY_DIVISION		0x00000105
227 #define SGD_KEY_COMPOSE			0x00000106
228 #define SGD_KEY_RENEWAL			0x00000107
229 #define SGD_KEY_BACKUP			0x00000108
230 #define SGD_KEY_RESTORE			0x00000109
231 #define SGD_KEY_DESTORY			0x0000010A
232 
233 /* system operations */
234 #define SGD_SYSTEM_INIT			0x00000201
235 #define SGD_SYSTEM_START		0x00000202
236 #define SGD_SYSTEM_SHUT			0x00000203
237 #define SGD_SYSTEM_RESTART		0x00000204
238 #define SGD_SYSTEM_QUERY		0x00000205
239 #define SGD_SYSTEM_BACKUP		0x00000206
240 #define SGD_SYSTEM_RESTORE		0x00000207
241 
242 /* device info */
243 #define SGD_DEVICE_SORT			0x00000201
244 #define SGD_DEVICE_TYPE			0x00000202
245 #define SGD_DEVICE_NAME			0x00000203
246 #define SGD_DEVICE_MANUFACTURER		0x00000204
247 #define SGD_DEVICE_HARDWARE_VERSION	0x00000205
248 #define SGD_DEVICE_SOFTWARE_VERSION	0x00000206
249 #define SGD_DEVICE_STANDARD_VERSION	0x00000207
250 #define SGD_DEVICE_SERIAL_NUMBER	0x00000208
251 #define SGD_DEVICE_SUPPORT_SYMM_ALG	0x00000209
252 #define SGD_DEVICE_SUPPORT_PKEY_ALG	0x0000020A
253 #define SGD_DEVICE_SUPPORT_HASH_ALG	0x0000020B
254 #define SGD_DEVICE_SUPPORT_STORAGE_SPACE 0x0000020C
255 #define SGD_DEVICE_SUPPORT_FREE_SPACE	0x0000020D
256 #define SGD_DEVICE_RUNTIME		0x0000020E
257 #define SGD_DEVICE_USED_TIMES		0x0000020F
258 #define SGD_DEVICE_LOCATION		0x00000210
259 #define SGD_DEVICE_DESCRIPTION		0x00000211
260 #define SGD_DEVICE_MANAGER_INFO		0x00000212
261 #define SGD_DEVICE_MAX_DATA_SIZE	0x00000213
262 
263 /* device types */
264 #define SGD_DEVICE_SORT_SJ		0x02000000 /* Server */
265 #define SGD_DEVICE_SORT_SK		0x03000000 /* PCI-E Card */
266 #define SGD_DEVICE_SORT_SM		0x04000000 /* USB-Key and SmartCard */
267 
268 /* device functionality */
269 #define SGD_DEVICE_SORT_FE		0x00000100 /* encryption */
270 #define SGD_DEVICE_SORT_FA		0x00000200 /* authentication */
271 #define SGD_DEVICE_SORT_FM		0x00000300 /* key management */
272 
273 /* device status */
274 #define SGD_STATUS_INIT			0x00000201
275 #define SGD_STATUS_READY		0x00000202
276 #define SGD_STATUS_EXCEPTION		0x00000203
277 
278 /* SKF */
279 #ifndef WIN32
280 typedef signed char		INT8;
281 typedef signed short		INT16;
282 typedef signed int		INT32;
283 typedef unsigned char		UINT8;
284 typedef unsigned short		UINT16;
285 typedef unsigned int		UINT32;
286 typedef long			BOOL;
287 typedef UINT8			BYTE;
288 typedef UINT8			CHAR;
289 typedef INT16			SHORT;
290 typedef UINT16			USHORT;
291 # ifndef SGD_NATIVE_LONG
292 typedef INT32			LONG;
293 typedef UINT32			ULONG;
294 # else
295 typedef long			LONG;
296 typedef unsigned long		ULONG;
297 # endif
298 typedef UINT32			UINT;
299 typedef UINT16			WORD;
300 typedef UINT32			DWORD;
301 typedef UINT32			FLAGS;
302 typedef CHAR *			LPSTR;
303 typedef void *			HANDLE;
304 #else
305 #ifndef _WINDEF_H
306 typedef signed char		INT8;
307 typedef signed short		INT16;
308 typedef signed int		INT32;
309 typedef unsigned char		UINT8;
310 typedef unsigned short		UINT16;
311 typedef unsigned int		UINT32;
312 typedef long			BOOL;
313 typedef UINT8			BYTE;
314 typedef UINT8			CHAR;
315 typedef INT16			SHORT;
316 typedef UINT16			USHORT;
317 # ifndef SGD_NATIVE_LONG
318 typedef INT32			LONG;
319 typedef UINT32			ULONG;
320 # else
321 typedef long			LONG;
322 typedef unsigned long		ULONG;
323 # endif
324 typedef UINT32			UINT;
325 typedef UINT16			WORD;
326 typedef UINT32			DWORD;
327 typedef UINT32			FLAGS;
328 typedef CHAR *			LPSTR;
329 typedef void *			HANDLE;
330 #endif
331 #endif
332 
333 typedef HANDLE DEVHANDLE;
334 typedef HANDLE HAPPLICATION;
335 typedef HANDLE HSESSION;
336 typedef HANDLE HCONTAINER;
337 
338 #ifndef FALSE
339 #define FALSE			0x00000000
340 #endif
341 
342 #ifndef TRUE
343 #define TRUE			0x00000001
344 #endif
345 
346 #ifdef WIN32
347 #define DEVAPI __stdcall
348 #else
349 #define DEVAPI
350 #endif
351 
352 #ifndef ADMIN_TYPE
353 #define ADMIN_TYPE			0
354 #endif
355 
356 #ifndef USER_TYPE
357 #define USER_TYPE			1
358 #endif
359 
360 #define MAX_RSA_MODULUS_LEN		256
361 #define MAX_RSA_EXPONENT_LEN		4
362 #define ECC_MAX_XCOORDINATE_BITS_LEN	512
363 #define ECC_MAX_YCOORDINATE_BITS_LEN	512
364 #define ECC_MAX_MODULUS_BITS_LEN	512
365 
366 #define MAX_IV_LEN			32
367 
368 #define MAX_FILE_NAME_SIZE		32
369 #define MAX_FILE_CONTAINER_NAME_SIZE	64
370 
371 #define SECURE_NEVER_ACCOUNT		0x00000000
372 #define SECURE_ADM_ACCOUNT		0x00000001
373 #define SECURE_USER_ACCOUNT		0x00000010
374 #define SECURE_ANYONE_ACCOUNT		0x000000FF
375 
376 
377 /* SDF */
378 
379 #define RSAref_MAX_BITS			2048
380 #define RSAref_MAX_LEN			((RSAref_MAX_BITS + 7) / 8)
381 #define RSAref_MAX_PBITS		((RSAref_MAX_BITS + 1) / 2)
382 #define RSAref_MAX_PLEN			((RSAref_MAX_PBITS + 7)/ 8)
383 
384 #ifdef SGD_MAX_ECC_BITS_256
385 #define ECCref_MAX_BITS			256
386 #else
387 #define ECCref_MAX_BITS			512
388 #endif
389 #define ECCref_MAX_LEN			((ECCref_MAX_BITS+7) / 8)
390 
391 
392 /* SAF */
393 #define SGD_MAX_COUNT		64
394 #define SGD_MAX_NAME_SIZE	256
395 
396 
397 #endif
398