[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] prop224: Rename padding size def to something less confusing.



commit 61f318b1b0bb1cb55d4f54eab87518a1b093ba08
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Fri Feb 24 12:44:34 2017 +0200

    prop224: Rename padding size def to something less confusing.
    
    People felt it could refer to the descriptor header section instead of
    the plaintext of the superencrypted section.
---
 src/or/hs_descriptor.c        | 13 ++++++-------
 src/test/test_hs_descriptor.c | 10 +++++-----
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/or/hs_descriptor.c b/src/or/hs_descriptor.c
index d15c160..f441fbf 100644
--- a/src/or/hs_descriptor.c
+++ b/src/or/hs_descriptor.c
@@ -558,18 +558,17 @@ static size_t
 compute_padded_plaintext_length(size_t plaintext_len)
 {
   size_t plaintext_padded_len;
+  const int padding_block_length = HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE;
 
   /* Make sure we won't overflow. */
-  tor_assert(plaintext_len <=
-             (SIZE_T_CEILING - HS_DESC_PLAINTEXT_PADDING_MULTIPLE));
+  tor_assert(plaintext_len <= (SIZE_T_CEILING - padding_block_length));
 
   /* Get the extra length we need to add. For example, if srclen is 10200
    * bytes, this will expand to (2 * 10k) == 20k thus an extra 9800 bytes. */
-  plaintext_padded_len = CEIL_DIV(plaintext_len,
-                                  HS_DESC_PLAINTEXT_PADDING_MULTIPLE) *
-                         HS_DESC_PLAINTEXT_PADDING_MULTIPLE;
+  plaintext_padded_len = CEIL_DIV(plaintext_len, padding_block_length) *
+                         padding_block_length;
   /* Can never be extra careful. Make sure we are _really_ padded. */
-  tor_assert(!(plaintext_padded_len % HS_DESC_PLAINTEXT_PADDING_MULTIPLE));
+  tor_assert(!(plaintext_padded_len % padding_block_length));
   return plaintext_padded_len;
 }
 
@@ -619,7 +618,7 @@ build_encrypted(const uint8_t *key, const uint8_t *iv, const char *plaintext,
     encrypted_len = build_plaintext_padding(plaintext, plaintext_len,
                                             &padded_plaintext);
     /* Extra precautions that we have a valid padding length. */
-    tor_assert(!(encrypted_len % HS_DESC_PLAINTEXT_PADDING_MULTIPLE));
+    tor_assert(!(encrypted_len % HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE));
   } else { /* No padding required for inner layers */
     padded_plaintext = tor_memdup(plaintext, plaintext_len);
     encrypted_len = plaintext_len;
diff --git a/src/test/test_hs_descriptor.c b/src/test/test_hs_descriptor.c
index 2a2188c..1a1b511 100644
--- a/src/test/test_hs_descriptor.c
+++ b/src/test/test_hs_descriptor.c
@@ -317,13 +317,13 @@ test_descriptor_padding(void *arg)
 /* Example: if l = 129, the ceiled division gives 2 and then multiplied by 128
  * to give 256. With l = 127, ceiled division gives 1 then times 128. */
 #define PADDING_EXPECTED_LEN(l) \
-  CEIL_DIV(l, HS_DESC_PLAINTEXT_PADDING_MULTIPLE) * \
-  HS_DESC_PLAINTEXT_PADDING_MULTIPLE
+  CEIL_DIV(l, HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE) * \
+  HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE
 
   (void) arg;
 
   { /* test #1: no padding */
-    plaintext_len = HS_DESC_PLAINTEXT_PADDING_MULTIPLE;
+    plaintext_len = HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE;
     plaintext = tor_malloc(plaintext_len);
     padded_len = build_plaintext_padding(plaintext, plaintext_len,
                                          &padded_plaintext);
@@ -339,7 +339,7 @@ test_descriptor_padding(void *arg)
   }
 
   { /* test #2: one byte padding? */
-    plaintext_len = HS_DESC_PLAINTEXT_PADDING_MULTIPLE - 1;
+    plaintext_len = HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE - 1;
     plaintext = tor_malloc(plaintext_len);
     padded_plaintext = NULL;
     padded_len = build_plaintext_padding(plaintext, plaintext_len,
@@ -356,7 +356,7 @@ test_descriptor_padding(void *arg)
   }
 
   { /* test #3: Lots more bytes of padding? */
-    plaintext_len = HS_DESC_PLAINTEXT_PADDING_MULTIPLE + 1;
+    plaintext_len = HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE + 1;
     plaintext = tor_malloc(plaintext_len);
     padded_plaintext = NULL;
     padded_len = build_plaintext_padding(plaintext, plaintext_len,



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits