ed25519/src/seed.c

41 lines
655 B
C
Raw Permalink Normal View History

#include "../include/ed25519.h"
2013-01-22 04:58:57 -05:00
2013-01-11 18:54:40 -05:00
#ifndef ED25519_NO_SEED
#ifdef _WIN32
#include <windows.h>
#include <wincrypt.h>
2013-01-11 18:54:40 -05:00
#else
#include <stdio.h>
#endif
int ed25519_create_seed(unsigned char *seed) {
2013-01-11 20:38:34 -05:00
#ifdef _WIN32
2013-04-26 09:32:01 -04:00
HCRYPTPROV prov;
2013-01-11 18:54:40 -05:00
2013-04-26 09:32:01 -04:00
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
return 1;
}
2013-01-11 18:54:40 -05:00
2013-04-26 09:32:01 -04:00
if (!CryptGenRandom(prov, 32, seed)) {
CryptReleaseContext(prov, 0);
return 1;
}
2013-04-26 09:32:01 -04:00
CryptReleaseContext(prov, 0);
2013-01-11 20:38:34 -05:00
#else
2013-04-26 09:32:01 -04:00
FILE *f = fopen("/dev/urandom", "rb");
2013-04-26 09:32:01 -04:00
if (f == NULL) {
return 1;
}
2013-04-26 09:32:01 -04:00
fread(seed, 1, 32, f);
fclose(f);
2013-01-11 20:38:34 -05:00
#endif
2013-01-22 04:58:57 -05:00
2013-01-11 20:38:34 -05:00
return 0;
2013-01-11 18:54:40 -05:00
}
#endif