資源簡介
OpenSSL 1.1.1 新特性: 全面支持國密SM2/SM3/SM4加密算法,最近的項目涉及到國密,又局限于資源有限,只能只能上了。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include??
#include??
#include?
#include?
#include??
#include??
#include?jects.h>?
#include??
#include??
#include?
#include?
#define?SM2_DEFAULT_USERID?“1234567812345678“
int?HSM_WriteFile(char?*filename?char?*mode?char?*buffer?int?size)
{
FILE?*fp;
int?wl?totle?=?0;
fp?=?fopen(filename?mode);
if?(fp?==?NULL)?{
return?-1;
}
do?{
wl?=?fwrite(buffer?+?totle?sizeof(char)?size?-?totle?fp);
if?(wl?==?0)?{
fclose(fp);
return?-1;
}
totle?+=?wl;
}?while?(totle? fclose(fp);
return?0;
}
int??HSM_ReadFile(char??*filename?char??*mode?char??*buffer?int??size)
{
FILE?*fp;
int?totle?=?0;
fp?=?fopen(filename?mode);
if?(fp?==?NULL)?{
return?-1;
}
totle?=?fread(buffer?sizeof(char)?size?fp);
fclose(fp);
return?totle;
}
int?Openssl_PrintHex(char?*itemNameunsigned?char?*sourceDataunsigned?int?dataLengthunsigned?int?rowCount)
{
int?i?j;
if?((sourceData?==?NULL)?||?(rowCount?==?0)?||?(dataLength?==?0))
return?-1;
if?(itemName?!=?NULL)
printf(“%s[%d]:\n“?itemName?dataLength);
for?(i?=?0;?i?(int)(dataLength?/?rowCount);?i++)
{
printf(“%08x??“?i*rowCount);
for?(j?=?0;?j?(int)rowCount;?j++)
{
printf(“%02x?“?*(sourceData?+?i?*?rowCount?+?j));
}
printf(“\n“);
}
if?(!(dataLength%rowCount))
return?0;
printf(“%08x??“?(dataLength?/?rowCount)*rowCount);
for?(j?=?0;?j?(int)(dataLength%rowCount);?j++)
{
printf(“%02x?“?*(sourceData?+?(dataLength?/?rowCount)*rowCount?+?j));
}
printf(“\n“);
return?0;
}
char?*?OpensslGetLastErr()
{
ERR_load_ERR_strings();
ERR_load_crypto_strings();
unsigned?long?ulErr?=?ERR_get_error();
char?szErrMsg[1024]?=?{?0?};
char?*pTmp?=?NULL;
pTmp?=?ERR_error_string(ulErr?szErrMsg);
return?pTmp;
}
int?SM3(char?*in?int?inLen?char?*out?int?*outLen)
{
int?nRet?=?-1;
char?tmpIn[8192?+?1]?=?{?0?};
int?tmpInLen?=?-1;
char?tmpOut[32?+?1]?=?{?0?};
int?tmpOutLen?=?-1;
const?EVP_MD?*md?=?NULL;
EVP_MD_CTX?*mctx?=?NULL;
if?(inLen?<=?0?||?inLen?>?8192)
{
return?-1;
}
tmpInLen?=?inLen;
memcpy(tmpIn?in?tmpInLen);
md?=?EVP_sm3();
mctx?=?EVP_MD_CTX_new();
if?(!mctx)
{
return?-1;
}
nRet?=?EVP_DigestInit(mctx?md);
if?(nRet?!=?1)
{
return?-2;
}
nRet?=?EVP_DigestUpdate(mctx?tmpIn?tmpInLen);
if?(nRet?!=?1)
{
return?-3;
}
nRet?=?EVP_DigestFinal(mctx?tmpOut?&tmpOutLen);
if?(nRet?!=?1)
{
return?-4;
}
EVP_MD_CTX_free(mctx);
*outLen?=?tmpOutLen;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-19?09:18??topenssl\
?????目錄???????????0??2018-11-08?15:29??topenssl\.vs\
?????目錄???????????0??2018-11-08?15:29??topenssl\.vs\topenssl\
?????目錄???????????0??2018-11-20?08:59??topenssl\.vs\topenssl\v15\
?????文件???????69632??2018-11-20?08:59??topenssl\.vs\topenssl\v15\.suo
?????文件?????5779456??2018-11-20?08:59??topenssl\.vs\topenssl\v15\Browse.VC.db
?????目錄???????????0??2018-11-08?15:31??topenssl\.vs\topenssl\v15\ipch\
?????目錄???????????0??2018-11-09?16:34??topenssl\.vs\topenssl\v15\ipch\AutoPCH\
?????目錄???????????0??2018-11-13?14:41??topenssl\.vs\topenssl\v15\ipch\AutoPCH\13bf54464b121fc6\
?????文件????17104896??2018-11-19?14:30??topenssl\.vs\topenssl\v15\ipch\AutoPCH\13bf54464b121fc6\TEST.ipch
?????目錄???????????0??2018-11-08?20:02??topenssl\.vs\topenssl\v15\ipch\AutoPCH\961c9ac41e801d6\
?????文件?????3014656??2018-11-08?20:02??topenssl\.vs\topenssl\v15\ipch\AutoPCH\961c9ac41e801d6\TEST.ipch
?????目錄???????????0??2018-11-19?11:30??topenssl\Debug\
?????文件?????2255360??2018-11-08?18:32??topenssl\Debug\libcrypto-1_1.dll
?????文件???????52736??2018-11-19?14:30??topenssl\Debug\topenssl.exe
?????文件??????619624??2018-11-19?14:30??topenssl\Debug\topenssl.ilk
?????文件??????651264??2018-11-19?14:30??topenssl\Debug\topenssl.pdb
?????目錄???????????0??2018-11-08?20:02??topenssl\Release\
?????目錄???????????0??2018-11-19?14:32??topenssl\topenssl\
?????文件????????1438??2018-11-08?15:29??topenssl\topenssl.sln
?????文件?????????846??2018-11-13?14:27??topenssl\topenssl\2.der
?????文件????????1086??2018-11-16?16:34??topenssl\topenssl\cacert1.pfx
?????文件?????????798??2018-10-12?15:33??topenssl\topenssl\CFCASM2cert_138095961425.cer
?????目錄???????????0??2018-11-19?14:30??topenssl\topenssl\Debug\
?????文件???????51024??2018-11-14?14:05??topenssl\topenssl\Debug\test.new.obj.enc
?????文件???????52568??2018-11-19?14:30??topenssl\topenssl\Debug\test.obj
?????文件????????1285??2018-11-12?09:01??topenssl\topenssl\Debug\topenssl.Build.CppClean.log
?????文件?????????127??2018-11-19?14:30??topenssl\topenssl\Debug\topenssl.log
?????目錄???????????0??2018-11-19?14:30??topenssl\topenssl\Debug\topenssl.tlog\
?????文件?????????846??2018-11-19?14:30??topenssl\topenssl\Debug\topenssl.tlog\CL.command.1.tlog
?????文件???????11714??2018-11-19?14:30??topenssl\topenssl\Debug\topenssl.tlog\CL.read.1.tlog
............此處省略27個文件信息
評論
共有 條評論