Home > Back-end >  Access Violation when using OpenSSL's Camellia
Access Violation when using OpenSSL's Camellia

Time:05-26

I'm trying to write a camellia decryption program in windows using c as the language and OpenSSL as the cryptographic provider. When attempting to execute the code I get the following error Exception thrown at 0x00007FFABB31AEF8 (libcrypto-3-x64.dll) in Lab8.exe: 0xC0000005: Access violation reading location 0x0000000000000028.

The code is:

#include <iostream>
#include <windows.h>
#include <openssl/camellia.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <string.h>
#pragma warning(disable : 4996)

unsigned char iv[] = "\xd4\xc5\x91\xad\xe5\x7e\x56\x69\xcc\xcd\xb7\x11\xcf\x02\xec\xbc";
unsigned char camcipher[] = "\x00\xf7\x41\x73\x04\x5b\x99\xea\xe5\x6d\x41\x8e\xc4\x4d\x21\x5c";
const unsigned char camkey[] = "\x92\x63\x88\x77\x9b\x02\xad\x91\x3f\xd9\xd2\x45\xb1\x92\x21\x5f\x9d\x48\x35\xd5\x6e\xf0\xe7\x3a\x39\x26\xf7\x92\xf7\x89\x5d\x75";
unsigned char plaintext;

CAMELLIA_KEY finalkey;

int main()
{

    Camellia_set_key(camkey, 256, &finalkey);

    Camellia_cbc_encrypt(camcipher, (unsigned char*)plaintext, CAMELLIA_BLOCK_SIZE,&finalkey, iv, 0);

    std::cout << plaintext;

}

The Key and IV were generated using urandom from python3 and then used to create the cipher text using the PyCryto library camellia.

I purposefully left the cipher text at 16 Bytes to avoid padding. I'm really not sure what I'm doing wrong at all. Any help would be awesome.

The plaintext should read "a secret message"

CodePudding user response:

Looks like you need to declare unsigned char plaintext; to be unsigned char plaintext[17];, otherwise you're overwriting uninitialized memory.

  • Related