Windows下gmssl使用记录

使用gmssl进行计算sm4,编译的版本是gmssl2.0,2.1版本编译不过去

第一步下载软件,下载Visual Studio 2010旗舰版、nasm-2.13.03-installer-x86、ActivePerl-5.22.4.2205-MSWin32-x86-64int-403863这三个软件,

注意vs版本不能太低,否则便宜的时候容易出现错误。

第二部使用命令进行编译,生成lib库和dll库,请选择好生成的版本,32位或者64位的dll库

perl Configure VC-WIN32
nmake
nmake install

第三步:在vs2010中调用该接口,可以使用dll直接调用,或者使用lib库,直接导入头文件。注意在选择选择vs2010中的平台配置,64位x64或者32位x86

HMODULE mHandle = LoadLibrary(L"libcrypto-1_1-x64.dll");

//pSms4_set_encrypt_key Sms4_set_encrypt_key = (pSms4_set_encrypt_key)GetProcAddress(mHandle, "sms4_set_encrypt_key");
//pSms4_encrypt Sms4_encrypt = (pSms4_encrypt)GetProcAddress(mHandle, "sms4_encrypt");

#pragma comment(lib, "libssl.lib")
#pragma comment(lib, "libcrypto.lib")

sms4_key_t key;

unsigned char user_key[16] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
};

unsigned char plaintext[16] = {
0x77, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
};

unsigned char buf[16];

/* test key scheduling */
sms4_set_encrypt_key(&key, user_key);

sms4_encrypt(plaintext, buf, &key);

 

posted on 2018-05-03 15:11  tistar  阅读(941)  评论(0编辑  收藏  举报