X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fcrypto.h;h=9fc4156c82a3aaf0e65dedefb453d3ece318242c;hb=6debc6c79ba385d35f646e0958f84ace5b8f4b4d;hp=74bab1b0a858b71bc4668a75f8d09e74afe600b4;hpb=42d2dff33306beae8ddbd9cc991ad80f135950a6;p=tinc diff --git a/src/crypto.h b/src/crypto.h index 74bab1b0..9fc4156c 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -1,6 +1,8 @@ #ifndef TINC_CRYPTO_H #define TINC_CRYPTO_H +#include "system.h" + /* crypto.h -- header for crypto.c Copyright (C) 2007-2013 Guus Sliepen @@ -22,6 +24,21 @@ extern void crypto_init(void); extern void crypto_exit(void); +extern uint64_t xoshiro(void); +extern void prng_init(void); +extern void prng_randomize(void *buf, size_t buflen); extern void randomize(void *buf, size_t buflen); +static inline uint32_t prng(uint32_t limit) { + uint64_t bins = UINT64_MAX / limit; + uint64_t reject_after = bins * limit; + uint64_t value; + + do { + value = xoshiro(); + } while(value >= reject_after); + + return value / bins; +} + #endif