ソースを参照

playing around with the correlation

Hans Martin 3 年 前
コミット
bce11d858a
5 ファイル変更26 行追加11 行削除
  1. 3 0
      cw_firmware/makefile
  2. 1 1
      cw_firmware/simple-speck.c
  3. BIN
      cw_firmware/speck
  4. 1 0
      cw_firmware/speck.h
  5. 21 10
      cw_firmware/speck3264.c

+ 3 - 0
cw_firmware/makefile

@@ -25,3 +25,6 @@ include deps/Makefile.simpleserial
 FIRMWAREPATH = deps/
 include $(FIRMWAREPATH)/Makefile.inc
 
+
+local:
+	gcc speck3264.c -o speck

+ 1 - 1
cw_firmware/simple-speck.c

@@ -43,7 +43,7 @@ uint8_t encrypt_block(uint8_t* pt, uint8_t len) {
     u8 key[8] = {0x00};
     memcpy(key, gkey, 8); // copy the globally set encryption key
     u8 ct[4] = {0x00};
-    EncryptBlock(pt, key, ct); // the encryption happens here
+    Speck3264_EncryptBlock(pt, key, ct); // the encryption happens here
 
     trigger_low(); // TRIGGER STOP
 

BIN
cw_firmware/speck


+ 1 - 0
cw_firmware/speck.h

@@ -33,6 +33,7 @@ void Speck128256KeySchedule(u64 K[],u64 rk[]);
 void Speck128256Encrypt(u64 Pt[],u64 Ct[],u64 rk[]);
 void Speck128256Decrypt(u64 Pt[],u64 Ct[],u64 rk[]);
 void EncryptBlock(u8 pt[], u8 k[], u8 ct[]);
+void Speck3264_EncryptBlock(u8 pt[], u8 k[], u8 ct[]);
 
 
 // 32 bit versions functions

+ 21 - 10
cw_firmware/speck3264.c

@@ -15,8 +15,7 @@ void Words16ToBytes(u16 words[],u8 bytes[],int numwords)
 
 void BytesToWords16(u8 bytes[],u16 words[],int numbytes)
 {
-    int i,j=0;
-    for(i=0;i<numbytes/2;i++){
+    int i,j=0; for(i=0;i<numbytes/2;i++){
         words[i]=(u16)bytes[j] | ((u16)bytes[j+1]<<8);
         j+=2;
     }
@@ -39,7 +38,10 @@ void Speck3264Encrypt(u16 Pt[],u16 Ct[],u16 rk[])
     u16 i;
     Ct[0]=Pt[0]; Ct[1]=Pt[1];
 
-    for(i=0;i<22;) ER16(Ct[1],Ct[0],rk[i++]);
+    // full 22  rounds
+    // for(i=0;i<22;) ER16(Ct[1],Ct[0],rk[i++]);
+    //ER16(Ct[1],Ct[0],rk[0]);
+    ER16(Ct[1],Ct[0],0x65);
 }
 
 
@@ -52,8 +54,7 @@ void Speck3264Decrypt(u16 Pt[],u16 Ct[],u16 rk[])
 }
 
 
-
-void EncryptBlock(u8 pt[], u8 k[], u8 ct[]) {
+void Speck3264_EncryptBlock(u8 pt[], u8 k[], u8 ct[]) {
 
     u16 Pt[2] = {0};
     u16 K[4] = {0};
@@ -65,22 +66,33 @@ void EncryptBlock(u8 pt[], u8 k[], u8 ct[]) {
 
     Speck3264KeySchedule(K,rk);
 
+    // DEBUG Purposes
+
+    /*
     for (int i=0; i < 16; i++)
     {
         printf("Key: 0x%x\n", rk[i]);
     }
+    */
     Speck3264Encrypt(Pt,Ct,rk);
     Words16ToBytes(Ct,ct,2);
 }
 
+/*
 
 int main() {
 
-    u8 key[8] = {0x1, 0x2,0x3,0x4,0x5,0x6,0x7,0x8};
-    u8 pt[4] = {0xde, 0xad, 0xbe, 0xef};
+
+    // test are from https://github.com/inmcm/Simon_Speck_Ciphers
+    //u8 key[8] = {0x00, 0x01, 0x08, 0x09, 0x10, 0x11, 0x18, 0x19};
+    u8 pt[4] = {0x4c, 0x69, 0x74, 0x65};
+
+    u8 key[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
+
+
     u8 ct[4] = {0x0};
 
-    EncryptBlock(pt, key, ct);
+    Speck3264_EncryptBlock(pt, key, ct);
     printf("[[ Speck 32/64  ]]\n");
 
     printf("The output: \n");
@@ -89,5 +101,4 @@ int main() {
     }
     return 0;
 }
-
-
+*/