ct: add mask32
This commit is contained in:
parent
dbf81b49d5
commit
f62f07aee6
1
README
1
README
@ -16,6 +16,7 @@ Utilities
|
|||||||
|
|
||||||
- Constant-time operations
|
- Constant-time operations
|
||||||
- [x] compare
|
- [x] compare
|
||||||
|
- [x] mask32: return a 1s mask if any bit is set, 0 otherwise
|
||||||
- Hexdump
|
- Hexdump
|
||||||
|
|
||||||
Hash
|
Hash
|
||||||
|
20
ct.c
20
ct.c
@ -25,10 +25,18 @@ lc_ct_cmp(const uint8_t *x, const uint8_t *y, size_t l)
|
|||||||
for (; l > 0; l--)
|
for (; l > 0; l--)
|
||||||
r |= *x++ ^ *y++;
|
r |= *x++ ^ *y++;
|
||||||
|
|
||||||
/* Ensures that if any bit is set, then LSB is set. */
|
return lc_ct_mask32(r);
|
||||||
r |= r >> 4;
|
}
|
||||||
r |= r >> 2;
|
|
||||||
r |= r >> 1;
|
uint32_t
|
||||||
|
lc_ct_mask32(uint32_t x)
|
||||||
return 0xffffffff + (r & 1);
|
{
|
||||||
|
/* Ensures that if any bit is set, then LSB is set. */
|
||||||
|
x |= x >> 16;
|
||||||
|
x |= x >> 8;
|
||||||
|
x |= x >> 4;
|
||||||
|
x |= x >> 2;
|
||||||
|
x |= x >> 1;
|
||||||
|
|
||||||
|
return UINT32_MAX + (x & 1);
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,7 @@ struct lc_hkdf_params {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
uint32_t lc_ct_cmp(const uint8_t *, const uint8_t *, size_t);
|
uint32_t lc_ct_cmp(const uint8_t *, const uint8_t *, size_t);
|
||||||
|
uint32_t lc_ct_mask32(uint32_t);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user