Created
January 14, 2021 01:13
-
-
Save 330132662/1c29a4ea042e04029315378d0c12b586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printf("encrypt test\n"); | |
UINT8 key[16] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, | |
0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; | |
UINT8 plaintext[16] = {0xff, 0xd7, 0x40, 0x57, 0x47, 0x68, 0x5e, 0xd6, | |
0xe0, 0x0b, 0xc6, 0x82, 0xa7, 0x72, 0x86, 0x09}; | |
UINT8 ciphertext[16],decodetext[16]; | |
sp5kSeCfg_t cfg; | |
sp5kSeData_t data; | |
UINT8 i; | |
UINT32 ret; | |
ret=sp5kOtpInit(); | |
printf("otp init ret=0x%x\n",ret); | |
ret=sp5kSeInit(); | |
printf("se init ret=0x%x\n",ret); | |
memset(&cfg, 0, sizeof(sp5kSeCfg_t)); | |
cfg.alg = SP5K_SE_ALG_AES_ECB_CLR_CLR, | |
cfg.keySizeId = SP5K_SE_KEY_SIZE_ID_AES_128; | |
//memcpy((void *)&cfg.key, (void *)key, 16); | |
cfg.key = key; | |
data.inAddr = plaintext; | |
data.outAddr = ciphertext; | |
data.size = sizeof(plaintext); | |
ret=sp5kSeEncrypt(SP5K_SE_DEV1, &cfg, &data, 1); | |
printf("encrypt ret=0x%x\n",ret); | |
//The correct result is: | |
//0x10, 0x99, 0x98, 0x06, 0x8e, 0xa7, 0x13, 0x8f, | |
//0x68, 0xa4, 0x27, 0x04, 0x88, 0x7a, 0xde, 0xd5, | |
data.inAddr = ciphertext; | |
data.outAddr = decodetext; | |
ret=sp5kSeDecrypt(SP5K_SE_DEV1, &cfg, &data, 1); | |
printf("decrypt ret=0x%x\n",ret); | |
for(i=0;i<16;i++){ | |
printf("in[%d]=0x%x, out[%d]=0x%x, out2[%d]=0x%x\n",i,plaintext[i],i,ciphertext[i],i,decodetext[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment