1 Star 0 Fork 0

Besti 20155338/Linux 20155338

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.c 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
Besti 20155338 提交于 2017-11-05 18:52 . week7
#include<string.h>
#include<stdio.h>
#include "sm4.h"
int main()
{
unsigned char key[16] = {0xB1,0x22,0xAD,0x0A,0x7A,0x36,0x2E,0xC3,0xAB,0xA1,0xDD,0xEF,0xB3,0xAF,0x49,0x15};
unsigned char iv[16] = {0x11,0x11,0x11,0x11,0xd1,0xa1,0x6c,0x20,0x67,0x70,0x8a,0xcb,0xd1,0xa1,0x6c,0x20};
unsigned char input[32] = {0x0B,0x0B,0x2B,0x4F,0x54,0x05,0xFE,0xF1,0xE8,0xA2,0x64,0xFC,0x89,0xAB,0x21,0x0A,
0x0B,0x0B,0x2B,0x4F,0x54,0x05,0xFE,0xF1,0xE8,0xA2,0x64,0xFC,0x89,0xAB,0x21,0x0A};
unsigned char output[32];
sm4_context ctx;
unsigned long i;
unsigned long len = 32;
printf("%-15s","Key:");
for(i=0;i<16;i++)
printf("%02x ", key[i]);
printf("\n");
printf("%-15s","IV:");
for(i=0;i<16;i++)
printf("%02x ", iv[i]);
printf("\n");
sm4_setkey_enc(&ctx,key);
sm4_crypt_ecb(&ctx,1,len,input,output);
printf("%-15s","ECB cipher:");
for(i=0;i<len;i++)
printf("%02x ", output[i]);
printf("\n");
sm4_setkey_dec(&ctx,key);
sm4_crypt_ecb(&ctx,0,len,output,output);
printf("%-15s","ECB dec plain:");
for(i=0;i<len;i++)
printf("%02x ", output[i]);
printf("\n");
sm4_setkey_enc(&ctx,key);
sm4_crypt_cbc(&ctx,1,len,iv,input,output);
printf("%-15s","CBC cipher:");
for(i=0;i<len;i++)
printf("%02x ", output[i]);
printf("\n");
sm4_setkey_dec(&ctx,key);
sm4_crypt_cbc(&ctx,0,len,iv,output,output);
printf("%-15s","ECB dec plain:");
for(i=0;i<len;i++)
printf("%02x ", output[i]);
printf("\n");
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Csj996/Besti.git
git@gitee.com:Csj996/Besti.git
Csj996
Besti
Linux 20155338
master

搜索帮助