1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 06:18:07 +00:00

fix(crypto): use logical instead of bitwise operator

Discovered via clang-14 warnings for -Wbitwise-instead-of-logical
Closes https://github.com/satoshilabs/trezor-firmware/issues/129
This commit is contained in:
Christian Reitter 2021-12-08 13:15:17 +01:00 committed by Andrew Kozlik
parent 86b02c6c06
commit 0c482173ab

View File

@ -271,7 +271,7 @@ int bn_is_equal(const bignum256 *x, const bignum256 *y) {
// &truecase == &falsecase or &res == &truecase == &falsecase
void bn_cmov(bignum256 *res, volatile uint32_t cond, const bignum256 *truecase,
const bignum256 *falsecase) {
assert((cond == 1) | (cond == 0));
assert((cond == 1) || (cond == 0));
uint32_t tmask = -cond; // tmask = 0xFFFFFFFF if cond else 0x00000000
uint32_t fmask = ~tmask; // fmask = 0x00000000 if cond else 0xFFFFFFFF
@ -290,7 +290,7 @@ void bn_cmov(bignum256 *res, volatile uint32_t cond, const bignum256 *truecase,
// Assumes prime is normalized and
// 0 < prime < 2**260 == 2**(BITS_PER_LIMB * LIMBS - 1)
void bn_cnegate(volatile uint32_t cond, bignum256 *x, const bignum256 *prime) {
assert((cond == 1) | (cond == 0));
assert((cond == 1) || (cond == 0));
uint32_t tmask = -cond; // tmask = 0xFFFFFFFF if cond else 0x00000000
uint32_t fmask = ~tmask; // fmask = 0x00000000 if cond else 0xFFFFFFFF