From dc215f4b97f48eabde28d08505c88cf5b6726082 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 2 Dec 2021 12:14:56 +0100 Subject: [PATCH] Simplify calculations for clear mask Signed-off-by: Przemyslaw Stekiel --- library/psa_crypto.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 9be1a684e6..6a67b28f4d 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -4914,10 +4914,8 @@ static psa_status_t psa_generate_derived_ecc_key_weierstrass_helper( * (8 * ceiling(m/8) - m) bits of the first byte in * the string to zero. */ - uint8_t clear_bit_count = (uint8_t) ( 8 * m_bytes - m ); - uint8_t clear_bit_mask = ( ( 1 << clear_bit_count ) - 1 ); - clear_bit_mask = ~( clear_bit_mask << ( 8 - clear_bit_count ) ); - *data[0] = ( *data[0] & clear_bit_mask ); + uint8_t clear_bit_mask = (1 << (m % 8)) - 1; + *data[0] &= clear_bit_mask; } /* 3. Convert the string to integer k by decoding it as a