Skip to content

Instantly share code, notes, and snippets.

@lionaneesh
Last active June 17, 2019 12:41
Show Gist options
  • Save lionaneesh/39143cbf4fb53cb4502582a9de2cdbe9 to your computer and use it in GitHub Desktop.
Save lionaneesh/39143cbf4fb53cb4502582a9de2cdbe9 to your computer and use it in GitHub Desktop.
Key Tuple Filtering LED Cipher
setGF2(4, 0b10011)
# define fault equations
faults_a = [[0, 4, 8, 12], [3, 7, 11, 15], [2, 6, 10, 14], [1, 5, 9, 13]]
faults_d = [[1, 5, 9, 13], [0, 4, 8, 12], [3, 7, 11, 15], [2, 6, 10, 14]]
faults_c = [[2, 6, 10, 14], [1, 5, 9, 13], [0, 4, 8, 12], [3, 7, 11, 15]]
faults_b = [[3, 7, 11, 15], [2, 6, 10, 14], [1, 5, 9, 13], [0, 4, 8, 12]]
coefs = {'a': [4, 8, 0xB, 2],
'b': [1, 6, 0xE, 2],
'c': [2, 5, 0xA, 0xF],
'd': [2, 6, 9, 0xB]}
sxis = {}
for z in range(0, 4):
for y in [faults_a, faults_b, faults_c, faults_d]:
eq = y[z]
sxi = []
if y == faults_a:
cur = 'a'
if y == faults_b:
cur = 'b'
if y == faults_c:
cur = 'c'
if y == faults_d:
cur = 'd'
for i in range(0, 0xF + 1):
sxi.append(set({}))
for i in range(0x0, 0xF + 1):
for j in range(0x0, 0xF + 1):
for k in range(0x0, 0xF + 1):
for l in range(0x0, 0xF + 1):
s = calculate_fault_equation([cipher[eq[0]], cipher[eq[1]], cipher[eq[2]], cipher[eq[3]]],
[i, j, k, l],
[cipherf[eq[0]], cipherf[eq[1]], cipherf[eq[2]], cipherf[eq[3]]],
z)
sxi[multGF2(find_inverse(coefs[cur][z]), s)].add((i, j, k, l))
sxis[(cur, z)] = sxi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment