X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fcrypto.c;h=3244a0b4628bdd2e6ddb6f49dbf1a0c30fab17ad;hp=1bdd8b0745597bd5a35f73bfefa18a7d10db3dca;hb=963c5055505f2fc117cd5efa06eaa02c9b2bf85d;hpb=dc0e52cb3e42620c3139e713b373d130aa30b698 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();