API Reference

Submodules

cryptomite.circulant module

Circulant is a seeded extractor that takes an input of n bits and a seed of n + 1 bits, where n + 1 is prime, to produce some error-perfect random bits.

class cryptomite.circulant.Circulant(n: int, m: int)[source]

Bases: object

Circulant extractor based on [For2024].

__init__(n: int, m: int)[source]

Create a Circulant Extractor.

Parameters
nint

The length of the input bits. ** n + 1 should be prime. **

mint

The length of the output bits.

extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract randomness.

Parameters
input1list of bits

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bits

The extracted output.

static from_params(min_entropy1: float, min_entropy2: float, log2_error: float, input_length1: int, input_length2: int, markov_q_proof: bool, verbose: bool = True) cryptomite.circulant.Circulant[source]

Calculate a valid input and output size for this extractor, given the initial lengths and min-entropies of the input sources and generate the associated extractor.

The input_length2 must be prime, else the code will chose a valid input_length2 choice and adjust the other parameters accordingly. The min_entropy inputs are a lower bound on the min-entropy of the related input string.

Parameters
min_entropy1float

The min-entropy of input source 1, the ‘input’.

min_entropy2float

The min-entropy of input source 2, the ‘(weak) seed’.

log2_errorfloat

The acceptable maximum extractor error, in the form error = b where extractor error = \(2 ^ b\).

input_length1int

The initial length of input source.

input_length2int

The initial length of the (weak) seed.

markov_q_proofbool

Boolean indicator of whether the extractor parameters should be calculated to account for being quantum-proof in the Markov model or not.

Returns
Circulant

The Circulant extractor.

cryptomite.dodis module

Dodis is a 2-source extractor that takes two equal length, independent, strings of bits to produce some error-perfect random bits.

class cryptomite.dodis.Dodis(n: int, m: int)[source]

Bases: object

Dodis extractor based on [Dodis2004].

__init__(n: int, m: int)[source]

Create a Dodis Extractor.

Parameters
nint

The length of the two input bits. ** This should be prime with primitive root 2. **

mint

The length of the output bits.

extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract randomness.

Parameters
input1list of bits

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bits

The extracted output.

static from_params(min_entropy1: float, min_entropy2: float, log2_error: float, input_length1: int, input_length2: int, markov_q_proof: bool, verbose: bool = True) cryptomite.dodis.Dodis[source]

Calculate a valid input and output size for this extractor, given the initial lengths and min-entropies of the input sources and generate the associated extractor.

The input_length must be prime with primitive root 2, else the code will chose a valid input_length choice and adjust the other parameters accordingly. The min entropy inputs are a lower bound on the min-entropy of the related input string.

Parameters
min_entropy1float

The min-entropy of input source 1, the ‘input’.

min_entropy2float

The min-entropy of input source 2, the ‘(weak) seed’.

log2_errorfloat

The acceptable maximum extractor error, in the form error = b where extractor error = \(2 ^ b\).

input_length1int

The initial length of input source.

input_length2int

The initial length of the (weak) seed.

markov_q_proofbool

Boolean indicator of whether the extractor parameters should be calculated to account for being quantum-proof in the Markov model or not.

Returns
Dodis

The Dodis extractor.

cryptomite.toeplitz module

Toeplitz is a seeded extractor that takes two differing length, independent, strings of bits to produce some error-perfect random bits.

class cryptomite.toeplitz.Toeplitz(n: int, m: int)[source]

Bases: object

Toeplitz extractor

__init__(n: int, m: int)[source]

Create a Circulant Extractor.

Parameters
nint

The length of the input bits.

mint

The length of the output bits.

extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract randomness.

Parameters
input1list of bits

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bits

The extracted output.

static from_params(min_entropy1: float, min_entropy2: float, log2_error: float, input_length1: int, input_length2: int, markov_q_proof: bool, verbose: bool = True) cryptomite.toeplitz.Toeplitz[source]

Calculate a valid input and output size for this extractor, given the initial lengths and min-entropies of the input sources and generate the associated extractor.

The min entropy inputs are a lower bound on the min-entropy of the related input string.

Parameters
min_entropy1float

The min-entropy of input source 1, the ‘input’.

min_entropy2float

The min-entropy of input source 2, the ‘(weak) seed’.

log2_errorfloat

The maximum acceptable extractor error, in the form error = b where extractor error = \(2 ^ b\).

input_length1int

The initial length of input source.

input_length2int

The initial length of the (weak) seed.

markov_q_proofbool

Boolean indicator of whether the extractor parameters should be calculated to account for being quantum-proof in the Markov model or not.

Returns
Toeplitz

The Toeplitz extractor.

cryptomite.trevisan module

Trevisan is a seeded extractor that takes two differing length, independent, strings of bits to produce some error-perfect random bits.

class cryptomite.trevisan.Trevisan(n: int, k: float, error: float)[source]

Bases: object

Trevisan extractor based on [Trev2001] and [Mauer2012].

__init__(n: int, k: float, error: float)[source]

Create a Trevisan Extractor.

Parameters
nint

The length of the input bits.

kfloat

The total 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

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bool

The output bits from the extractor.

cryptomite.utils module

This is a module.

cryptomite.utils.closest_na_set(k: int) int[source]

Finds the closest integer to the input that is prime with primitive root 2. If both directions are equidistant, outputs the prime with primitive root 2 less than the input.

Parameters
kint

number to check is prime with primitive root 2.

Returns
int :

prime with primitive root 2.

cryptomite.utils.closest_prime(k: int) int[source]

Finds the closest integer to the input that is prime. If both directions are equidistant, outputs the prime less than the input.

Parameters
kint

number to check is prime.

Returns
int :

prime.

cryptomite.utils.is_prime(n: int) bool[source]

Checks an integer for primality.

Parameters
nint

integer to check for primality.

Returns
boolWhether n is prime.
cryptomite.utils.next_na_set(k: int) int[source]

Finds the smallest integer larger than the input that is prime with primitive root 2.

Parameters
kint

number to check is prime with primitive root 2.

Returns
int :

prime with primitive root 2.

cryptomite.utils.next_prime(k: int) int[source]

Finds the smallest integer larger than or equal to the input that is prime.

Parameters
kint

number to check is prime.

Returns
int :

prime.

cryptomite.utils.previous_na_set(k: int) int[source]

Finds the largest integer smaller than the input that is prime with primitive root 2.

Parameters
kint

number to check is prime with primitive root 2.

Returns
int :

prime with primitive root 2.

cryptomite.utils.previous_prime(k: int) int[source]

Finds the largest integer smaller than or equal to the input that is prime.

Parameters
kint

number to check is prime.

Returns
int :

prime.

cryptomite.utils.prime_facto(n: int) tuple[list[int], list[int]][source]

Defines the factors of the prime numbers used. It is required for the later function: na_set.

Parameters
nint

number to check.

Returns
list :

Returns factors and powers.

cryptomite.utils.suggest_extractor(input_length1: 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
input_length1int

The initial length of input source.

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.

cryptomite.utils.von_neumann(bits: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract using Von-Neumann extractor.

Module contents

class cryptomite.Circulant(n: int, m: int)[source]

Bases: object

Circulant extractor based on [For2024].

__init__(n: int, m: int)[source]

Create a Circulant Extractor.

Parameters
nint

The length of the input bits. ** n + 1 should be prime. **

mint

The length of the output bits.

extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract randomness.

Parameters
input1list of bits

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bits

The extracted output.

static from_params(min_entropy1: float, min_entropy2: float, log2_error: float, input_length1: int, input_length2: int, markov_q_proof: bool, verbose: bool = True) cryptomite.circulant.Circulant[source]

Calculate a valid input and output size for this extractor, given the initial lengths and min-entropies of the input sources and generate the associated extractor.

The input_length2 must be prime, else the code will chose a valid input_length2 choice and adjust the other parameters accordingly. The min_entropy inputs are a lower bound on the min-entropy of the related input string.

Parameters
min_entropy1float

The min-entropy of input source 1, the ‘input’.

min_entropy2float

The min-entropy of input source 2, the ‘(weak) seed’.

log2_errorfloat

The acceptable maximum extractor error, in the form error = b where extractor error = \(2 ^ b\).

input_length1int

The initial length of input source.

input_length2int

The initial length of the (weak) seed.

markov_q_proofbool

Boolean indicator of whether the extractor parameters should be calculated to account for being quantum-proof in the Markov model or not.

Returns
Circulant

The Circulant extractor.

class cryptomite.Dodis(n: int, m: int)[source]

Bases: object

Dodis extractor based on [Dodis2004].

__init__(n: int, m: int)[source]

Create a Dodis Extractor.

Parameters
nint

The length of the two input bits. ** This should be prime with primitive root 2. **

mint

The length of the output bits.

extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract randomness.

Parameters
input1list of bits

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bits

The extracted output.

static from_params(min_entropy1: float, min_entropy2: float, log2_error: float, input_length1: int, input_length2: int, markov_q_proof: bool, verbose: bool = True) cryptomite.dodis.Dodis[source]

Calculate a valid input and output size for this extractor, given the initial lengths and min-entropies of the input sources and generate the associated extractor.

The input_length must be prime with primitive root 2, else the code will chose a valid input_length choice and adjust the other parameters accordingly. The min entropy inputs are a lower bound on the min-entropy of the related input string.

Parameters
min_entropy1float

The min-entropy of input source 1, the ‘input’.

min_entropy2float

The min-entropy of input source 2, the ‘(weak) seed’.

log2_errorfloat

The acceptable maximum extractor error, in the form error = b where extractor error = \(2 ^ b\).

input_length1int

The initial length of input source.

input_length2int

The initial length of the (weak) seed.

markov_q_proofbool

Boolean indicator of whether the extractor parameters should be calculated to account for being quantum-proof in the Markov model or not.

Returns
Dodis

The Dodis extractor.

class cryptomite.Toeplitz(n: int, m: int)[source]

Bases: object

Toeplitz extractor

__init__(n: int, m: int)[source]

Create a Circulant Extractor.

Parameters
nint

The length of the input bits.

mint

The length of the output bits.

extract(input1: Sequence[Literal[0, 1]], input2: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract randomness.

Parameters
input1list of bits

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bits

The extracted output.

static from_params(min_entropy1: float, min_entropy2: float, log2_error: float, input_length1: int, input_length2: int, markov_q_proof: bool, verbose: bool = True) cryptomite.toeplitz.Toeplitz[source]

Calculate a valid input and output size for this extractor, given the initial lengths and min-entropies of the input sources and generate the associated extractor.

The min entropy inputs are a lower bound on the min-entropy of the related input string.

Parameters
min_entropy1float

The min-entropy of input source 1, the ‘input’.

min_entropy2float

The min-entropy of input source 2, the ‘(weak) seed’.

log2_errorfloat

The maximum acceptable extractor error, in the form error = b where extractor error = \(2 ^ b\).

input_length1int

The initial length of input source.

input_length2int

The initial length of the (weak) seed.

markov_q_proofbool

Boolean indicator of whether the extractor parameters should be calculated to account for being quantum-proof in the Markov model or not.

Returns
Toeplitz

The Toeplitz extractor.

class cryptomite.Trevisan(n: int, k: float, error: float)[source]

Bases: object

Trevisan extractor based on [Trev2001] and [Mauer2012].

__init__(n: int, k: float, error: float)[source]

Create a Trevisan Extractor.

Parameters
nint

The length of the input bits.

kfloat

The total 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

The first list of bits, the ‘input’.

input2list of bits

The second list of bits, the ‘(weak) seed’.

Returns
list of bool

The output bits from the extractor.

cryptomite.von_neumann(bits: Sequence[Literal[0, 1]]) Sequence[Literal[0, 1]][source]

Extract using Von-Neumann extractor.