]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix some conversion problems
authorNick Mathewson <nickm@torproject.org>
Thu, 23 Apr 2015 13:16:42 +0000 (09:16 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 23 Apr 2015 13:16:42 +0000 (09:16 -0400)
src/common/crypto.c
src/common/crypto.h
src/common/tortls.c
src/or/entrynodes.c
src/or/main.c

index e723f3d5d2ce50696a7b6cd1a5a9abff3789cf19..f0d4fbbf21ec9947865f6081b15a8c7236d4cba2 100644 (file)
@@ -2336,6 +2336,21 @@ crypto_rand_int_range(unsigned int min, unsigned int max)
   return min + crypto_rand_int(max - min);
 }
 
+/** As crypto_rand_int_range, but supports uint64_t. */
+uint64_t
+crypto_rand_uint64_range(uint64_t min, uint64_t max)
+{
+  tor_assert(min < max);
+  return min + crypto_rand_uint64(max - min);
+}
+
+/** As crypto_rand_int_range, but supports time_t. */
+time_t
+crypto_rand_time_range(time_t min, time_t max)
+{
+  return (time_t) crypto_rand_uint64_range(min, max);
+}
+
 /** Return a pseudorandom 64-bit integer, chosen uniformly from the values
  * between 0 and <b>max</b>-1. */
 uint64_t
index aa587fd08bbba234f74dfd95b047a2445d91c72f..1ac02ea7a5070e91b39b7d52ab5dfc8d71e11982 100644 (file)
@@ -255,6 +255,8 @@ MOCK_DECL(int,crypto_rand,(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);
+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;
index 7809c1adaa4c2f06893896c4aa11c5f9ae605d95..bd7e95c033b0a820258d478a4015e8764ff59861 100644 (file)
@@ -660,7 +660,7 @@ tor_tls_create_certificate(crypto_pk_t *rsa,
    * then we might pick a time where we're about to expire. Lastly, be
    * sure to start on a day boundary. */
   time_t now = time(NULL);
-  start_time = crypto_rand_int_range(now - cert_lifetime, now) + 2*24*3600;
+  start_time = crypto_rand_time_range(now - cert_lifetime, now) + 2*24*3600;
   start_time -= start_time % (24*3600);
 
   tor_assert(rsa);
index 9f07d5ad69023d71e7812b23769d791f05a2170d..ebf675166b1f1128c464edb5108a4b3536699c4f 100644 (file)
@@ -441,7 +441,7 @@ add_an_entry_guard(const node_t *chosen, int reset_status, int prepend,
    * precise timestamp in the state file about when we first picked
    * this guard. For details, see the Jan 2010 or-dev thread. */
   time_t now = time(NULL);
-  entry->chosen_on_date = crypto_rand_int_range(now - 3600*24*30, now);
+  entry->chosen_on_date = crypto_rand_time_range(now - 3600*24*30, now);
   entry->chosen_by_version = tor_strdup(VERSION);
 
   /* Are we picking this guard because all of our current guards are
@@ -1441,7 +1441,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
      } else {
        if (state_version) {
          time_t now = time(NULL);
-         e->chosen_on_date = crypto_rand_int_range(now - 3600*24*30, now);
+         e->chosen_on_date = crypto_rand_time_range(now - 3600*24*30, now);
          e->chosen_by_version = tor_strdup(state_version);
        }
      }
index b9009db151688b39259a0661f8ca38bbc04b24b0..22b006a3c809809bd96649c4b43a200461462966 100644 (file)
@@ -1623,7 +1623,7 @@ run_scheduled_events(time_t now)
       time_to.check_for_correct_dns < now &&
       ! router_my_exit_policy_is_reject_star()) {
     if (!time_to.check_for_correct_dns) {
-      time_to.check_for_correct_dns = crypto_rand_int_range(now, now + 120) + 60;
+      time_to.check_for_correct_dns = crypto_rand_time_range(now, now + 120) + 60;
     } else {
       dns_launch_correctness_checks();
       time_to.check_for_correct_dns = now + 12*3600 +