projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use xoshiro256** to generate pseudo-random numbers.
[tinc]
/
src
/
crypto.h
diff --git
a/src/crypto.h
b/src/crypto.h
index
74bab1b
..
9fc4156
100644
(file)
--- a/
src/crypto.h
+++ b/
src/crypto.h
@@
-1,6
+1,8
@@
#ifndef TINC_CRYPTO_H
#define TINC_CRYPTO_H
#ifndef TINC_CRYPTO_H
#define TINC_CRYPTO_H
+#include "system.h"
+
/*
crypto.h -- header for crypto.c
Copyright (C) 2007-2013 Guus Sliepen <guus@tinc-vpn.org>
/*
crypto.h -- header for crypto.c
Copyright (C) 2007-2013 Guus Sliepen <guus@tinc-vpn.org>
@@
-22,6
+24,21
@@
extern void crypto_init(void);
extern void crypto_exit(void);
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);
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
#endif