写一个 国密库sm4算法适用于32字节的代码 
时间: 2023-04-04 09:02:54 浏览: 42
以下是适用于32字节的国密库sm4算法代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sm4.h"
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[32] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10};
unsigned char output[32];
unsigned char key_schedule[16 * (SM4_ROUNDS + 1)];
sm4_setkey_enc(key, key_schedule);
sm4_crypt_ecb(key_schedule, SM4_ENCRYPT, 32, input, output);
printf("Input: ");
for (int i = 0; i < 32; i++) {
printf("%02x ", input[i]);
}
printf("\n");
printf("Output: ");
for (int i = 0; i < 32; i++) {
printf("%02x ", output[i]);
}
printf("\n");
return 0;
}
相关推荐
















