Browse Source

almost the full key attack

Hans Martin 3 years ago
parent
commit
697ec9cb59

File diff suppressed because it is too large
+ 20 - 21
.ipynb_checkpoints/Speck-Analysis-checkpoint.ipynb


File diff suppressed because it is too large
+ 20 - 21
Speck-Analysis.ipynb


BIN
cw_firmware/speck


+ 19 - 5
cw_firmware/speck3264.c

@@ -25,10 +25,26 @@ void Speck3264KeySchedule(u16 K[],u16 rk[])
 {
     u16 i,D=K[3],C=K[2],B=K[1],A=K[0];
 
+    printf("A = 0x%x ; B = 0x%x ; C = 0x%x ; D = 0x%x\n", A, B, C, D);
+
     for(i=0;i<22;){
-        rk[i]=A; ER16(B,A,i++);
-        rk[i]=A; ER16(C,A,i++);
-        rk[i]=A; ER16(D,A,i++);
+
+        printf("A = 0x%x ; B = 0x%x ; C = 0x%x ; D = 0x%x\n", A, B, C, D);
+
+        rk[i]=A;
+        ER16(B,A,i++);
+        printf("rk[%d] =  0x%x\n", i-1, A);
+
+        printf("A = 0x%x ; B = 0x%x ; C = 0x%x ; D = 0x%x\n", A, B, C, D);
+        rk[i]=A;
+        ER16(C,A,i++);
+        printf("rk[%d] =  0x%x\n", i-1, A);
+
+        printf("A = 0x%x ; B = 0x%x ; C = 0x%x ; D = 0x%x\n", A, B, C, D);
+        rk[i]=A;
+        ER16(D,A,i++);
+        printf("rk[%d] =  0x%x\n  <- D = 0x%x", i-1, A, D);
+        printf("----------------------\n");
     }
 }
 
@@ -82,7 +98,6 @@ void Speck3264_EncryptBlock(u8 pt[], u8 k[], u8 ct[]) {
     Words16ToBytes(Ct,ct,2);
 }
 
-/*
 
 int main() {
 
@@ -105,4 +120,3 @@ int main() {
     }
     return 0;
 }
-*/

+ 13 - 2
simulation/speck.py

@@ -117,7 +117,7 @@ class SpeckCipher(object):
         l_schedule = [(self.key >> (x * self.word_size)) & self.mod_mask for x in
                       range(1, self.key_size // self.word_size)]
 
-        print([hex(x) for x in l_schedule])
+        #print([hex(x) for x in l_schedule])
         for x in range(self.rounds - 1):
             new_l_k = self.encrypt_round(l_schedule[x], self.key_schedule[x], x)
             l_schedule.append(new_l_k[0])
@@ -314,7 +314,18 @@ class SpeckCipher(object):
 
 if __name__ == "__main__":
     #cipher = SpeckCipher(0x1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100, 256, 128, 'ECB')
-    cipher = SpeckCipher(0x0102030405060708, 64, 32, 'ECB')
+    cipher = SpeckCipher(0x8877665544332211, 64, 32, 'ECB')
+
+    for i in range(22):
+        a, b = cipher.decrypt_round(0x2211, 0x00dd, i)
+        print(hex(a))
+        print(hex(b))
+
+    for key in range(2**16):
+        _, a = cipher.encrypt_round(key, 0x2211, 0)
+
+        if a == 0xdd:
+            print("found: " + hex(key))
 
     #g = cipher.encrypt(0x65736f6874206e49202e72656e6f6f70)
     g = cipher.encrypt(0xdeadbeef)

Some files were not shown because too many files changed in this diff