ed25519/src/seed.c

40 lines
586 B
C
Raw Normal View History

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