Skip to content

module thinko in src/lib/crypt_ops/crypto_rand.c

Summary

I do wonder if

  • "modulo 5" should be "modulo 8"
  • the bits -> bytes calculation have to made afterwards
  • the goal is to calculate the amount of bytes needed for N base32 characters then even the "+7" is wrong
index 5bf3a65b3b..90a755537c 100644
--- a/src/lib/crypt_ops/crypto_rand.c
+++ b/src/lib/crypt_ops/crypto_rand.c
@@ -568,9 +568,10 @@ crypto_random_hostname(int min_rand_len, int max_rand_len, const char *prefix,
   prefixlen = strlen(prefix);
   resultlen = prefixlen + strlen(suffix) + randlen + 16;
 
-  rand_bytes_len = ((randlen*5)+7)/8;
-  if (rand_bytes_len % 5)
-    rand_bytes_len += 5 - (rand_bytes_len%5);
+  rand_bytes_len = randlen*5;
+  if (rand_bytes_len % 8)
+    rand_bytes_len += 8 - (rand_bytes_len%8);
+  rand_bytes_len /= 8;
   rand_bytes = tor_malloc(rand_bytes_len);
   crypto_rand(rand_bytes, rand_bytes_len);

Or?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information