Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't get the right answers when cross-compiled on RISC-V processor #578

Open
gunslnger42 opened this issue Dec 11, 2021 · 0 comments
Open

Comments

@gunslnger42
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant