代码拉取完成,页面将自动刷新
#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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。