aboutsummaryrefslogtreecommitdiff
path: root/src/lib/crypt_ops/crypto_rand.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-21 12:46:11 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-21 13:14:14 -0400
commit25ccfff86a5b29c9c1ec9b3d01fe1dc796e9afa0 (patch)
tree1c23ec9dd2cea5d00e4262fa4574ffdb9e250aa7 /src/lib/crypt_ops/crypto_rand.h
parent49d7c9ce53daa13daae59eedceb07d28e06e4395 (diff)
downloadtor-25ccfff86a5b29c9c1ec9b3d01fe1dc796e9afa0.tar.gz
tor-25ccfff86a5b29c9c1ec9b3d01fe1dc796e9afa0.zip
Split crypto and tls libraries into directories
I am calling the crypto library "crypt_ops", since I want higher-level crypto things to be separated from lower-level ones. This library will hold only the low-level ones, once we have it refactored.
Diffstat (limited to 'src/lib/crypt_ops/crypto_rand.h')
-rw-r--r--src/lib/crypt_ops/crypto_rand.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib/crypt_ops/crypto_rand.h b/src/lib/crypt_ops/crypto_rand.h
new file mode 100644
index 0000000000..8309bb21ca
--- /dev/null
+++ b/src/lib/crypt_ops/crypto_rand.h
@@ -0,0 +1,52 @@
+/* Copyright (c) 2001, Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file crypto_rand.h
+ *
+ * \brief Common functions for using (pseudo-)random number generators.
+ **/
+
+#ifndef TOR_CRYPTO_RAND_H
+#define TOR_CRYPTO_RAND_H
+
+#include "lib/cc/torint.h"
+#include "common/util.h"
+
+/* random numbers */
+int crypto_seed_rng(void) ATTR_WUR;
+MOCK_DECL(void,crypto_rand,(char *to, size_t n));
+void crypto_rand_unmocked(char *to, size_t n);
+void crypto_strongest_rand(uint8_t *out, size_t out_len);
+int crypto_rand_int(unsigned int max);
+int crypto_rand_int_range(unsigned int min, unsigned int max);
+uint64_t crypto_rand_uint64_range(uint64_t min, uint64_t max);
+time_t crypto_rand_time_range(time_t min, time_t max);
+uint64_t crypto_rand_uint64(uint64_t max);
+double crypto_rand_double(void);
+struct tor_weak_rng_t;
+void crypto_seed_weak_rng(struct tor_weak_rng_t *rng);
+
+char *crypto_random_hostname(int min_rand_len, int max_rand_len,
+ const char *prefix, const char *suffix);
+
+struct smartlist_t;
+void *smartlist_choose(const struct smartlist_t *sl);
+void smartlist_shuffle(struct smartlist_t *sl);
+int crypto_force_rand_ssleay(void);
+
+#ifdef CRYPTO_RAND_PRIVATE
+
+STATIC int crypto_strongest_rand_raw(uint8_t *out, size_t out_len);
+
+#ifdef TOR_UNIT_TESTS
+extern int break_strongest_rng_syscall;
+extern int break_strongest_rng_fallback;
+#endif
+#endif /* defined(CRYPTO_RAND_PRIVATE) */
+
+#endif /* !defined(TOR_CRYPTO_RAND_H) */
+