1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

Fixes padding for blocksizes > 256

This commit is contained in:
Jakob Rieck 2018-08-27 11:42:49 +02:00
parent 05446caf33
commit 543b5ad068
2 changed files with 3 additions and 2 deletions

View File

@ -695,7 +695,8 @@ sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
}
mask = 0U;
for (i = 0; i < blocksize; i++) {
barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U) >> 8);
barrier_mask = (unsigned char)(((i ^ xpadlen) - 1U)
>> ((sizeof(size_t) - 1) * CHAR_BIT));
tail[-i] = (tail[-i] & mask) | (0x80 & barrier_mask);
mask |= barrier_mask;
}

View File

@ -144,7 +144,7 @@ main(void)
for (i = 0; i < 2000U; i++) {
bin_len = randombytes_uniform(200U);
blocksize = 1U + randombytes_uniform(100U);
blocksize = 1U + randombytes_uniform(500U);
bin_padded_maxlen = bin_len + (blocksize - bin_len % blocksize);
bin_padded = (unsigned char *) sodium_malloc(bin_padded_maxlen);
randombytes_buf(bin_padded, bin_padded_maxlen);