# analysis of KF VMAC ROTR operations on the key # # values in K represent shift amounts # number of rounds, must be >= 16 # N = 64 # 8 32-bit pieces of the key # K = [ [] for i in range(8)] # shift amount as a function of the round index # def Shift( i, j): # # ORIGINAL: this produces some duplicate shifts for N > 31 # # return i%31 # # (i%k has duplicate shifts for all possible values of k with N = 64) # # MODIFIED: no duplicate shifts # return 3*j+(i>>3) # no mod needed, max is 3*7+63//8 = 21+7 = 28 # W[i] is XOR'd with ROTR( K[j], i%31) # # j = i, i=0:7 # j = i-5, i=8:12 # j = (i-12)%3, i=13:15 # j = (63-i)%8, i=16:N-1 # jlist = [] # for i in range(8): j = i; jlist.append( j); K[j].append( Shift(i,j)) # for i in range(8,13): j = i-5; jlist.append( j); K[j].append( Shift(i,j)) # for i in range(13,16): j = (i-12)%3; jlist.append( j); K[j].append( Shift(i,j)) # for i in range(16,N): j = (63-i)%8; jlist.append( j); K[j].append( Shift(i,j)) # debug if 0: print( "i j") for i in range(N): print( i, jlist[i]) print("K rotations") for i in range(8): print( "K", i, "=", K[i]) print("K rotations, sorted") for i in range(8): x = "" if len(set(K[i])) != len(K[i]): x = "duplicates" print( "K", i, "=", sorted(K[i]), x) print("All rotations, sorted") A = [] for i in range(8): for j in range(len(K[i])): A.append(K[i][j]) print(sorted(A)) # results: # # ORIGINAL: # K rotations # K 0 = [0, 15, 23, 0, 8, 16, 24, 1] duplicate 0 # K 1 = [1, 13, 22, 30, 7, 15, 23, 0] # K 2 = [2, 14, 21, 29, 6, 14, 22, 30] duplicate 14 # K 3 = [3, 8, 20, 28, 5, 13, 21, 29] # K 4 = [4, 9, 19, 27, 4, 12, 20, 28] duplicate 4 # K 5 = [5, 10, 18, 26, 3, 11, 19, 27] # K 6 = [6, 11, 17, 25, 2, 10, 18, 26] # K 7 = [7, 12, 16, 24, 1, 9, 17, 25] # # MODIFIED: # K rotations # K 0 = [0, 1, 2, 3, 4, 5, 6, 7] # K 1 = [3, 4, 5, 6, 7, 8, 9, 10] # K 2 = [6, 7, 8, 9, 10, 11, 12, 13] # K 3 = [9, 10, 11, 12, 13, 14, 15, 16] # K 4 = [12, 13, 14, 15, 16, 17, 18, 19] # K 5 = [15, 16, 17, 18, 19, 20, 21, 22] # K 6 = [18, 19, 20, 21, 22, 23, 24, 25] # K 7 = [21, 22, 23, 24, 25, 26, 27, 28]