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

Request for AES128_CBC Encryption Help #224

Open
tecsantoshkumar opened this issue Mar 20, 2024 · 1 comment
Open

Request for AES128_CBC Encryption Help #224

tecsantoshkumar opened this issue Mar 20, 2024 · 1 comment

Comments

@tecsantoshkumar
Copy link

I am currently working on implementing AES128_CBC encryption on an STM32 embedded system. I have encountered some difficulties with incorporating salt and iteration counts into the encryption process.

I would greatly appreciate it if you could provide some guidance or suggestions on how to correctly implement AES128_CBC encryption with salt and iteration counts with or without OpenSSL library on an STM32 embedded system.

Thank you very much for your time and assistance. I look forward to hearing from you soon.

@Xeraster
Copy link

Xeraster commented May 22, 2024

i'm curious to see any response to this. I'm trying to get this working on a kernel written in c++that can't have anything higher than i486 opcodes in it. This library just doesn't work on it for some reason, it never encrypts or decrypts to the correct value on any combination of settings. Changing really minor things such as commenting out CBC define or running AES_init_ctx before decrypting vs not doing that makes it give me different but still incorrect outputs.

I had to change every occurrence of uint8_t to char because I can't get uint8_t on here. Attempting a manual implementation of uint8_t is only going to add another dimension to this issue and probably cause even more problems when I inevitably don't get it 100% accurate.

If anyone with experience can identify problems in my code that would be helpful:
`
char key[] = { (char)0x2b, (char)0x7e, (char)0x15, (char)0x16, (char)0x28, (char)0xae, (char)0xd2, (char)0xa6, (char)0xab, (char)0xf7, (char)0x15, (char)0x88, (char)0x09, (char)0xcf, (char)0x4f, (char)0x3c };
//char out[] = { (char)0x3a, (char)0xd7, (char)0x7b, (char)0xb4, (char)0x0d, (char)0x7a, (char)0x36, (char)0x60, (char)0xa8, (char)0x9e, (char)0xca, (char)0xf3, (char)0x24, (char)0x66, (char)0xef, (char)0x97 };
char in[] = { (char)0x6b, (char)0xc1, (char)0xbe, (char)0xe2, (char)0x2e, (char)0x40, (char)0x9f, (char)0x96, (char)0xe9, (char)0x3d, (char)0x7e, (char)0x11, (char)0x73, (char)0x93, (char)0x17, (char)0x2a };
char iv[] = { (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x04, (char)0x05, (char)0x06, (char)0x07, (char)0x08, (char)0x09, (char)0x0a, (char)0x0b, (char)0x0c, (char)0x0d, (char)0x0e, (char)0x0f };

for (int i = 0; i < 16; i++)
{
    print8BitHexInt(in[i]);
}
consoleNewLine();

struct AES_ctx ctx;
AES_init_ctx(&ctx, key);
AES_ECB_encrypt(&ctx, in);
for (int i = 0; i < 16; i++)
{
    print8BitHexInt(in[i]);
}
consoleNewLine();

//now decrypt it back
AES_ECB_decrypt(&ctx, in);
for (int i = 0; i < 16; i++)
{
    print8BitHexInt(in[i]);
}

`

Edit: ok so ctrl+F then replacing every instance of uint8_t to unsigned char rather than char seems to allow it to work on my system. Implementing cstdint to get uint8 means also including memcpy which conflicts with my memory manager (I have a function named memcpy that works the same as the real memcpy but the memory manager needs it for speed reasons).

so the tl;dr is that if you absolutely cannot get cstdint so you can get uint8_t, unsigned char works instead.

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

2 participants