libtomcrypt
libtomcrypt copied to clipboard
Don't get the right answers when cross-compiled on RISC-V processor
Description
I'm cross-compiling the basic library with just AES cipher (CTR, ECB, and GCM modes only) on a RISC-V processor and I'm comparing to a test program running on an Intel PC, but I do not get the same results.
Steps to Reproduce
This is the relevant part of my test program on the PC. The program on the RISC-V is calling the same library functions in the same order. Using the same key, IV, and input, I get different ciphertext output.
symmetric_CTR g_ctr_key;
int cipher_idx = 0;
void StartCtr(unsigned char* key)
{
unsigned char blank_iv[IVSIZE] = { 0 };
int err = ctr_start(cipher_idx, blank_iv, key, KEYSIZE, 0, CTR_COUNTER_BIG_ENDIAN, &g_ctr_key);
}
void DoEncryptCtr(unsigned char* IV, unsigned char* inbuf)
{
unsigned char ciphertext[BLOCKSIZE];
int err = ctr_setiv(IV, IVSIZE, &g_ctr_key);
err = ctr_encrypt(inbuf, ciphertext, BLOCKSIZE, &g_ctr_key);
// print out ciphertext here
}
void StopCtr(void)
{
int err = ctr_done(&g_ctr_key);
}
void main( void )
{
unsigned char key[KEYSIZE];
unsigned char IV[IVSIZE];
unsigned char inbuf[BLOCKSIZE];
// register ciphers and get cipher_idx here
StartCtr(key);
DoEncryptCtr(IV, inbuf);
StopCtr();
}
Version
I'm using version 1.18.2 in both programs. I'm using Visual Studio 2019 Community on the PC and the GCC compiler from Microsemi/Microchip that comes with SoftConsole 2021.1. It's using GNU RISC-V Cross Compiler gcc version 8.3.0 "riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -msmall-data-limit=8"