summaryrefslogtreecommitdiffstats
path: root/3rd_party/ed25519/seed.c
diff options
context:
space:
mode:
Diffstat (limited to '3rd_party/ed25519/seed.c')
-rw-r--r--3rd_party/ed25519/seed.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/3rd_party/ed25519/seed.c b/3rd_party/ed25519/seed.c
new file mode 100644
index 0000000..cf252b8
--- /dev/null
+++ b/3rd_party/ed25519/seed.c
@@ -0,0 +1,40 @@
1#include "ed25519.h"
2
3#ifndef ED25519_NO_SEED
4
5#ifdef _WIN32
6#include <windows.h>
7#include <wincrypt.h>
8#else
9#include <stdio.h>
10#endif
11
12int ed25519_create_seed(unsigned char *seed) {
13#ifdef _WIN32
14 HCRYPTPROV prov;
15
16 if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
17 return 1;
18 }
19
20 if (!CryptGenRandom(prov, 32, seed)) {
21 CryptReleaseContext(prov, 0);
22 return 1;
23 }
24
25 CryptReleaseContext(prov, 0);
26#else
27 FILE *f = fopen("/dev/urandom", "rb");
28
29 if (f == NULL) {
30 return 1;
31 }
32
33 if(fread(seed, 1, 32, f)){}
34 fclose(f);
35#endif
36
37 return 0;
38}
39
40#endif