ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Crypt-Ed25519/ed25519/src/seed.c
Revision: 1.2
Committed: Tue Feb 28 19:53:08 2017 UTC (7 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-1_04, rel-1_05, HEAD
Changes since 1.1: +3 -3 lines
Log Message:
1.04

File Contents

# Content
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
12 int 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 fread(seed, 1, 32, f);
34 fclose(f);
35 #endif
36
37 return 0;
38 }
39
40 #endif