]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add crypto_rand_unmocked, which is crypto_rand without mocking.
authorYawning Angel <yawning@schwanenlied.me>
Wed, 12 Aug 2015 15:57:05 +0000 (15:57 +0000)
committerYawning Angel <yawning@schwanenlied.me>
Wed, 12 Aug 2015 15:57:05 +0000 (15:57 +0000)
There is odd issues with calling crypto_rand from our copy of
ed25519-donna, due to mocking that are not easily resolved.

src/common/crypto.c
src/common/crypto.h

index 2121383c75a66333430ef280617cdb0473141d62..6d4b0d7e16b86755766a3e644f534db79150e210 100644 (file)
@@ -2365,10 +2365,19 @@ crypto_seed_rng(void)
 }
 
 /** Write <b>n</b> bytes of strong random data to <b>to</b>. Return 0 on
- * success, -1 on failure.
+ * success, -1 on failure, with support for mocking for unit tests.
  */
 MOCK_IMPL(int,
 crypto_rand, (char *to, size_t n))
+{
+  return crypto_rand_unmocked(to, n);
+}
+
+/** Write <b>n</b> bytes of strong random data to <b>to</b>. Return 0 on
+ * success, -1 on failure.  Most callers will want crypto_rand instead.
+ */
+int
+crypto_rand_unmocked(char *to, size_t n)
 {
   int r;
   tor_assert(n < INT_MAX);
index 368e9d8e32fd55047efdaa4e37e89465211179f6..6256f7346b5a38a8e50cae6953c4e99deba708b7 100644 (file)
@@ -260,6 +260,7 @@ int crypto_expand_key_material_rfc5869_sha256(
 /* random numbers */
 int crypto_seed_rng(void);
 MOCK_DECL(int,crypto_rand,(char *to, size_t n));
+int crypto_rand_unmocked(char *to, size_t n);
 int 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);