blocks.present.py

Description

The PRESENT block cipher [BKL2007] has reference configurations suitable for essential one text size. Based on that, two key sizes are possible.

PRESENT

Implementation [BKL2007]

class urca.cpu.blocks.present.Present(text_size: int = 64, key_size: int = 80)

Bases: Block

decrypt(texts: ndarray, keys: ndarray, current_round: int, n_rounds: int) None

Dencrypt in-place.

Parameters:
  • texts (np.ndarray) – ciphertexts

  • keys (np.ndarray) – keys

  • current_round (int) – current round

  • n_rounds (int) – number of decryption rounds

encrypt(texts: ndarray, keys: ndarray, current_round: int, n_rounds: int) None

Encrypt in-place.

Parameters:
  • texts (np.ndarray) – plaintexts

  • keys (np.ndarray) – keys

  • current_round (int) – current round

  • n_rounds (int) – number of encryption rounds

keysize_to_counterlow = {80: 60, 128: 61}
keysize_to_keybitsinsbox = {80: 4, 128: 8}
reversed_sbox = array([ 85,  94,  95,  88,  92,  81,  82,  93,  91,  84,  86,  83,  80,         87,  89,  90, 229, 238, 239, 232, 236, 225, 226, 237, 235, 228,        230, 227, 224, 231, 233, 234, 245, 254, 255, 248, 252, 241, 242,        253, 251, 244, 246, 243, 240, 247, 249, 250, 133, 142, 143, 136,        140, 129, 130, 141, 139, 132, 134, 131, 128, 135, 137, 138, 197,        206, 207, 200, 204, 193, 194, 205, 203, 196, 198, 195, 192, 199,        201, 202,  21,  30,  31,  24,  28,  17,  18,  29,  27,  20,  22,         19,  16,  23,  25,  26,  37,  46,  47,  40,  44,  33,  34,  45,         43,  36,  38,  35,  32,  39,  41,  42, 213, 222, 223, 216, 220,        209, 210, 221, 219, 212, 214, 211, 208, 215, 217, 218, 181, 190,        191, 184, 188, 177, 178, 189, 187, 180, 182, 179, 176, 183, 185,        186,  69,  78,  79,  72,  76,  65,  66,  77,  75,  68,  70,  67,         64,  71,  73,  74, 101, 110, 111, 104, 108,  97,  98, 109, 107,        100, 102,  99,  96, 103, 105, 106,  53,  62,  63,  56,  60,  49,         50,  61,  59,  52,  54,  51,  48,  55,  57,  58,   5,  14,  15,          8,  12,   1,   2,  13,  11,   4,   6,   3,   0,   7,   9,  10,        117, 126, 127, 120, 124, 113, 114, 125, 123, 116, 118, 115, 112,        119, 121, 122, 149, 158, 159, 152, 156, 145, 146, 157, 155, 148,        150, 147, 144, 151, 153, 154, 165, 174, 175, 168, 172, 161, 162,        173, 171, 164, 166, 163, 160, 167, 169, 170], dtype=uint8)
revert_keys(keys: ndarray, round_number: int) None

Revert the keys in-place.

Parameters:
  • keys (np.ndarray) – keys

  • round_number (int) – current round

rotation_amount

The amount of the rotation in the key schedule.

sbox = array([204, 197, 198, 203, 201, 192, 202, 205, 195, 206, 207, 200, 196,        199, 193, 194,  92,  85,  86,  91,  89,  80,  90,  93,  83,  94,         95,  88,  84,  87,  81,  82, 108, 101, 102, 107, 105,  96, 106,        109,  99, 110, 111, 104, 100, 103,  97,  98, 188, 181, 182, 187,        185, 176, 186, 189, 179, 190, 191, 184, 180, 183, 177, 178, 156,        149, 150, 155, 153, 144, 154, 157, 147, 158, 159, 152, 148, 151,        145, 146,  12,   5,   6,  11,   9,   0,  10,  13,   3,  14,  15,          8,   4,   7,   1,   2, 172, 165, 166, 171, 169, 160, 170, 173,        163, 174, 175, 168, 164, 167, 161, 162, 220, 213, 214, 219, 217,        208, 218, 221, 211, 222, 223, 216, 212, 215, 209, 210,  60,  53,         54,  59,  57,  48,  58,  61,  51,  62,  63,  56,  52,  55,  49,         50, 236, 229, 230, 235, 233, 224, 234, 237, 227, 238, 239, 232,        228, 231, 225, 226, 252, 245, 246, 251, 249, 240, 250, 253, 243,        254, 255, 248, 244, 247, 241, 242, 140, 133, 134, 139, 137, 128,        138, 141, 131, 142, 143, 136, 132, 135, 129, 130,  76,  69,  70,         75,  73,  64,  74,  77,  67,  78,  79,  72,  68,  71,  65,  66,        124, 117, 118, 123, 121, 112, 122, 125, 115, 126, 127, 120, 116,        119, 113, 114,  28,  21,  22,  27,  25,  16,  26,  29,  19,  30,         31,  24,  20,  23,  17,  18,  44,  37,  38,  43,  41,  32,  42,         45,  35,  46,  47,  40,  36,  39,  33,  34], dtype=uint8)
update_keys(keys: ndarray, round_number: int) None

Update the keys in-place.

Parameters:
  • keys (np.ndarray) – keys

  • round_number (int) – current round