Skip to content

AES-CTR PRNG Implementation in OpenSSL with Consistent Output and Memory Leak Issues - OpenSSL 3.1.1 #23958

Closed Answered by Knogle
Knogle asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks a lot folks for your help. I was able to fix the issue.
What caused the issue, was likely a buffer overflow of bufpos, corrupting the memory of the other parameters.
I've modified the code now, providing a temporary buffer, and writing 4x 32-Bit instead of one-time 128-Bit, and now it's performing properly!

Before:

    void aes_ctr_prng_genrand_uint128_to_buf(aes_ctr_state_t* state, unsigned char* bufpos) {
        int outlen;
    
        EVP_EncryptUpdate(state->ctx, bufpos, &outlen, bufpos, 16);
        // OpenSSL internally calls CRYPTO_ctr128_encrypt_ctr32
    }

After:

    /* Generates pseudorandom numbers and writes them to a buffer.
       - state: Pointer to the initialized…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Knogle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
triaged: question The issue contains a question
2 participants
Converted from issue

This discussion was converted from issue #23957 on March 23, 2024 14:26.