-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·129 lines (99 loc) · 3.28 KB
/
main.c
File metadata and controls
executable file
·129 lines (99 loc) · 3.28 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Keymaker : a linux based cli tool for getting random and pseudorandom bits from /dev/random and /dev/urandom
Copyright (C) 2025 Dustyn Gibb
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifdef __WIN32__
#ifdef __WIN64__
#error This program is only meant to run on linux ,bsd, darwin
#endif
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define RANDOM_HIGH_QUALITY "/dev/random"
#define RANDOM_LOWER_QUALITY "/dev/urandom"
#define ENTROPY_POOL_SIZE 4096
char entropy_pool[ENTROPY_POOL_SIZE];
int64_t bits = 0;
char random_file[64];
void check_file(const char* arg) {
if (strncmp(arg, "high", 8) == 0) {
strcpy(random_file,RANDOM_HIGH_QUALITY);
return;
}
if (strncmp(arg, "low", 8) == 0) {
strcpy(random_file,RANDOM_LOWER_QUALITY);
return;
}
printf("Invalid quality identifier!\n");
exit(1);
}
void warn_user(char* warning) {
printf("WARNING: %s\n", warning);
}
void help_message() {
printf("Usage: ./keymaker num_bits quality(high/low)\n");
exit(1);
}
void check_help(int argc, const char* argv[]) {
if (argc >= 2 && strncmp(argv[1], "--help", 8) == 0) {
help_message();
}
}
void chip_security_checks() {
#ifdef __x86_64__
warn_user(
"Be wary using modern intel or amd chips, they have a known management engine backdoor. If this secret is of life or death stakes, do not use this machine");
#elifdef __aarch64__
warn_user(
"Be wary using modern arm chips, many of them have a known management engine backdoor. If this secret is of life or death stakes, do not use this machine");
#endif
}
int main(const int argc, const char* argv[]) {
check_help(argc, argv);
if (argc > 3 || argc < 3) {
help_message();
}
chip_security_checks();
char* endptr;
bits = strtol(argv[1], &endptr, 10);
if (bits < 0) {
printf("Invalid bit count! Are you sure it's a numerical value?\n");
exit(1);
}
if (bits % 8 != 0) {
printf(
"Num bits required must be divisible by 8! Who the fuck even needs sub byte quantities of bits for a key!\n");
exit(1);
}
uint64_t bytes = bits / 8;
check_file(argv[2]);
FILE* f = fopen(random_file, "rb");
if (f == NULL) {
printf("Failed to open file %s\n", random_file);
exit(1);
}
int64_t ret = fread(entropy_pool,ENTROPY_POOL_SIZE, bytes, f);
if (ret < 0) {
printf("Failed to read file %s\n", random_file);
exit(1);
}
printf("Your key is 0x");
for (int i = 0; i < bytes; i++) {
printf("%02X", entropy_pool[i] & 0xFF);
}
printf("\n");
return 0;
}