mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
crypto: fix undefined behavior in shamir unbitslice (#1219)
This commit is contained in:
parent
db020c7a47
commit
5429acdb7f
@ -48,7 +48,7 @@ static void bitslice(uint32_t r[8], const uint8_t *x, size_t len) {
|
|||||||
for (arr_idx = 0; arr_idx < len; arr_idx++) {
|
for (arr_idx = 0; arr_idx < len; arr_idx++) {
|
||||||
cur = (uint32_t)x[arr_idx];
|
cur = (uint32_t)x[arr_idx];
|
||||||
for (bit_idx = 0; bit_idx < 8; bit_idx++) {
|
for (bit_idx = 0; bit_idx < 8; bit_idx++) {
|
||||||
r[bit_idx] |= ((cur & (1 << bit_idx)) >> bit_idx) << arr_idx;
|
r[bit_idx] |= ((cur >> bit_idx) & 1) << arr_idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ static void unbitslice(uint8_t *r, const uint32_t x[8], size_t len) {
|
|||||||
for (bit_idx = 0; bit_idx < 8; bit_idx++) {
|
for (bit_idx = 0; bit_idx < 8; bit_idx++) {
|
||||||
cur = (uint32_t)x[bit_idx];
|
cur = (uint32_t)x[bit_idx];
|
||||||
for (arr_idx = 0; arr_idx < len; arr_idx++) {
|
for (arr_idx = 0; arr_idx < len; arr_idx++) {
|
||||||
r[arr_idx] |= ((cur & (1 << arr_idx)) >> arr_idx) << bit_idx;
|
r[arr_idx] |= ((cur >> arr_idx) & 1) << bit_idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user