Baksheesh

class urca.cpu.blockciphers.baksheesh.Baksheesh(block_size: int = 128, key_size: int = 128, sbox: tuple[int, ...] = (3, 0, 6, 13, 11, 5, 8, 14, 12, 15, 9, 2, 4, 10, 7, 1), permutation: ndarray = array([96, 1, 34, 67, 64, 97, 2, 35, 32, 65, 98, 3, 0, 33, 66, 99, 100, 5, 38, 71, 68, 101, 6, 39, 36, 69, 102, 7, 4, 37, 70, 103, 104, 9, 42, 75, 72, 105, 10, 43, 40, 73, 106, 11, 8, 41, 74, 107, 108, 13, 46, 79, 76, 109, 14, 47, 44, 77, 110, 15, 12, 45, 78, 111, 112, 17, 50, 83, 80, 113, 18, 51, 48, 81, 114, 19, 16, 49, 82, 115, 116, 21, 54, 87, 84, 117, 22, 55, 52, 85, 118, 23, 20, 53, 86, 119, 120, 25, 58, 91, 88, 121, 26, 59, 56, 89, 122, 27, 24, 57, 90, 123, 124, 29, 62, 95, 92, 125, 30, 63, 60, 93, 126, 31, 28, 61, 94, 127], dtype=uint8))

Bases: BlockCipher

The Baksheesh block cipher.

Parameters:
  • block_size (int, optional, default = 128) – the bit size of the block

  • key_size (int, optional, default = 128) – the bit size of the key

  • sbox (tuple[int, …], optional, default = original) – the s-box for the cipher

  • permutation (numpy.array, optional, default = original) – the permutation for the cipher

decrypt(blocks: ndarray, keys: ndarray, state_index: int, n_rounds: int) → None

Dencrypt in-place.

Parameters:
  • blocks (np.ndarray) – blocks

  • keys (np.ndarray) – keys

  • state_index (int) – index of the current state

  • n_rounds (int) – number of decryption rounds

encrypt(blocks: ndarray, keys: ndarray, state_index: int, n_rounds: int) → None

Encrypt in-place.

Parameters:
  • blocks (np.ndarray) – blocks

  • keys (np.ndarray) – keys

  • state_index (int) – index of the current state

  • n_rounds (int) – number of encryption rounds

round_constant_positions = array([ 21,  60,  92, 108, 114, 119], dtype=uint8)
round_constants = array([[0, 0, 0, 0, 1, 0],        [1, 0, 0, 0, 0, 1],        [0, 1, 0, 0, 0, 0],        [0, 0, 1, 0, 0, 1],        [1, 0, 0, 1, 0, 0],        [0, 1, 0, 0, 1, 1],        [1, 0, 1, 0, 0, 0],        [1, 1, 0, 1, 0, 1],        [0, 1, 1, 0, 1, 0],        [0, 0, 1, 1, 0, 1],        [1, 0, 0, 1, 1, 0],        [1, 1, 0, 0, 1, 1],        [1, 1, 1, 0, 0, 0],        [1, 1, 1, 1, 0, 1],        [1, 1, 1, 1, 1, 0],        [0, 1, 1, 1, 1, 1],        [0, 0, 1, 1, 1, 0],        [0, 0, 0, 1, 1, 1],        [1, 0, 0, 0, 1, 0],        [1, 1, 0, 0, 0, 1],        [0, 1, 1, 0, 0, 0],        [1, 0, 1, 1, 0, 1],        [1, 1, 0, 1, 1, 0],        [1, 1, 1, 0, 1, 1],        [0, 1, 1, 1, 0, 0],        [1, 0, 1, 1, 1, 1],        [0, 1, 0, 1, 1, 0],        [1, 0, 1, 0, 1, 1],        [0, 1, 0, 1, 0, 0],        [0, 0, 1, 0, 1, 1],        [0, 0, 0, 1, 0, 0],        [0, 0, 0, 0, 1, 1],        [1, 0, 0, 0, 0, 0],        [0, 1, 0, 0, 0, 1],        [0, 0, 1, 0, 0, 0]], dtype=uint8)