算法的C语言实现

时间:2018-05-07 02:10:28
【文件属性】:

文件名称:算法的C语言实现

文件大小:10KB

文件格式:ZIP

更新时间:2018-05-07 02:10:28

SM4算法

int main() { unsigned char key[16] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; unsigned char input[16] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; unsigned char output[16]; sm4_context ctx; unsigned long i; //encrypt standard testing vector sm4_setkey_enc(&ctx,key); sm4_crypt_ecb(&ctx,1,16,input,output); for(i=0;i<16;i++) printf("x ", output[i]); printf("\n"); //decrypt testing sm4_setkey_dec(&ctx,key); sm4_crypt_ecb(&ctx,0,16,output,output); for(i=0;i<16;i++) printf("x ", output[i]); printf("\n"); //decrypt 1M times testing vector based on standards. i = 0; sm4_setkey_enc(&ctx,key); while (i<1000000) { sm4_crypt_ecb(&ctx,1,16,input,input); i++; } for(i=0;i<16;i++) printf("x ", input[i]); printf("\n"); return 0; }


【文件预览】:
SM4
----sm4.c(10KB)
----sm4.dsw(529B)
----sm4.dsp(3KB)
----sm4test.c(1024B)
----sms4.c(12KB)
----sm4.h(2KB)

网友评论