Basic Usage

In this notebook, we give a few examples of how to use Cryptomite and accompanying utility functions. A similar, more introductory, guide to getting started can be found in this blog post.

Quick Start

pip install cryptomite

Generating an extractor

Using Cryptomite, extractors can be generated directly by giving the input length (in bits) n and output length (in bits) m, or for the Trevisan extractor, giving the input length n, output length m and maximum error,error. We generate all the extractors of Cryptomite below, for an example n, m, error:

[1]:
import cryptomite
n, m, error = 100, 90, 0.0001
circulant = cryptomite.Circulant(n, m)
dodis = cryptomite.Dodis(n, m)
toeplitz = cryptomite.Toeplitz(n, m)
trevisan = cryptomite.Trevisan(n, m, error)

Extraction

Now the extractors have been generated, we show how to perform extraction. The extractors take as input a list of input bits and a list of (weak) seed bits, and outputs a new list of bits. Note that each extractor of Cryptomite requires a different amount of seed bits, the calculation of this is left to the user (manually or using our from_params utility functions) and denoted seed_length in the following example code. In this example, we generate both the input string and the (weak) seed using randint function from the random Python library - which a user would replace with their desired generation methods:

[ ]:
from random import randint
input_bits = [randint(0, 1) for _ in range(n)]
circulant.extract(input_bits, [randint(0, 1) for _ in range(seed_length)])
dodis.extract(input_bits, [randint(0, 1) for _ in range(seed_length)])
toeplitz.extract(input_bits, [randint(0, 1) for _ in range(seed_length)])
trevisan.extract(input_bits, [randint(0, 1) for _ in range(seed_length)])

Using the from_params Utility functions

Alternatively, all Cryptomite extractors (except Trevisan) can be generated without needing to calculate the output length or required seed length yourself using the from_params utility functions. This is performed by providing the input min-entropy, seed min-entropy, log2 of the error, input length, seed length, and whether to calculate the output length in the (quantum-proof) Markov model, for example

[2]:
import cryptomite
from math import log2
input_length, seed_length = 100, 100
input_entropy, seed_entropy = 60, 80
error = 0.00001
markov_q_proof = False
log2_error = log2(error)
circulant = cryptomite.circulant.from_params(input_entropy,
                                             seed_entropy,
                                             log2_error,
                                             input_length,
                                             seed_length,
                                             markov_q_proof)
dodis = cryptomite.dodis.from_params(input_entropy,
                                     seed_entropy,
                                     log2_error,
                                     input_length,
                                     seed_length,
                                     markov_q_proof)
toeplitz = cryptomite.Toeplitz.from_params(input_entropy,
                                           seed_entropy,
                                           log2_error,
                                           input_length,
                                           seed_length,
                                           markov_q_proof)

In this case, a valid extractor is generated from the specified parameters (i.e. one that adheres to the required input and seed length criteria for that extractor). Any changes to input length, seed length, input entropy and seed entropy printed.