15:21 9nov

Dependencies:   mbed mbedtls

Revision:
3:7a6787f99da2
Parent:
2:cee7ee508f77
Child:
4:98332985e06f
--- a/main.cpp	Fri Nov 09 09:58:06 2018 +0000
+++ b/main.cpp	Fri Nov 09 10:05:12 2018 +0000
@@ -4,52 +4,54 @@
 PwmOut r(LED_RED);
 PwmOut g(LED_GREEN);
 PwmOut b(LED_BLUE);
-r = g = b = 1;
-g = 0;
-int main(){
+Serial pc(USBTX, USBRX);
+int main()
+{
+    pc.printf("INITIALIZING...");
+    wait(1);
+    r = g = b = 1;
+    g = 0;
     int ret = 0;
     mbedtls_pk_context pk;
 
     mbedtls_pk_init( &pk );
     const unsigned char key[]="-----BEGIN RSA PUBLIC KEY-----"
-"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMYfnvWtC8Id5bPKae5yXSxQTt"
-"+Zpul6AnnZWfI2TtIarvjHBFUtXRo96y7hoL4VWOPKGCsRqMFDkrbeUjRrx8iL91"
-"4/srnyf6sh9c8Zk04xEOpK1ypvBz+Ks4uZObtjnnitf0NBGdjMKxveTq+VE7BWUI"
-"yQjtQ8mbDOsiLLvh7wIDAQAB"
-"-----END RSA PUBLIC KEY-----";
-    
+                              "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMYfnvWtC8Id5bPKae5yXSxQTt"
+                              "+Zpul6AnnZWfI2TtIarvjHBFUtXRo96y7hoL4VWOPKGCsRqMFDkrbeUjRrx8iL91"
+                              "4/srnyf6sh9c8Zk04xEOpK1ypvBz+Ks4uZObtjnnitf0NBGdjMKxveTq+VE7BWUI"
+                              "yQjtQ8mbDOsiLLvh7wIDAQAB"
+                              "-----END RSA PUBLIC KEY-----";
+
 
     /*
      * Read the RSA public key
      */
-    if( ( ret = mbedtls_pk_parse_public_key( &pk, key,sizeof(key)) ) != 0 )
-    {
+    if( ( ret = mbedtls_pk_parse_public_key( &pk, key,sizeof(key)) ) != 0 ) {
         printf( " failed\n  ! mbedtls_pk_parse_public_key returned -0x%04x\n", -ret );
         g = b = 1;
         r = 0;
         goto exit;
     }
-    
-        unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
+
+    unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
     size_t olen = 0;
 
     /*
      * Calculate the RSA encryption of the data.
      */
-    printf( "\n  . Generating the encrypted value" );
+    printf(pc. "\n  . Generating the encrypted value" );
     fflush( stdout );
-    const unsigned char to_encrypt[] ="HelloWorld";
+    const unsigned char to_encrypt[] = "HelloWorld";
     mbedtls_ctr_drbg_context ctr_drbg;
-    
+
     if( ( ret = mbedtls_pk_encrypt( &pk, to_encrypt, sizeof(to_encrypt),
                                     buf, &olen, sizeof(buf),
-                                    mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 )
-    {
-        printf( " failed\n  ! mbedtls_pk_encrypt returned -0x%04x\n", -ret );
+                                    mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 ) {
+        pc.printf( " failed\n  ! mbedtls_pk_encrypt returned -0x%04x\n", -ret );
         r = g = 1;
         b = 0;
         goto exit;
     }
-    exit:
+exit:
     return 0;
 }
\ No newline at end of file