diff --git a/ed25519/src/seed.cpp b/ed25519/src/seed.cpp index d595cdc11..63da924c0 100644 --- a/ed25519/src/seed.cpp +++ b/ed25519/src/seed.cpp @@ -1,6 +1,8 @@ // ignore warnings in this file #include "libtorrent/aux_/disable_warnings_push.hpp" +#include +#include #include "libtorrent/ed25519.hpp" #ifndef ED25519_NO_SEED @@ -12,17 +14,19 @@ #include #endif -int ed25519_create_seed(unsigned char *seed) { +void ed25519_create_seed(unsigned char *seed) { #ifdef _WIN32 HCRYPTPROV prov; if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { - return 1; + throw boost::system::system_error(boost::system::error_code(GetLastError() + , boost::system::system_category())); } if (!CryptGenRandom(prov, 32, seed)) { CryptReleaseContext(prov, 0); - return 1; + throw boost::system::system_error(boost::system::error_code(GetLastError() + , boost::system::system_category())); } CryptReleaseContext(prov, 0); @@ -30,14 +34,17 @@ int ed25519_create_seed(unsigned char *seed) { FILE *f = fopen("/dev/urandom", "rb"); if (f == NULL) { - return 1; + throw boost::system::system_error(boost::system::error_code(errno, boost::system::generic_category())); + } + + int read = fread(seed, 1, 32, f); + if (read != 32) { + fclose(f); + throw boost::system::system_error(boost::system::error_code(errno, boost::system::generic_category())); } - fread(seed, 1, 32, f); fclose(f); #endif - - return 0; } #endif diff --git a/include/libtorrent/ed25519.hpp b/include/libtorrent/ed25519.hpp index 970168077..bb343ccd0 100644 --- a/include/libtorrent/ed25519.hpp +++ b/include/libtorrent/ed25519.hpp @@ -17,7 +17,7 @@ enum extern "C" { #ifndef ED25519_NO_SEED -int TORRENT_EXPORT ed25519_create_seed(unsigned char *seed); +void TORRENT_EXPORT ed25519_create_seed(unsigned char *seed); #endif void TORRENT_EXPORT ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);