boolcrypt.classification module

Classify a list of permutations of the same bitsize according to given properties.

class boolcrypt.classification.Properties(diff, lin, maxD, minD, linC, linS, linSE, affSE, addSE, niSE, ndSE, dec)[source]

Bases: boolcrypt.classification.Properties

Abstract class that list the cryptographic properties to classify a list of permutations.

Subclasses override the bitsize n of the functions and whether to ignore the self-equivalence properties ignore_se and the decomposition properties ignore_dec.

An instance of a subclass represents the properties of a particular permutations.

Base cryptographic properties: - diff: differential uniformity (log2) - lin: linearity (log2) - maxD: high (max) degree - minD: low (min) degree - linC: an n-bit hex value with i-th bit active if i-th component is linear - linS: an n-bit hex value with i-th bit active if i-th component has a linear structure

Self-equivalence properties: - linSE: number of linear self-equivalences (log2) - affSE: number of affine self-equivalences (log2) - addSE: number of additive self-equivalences (log2) - niSE: whether has non-invertible affine self-equivalences - ndSE: whether has non-diagonal affine self-equivalence when concatenated with itself

Decomposition property: - dec: an n-bit hex value with i-th bit active if is affine equivalent to F(x1,..,xi)|G(x{i+1),…)

boolcrypt.classification.get_properties(bitsize, ignore_se_properties=True, ignore_dec_properties=True)[source]

Return a subclass of Properties used in classify_sboxes_properties().

Return a subclass of Properties where it is fixed the bitsize and whether to include self-equivalence and decomposition properties.

>>> Prop3b = get_properties(3, False, False)
>>> Prop3b.get_property_names()
'diff,lin,maxD,minD,linC,linS,linSE,affSE,addSE,niSE,ndSE,dec'
>>> str(Prop3b.get_properties_identity())
'8,4,1,1,0x7f,0xfe,168,1344,8,True,True,0x2'
>>> str(Prop3b.get_properties_inversion())  
'2,2,2,2,0x0,0xfe,21,168,1,False,False,0x0'
>>> Prop4b = get_properties(4)
>>> Prop4b.get_property_names()
'diff,lin,maxD,minD,linC,linS'
>>> str(Prop4b.get_properties_identity())
'16,8,1,1,0x7fff,0xfffe'
>>> str(Prop4b.get_properties_inversion())
'4,4,3,3,0x0,0x0'
boolcrypt.classification.classify_sboxes(candidates, properties, add_identity_row=False, add_inversion_row=False, verbose=False, filename=None, **sat_args)[source]

Classify a list of permutations of the same bitsize according to given properties.

Returns a CSV-like list, where each row is the list of properties of an S-box. The first row is the header with the names of each column property.

The argument properties can be obtained from get_properties().

If add_identity_row=True, the properties of the identity function are added after the header. If add_inversion_row=True, the properties of the inversion function are added after the header.

>>> from boolcrypt.sboxes import affine_3b_classes
>>> Prop3b = get_properties(3, ignore_se_properties=False, ignore_dec_properties=False)
>>> classify_sboxes(affine_3b_classes, Prop3b)  
lut,diff,lin,maxD,minD,linC,linS,linSE,affSE,addSE,niSE,ndSE,dec
01234567,8,4,1,1,0x7f,0xfe,168,1344,8,True,True,0x6
01234576,8,4,2,1,0x2a,0xfe,24,192,2,True,True,0x0
01234675,4,4,2,1,0x8,0xfe,12,96,1,True,False,0x0
01243675,2,2,2,2,0x0,0xfe,21,168,1,False,False,0x0
>>> from boolcrypt.sboxes import high_se_4bit_2deg_sboxes
>>> Prop4b = get_properties(4, ignore_se_properties=False, ignore_dec_properties=False)
>>> classify_sboxes(high_se_4bit_2deg_sboxes, Prop4b, add_identity_row=True)  
lut,diff,lin,maxD,minD,linC,linS,linSE,affSE,addSE,niSE,ndSE,dec
0123456789abcdef,16,8,1,1,0x7fff,0xfffe,20160,322560,16,True,True,0x6
6512304789abcdef,8,8,2,1,0x80,0xfffe,8,448,1,True,False,0x0
40132567c89badef,16,8,2,1,0x80,0xfffe,3,336,2,True,True,0x0
40623517a98bcdef,16,8,2,1,0x80,0xfffe,4,384,2,True,True,0x0
2013645789abcdef,16,8,2,1,0x888,0xfffe,8,384,2,True,True,0x0
1032456789abcdef,16,8,2,1,0x2aaa,0xfffe,192,3072,4,True,True,0x0