Cybersecurity Project / Mbed 2 deprecated sd_duplicator

Dependencies:   mbed-rtos mbed wolfSSL

Fork of sd_duplicator by Titi Asrat

Files at this revision

API Documentation at this revision

Comitter:
jlharper
Date:
Tue Dec 13 05:54:12 2016 +0000
Parent:
3:57cbfc7d9b62
Commit message:
everything works. signing stilll needs to be verified

Changed in this revision

Crypto.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
wolfSSL.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Crypto.lib	Tue Dec 06 13:27:55 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/feb11/code/Crypto/#f04410cef037
--- a/main.cpp	Tue Dec 06 13:27:55 2016 +0000
+++ b/main.cpp	Tue Dec 13 05:54:12 2016 +0000
@@ -1,41 +1,50 @@
+
 #include "mbed.h"
 #include "SDBlock.h"
-#include "Crypto.h"
+#include <wolfssl/wolfcrypt/ecc.h>
 
 DigitalOut led1(LED1);
 DigitalOut led4(LED4);
 
 uint8_t hash[32];
 uint8_t buffer[512];
-SHA256 h;
+uint8_t signature[5];
+Sha256 h; 
+ecc_key key;
+RNG rng;
+
+byte sig[512]; // will hold generated signature
+
 
 int main() 
 {   
     SDBlock original(p5, p6, p7, p22);
     const int x = original.disk_initialize();
-    printf("************\n");
-    printf("%d\n", x);
+    printf("************\r\n");
+    printf("%d\r\n", x);
     SDBlock duplicate(p11, p12, p13, p21);   
     const int z = duplicate.disk_initialize();
-    printf("%d\n", z);
+    printf("%d\r\n", z);
     const int y = original.disk_status();
-    printf("original status: %d\n", y);
+    printf("original status: %d\r\n", y);
     const int t = duplicate.disk_status();
-    printf("duplicate status: %d\n", t);
+    printf("duplicate status: %d\r\n", t);
     //s is sector 
     const uint32_t s = original.disk_sectors();
-    printf("sector size %d\n", s);
-    printf("buffer %d\n", buffer);
+    printf("sector size %d\r\n", s);
+    printf("buffer %d\r\n", buffer);
+    
+    wc_InitSha256(&h);
     
     
     //start time
     //time_t time_start = time(NULL);
-    for (int i = 0; i <= 100; ++i)
+    for (int i = 0; i <= 99; ++i)
     {
         const int r = original.disk_read(buffer, i, 1);
         if (r !=0)
         {
-            printf("%d\n", r);
+            printf("%d\r\n", r);
         }   
         printf("disk read ");
        /* const int rd2 = duplicate.disk_write(buffer, i, 1);
@@ -43,9 +52,9 @@
         {
            printf("%d\n", rd2);
         }*/
-        
-        h.update(buffer, 512);
-        printf("digest updated, block %d",i);
+        //update hash
+        wc_Sha256Update(&h, buffer, 512);
+        printf("digest updated, block %d  \r\n",i);
         
       /*  if(i % 1000 == 0)
         {
@@ -59,14 +68,46 @@
             
             printf("speed (bytes/s): %d\n", speed);
         } */
-    }
-    h.finalize(hash);
-    printf("finished\n");
+    }//end of for 
+    wc_Sha256Final(&h,hash);
+    //sign the hash
+    int ret;
+    uint32_t sigSz; 
+    wc_InitRng(&rng);
+    wc_ecc_init(&key);
+
+       
+    //print the hash
     printf("hash: ");
     for(int i = 0; i < 32; ++i)
         printf("%02x", hash[i]);
-    printf("\n");
+    printf("\r\n");
+    
+    //print signature
+    printf("hash: ");
+    //byte digest[] = hash;
+    //int wc_ecc_sign_hash(const byte* hash, uint32_t len(hash), byte* sig, word32 *outlen, RNG* rng, 
+//ecc_key* key);
+    uint32_t hashsize = 8; 
+    wc_InitRng(&rng); // initialize rng
+    wc_ecc_init(&key); // initialize key
+    wc_ecc_make_key(&rng, 32, &key); // make public/private key pair
+    sigSz = sizeof(sig);
+    ret = wc_ecc_sign_hash(hash, hashsize, sig, &sigSz,&rng, &key);
     
+    printf("ret %i  \r\n",ret);
+    
+    if ( ret != 0 ) 
+    {
+    // error generating message signature
+        printf("Error generating signature/r/n");
+    }
+    printf("finished\r\n");
+    
+    for(int i = 0; i < 512; ++i)
+        printf("%02x", sig[i]);
+    printf("\r\n");
+ 
     //when finished do this light pattern   
     while(true)
     {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Dec 13 05:54:12 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wolfSSL.lib	Tue Dec 13 05:54:12 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wolfSSL/code/wolfSSL/#dc26f46317d3