#/* # * Copyright (C) 2017 - This file is part of libecc project # * # * Authors: # * Ryad BENADJILA # * Arnaud EBALARD # * Jean-Pierre FLORI # * # * Contributors: # * Nicolas VIVET # * Karim KHALFALLAH # * # * This software is licensed under a dual BSD and GPL v2 license. # * See LICENSE file at the root folder of the project. # */ import struct, sys keccak_rc = [ 0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000, 0x000000000000808B, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008A, 0x0000000000000088, 0x0000000080008009, 0x000000008000000A, 0x000000008000808B, 0x800000000000008B, 0x8000000000008089, 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 0x000000000000800A, 0x800000008000000A, 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 ] keccak_rot = [ [ 0, 36, 3, 41, 18 ], [ 1, 44, 10, 45, 2 ], [ 62, 6, 43, 15, 61 ], [ 28, 55, 25, 21, 56 ], [ 27, 20, 39, 8, 14 ], ] def is_python_2(): if sys.version_info[0] < 3: return True else: return False # Keccak function def keccak_rotl(x, l): return (((x << l) ^ (x >> (64 - l))) & (2**64-1)) def keccakround(bytestate, rc): # Import little endian state state = [0] * 25 for i in range(0, 25): to_unpack = ''.join(bytestate[(8*i):(8*i)+8]) if is_python_2() == False: to_unpack = to_unpack.encode('latin-1') (state[i],) = struct.unpack('