Package tlslite :: Package utils :: Module constanttime
[hide private]
[frames] | no frames]

Module constanttime

source code

Various constant time functions for processing sensitive data

Functions [hide private]
boolean
ct_check_cbc_mac_and_pad(data, mac, seqnumBytes, contentType, version)
Check CBC cipher HMAC and padding.
source code
int
ct_eq_u32(val_a, val_b)
Return 1 if val_a == val_b, 0 otherwise.
source code
int
ct_gt_u32(val_a, val_b)
Return 1 if val_a > val_b, 0 otherwise.
source code
int
ct_isnonzero_u32(val)
Returns 1 if val is != 0, 0 otherwise.
source code
int
ct_le_u32(val_a, val_b)
Return 1 if val_a <= val_b, 0 otherwise.
source code
 
ct_lsb_prop_u8(val)
Propagate LSB to all 8 bits of the returned byte.
source code
int
ct_lt_u32(val_a, val_b)
Returns 1 if val_a < val_b, 0 otherwise.
source code
int
ct_neq_u32(val_a, val_b)
Return 1 if val_a != val_b, 0 otherwise.
source code
Variables [hide private]
  __package__ = 'tlslite.utils'
Function Details [hide private]

ct_check_cbc_mac_and_pad(data, mac, seqnumBytes, contentType, version)

source code 

Check CBC cipher HMAC and padding. Close to constant time.

Parameters:
  • data (bytearray) - data with HMAC value to test and padding
  • mac (hashlib mac) - empty HMAC, initialised with a key
  • seqnumBytes (bytearray) - TLS sequence number, used as input to HMAC
  • contentType (int) - a single byte, used as input to HMAC
  • version (tuple of int) - a tuple of two ints, used as input to HMAC and to guide checking of padding
Returns: boolean
True if MAC and pad is ok, False otherwise

ct_eq_u32(val_a, val_b)

source code 

Return 1 if val_a == val_b, 0 otherwise. Constant time.

Parameters:
  • val_a (int) - an unsigned integer representable as a 32 bit value
  • val_b (int) - an unsigned integer representable as a 32 bit value
Returns: int

ct_gt_u32(val_a, val_b)

source code 

Return 1 if val_a > val_b, 0 otherwise. Constant time.

Parameters:
  • val_a (int) - an unsigned integer representable as a 32 bit value
  • val_b (int) - an unsigned integer representable as a 32 bit value
Returns: int

ct_isnonzero_u32(val)

source code 

Returns 1 if val is != 0, 0 otherwise. Constant time.

Parameters:
  • val (int) - an unsigned integer representable as a 32 bit value
Returns: int

ct_le_u32(val_a, val_b)

source code 

Return 1 if val_a <= val_b, 0 otherwise. Constant time.

Parameters:
  • val_a (int) - an unsigned integer representable as a 32 bit value
  • val_b (int) - an unsigned integer representable as a 32 bit value
Returns: int

ct_lsb_prop_u8(val)

source code 

Propagate LSB to all 8 bits of the returned byte. Constant time.

ct_lt_u32(val_a, val_b)

source code 

Returns 1 if val_a < val_b, 0 otherwise. Constant time.

Parameters:
  • val_a (int) - an unsigned integer representable as a 32 bit value
  • val_b (int) - an unsigned integer representable as a 32 bit value
Returns: int

ct_neq_u32(val_a, val_b)

source code 

Return 1 if val_a != val_b, 0 otherwise. Constant time.

Parameters:
  • val_a (int) - an unsigned integer representable as a 32 bit value
  • val_b (int) - an unsigned integer representable as a 32 bit value
Returns: int