Common

urca.common.gen_bits(values: tuple[int, ...], value_size: int) tuple[tuple[int, ...], ...]

The bit representation of the values.

Parameters:
  • values (tuple[int]) – integers whose bit representation is needed

  • value_size (int) – the bit size for each integer

Returns:

a tuple whose size is (len(values), value_size)

Return type:

tuple[tuple[int], …]

Examples

>>> from urca.common import gen_bits
>>> gen_bits((0x6, 0xA, 0x1, 0xA), 4)
((0, 1, 1, 0), (1, 0, 1, 0), (0, 0, 0, 1), (1, 0, 1, 0))
urca.common.gen_bytesbox(sbox: tuple[int, ...]) tuple[int, ...]

The byte sbox from the nibble one.

Parameters:

sbox (tuple[int]) – the nibble s-box whose byte version is required

Returns:

the byte version of the sbox

Return type:

tuple[int]

Examples

>>> from urca.common import gen_bytesbox
>>> gift_sbox = (0x1, 0xA, 0x4, 0xC, 0x6, 0xF, 0x3, 0x9, 0x2, 0xD, 0xB, 0x7, 0x5, 0x0, 0x8, 0xE)
>>> gift_bytesbox = gen_bytesbox(gift_sbox)
>>> gift_bytesbox[0x15] == 0xAF
True
urca.common.get_dtype(word_size: int) dtype[uint8]

Return the minimum size dtype.

This function returns the minimum size dtype object that can contain the word size. This is useful for those primitives having a non-power-of-2 word size (e.g. Speck 48/96).

Parameters:

word_size (int) – the size of the word in bits

Returns:

the numpy dtype object of the minimum size

Return type:

np.dtype

Examples

>>> from urca.common import get_dtype
>>> get_dtype(24)
dtype('uint32')
urca.common.invert_sbox(sbox: tuple[int, ...]) tuple[int, ...]

The inverted S-box.

Parameters:

sbox (tuple[int]) – the S-box to be inverted

Returns:

the inverted S-box

Return type:

tuple[int]

Examples

>>> from urca.common import invert_sbox
>>> gift_sbox = (0x1, 0xA, 0x4, 0xC, 0x6, 0xF, 0x3, 0x9, 0x2, 0xD, 0xB, 0x7, 0x5, 0x0, 0x8, 0xE)
>>> invert_sbox(gift_sbox)
(13, 0, 8, 6, 2, 12, 4, 11, 14, 7, 1, 10, 3, 9, 15, 5)