API Reference
Submodules
cryptomite.circulant module
The Circulant extractor [For2024] takes an input of `n_1’ bits and a (weak) seed of `n_1 + 1’ bits, where `n_1 + 1’ is prime.
- class cryptomite.circulant.Circulant(n_1: int, m: int)[source]
Bases:
object
Circulant extractor based on [For2024].
- __init__(n_1: int, m: int)[source]
Initialize a Circulant extractor.
- Parameters
- n_1int
The length of the first input (in bits). Note: n_1 + 1 must be prime.
- mint
The length of the extractor output (in bits).
- extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]] [source]
Perform randomness extraction.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n_1 bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’), consisting of n_2 = n_1 + 1 bits.
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.
- static from_params(n_1: int, k_1: float, n_2: int, k_2: float, log2_error: float, q_proof: bool, verbose: bool = True) cryptomite.circulant.Circulant [source]
Generate a Circulant extractor with valid parameters based on input constraints.
- Parameters
- n_1int
The length of the first input (in bits).
- k_1float
The min-entropy of the first input.
- n_2int
The length of the second input (in bits).
- k_2float
The min-entropy of the second input.
- log2_errorfloat
The logarithm (base 2) of the acceptable extractor error. Must be negative, as the extractor error is 2^log2_error.
- q_proofbool
If True, adjusts parameters to ensure quantum-proof extraction in the Markov and product sources models (see [For2024]).
- verbosebool
If True, prints the parameters used for extraction (default: True).
- Returns
- Circulant
A configured Circulant extractor.
- Raises
- ValueError
If the output length is non-positive.
Notes
If n_2 is not prime, the function selects the closest prime and adjusts the other parameters accordingly.
For this extractor, the output length remains the same when it is classical-proof, quantum-proof in the product sources model, and quantum-proof in the Markov model (see [For2024]).
cryptomite.dodis module
The Dodis et al. extractor [Dodis2004] takes two equal length inputs, each of length `n = n_1 = n_2’. This implementation is based on the improved cyclic shift matrices construction from [For2020], which requires n to be prime with primitive root 2.
- class cryptomite.dodis.Dodis(n: int, m: int)[source]
Bases:
object
Dodis et al. extractor [Dodis2004], with implementation based on [For2020, For2024]_.
- __init__(n: int, m: int)[source]
Initialize a Dodis extractor.
- Parameters
- nint
The length of the first input (in bits). Note: n must be prime with primitive root 2.
- mint
The length of the extractor output (in bits).
- extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]] [source]
Perform randomness extraction.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’), consisting of n bits.
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.
- static from_params(n_1: int, k_1: float, n_2: int, k_2: float, log2_error: float, q_proof: bool, verbose: bool = True) cryptomite.dodis.Dodis [source]
Generate a Dodis et al. extractor with valid parameters based on input constraints.
- Parameters
- n_1int
The length of the first input (in bits).
- k_1float
The min-entropy of the first input.
- n_2int
The length of the second input (in bits).
- k_2float
The min-entropy of the second input.
- log2_errorfloat
The logarithm (base 2) of the acceptable extractor error. Must be negative, as the extractor error is 2^log2_error.
- q_proofbool
If True, adjusts parameters to ensure quantum-proof extraction in the Markov and product sources models (see [For2024]).
- verbosebool
If True, prints the parameters used for extraction (default: True).
- Returns
- Dodis
A configured Dodis et al. extractor.
- Raises
- ValueError
If the output length is non-positive.
Notes
If n is not prime with primitive root 2, the function selects the closest prime with primitive root 2 and adjusts the other parameters accordingly.
cryptomite.toeplitz module
The Toeplitz extractor takes an input of `n_1’ bits and a (weak) seed of `n_2 = n_1 + m - 1’ bits, where `m’ is output length. This implementation is based on the efficient implementation presented in [For2024].
- class cryptomite.toeplitz.Toeplitz(n_1: int, m: int)[source]
Bases:
object
Toeplitz extractor with implementation based on [For2024].
- __init__(n_1: int, m: int)[source]
Initialize a Toeplitz extractor.
- Parameters
- n_1int
The length of the first input (in bits).
- mint
The length of the extractor output (in bits).
- extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]] [source]
Perform randomness extraction.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n_1 bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’), consisting of n_2 = n_1 + m - 1 bits.
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.
- static from_params(n_1: int, k_1: float, n_2: int, k_2: float, log2_error: float, q_proof: bool, verbose: bool = True) cryptomite.toeplitz.Toeplitz [source]
Generate a Toeplitz extractor with valid parameters based on input constraints.
- Parameters
- n_1int
The length of the first input (in bits).
- k_1float
The min-entropy of the first input.
- n_2int
The length of the second input (in bits).
- k_2float
The min-entropy of the second input.
- log2_errorfloat
The logarithm (base 2) of the acceptable extractor error. Must be negative, as the extractor error is 2^log2_error.
- q_proofbool
If True, adjusts parameters to ensure quantum-proof extraction in the Markov and product sources models (see [For2024]).
- verbosebool
If True, prints the parameters used for extraction (default: True).
- Returns
- Toeplitz
A configured Toeplitz extractor.
- Raises
- ValueError
If the length of the first source is great than or equal to that of the second.
- ValueError
If the output length is non-positive.
Notes
For this extractor, the output length remains the same when it is classical-proof, quantum-proof in the product sources model, and quantum-proof in the Markov model (see [For2024]).
cryptomite.trevisan module
The Trevisan extractor [Trev2001] takes an input of `n_1’ bits and a seed of `n_2 = O(log n_1)’ bits. This implementation is based on the implementation in [Mauer2012] and [For2024].
- class cryptomite.trevisan.Trevisan(n: int, k: float, error: float)[source]
Bases:
object
Trevisan extractor [Trev2001] with implementation based on [Mauer2012] and [For2024].
- __init__(n: int, k: float, error: float)[source]
Initialize a Trevisan Extractor.
- Parameters
- nint
The length of the input bits.
- kfloat
The min-entropy of the input bits.
- errorfloat
The maximum acceptable extractor error.
- extract(input1: list[bool], input2: list[bool]) list[bool] [source]
Extract randomness.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’).
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.
cryptomite.utils module
This is a module.
- cryptomite.utils.closest_na_set(k: int) int [source]
Finds the closest prime number to the given input.
- kint
The input value to find the closest prime with primitive root 2 to.
- Returns
- int
The closest prime number with primitive root 2 to k.
- cryptomite.utils.closest_prime(k: int) int [source]
Finds the closest prime number to the given input.
- kint
The input value to find the closest prime number to.
- Returns
- int
The closest prime number to k.
- cryptomite.utils.is_prime(n: int) bool [source]
Checks whether an integer is prime.
- Parameters
- nint
The integer to check for primality.
- Returns
- bool
Whether n is prime.
- cryptomite.utils.next_na_set(k: int) int [source]
Finds the smallest prime number with primitive root 2 greater than or equal to the given input.
- Parameters
- kint
The lower limit for checking prime numbers with primitive root 2.
- Returns
- int
The smallest prime number with primitive root 2 greater than or equal to k.
- cryptomite.utils.next_prime(k: int) int [source]
Finds the smallest prime number greater than or equal to the given input.
- Parameters
- kint
The lower limit for checking prime numbers.
- Returns
- int
The smallest prime number greater than or equal to k.
- cryptomite.utils.previous_na_set(k: int) int [source]
Finds the largest prime number with primitive root 2 less than or equal to the given input.
- Parameters
- kint
The upper limit for checking prime numbers with primitive root 2.
- Returns
- int
The largest prime number with primitive root 2 less than or equal to k.
- cryptomite.utils.previous_prime(k: int) int [source]
Finds the largest prime number less than or equal to the given input.
- Parameters
- kint
The upper limit for checking prime numbers.
- Returns
- int
The largest prime number less than or equal to k.
- cryptomite.utils.prime_facto(n: int) tuple[list[int], list[int]] [source]
Factorizes an integer into its prime factors and their powers. It is required for the later function: na_set.
- Parameters
- nint
The integer to check.
- Returns
- list
A list representing the prime factorization of n.
- cryptomite.utils.suggest_extractor(n_1: int, exchangeable_sequence: bool, efficiency_required: bool) str [source]
Suggests the best extractor for a user, based on Fig.2 from the technical paper.
- Parameters
- n_1int
The length of the first input (in bits).
- exchangeable_sequencebool
Boolean input indicating whether the source forms an exchangeable sequence.
- efficiency_requiredbool
Boolean input indicating whether the user requires efficient extraction.
- Returns
- string
The suggested extractor.
Module contents
- class cryptomite.Circulant(n_1: int, m: int)[source]
Bases:
object
Circulant extractor based on [For2024].
- __init__(n_1: int, m: int)[source]
Initialize a Circulant extractor.
- Parameters
- n_1int
The length of the first input (in bits). Note: n_1 + 1 must be prime.
- mint
The length of the extractor output (in bits).
- extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]] [source]
Perform randomness extraction.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n_1 bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’), consisting of n_2 = n_1 + 1 bits.
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.
- static from_params(n_1: int, k_1: float, n_2: int, k_2: float, log2_error: float, q_proof: bool, verbose: bool = True) cryptomite.circulant.Circulant [source]
Generate a Circulant extractor with valid parameters based on input constraints.
- Parameters
- n_1int
The length of the first input (in bits).
- k_1float
The min-entropy of the first input.
- n_2int
The length of the second input (in bits).
- k_2float
The min-entropy of the second input.
- log2_errorfloat
The logarithm (base 2) of the acceptable extractor error. Must be negative, as the extractor error is 2^log2_error.
- q_proofbool
If True, adjusts parameters to ensure quantum-proof extraction in the Markov and product sources models (see [For2024]).
- verbosebool
If True, prints the parameters used for extraction (default: True).
- Returns
- Circulant
A configured Circulant extractor.
- Raises
- ValueError
If the output length is non-positive.
Notes
If n_2 is not prime, the function selects the closest prime and adjusts the other parameters accordingly.
For this extractor, the output length remains the same when it is classical-proof, quantum-proof in the product sources model, and quantum-proof in the Markov model (see [For2024]).
- class cryptomite.Dodis(n: int, m: int)[source]
Bases:
object
Dodis et al. extractor [Dodis2004], with implementation based on [For2020, For2024]_.
- __init__(n: int, m: int)[source]
Initialize a Dodis extractor.
- Parameters
- nint
The length of the first input (in bits). Note: n must be prime with primitive root 2.
- mint
The length of the extractor output (in bits).
- extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]] [source]
Perform randomness extraction.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’), consisting of n bits.
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.
- static from_params(n_1: int, k_1: float, n_2: int, k_2: float, log2_error: float, q_proof: bool, verbose: bool = True) cryptomite.dodis.Dodis [source]
Generate a Dodis et al. extractor with valid parameters based on input constraints.
- Parameters
- n_1int
The length of the first input (in bits).
- k_1float
The min-entropy of the first input.
- n_2int
The length of the second input (in bits).
- k_2float
The min-entropy of the second input.
- log2_errorfloat
The logarithm (base 2) of the acceptable extractor error. Must be negative, as the extractor error is 2^log2_error.
- q_proofbool
If True, adjusts parameters to ensure quantum-proof extraction in the Markov and product sources models (see [For2024]).
- verbosebool
If True, prints the parameters used for extraction (default: True).
- Returns
- Dodis
A configured Dodis et al. extractor.
- Raises
- ValueError
If the output length is non-positive.
Notes
If n is not prime with primitive root 2, the function selects the closest prime with primitive root 2 and adjusts the other parameters accordingly.
- class cryptomite.Toeplitz(n_1: int, m: int)[source]
Bases:
object
Toeplitz extractor with implementation based on [For2024].
- __init__(n_1: int, m: int)[source]
Initialize a Toeplitz extractor.
- Parameters
- n_1int
The length of the first input (in bits).
- mint
The length of the extractor output (in bits).
- extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]] [source]
Perform randomness extraction.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n_1 bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’), consisting of n_2 = n_1 + m - 1 bits.
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.
- static from_params(n_1: int, k_1: float, n_2: int, k_2: float, log2_error: float, q_proof: bool, verbose: bool = True) cryptomite.toeplitz.Toeplitz [source]
Generate a Toeplitz extractor with valid parameters based on input constraints.
- Parameters
- n_1int
The length of the first input (in bits).
- k_1float
The min-entropy of the first input.
- n_2int
The length of the second input (in bits).
- k_2float
The min-entropy of the second input.
- log2_errorfloat
The logarithm (base 2) of the acceptable extractor error. Must be negative, as the extractor error is 2^log2_error.
- q_proofbool
If True, adjusts parameters to ensure quantum-proof extraction in the Markov and product sources models (see [For2024]).
- verbosebool
If True, prints the parameters used for extraction (default: True).
- Returns
- Toeplitz
A configured Toeplitz extractor.
- Raises
- ValueError
If the length of the first source is great than or equal to that of the second.
- ValueError
If the output length is non-positive.
Notes
For this extractor, the output length remains the same when it is classical-proof, quantum-proof in the product sources model, and quantum-proof in the Markov model (see [For2024]).
- class cryptomite.Trevisan(n: int, k: float, error: float)[source]
Bases:
object
Trevisan extractor [Trev2001] with implementation based on [Mauer2012] and [For2024].
- __init__(n: int, k: float, error: float)[source]
Initialize a Trevisan Extractor.
- Parameters
- nint
The length of the input bits.
- kfloat
The min-entropy of the input bits.
- errorfloat
The maximum acceptable extractor error.
- extract(input1: list[bool], input2: list[bool]) list[bool] [source]
Extract randomness.
- Parameters
- input1list of bits (0s and 1s)
The first input (the ‘weak input’), consisting of n bits.
- input2list of bits (0s and 1s)
The second input (the ‘(weak) seed’).
- Returns
- list of bits (0s and 1s)
The extractor output bits, of length m.