I had some errors in my code and I was able to pinpoint the issue to the RAND_bytes function
Basically no matter how I use this function I kept ending up with return value 3221225477 after compiling, which is the STATUS_ACCESS_VIOLATION
Minimal reproducible example:
#include <iostream>
#include <openssl/rand.h>
using namespace std;
int main() {
unsigned char buf[16] = {0};
cout << "Line1 << endl;
int re = RAND_bytes(buf, sizeof(buf)); //the rest won't be executed, indicated by the cout
cout << "Line2 << endl;
for (int i = 0; i < sizeof(buf); i++)
cout << (int)buf[i] << " ";
cout << "Line3 << endl;
cout << endl;
getchar();
return 0;
}
Additional information:
1. Placing the entire code in (try...catch) does not result in any error
2. Errors: 0, Warnings: 0, even in debugger mode
3. Also tried some other implementations of RAND_bytes ([Code1](/questions/23234390/openssl-and-rand-bytes), [text](https://stackoverflow.com))
It's worth noting to mention that
1. I can't use another compiler (I'm a student and my teacher wouldn't allow it)
2. I'm using Dev-C++, version 5.11, OpenSSL 3.2.0 23 Nov 2023 (Library: OpenSSL 3.2.0 23 Nov 2023), and of all the tutorials I found are either in linux/mac, or in windows but in CodeBlocks/VS, it's very likely that something went wrong with my settings (using the "keyword" searching in google does not yield any useful result, including "RAND_bytes" "3221225477")
Here are my settings on my compiler:
[Project Options -> Linker (Can't see the full pic, its in the form ../../../../OpenSSL/3.3.0/lib/libcrypto.lib, my code is inside a folder in my desktop, added via the built-in search feature so this directory should be correct](https://i.sstatic.net/A2XkggK8.png)
[Compiler Options -> Binaries](https://i.sstatic.net/MmBU6GpB.png)
[Compiler Options -> Libaries](https://i.sstatic.net/OlZUnzS1.png)
[Compiler Options -> C++ includes](https://i.sstatic.net/BhRQL4zu.png)
I can't response right now until 8 hours, sorry for inconvenience
Pinpointed the problem to the function RAND_bytes in OpenSSL
Used try catch to see if I can get any errors, no result
Provided a minimal reproducible example, compiler details and settings, OpenSSL version, running the code in debugger mode, searched on the internet but to no`your text` avail
Checked for duplicated questions and none of them are similar to this`your text`
New contributor
Mark Moon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.