Is there any way to set members of opaque structs in openssl v1.1.0 or greater?

106 views Asked by At

I am restructuring a legacy code to be compatiable with OpenSSL 1.1.1, During the upgrade of OpenSSL from 1.0.2 -> 1.1.1, serveral structs were made opaque and direct member access is no longer possible.

I have a requirement to set buf_len of EVP_CIPHER_CTX to 0. Is there a way to achieve this?

EVP_CIPHER_CTX* p_ctx;
p_ctx = EVP_CIPHER_CTX_new();
...

p_ctx->buf_len = 0;
1

There are 1 answers

0
Kethiri Sundar On

I did this with a dirtiest hack possible in c++

int buf_len = 0;

//Offset of buf_len in EVP_CIPHER_CTX is 20
int* buf_len_pointer = (int*)((char*)p_ctx + 20); 

memcpy(buf_len_pointer,&buf_len ,sizeof(buf_len));