Fixes padding for blocksizes > 256
This commit is contained in:
parent
05446caf33
commit
543b5ad068
@ -695,7 +695,8 @@ sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
|
|||||||
}
|
}
|
||||||
mask = 0U;
|
mask = 0U;
|
||||||
for (i = 0; i < blocksize; i++) {
|
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);
|
tail[-i] = (tail[-i] & mask) | (0x80 & barrier_mask);
|
||||||
mask |= barrier_mask;
|
mask |= barrier_mask;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ main(void)
|
|||||||
|
|
||||||
for (i = 0; i < 2000U; i++) {
|
for (i = 0; i < 2000U; i++) {
|
||||||
bin_len = randombytes_uniform(200U);
|
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_maxlen = bin_len + (blocksize - bin_len % blocksize);
|
||||||
bin_padded = (unsigned char *) sodium_malloc(bin_padded_maxlen);
|
bin_padded = (unsigned char *) sodium_malloc(bin_padded_maxlen);
|
||||||
randombytes_buf(bin_padded, bin_padded_maxlen);
|
randombytes_buf(bin_padded, bin_padded_maxlen);
|
||||||
|
Loading…
Reference in New Issue
Block a user