Skip to content

Streams

Karel Kubicek edited this page Jun 25, 2018 · 14 revisions

Streams classes are used for managing test vectors, their generation, saving, and loading.

Streams are identified by type in CryptoStreams configuration file. Every stream has to be inherited from abstract stream interface and provide implementation at least to method next() and osize(). Streams may be encapsulated to other streams, such as "plaintext generator" stream or post-processed by output modification stream.

The generalization of data generation allows higher customizability and code reduction due to re-usage of commonly used streams (like counter plaintext).

Cryptographical function streams

Specific streams are dedicated to cryptographical primitives as block ciphers, stream ciphers, and hash functions. These streams are described in dedicated pages.

Streams for generation of the input (keys, plaintexts...)

Trivial streams

  • dummy-stream: a stream that does nothing. It is controlled externally using set_data(vec_cview data) function.
  • tuple_stream: a stream consisting of multiple streams printed in given order. The internal streams are defined as JSON array in argument sources ("sources":[{source1},{source2}...]).

Source only streams

  • file-stream: contains path to file, which is read as input.
  • true-stream and false-stream: generate vectors of ones, zeros respectively.
  • mt19937-stream and pcg32-stream: PRNG Mersenne Twister MT19937-64, PCG (faster and more statistically random, preferred)

Types of plaintext (also only sources)

  • counter: generates increasing numbers. The first generated number vector is 1 (zero is omitted).
  • random_start_counter: same as counter, but starts with random initial value.
  • sac (Strict avalanche criterion): generates firstly random vector (source is PCG32); secondly the copy of the first vector with exactly one bit flipped. The position of the flipped bit is random.
  • sac-fixed-position: similar to SAC, but the position of bit flip is given by argument position (requires number).
  • sac-2d-all-positions: the first vector is random and then follows (size * 8) - 1 copies of the original vector, with one bit flipped per copy.
  • hw-counter: generates all vectors with given hamming weight.
    • hw (unsigned) sets-up target hamming weight.
    • increase_hw (Boolean) allows increase after generating all possible vectors (the number of vectors of length l with hamming weight at most h is (l over h).
    • randomize_overflow (Boolean) generates a new base random vector (from which is counted the target hamming weight) after generating all possible combinations.

Sources with a statistical distribution

  • bernoulli_distribution biased stream, that generates a binary vector, where "0" has probability given by argument p.
  • binomial_distribution outputs vector of the binomial distribution. How many "1" flipped on a coin with p probability and max_value trials?
  • normal_distribution similar to binomial_distribution using normal distribution with mean and std_dev arguments. The generated real value is cut to 4 sigmas and this value is projected to the byte value.
  • poisson_distribution Poisson distribution has an argument mean. If an event occurs mean times a minute on average, how often is it that it occurs N times in one minute? Output N
  • exponential_distribution with argument lambda. If particles decay lambda times per second on average, how much time, in seconds, until the next one?

Pipes

  • pipe_in_stream: the beginning of the pipe - passes data from the source via next() and allows the other end of pipe to read these data. Identification is by string in argument id. The source id has to be unique, else the behavior is undefined.
  • pipe_out_stream: the end of pipe - copies data from the pipe source. Identified by id, there can be multiple pipe_out_streams with same id. The id of pipe output has to fit some input, else the behavior is undefined.

Modifiers streams

These stream modifiers always contain inner JSON subtree with usually some cipher.

Modifiers used as cryptoprimitive's input

  • single_value_stream: passes repeatedly same value. Initialized by the internal stream. Useful for repeating passing single value of other random streams.
  • repeating_stream: repeats the same vector for period of calls.

Cryptoprimitives' postprocessing streams

  • xor-stream: splits the input into two halves and XOR these two parts. Fits for checking sac and rnd_plt_ctx_stream.
  • column: the ciphertext is transposed, and vectors are created from the ith bit of the ciphertext for i in range size.
  • column-fixed-position: every vector is created from the positionth bit of the ciphertext. The position is a number argument in interval (0, size-1).