floating_point.secure_bit_length module¶
Module containing a protocol to securely compute the bit length of an MPyC secure integer.
- floating_point.secure_bit_length.bit_length(secure_element, *, two_to_pow=False, inv_two_to_pow=False, lower_bound=0, upper_bound=None)[source]¶
Implementation of Thijs Veugen’s secure bit length protocol.
!! The current implementation only supports non-negative inputs !!
- Parameters:
secure_element (
SecureInteger) – secret shared value of which the bit length needs to be determined. The secret value is assumed to be non-negative.two_to_pow (
bool) – If True, also compute and return 2 ** bit_length. This is more efficient than computing the exponentiation afterwards.inv_two_to_pow (
bool) – If True, also compute and return 2 ** -bit_length. This is more efficient than computing the exponentiation afterwards.lower_bound (
int) – Lower bound on the bit length of the provided value. This parameter allows for a more efficient protocol, but it will also yield an incorrect result if the lower bound is larger than the actual bit length.upper_bound (
int|None) – Upper bound on the bit length of the provided value. This parameter allows for a more efficient protocol, but it will also yield an incorrect result if the upper bound is smaller than the actual bit length.
- Return type:
SecureInteger|tuple[SecureInteger,SecureInteger] |tuple[SecureInteger,SecureInteger,SecureInteger]- Returns:
A secret-shared value representing the bit length of the input. If two_to_pow=True, the second return value is its power base two. If inv_two_to_pow=True, the final return value is the inverse of its power base two.
- floating_point.secure_bit_length.most_significant_bit(secure_element, *, two_to_pow=False, inv_two_to_pow=False, lower_bound=0, upper_bound=None)[source]¶
Implementation of Thijs Veugen’s secure most significant bit (MSB) protocol.
The function will return the index of the most significant bit. Thus, MSB(1) = 0, MSB(2) = 1, MSB(3) = 1, etc. The edge case MSB(0) returns -1. For consistency, 2 ** -MSB(0) returns 2 and 2 ** MSB(0) returns the multiplicative inverse of 2 in the finite field.
- Parameters:
secure_element (
SecureInteger) – Secret shared value of which the most significant bit needs to be determined.two_to_pow (
bool) – If True, also compute and return 2 ** MSB. This is more efficient than computing the exponentiation afterwards.inv_two_to_pow (
bool) – If True, also compute and return 2 ** -MSB. This is more efficient than computing the exponentiation afterwards.lower_bound (
int) – Lower bound on the most significant bit index of the provided value. This parameter allows for a more efficient protocol, but it will also yield an incorrect result if the lower bound is larger than the actual MSB index.upper_bound (
int|None) – Upper bound on the most significant bit index of the provided value. This parameter allows for a more efficient protocol, but it will also yield an incorrect result if the upper bound is smaller than the actual MSB index.
- Raises:
ValueError – The provided bounds are unacceptable.
- Return type:
SecureInteger|tuple[SecureInteger,SecureInteger] |tuple[SecureInteger,SecureInteger,SecureInteger]- Returns:
The index of the most significant bit of input secure_element. If two_to_pow=True, the second return value is its power base two. If inv_two_to_pow=True, the final return value is the inverse of its power base two.