Distribution of the values of an expression by enumeration
The following python program allows to analyse by an enumeration technique the distribution of the values of an expression. The variables considered for the expression have either a uniform distribution (mask type variable), or an unknown distribution (secret variable).Link to the file
The analysis gives three possible results:
- RUD: the distribution of the expression is random uniform
- ISD: the distribution of the expression is statistically independent from the secret variables
- UKD: the distribution of the expression depends upon the distribution of at least one of the secret variables
$ ./check_formula_distrib.py -l "k ^ m"
Variable size should be less than 16 bits, and must configured in the python file.In the expression, by convention, mask type variables are those whose name starts is m<val> or r<val>, and secret variables are those with a name like k<val> or s<val>.
About shifts, the >> operator does a logical right shift, whereas the function sra(m, sh) does a signed (arithmetic) right shift.
For example:
- the expressions (k ^ m1) ^ m2 and (k ^ m) ^ (m << 1) are random uniform (RUD)
- the expression (k ^ m1) & m2 is not uniform but is statistically independent from f (ISD)
- the expression (k ^ m) & m is statistically dependent upon k (UKD)