X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fcrypto.c;h=3244a0b4628bdd2e6ddb6f49dbf1a0c30fab17ad;hp=1bdd8b0745597bd5a35f73bfefa18a7d10db3dca;hb=9cde0d32cf209388cc59b06b7dcb0c3432f97da5;hpb=9e8e77dba3462c4a7f7e758ade4d16bc669fc4a7 diff --git a/src/crypto.c b/src/crypto.c index 1bdd8b07..3244a0b4 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -28,6 +28,8 @@ static int random_fd = -1; void crypto_init(void) { + assert(random_fd == -1); + random_fd = open("/dev/urandom", O_RDONLY); if(random_fd < 0) { @@ -41,10 +43,15 @@ void crypto_init(void) { } void crypto_exit(void) { + assert(random_fd != -1); + close(random_fd); + random_fd = -1; } void randomize(void *out, size_t outlen) { + assert(outlen); + char *ptr = out; while(outlen) { @@ -81,6 +88,8 @@ void crypto_exit(void) { } void randomize(void *out, size_t outlen) { + assert(outlen); + if(!CryptGenRandom(prov, outlen, out)) { fprintf(stderr, "CryptGenRandom() failed\n"); abort();