arxpy.primitives.primitives module¶
Represent symmetric primitives.
- 
class 
arxpy.primitives.primitives.BvFunction[source]¶ Bases:
objectRepresent (iterated) fixed-width bit-vector functions.
A
BvFunctiontakes fixed-widthConstantoperands and return a tuple of fixed-widthConstant. An iterated bit-vector function contains a subroutine that is iterated a certain number of rounds, which can be changed usingset_rounds.Similar to
Operation,BvFunctionis evaluated using the operator()and provides Automatic Constant Conversion. Note thatBvFunctiononly acceptsConstantoperands and always return a tuple, as opposed toOperationthat acceptsTermand scalar operands and returns a singleTerm.>>> from arxpy.primitives.primitives import BvFunction >>> from arxpy.primitives.chaskey import ChaskeyPi >>> issubclass(ChaskeyPi, BvFunction) True >>> ChaskeyPi(0, 0, 0, 0) # automatic conversion from int to Constant (0x00000000, 0x00000000, 0x00000000, 0x00000000)
- 
input_widths¶ a list containing the widths of the inputs
- 
output_widths¶ a list containing the widths of the outputs
- 
rounds¶ the number of iterations
- 
classmethod 
set_rounds(new_rounds)[source]¶ Change the number of rounds and adjust the input/output widths.
- 
classmethod 
ssa(input_names, id_prefix)[source]¶ Return a static single assignment program representing the function.
- Parameters
 input_names – the names for the input variables
id_prefix – the prefix to denote the intermediate variables
- Returns
 a dictionary with three keys
>>> from arxpy.primitives.chaskey import ChaskeyPi >>> ChaskeyPi.set_rounds(1) >>> ChaskeyPi.ssa(["v0", "v1", "v2", "v3"], "x") {'input_vars': (v0, v1, v2, v3), 'output_vars': (x7, x12, x13, x9), 'assignments': ((x0, v0 + v1), (x1, v1 <<< 5), (x2, x0 ^ x1), (x3, x0 <<< 16), (x4, v2 + v3), (x5, v3 <<< 8), (x6, x4 ^ x5), (x7, x3 + x6), (x8, x6 <<< 13), (x9, x7 ^ x8), (x10, x2 + x4), (x11, x2 <<< 7), (x12, x10 ^ x11), (x13, x10 <<< 16))}
- 
 
- 
class 
arxpy.primitives.primitives.KeySchedule[source]¶ Bases:
arxpy.primitives.primitives.BvFunctionRepresent key schedule functions.
A key schedule function is a
BvFunctionthat takes the masterkey as input and returns the round keys. SeeBvFunctionfor more information.
- 
class 
arxpy.primitives.primitives.Encryption[source]¶ Bases:
arxpy.primitives.primitives.BvFunctionRepresent encryption functions.
An encryption function is a
BvFunctionthat takes the plaintext as input and returns the ciphertext for some fixed key. SeeBvFunctionfor more information.
- 
class 
arxpy.primitives.primitives.Cipher[source]¶ Bases:
objectRepresent (iterated) block ciphers.
A (iterated) block cipher consists of
KeySchedulefunction that computes round keys from a master key and anEncryptionfunction that computes a ciphertext from a given plaintext and the round keys.Given a
cipher, it can be evaluated with the operator()by passing it as arguments the plaintext and the master key, that is,cipher(plaintext, masterkey)returns the ciphertext.>>> from arxpy.primitives.primitives import Cipher >>> from arxpy.primitives import speck >>> Speck32 = speck.get_Speck_instance(speck.SpeckInstance.speck_32_64) >>> issubclass(Speck32, Cipher) True >>> plaintext = [0, 0] >>> masterkey = [0, 0, 0, 0] >>> Speck32(plaintext, masterkey) (0x2bb9, 0xc642)
- 
key_schedule¶ the
KeySchedulefunction of the cipher
- 
encryption¶ the
Encryptionfunction of the cipher
-