-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
50 lines (40 loc) · 1.71 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <openssl/rand.h>
#include <fstream>
#include <iostream>
#include <sys/time.h>
#include <unistd.h>
#include <cstring> // Include cstring for memcpy
int main() {
const int keySize = 32; // 32 bytes (256 bits) for a Bitcoin private key
unsigned char buffer[keySize];
// Hard-coded entropy sources
struct timeval tv;
gettimeofday(&tv, nullptr); // Get the current time
double timestamp = tv.tv_sec + (tv.tv_usec / 1000000.0); // Convert to seconds with microseconds as decimal
pid_t pid = getpid(); // Get the current process ID
int mouseMovement = 12345; // Example hard-coded mouse movement value
// Combine entropy sources into a single buffer for RAND_add
unsigned char entropy[16]; // Example size; adjust as needed
memcpy(entropy, ×tamp, sizeof(timestamp));
memcpy(entropy + sizeof(timestamp), &pid, sizeof(pid));
memcpy(entropy + sizeof(timestamp) + sizeof(pid), &mouseMovement, sizeof(mouseMovement));
// Add entropy to OpenSSL's randomness pool
RAND_add(entropy, sizeof(entropy), 1.5); // Entropy estimate of 8.0, adjust as needed
// Generate 32 random bytes
if (RAND_bytes(buffer, keySize) != 1) {
std::cerr << "Failed to generate random bytes." << std::endl;
return 1;
}
// Open a file in binary mode
std::ofstream outFile("random_byte.bin", std::ios::binary);
if (!outFile) {
std::cerr << "Failed to open file for writing." << std::endl;
return 1;
}
// Write the binary data to the file
outFile.write(reinterpret_cast<const char*>(buffer), keySize);
// Close the file
outFile.close();
std::cout << "Random byte saved to random_byte.bin" << std::endl;
return 0;
}