arxpy.primitives.primitives module

Represent symmetric primitives.

class arxpy.primitives.primitives.BvFunction[source]

Bases: object

Represent (iterated) fixed-width bit-vector functions.

A BvFunction takes fixed-width Constant operands and return a tuple of fixed-width Constant. An iterated bit-vector function contains a subroutine that is iterated a certain number of rounds, which can be changed using set_rounds.

Similar to Operation, BvFunction is evaluated using the operator () and provides Automatic Constant Conversion. Note that BvFunction only accepts Constant operands and always return a tuple, as opposed to Operation that accepts Term and scalar operands and returns a single Term.

>>> 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 eval(*args)[source]

Evaluate the function (internal method).

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

  • input_vars: a list of Variable representing the inputs

  • output_vars: a list of Variable representing the outputs

  • assignments: an ordered sequence of pairs (Variable, Operation) representing each assignment of the SSA program.

>>> 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.BvFunction

Represent key schedule functions.

A key schedule function is a BvFunction that takes the masterkey as input and returns the round keys. See BvFunction for more information.

class arxpy.primitives.primitives.Encryption[source]

Bases: arxpy.primitives.primitives.BvFunction

Represent encryption functions.

An encryption function is a BvFunction that takes the plaintext as input and returns the ciphertext for some fixed key. See BvFunction for more information.

round_keys

a list of Term representing the round keys

class arxpy.primitives.primitives.Cipher[source]

Bases: object

Represent (iterated) block ciphers.

A (iterated) block cipher consists of KeySchedule function that computes round keys from a master key and an Encryption function 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 KeySchedule function of the cipher

encryption

the Encryption function of the cipher

classmethod set_rounds(new_rounds)[source]

Change the number of rounds and adjust the input/output widths.