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.
This commit is contained in:
George Kadianakis 2017-02-24 12:44:34 +02:00
parent e6b03151fb
commit 61f318b1b0
2 changed files with 11 additions and 12 deletions

View file

@ -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;

View file

@ -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,