mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
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:
parent
e6b03151fb
commit
61f318b1b0
2 changed files with 11 additions and 12 deletions
|
@ -558,18 +558,17 @@ static size_t
|
||||||
compute_padded_plaintext_length(size_t plaintext_len)
|
compute_padded_plaintext_length(size_t plaintext_len)
|
||||||
{
|
{
|
||||||
size_t plaintext_padded_len;
|
size_t plaintext_padded_len;
|
||||||
|
const int padding_block_length = HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE;
|
||||||
|
|
||||||
/* Make sure we won't overflow. */
|
/* Make sure we won't overflow. */
|
||||||
tor_assert(plaintext_len <=
|
tor_assert(plaintext_len <= (SIZE_T_CEILING - padding_block_length));
|
||||||
(SIZE_T_CEILING - HS_DESC_PLAINTEXT_PADDING_MULTIPLE));
|
|
||||||
|
|
||||||
/* Get the extra length we need to add. For example, if srclen is 10200
|
/* 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. */
|
* bytes, this will expand to (2 * 10k) == 20k thus an extra 9800 bytes. */
|
||||||
plaintext_padded_len = CEIL_DIV(plaintext_len,
|
plaintext_padded_len = CEIL_DIV(plaintext_len, padding_block_length) *
|
||||||
HS_DESC_PLAINTEXT_PADDING_MULTIPLE) *
|
padding_block_length;
|
||||||
HS_DESC_PLAINTEXT_PADDING_MULTIPLE;
|
|
||||||
/* Can never be extra careful. Make sure we are _really_ padded. */
|
/* 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;
|
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,
|
encrypted_len = build_plaintext_padding(plaintext, plaintext_len,
|
||||||
&padded_plaintext);
|
&padded_plaintext);
|
||||||
/* Extra precautions that we have a valid padding length. */
|
/* 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 */
|
} else { /* No padding required for inner layers */
|
||||||
padded_plaintext = tor_memdup(plaintext, plaintext_len);
|
padded_plaintext = tor_memdup(plaintext, plaintext_len);
|
||||||
encrypted_len = plaintext_len;
|
encrypted_len = plaintext_len;
|
||||||
|
|
|
@ -317,13 +317,13 @@ test_descriptor_padding(void *arg)
|
||||||
/* Example: if l = 129, the ceiled division gives 2 and then multiplied by 128
|
/* 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. */
|
* to give 256. With l = 127, ceiled division gives 1 then times 128. */
|
||||||
#define PADDING_EXPECTED_LEN(l) \
|
#define PADDING_EXPECTED_LEN(l) \
|
||||||
CEIL_DIV(l, HS_DESC_PLAINTEXT_PADDING_MULTIPLE) * \
|
CEIL_DIV(l, HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE) * \
|
||||||
HS_DESC_PLAINTEXT_PADDING_MULTIPLE
|
HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE
|
||||||
|
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
{ /* test #1: no padding */
|
{ /* test #1: no padding */
|
||||||
plaintext_len = HS_DESC_PLAINTEXT_PADDING_MULTIPLE;
|
plaintext_len = HS_DESC_SUPERENC_PLAINTEXT_PAD_MULTIPLE;
|
||||||
plaintext = tor_malloc(plaintext_len);
|
plaintext = tor_malloc(plaintext_len);
|
||||||
padded_len = build_plaintext_padding(plaintext, plaintext_len,
|
padded_len = build_plaintext_padding(plaintext, plaintext_len,
|
||||||
&padded_plaintext);
|
&padded_plaintext);
|
||||||
|
@ -339,7 +339,7 @@ test_descriptor_padding(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
{ /* test #2: one byte padding? */
|
{ /* 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);
|
plaintext = tor_malloc(plaintext_len);
|
||||||
padded_plaintext = NULL;
|
padded_plaintext = NULL;
|
||||||
padded_len = build_plaintext_padding(plaintext, plaintext_len,
|
padded_len = build_plaintext_padding(plaintext, plaintext_len,
|
||||||
|
@ -356,7 +356,7 @@ test_descriptor_padding(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
{ /* test #3: Lots more bytes of padding? */
|
{ /* 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);
|
plaintext = tor_malloc(plaintext_len);
|
||||||
padded_plaintext = NULL;
|
padded_plaintext = NULL;
|
||||||
padded_len = build_plaintext_padding(plaintext, plaintext_len,
|
padded_len = build_plaintext_padding(plaintext, plaintext_len,
|
||||||
|
|
Loading…
Add table
Reference in a new issue