/* ==================================================================== * Copyright (c) 2015 - 2016 The GmSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the GmSSL Project. * (http://gmssl.org/)" * * 4. The name "GmSSL Project" must not be used to endorse or promote * products derived from this software without prior written * permission. For written permission, please contact * guanzhi1980@gmail.com. * * 5. Products derived from this software may not be called "GmSSL" * nor may "GmSSL" appear in their names without prior written * permission of the GmSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the GmSSL Project * (http://gmssl.org/)" * * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ #ifndef HEADER_GMSDF_H #define HEADER_GMSDF_H #include #include #include #define SDF_MIN_KEY_INDEX 1 /* defined by GM/T 0018 */ #define SDF_MAX_KEY_INDEX 32 /* defined by GmSSL as vendor */ #define SDF_MIN_PASSWORD_LENGTH 8 /* defined by GM/T 0018 */ #define SDF_MAX_PASSWORD_LENGTH 255 /* defined by GmSSL as vendor */ #define ECCref_MAX_CIPHER_LEN 255 #ifdef __cplusplus extern "C" { #endif int SDF_PrintDeviceInfo(FILE *fp, DEVICEINFO *devInfo); int SDF_PrintRSAPublicKey(FILE *fp, RSArefPublicKey *pk); int SDF_PrintRSAPrivateKey(FILE *fp, RSArefPrivateKey *pk); int SDF_PrintECCPublicKey(FILE *fp, ECCrefPublicKey *pk); int SDF_PrintECCPrivateKey(FILE *fp, ECCrefPrivateKey *pk); int SDF_PrintECCCipher(FILE *fp, ECCCipher *cipher); int SDF_PrintECCSignature(FILE *fp, ECCSignature *sig); const char *SDF_GetErrorString(int err); //FIXME: implement this in a standalone file in sdf module int SDF_ImportKey( void *hSessionHandle, unsigned char *pucKey, unsigned int uiKeyLength, void **phKeyHandle); /* BEGIN ERROR CODES */ /* * The following lines are auto generated by the script mkerr.pl. Any changes * made after this point may be overwritten when the script is next run. */ int ERR_load_SDF_strings(void); /* Error codes for the SDF functions. */ /* Function codes. */ # define SDF_F_SDF_CALCULATEMAC 100 # define SDF_F_SDF_CLOSEDEVICE 145 # define SDF_F_SDF_CLOSESESSION 101 # define SDF_F_SDF_DECODE_EC_SIGNATURE 102 # define SDF_F_SDF_DECRYPT 103 # define SDF_F_SDF_ENCODE_EC_SIGNATURE 104 # define SDF_F_SDF_ENCRYPT 105 # define SDF_F_SDF_EXPORTENCPUBLICKEY_ECC 106 # define SDF_F_SDF_EXPORTENCPUBLICKEY_RSA 107 # define SDF_F_SDF_EXPORTSIGNPUBLICKEY_ECC 108 # define SDF_F_SDF_EXPORTSIGNPUBLICKEY_RSA 109 # define SDF_F_SDF_EXTERNALDECRYPT_ECC 110 # define SDF_F_SDF_EXTERNALENCRYPT_ECC 111 # define SDF_F_SDF_EXTERNALPRIVATEKEYOPERATION_RSA 112 # define SDF_F_SDF_EXTERNALPUBLICKEYOPERATION_RSA 113 # define SDF_F_SDF_EXTERNALSIGN_ECC 114 # define SDF_F_SDF_EXTERNALVERIFY_ECC 115 # define SDF_F_SDF_GENERATEKEYPAIR_ECC 116 # define SDF_F_SDF_GENERATEKEYPAIR_RSA 117 # define SDF_F_SDF_GENERATEKEYWITHEPK_ECC 118 # define SDF_F_SDF_GENERATEKEYWITHEPK_RSA 119 # define SDF_F_SDF_GENERATEKEYWITHIPK_ECC 120 # define SDF_F_SDF_GENERATEKEYWITHIPK_RSA 121 # define SDF_F_SDF_GENERATERANDOM 122 # define SDF_F_SDF_GETDEVICEINFO 123 # define SDF_F_SDF_GETPRIVATEKEYACCESSRIGHT 124 # define SDF_F_SDF_GET_CIPHER 125 # define SDF_F_SDF_GET_DIGEST 126 # define SDF_F_SDF_HASHFINAL 127 # define SDF_F_SDF_HASHINIT 128 # define SDF_F_SDF_HASHUPDATE 129 # define SDF_F_SDF_IMPORTKEY 130 # define SDF_F_SDF_IMPORTKEYWITHISK_ECC 131 # define SDF_F_SDF_IMPORTKEYWITHISK_RSA 132 # define SDF_F_SDF_INTERNALDECRYPT_ECC 133 # define SDF_F_SDF_INTERNALENCRYPT_ECC 134 # define SDF_F_SDF_INTERNALPRIVATEKEYOPERATION_RSA 135 # define SDF_F_SDF_INTERNALPUBLICKEYOPERATION_RSA 136 # define SDF_F_SDF_INTERNALSIGN_ECC 137 # define SDF_F_SDF_INTERNALVERIFY_ECC 138 # define SDF_F_SDF_LOAD_EC_PRIVATE_KEY 139 # define SDF_F_SDF_LOAD_EC_PUBLIC_KEY 140 # define SDF_F_SDF_LOAD_RSA_PRIVATE_KEY 141 # define SDF_F_SDF_LOAD_RSA_PUBLIC_KEY 142 # define SDF_F_SDF_OPENDEVICE 143 # define SDF_F_SDF_OPENSESSION 144 # define SDF_F_SDF_RELEASEPRIVATEKEYACCESSRIGHT 146 /* Reason codes. */ # define SDF_R_BUFFER_TOO_SMALL 100 # define SDF_R_BUUTER_TOO_SMALL 101 # define SDF_R_CBCMAC_FAILURE 102 # define SDF_R_CMAC_FAILURE 126 # define SDF_R_COMPUTE_SM2_ID_FAILURE 103 # define SDF_R_ENGINE_LOAD_KEY_FAILURE 104 # define SDF_R_GET_PRIVATE_KEY_FAILED 105 # define SDF_R_GET_PUBLIC_KEY_FAILED 106 # define SDF_R_INVALID_ALGOR 107 # define SDF_R_INVALID_DEVICE_HANDLE 122 # define SDF_R_INVALID_EC_CIPHERTEXT 108 # define SDF_R_INVALID_EC_PRIVATE_KEY 109 # define SDF_R_INVALID_EC_PUBLIC_KEY 110 # define SDF_R_INVALID_INPUT_LENGTH 111 # define SDF_R_INVALID_KEY_HANDLE 112 # define SDF_R_INVALID_KEY_INDEX 123 # define SDF_R_INVALID_KEY_LENGTH 113 # define SDF_R_INVALID_KEY_USAGE 114 # define SDF_R_INVALID_LENGTH 115 # define SDF_R_INVALID_OPERATION_STATE 116 # define SDF_R_INVALID_PASSWORD_LENGTH 124 # define SDF_R_INVALID_SESSION 117 # define SDF_R_INVALID_SESSION_HANDLE 125 # define SDF_R_KEY_TYPE_NOT_MATCH 118 # define SDF_R_LOAD_ENGINE_FAILURE 119 # define SDF_R_RANDOM_FAILURE 120 # define SDF_R_SDF_SESSION_NO_ENGINE 121 # ifdef __cplusplus } # endif #endif