Browse Source

new version, and almost right asm

Marius Schwarz 3 years ago
parent
commit
6a6bdf3a6d
3 changed files with 61 additions and 54 deletions
  1. 19 19
      Speck-Analysis.ipynb
  2. 21 14
      Speck-Masked.ipynb
  3. 21 21
      cw_firmware_masked/speck3264.c

+ 19 - 19
Speck-Analysis.ipynb

@@ -21,15 +21,7 @@
    "execution_count": 1,
    "id": "0cccc556",
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stderr",
-     "output_type": "stream",
-     "text": [
-      "WARNING:ChipWhisperer Other:ChipWhisperer update available! See https://chipwhisperer.readthedocs.io/en/latest/installing.html for updating instructions\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "import chipwhisperer as cw\n",
     "import time"
@@ -43,7 +35,8 @@
    "outputs": [],
    "source": [
     "# Path to the Speck .hex file for reflashing\n",
-    "PATH=\"/home/msc/documents/obsidian_notes/master-aits/subjects/implementation_attacks_and_countermeasures/praktikum/speck_cpa_cw/cw_firmware/simple-speck-CWLITEARM.hex\""
+    "PATH=\"/home/msc/documents/obsidian_notes/master-aits/subjects/implementation_attacks_and_countermeasures/praktikum/speck_cpa_cw/cw_firmware/simple-speck-CWLITEARM.hex\"\n",
+    "PATH=\"/home/juan/documents/master-aits/subjects/implementation_attacks_and_countermeasures/praktikum/speck_cpa_cw/cw_firmware_masked/simple-speck-CWLITEARM.hex\""
    ]
   },
   {
@@ -122,7 +115,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 9,
    "id": "4cc49970",
    "metadata": {},
    "outputs": [],
@@ -140,7 +133,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 10,
    "id": "de6112ec",
    "metadata": {},
    "outputs": [
@@ -150,10 +143,10 @@
      "text": [
       "Detected known STMF32: STM32F302xB(C)/303xB(C)\n",
       "Extended erase (0x44), this can take ten seconds or more\n",
-      "Attempting to program 5431 bytes at 0x8000000\n",
+      "Attempting to program 5455 bytes at 0x8000000\n",
       "STM32F Programming flash...\n",
       "STM32F Reading flash...\n",
-      "Verified flash OK, 5431 bytes\n"
+      "Verified flash OK, 5455 bytes\n"
      ]
     }
    ],
@@ -171,7 +164,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 11,
    "id": "103040b9",
    "metadata": {},
    "outputs": [],
@@ -195,7 +188,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 12,
    "id": "bdfe5aba",
    "metadata": {},
    "outputs": [
@@ -222,15 +215,22 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 14,
    "id": "180eb01b",
    "metadata": {},
    "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "WARNING:ChipWhisperer Target:Unexpected start to command: \n"
+     ]
+    },
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "CWbytearray(b'5d 7c 46 6d')\n"
+      "None\n"
      ]
     }
    ],
@@ -4210,7 +4210,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.9.7"
+   "version": "3.9.6"
   }
  },
  "nbformat": 4,

+ 21 - 14
Speck-Masked.ipynb

@@ -105,7 +105,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 68,
+   "execution_count": 82,
    "id": "4cc49970",
    "metadata": {},
    "outputs": [],
@@ -123,7 +123,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 69,
+   "execution_count": 83,
    "id": "de6112ec",
    "metadata": {},
    "outputs": [
@@ -133,10 +133,10 @@
      "text": [
       "Detected known STMF32: STM32F302xB(C)/303xB(C)\n",
       "Extended erase (0x44), this can take ten seconds or more\n",
-      "Attempting to program 5451 bytes at 0x8000000\n",
+      "Attempting to program 5459 bytes at 0x8000000\n",
       "STM32F Programming flash...\n",
       "STM32F Reading flash...\n",
-      "Verified flash OK, 5451 bytes\n"
+      "Verified flash OK, 5459 bytes\n"
      ]
     }
    ],
@@ -154,7 +154,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 70,
+   "execution_count": 84,
    "id": "103040b9",
    "metadata": {},
    "outputs": [],
@@ -178,7 +178,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 71,
+   "execution_count": 85,
    "id": "bdfe5aba",
    "metadata": {},
    "outputs": [
@@ -205,15 +205,22 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 72,
+   "execution_count": 86,
    "id": "180eb01b",
    "metadata": {},
    "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "WARNING:ChipWhisperer Target:Unexpected start to command: \n"
+     ]
+    },
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "CWbytearray(b'5d 7c 46 6d')\n"
+      "None\n"
      ]
     }
    ],
@@ -226,7 +233,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "48725a67",
+   "id": "1b574c30",
    "metadata": {},
    "source": [
     "Output is supposed to be: **CWbytearray(b'5d 7c 46 6d')**"
@@ -1394,7 +1401,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "86ef92db",
+   "id": "4fd692ce",
    "metadata": {},
    "source": [
     "# T-Test"
@@ -1402,7 +1409,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "f7f9b621",
+   "id": "f3d7e1e4",
    "metadata": {},
    "source": [
     "### Helper Functions"
@@ -1411,7 +1418,7 @@
   {
    "cell_type": "code",
    "execution_count": 11,
-   "id": "35b906db",
+   "id": "6c4fb9ed",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -1430,7 +1437,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "0a4ab9c6",
+   "id": "3e698b7a",
    "metadata": {},
    "source": [
     "### Tracing"
@@ -1439,7 +1446,7 @@
   {
    "cell_type": "code",
    "execution_count": 14,
-   "id": "2aa6a65a",
+   "id": "95efbd15",
    "metadata": {},
    "outputs": [
     {

+ 21 - 21
cw_firmware_masked/speck3264.c

@@ -16,6 +16,7 @@ void FuncER16(u16 *x, u16 *y, u16 k)
 
     *y = (((tmp_y)<<(2)) | (tmp_y>>(16-(2))));
     *y = *y ^ *x;
+
 }
 
 
@@ -25,27 +26,26 @@ void FuncER16_ASM(u16 *x, u16 *y, u16 k)
 {
 
     asm volatile (
-"nop\n\t"
-"push	{r4, r5, lr}\n\t"
-"ldrh	r5, [r0, #0]\n\t"
-"ldrh	r4, [r1, #0]\n\t"
-"lsls	r3, r5, #9\n\t"
-"orr.w	r3, r3, r5, lsr #7\n\t"
-"uxth	r3, r3\n\t"
-"strh	r3, [r0, #0]\n\t"
-"ldrh	r5, [r1, #0]\n\t"
-"add	r3, r5\n\t"
-"eors	r2, r3\n\t"
-"lsls	r3, r4, #2\n\t"
-"orr.w	r3, r3, r4, lsr #14\n\t"
-"uxth	r3, r3\n\t"
-"strh	r2, [r0, #0]\n\t"
-"strh	r3, [r1, #0]\n\t"
-"ldrh	r2, [r0, #0]\n\t"
-"eors	r3, r2\n\t"
-"strh	r3, [r1, #0]\n\t"
-"pop	{r4, r5, pc}\n\t"
-"nop\n\t"
+        "nop\n\t"
+        "push	{r4, r5, lr}\n\t"
+        "ldrh	r5, [r0, #0]\n\t"
+        "ldrh	r4, [r1, #0]\n\t"
+        "lsls	r3, r5, #9\n\t"
+        "orr.w	r3, r3, r5, lsr #7\n\t"
+        "uxth	r3, r3\n\t"
+        "strh	r3, [r0, #0]\n\t"
+        "ldrh	r5, [r1, #0]\n\t"
+        "add	r3, r5\n\t"
+        "eors	r2, r3\n\t"
+        "lsls	r3, r4, #2\n\t"
+        "orr.w	r3, r3, r4, lsr #14\n\t"
+        "uxth	r3, r3\n\t"
+        "strh	r2, [r0, #0]\n\t"
+        "strh	r3, [r1, #0]\n\t"
+        "ldrh	r2, [r0, #0]\n\t"
+        "eors	r3, r2\n\t"
+        "strh	r3, [r1, #0]\n\t"
+        "pop	{r4, r5, pc}\n\t"
     );
 
 }