简体   繁体   中英

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

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;

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM