def KalynaEncrypt(parameters: tuple, p_text: Union[str, int], main_key: int, state_0: int): l, k, t, c = parameters rks = KalynaKeyExpansion(parameters, main_key, state_0) k_e = KalynaObject(l, k, t, c) return EncryptBlock(k_e, p_text, rks, all_sub_tables, all_mix_cols, mds_matrix)
def KalynaDecrypt(parameters: tuple, c_text: Union[str, int], main_key: int, state_0: int): l, k, t, c = parameters rks = KalynaKeyExpansion(parameters, main_key, state_0) k_d = KalynaObject(l, k, t, c) return DecryptBlock(k_d, c_text, rks, all_inv_tables, all_inv_mix_cols, inverse_mds_matrix)
def KalynaKeyExpansion(parameters: tuple, main_key: int, state_0: int): l, k, t, c = parameters # Declare KalynaObject for round key generation k_c = KalynaObject(l, k, t, c) KT = 0 if k == l: k0_b = key_to_bytes( hex(main_key)[2:], k_c.state.shape[1], c, k_c.PadKeyLength) # k_alpha k1_b = key_to_bytes( hex(main_key)[2:], k_c.state.shape[1], c, k_c.PadKeyLength) # k_omega KT = KeyExpansionKT(k_c, main_key, k0_b, k1_b, all_sub_tables, all_mix_cols, mds_matrix, state_0) k_c.state = KT elif k == 2 * l: # Number of State Matrix Rows i.e. k_obj.NumStateMatrixRows for key handling is different for k=2*l cases # k_alpha k0 = LsbReturn(main_key, l, k_c.PadKeyLength) k0_b = key_to_bytes( hex(k0)[2:], k_c.state.shape[1], c, k_c.HexKeyLength) # k_omega k1 = MsbReturn(main_key, l, k_c.PadKeyLength) k1_b = key_to_bytes( hex(k1)[2:], k_c.state.shape[1], c, k_c.HexKeyLength) KT = KeyExpansionKT(k_c, main_key, k0_b, k1_b, all_sub_tables, all_mix_cols, mds_matrix, state_0) k_c.state = KT roundkeys = KeyExpansionEven(k_c, KT, main_key, all_sub_tables, all_mix_cols, mds_matrix) roundkeys = KeyExpansionOdd(k_c, roundkeys) return roundkeys