Skip to content

Commit da3a797

Browse files
committed
Use a mask rather than a conditional jump in ipcrypt_pfx_set_bit
1 parent 3e92b9f commit da3a797

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/ipcrypt2.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ typedef struct PFXState {
348348
* st: the AesState structure to be populated.
349349
* key: a 16-byte AES key.
350350
*/
351-
static void __vectorcall expand_key(KeySchedule rkeys, const unsigned char key[IPCRYPT_KEYBYTES])
351+
static void __vectorcall
352+
expand_key(KeySchedule rkeys, const unsigned char key[IPCRYPT_KEYBYTES])
352353
{
353354
BlockVec t, s;
354355
size_t i = 0;
@@ -978,11 +979,11 @@ ipcrypt_pfx_get_bit(const uint8_t ip16[16], const unsigned int bit_index)
978979
static void
979980
ipcrypt_pfx_set_bit(uint8_t ip16[16], const unsigned int bit_index, const uint8_t bit_value)
980981
{
981-
if (bit_value) {
982-
ip16[15 - bit_index / 8] |= (1 << (bit_index % 8));
983-
} else {
984-
ip16[15 - bit_index / 8] &= ~(1 << (bit_index % 8));
985-
}
982+
const size_t byte_index = 15 - bit_index / 8;
983+
const uint8_t bit_mask = (uint8_t) (1 << (bit_index % 8));
984+
const uint8_t mask = (uint8_t) -((bit_value & 1));
985+
986+
ip16[byte_index] = (ip16[byte_index] & ~bit_mask) | (bit_mask & mask);
986987
}
987988

988989
static void

0 commit comments

Comments
 (0)