-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmkSecretTxt.c
More file actions
66 lines (55 loc) · 1.64 KB
/
mkSecretTxt.c
File metadata and controls
66 lines (55 loc) · 1.64 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
/* Placed in public domain 2010 by Sam Trenholme */
/* To compile:
*
* Install MinGW-3.4.2 (Look for MinGW-3.4.2.exe on the internet)
*
* Install MSYS-1.0.10 (Look for MSYS-1.0.10.exe on the internet; use
* newer MSYS if using a 64-bit system)
*
* From a MSYS command prompt: gcc -Os -o mkSecretTxt mkSecretTxt.c
*
* This is only for Windows systems; the *NIX equivalent is:
*
* dd if=/dev/urandom of=secret.txt bs=64 count=1
*/
#include <stdio.h>
#include <stdint.h>
#include <winsock.h>
#include <wincrypt.h> /* Windows only; *NIX has /dev/random */
main() {
uint8_t pool[65];
HCRYPTPROV CryptContext;
int a;
int b;
FILE *out;
for(a = 0; a < 64 ; a++) {
pool[a] = 0;
}
out = fopen("secret.txt","rb");
if(out != NULL) {
printf("secret.txt already exists\n");
return 4;
}
out = fopen("secret.txt","wb");
if(out == NULL) {
printf("Fatal error opening secret.txt for writing");
return 3;
}
b = CryptAcquireContext(&CryptContext, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT);
if(b != 1) {
printf("Fatal error with CryptAcquireContext()\n");
return 1;
}
b = CryptGenRandom(CryptContext, 64, pool);
if(b != 1) {
printf("Fatal error with CryptGenRandom()\n");
return 2;
}
CryptReleaseContext(CryptContext,0);
for(a = 0; a < 64 ; a++) {
putc(pool[a], out);
}
fclose(out);
return 0;
}