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 #ifndef SDFUTIL_SDF_SANSEC_H 11 #define SDFUTIL_SDF_SANSEC_H 12 13 #include "../sgd.h" 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 #define SANSEC_SM1 (SGD_SM1) 20 #define SANSEC_SM1_ECB (SANSEC_SM1|SGD_ECB) 21 #define SANSEC_SM1_CBC (SANSEC_SM1|SGD_CBC) 22 #define SANSEC_SM1_CFB (SANSEC_SM1|SGD_CFB) 23 #define SANSEC_SM1_OFB (SANSEC_SM1|SGD_OFB) 24 #define SANSEC_SM1_MAC (SANSEC_SM1|SGD_MAC) 25 26 #define SANSEC_SM4 0x00002000 27 #define SANSEC_SM4_ECB (SANSEC_SM4|SGD_ECB) 28 #define SANSEC_SM4_CBC (SANSEC_SM4|SGD_CBC) 29 #define SANSEC_SM4_CFB (SANSEC_SM4|SGD_CFB) 30 #define SANSEC_SM4_OFB (SANSEC_SM4|SGD_OFB) 31 #define SANSEC_SM4_MAC (SANSEC_SM4|SGD_MAC) 32 33 #define SANSEC_SSF33 (SGD_SSF33) 34 #define SANSEC_SSF33_ECB (SANSEC_SSF33|SGD_ECB) 35 #define SANSEC_SSF33_CBC (SANSEC_SSF33|SGD_CBC) 36 #define SANSEC_SSF33_CFB (SANSEC_SSF33|SGD_CFB) 37 #define SANSEC_SSF33_OFB (SANSEC_SSF33|SGD_OFB) 38 #define SANSEC_SSF33_MAC (SANSEC_SSF33|SGD_MAC) 39 40 #define SANSEC_AES 0x00000400 41 #define SANSEC_AES_ECB (SANSEC_AES|SGD_ECB) 42 #define SANSEC_AES_CBC (SANSEC_AES|SGD_CBC) 43 #define SANSEC_AES_CFB (SANSEC_AES|SGD_CFB) 44 #define SANSEC_AES_OFB (SANSEC_AES|SGD_OFB) 45 #define SANSEC_AES_MAC (SANSEC_AES|SGD_MAC) 46 47 #define SANSEC_DES 0x00004000 48 #define SANSEC_DES_ECB (SANSEC_DES|SGD_ECB) 49 #define SANSEC_DES_CBC (SANSEC_DES|SGD_CBC) 50 #define SANSEC_DES_CFB (SANSEC_DES|SGD_CFB) 51 #define SANSEC_DES_OFB (SANSEC_DES|SGD_OFB) 52 #define SANSEC_DES_MAC (SANSEC_DES|SGD_MAC) 53 54 #define SANSEC_3DES 0x00000800 55 #define SANSEC_3DES_ECB (SANSEC_3DES|SGD_ECB) 56 #define SANSEC_3DES_CBC (SANSEC_3DES|SGD_CBC) 57 #define SANSEC_3DES_CFB (SANSEC_3DES|SGD_CFB) 58 #define SANSEC_3DES_OFB (SANSEC_3DES|SGD_OFB) 59 #define SANSEC_3DES_MAC (SANSEC_3DES|SGD_MAC) 60 61 #define SANSEC_SM3 (SGD_SM3) 62 #define SANSEC_SHA1 (SGD_SHA1) 63 #define SANSEC_SHA256 (SGD_SHA256) 64 #define SANSEC_SHA512 0x00000008 65 #define SANSEC_SHA384 0x00000010 66 #define SANSEC_SHA224 0x00000020 67 #define SANSEC_MD5 0x00000080 68 69 #define SANSEC_RSA (SGD_RSA) 70 #define SANSEC_RSA_SIGN (SGD_RSA_SIGN) 71 #define SANSEC_RSA_ENC 0x00010200 72 #define SANSEC_SM2 (SGD_SM2) 73 #define SANSEC_SM2_1 (SGD_SM2_1) 74 #define SANSEC_SM2_2 (SGD_SM2_2) 75 #define SANSEC_SM2_3 (SGD_SM2_3) 76 77 #define SANSEC_BASE (SDR_BASE + 0x00010000) 78 #define SANSEC_INVALID_USER (SANSEC_BASE + 0x00000001) 79 #define SANSEC_INVALID_AUTHENCODE (SANSEC_BASE + 0x00000002) 80 #define SANSEC_PROTOCOL_VERSION_ERROR (SANSEC_BASE + 0x00000003) 81 #define SANSEC_INVALID_COMMAND (SANSEC_BASE + 0x00000004) 82 #define SANSEC_INVALID_PARAMETERS (SANSEC_BASE + 0x00000005) 83 #define SANSEC_FILE_ALREADY_EXIST (SANSEC_BASE + 0x00000006) 84 #define SANSEC_SYNC_ERROR (SANSEC_BASE + 0x00000007) 85 #define SANSEC_SYNC_LOGIN_ERROR (SANSEC_BASE + 0x00000008) 86 #define SANSEC_SOCKET_TIMEOUT (SANSEC_BASE + 0x00000100) 87 #define SANSEC_CONNECT_ERROR (SANSEC_BASE + 0x00000101) 88 #define SANSEC_SET_SOCKET_OPTION_ERROR (SANSEC_BASE + 0x00000102) 89 #define SANSEC_SOCKET_SEND_ERROR (SANSEC_BASE + 0x00000104) 90 #define SANSEC_SOCKET_RECV_ERROR (SANSEC_BASE + 0x00000105) 91 #define SANSEC_SOCKET_RECV_0 (SANSEC_BASE + 0x00000106) 92 #define SANSEC_SEM_TIMEOUT (SANSEC_BASE + 0x00000200) 93 #define SANSEC_NO_AVAILABLE_HSM (SANSEC_BASE + 0x00000201) 94 #define SANSEC_NO_AVAILABLE_CSM (SANSEC_BASE + 0x00000202) 95 #define SANSEC_CONFIG_ERROR (SANSEC_BASE + 0x00000301) 96 #define SANSEC_CARD_BASE (SDR_BASE + 0x00020000) 97 #define SANSEC_CARD_UNKNOW_ERROR (SANSEC_CARD_BASE + 0x00000001) 98 #define SANSEC_CARD_NOT_SUPPORTED (SANSEC_CARD_BASE + 0x00000002) 99 #define SANSEC_CARD_COMMMUCATION_FAILED (SANSEC_CARD_BASE + 0x00000003) 100 #define SANSEC_CARD_HARDWARE_FAILURE (SANSEC_CARD_BASE + 0x00000004) 101 #define SANSEC_CARD_OPEN_DEVICE_FAILED (SANSEC_CARD_BASE + 0x00000005) 102 #define SANSEC_CARD_OPEN_SESSION_FAILED (SANSEC_CARD_BASE + 0x00000006) 103 #define SANSEC_CARD_PRIVATE_KEY_ACCESS_DENYED (SANSEC_CARD_BASE + 0x00000007) 104 #define SANSEC_CARD_KEY_NOT_EXIST (SANSEC_CARD_BASE + 0x00000008) 105 #define SANSEC_CARD_ALGOR_NOT_SUPPORTED (SANSEC_CARD_BASE + 0x00000009) 106 #define SANSEC_CARD_ALG_MODE_NOT_SUPPORTED (SANSEC_CARD_BASE + 0x00000010) 107 #define SANSEC_CARD_PUBLIC_KEY_OPERATION_ERROR (SANSEC_CARD_BASE + 0x00000011) 108 #define SANSEC_CARD_PRIVATE_KEY_OPERATION_ERROR (SANSEC_CARD_BASE + 0x00000012) 109 #define SANSEC_CARD_SIGN_ERROR (SANSEC_CARD_BASE + 0x00000013) 110 #define SANSEC_CARD_VERIFY_ERROR (SANSEC_CARD_BASE + 0x00000014) 111 #define SANSEC_CARD_SYMMETRIC_ALGOR_ERROR (SANSEC_CARD_BASE + 0x00000015) 112 #define SANSEC_CARD_STEP_ERROR (SANSEC_CARD_BASE + 0x00000016) 113 #define SANSEC_CARD_FILE_SIZE_ERROR (SANSEC_CARD_BASE + 0x00000017) 114 #define SANSEC_CARD_FILE_NOT_EXIST (SANSEC_CARD_BASE + 0x00000018) 115 #define SANSEC_CARD_FILE_OFFSET_ERROR (SANSEC_CARD_BASE + 0x00000019) 116 #define SANSEC_CARD_KEY_TYPE_ERROR (SANSEC_CARD_BASE + 0x00000020) 117 #define SANSEC_CARD_KEY_ERROR (SANSEC_CARD_BASE + 0x00000021) 118 #define SANSEC_CARD_BUFFER_TOO_SMALL (SANSEC_CARD_BASE + 0x00000101) 119 #define SANSEC_CARD_DATA_PADDING_ERROR (SANSEC_CARD_BASE + 0x00000102) 120 #define SANSEC_CARD_DATA_SIZE (SANSEC_CARD_BASE + 0x00000103) 121 #define SANSEC_CARD_CRYPTO_NOT_INITED (SANSEC_CARD_BASE + 0x00000104) 122 #define SANSEC_CARD_MANAGEMENT_DENYED (SANSEC_CARD_BASE + 0x00001001) 123 #define SANSEC_CARD_OPERATION_DENYED (SANSEC_CARD_BASE + 0x00001002) 124 #define SANSEC_CARD_DEVICE_STATUS_ERROR (SANSEC_CARD_BASE + 0x00001003) 125 #define SANSEC_CARD_LOGIN_ERROR (SANSEC_CARD_BASE + 0x00001011) 126 #define SANSEC_CARD_USERID_ERROR (SANSEC_CARD_BASE + 0x00001012) 127 #define SANSEC_CARD_PARAMENT_ERROR (SANSEC_CARD_BASE + 0x00001013) 128 #define SANSEC_CARD_MANAGEMENT_DENYED_05 (SANSEC_CARD_BASE + 0x00000801) 129 #define SANSEC_CARD_OPERATION_DENYED_05 (SANSEC_CARD_BASE + 0x00000802) 130 #define SANSEC_CARD_DEVICE_STATUS_ERROR_05 (SANSEC_CARD_BASE + 0x00000803) 131 #define SANSEC_CARD_LOGIN_ERROR_05 (SANSEC_CARD_BASE + 0x00000811) 132 #define SANSEC_CARD_USERID_ERROR_05 (SANSEC_CARD_BASE + 0x00000812) 133 #define SANSEC_CARD_PARAMENT_ERROR_05 (SANSEC_CARD_BASE + 0x00000813) 134 #define SANSEC_CARD_READER_BASE (SDR_BASE + 0x00030000) 135 #define SANSEC_CARD_READER_PIN_ERROR (SANSEC_CARD_READER_BASE + 0x000063CE) 136 #define SANSEC_CARD_READER_NO_CARD (SANSEC_CARD_READER_BASE + 0x0000FF01) 137 #define SANSEC_CARD_READER_CARD_INSERT (SANSEC_CARD_READER_BASE + 0x0000FF02) 138 #define SANSEC_CARD_READER_CARD_INSERT_TYPE (SANSEC_CARD_READER_BASE + 0x0000FF03) 139 140 #pragma pack(1) 141 typedef struct { 142 unsigned int clength; 143 unsigned char x[ECCref_MAX_LEN]; 144 unsigned char y[ECCref_MAX_LEN]; 145 unsigned char C[136]; 146 unsigned char M[ECCref_MAX_LEN]; 147 } SANSEC_ECCCipher; 148 #pragma pack() 149 150 #ifdef __cplusplus 151 } 152 #endif 153 #endif 154