Browse Source

Changed the order of the private and the public key in the serialization and deserialization functions, so that a public key can be serialized for ECDSA signing

dettanym 5 years ago
parent
commit
5196f3802a
1 changed files with 45 additions and 16 deletions
  1. 45 16
      LocalAttestationCode/EnclaveMessageExchange.cpp

+ 45 - 16
LocalAttestationCode/EnclaveMessageExchange.cpp

@@ -203,32 +203,61 @@ uint32_t create_ecdsa_key_pair(sgx_ec256_public_t* pub_key, sgx_ec256_private_t*
 }
 
 // todo: set to private
+// todo: assumes that the length of the keystring is at least 3*SGX_ECP256_KEY_SIZE
 void serialize_signing_key_pair_to_string(sgx_ec256_public_t* pub_key, sgx_ec256_private_t* signing_priv_key, uint8_t* private_public_key_string)
 {
-  uint32_t counter;
-  for(counter=0;counter<SGX_ECP256_KEY_SIZE; counter++)
-    *(private_public_key_string+counter)=signing_priv_key->r[counter];
-
-  for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++)
-    *(private_public_key_string+counter)=pub_key->gx[counter-SGX_ECP256_KEY_SIZE];
-
-  for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
-    *(private_public_key_string+counter)=pub_key->gy[counter-2*SGX_ECP256_KEY_SIZE];
+  if(private_public_key_string != NULL)  // nowhere to serialize to
+  {
+     uint32_t counter;
+     if(pub_key != NULL)  // public key to serialize
+     {
+        for(counter=0;counter<SGX_ECP256_KEY_SIZE; counter++)
+          *(private_public_key_string+counter)=pub_key->gx[counter];
+
+        for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++)
+           *(private_public_key_string+counter)=pub_key->gy[counter-SGX_ECP256_KEY_SIZE];
+     }
+
+     if(signing_priv_key != NULL) // private key to serialize
+     {
+       for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
+          *(private_public_key_string+counter)=signing_priv_key->r[counter - 2*SGX_ECP256_KEY_SIZE];
+     }
+/*
+     if(pub_key != NULL)  // public key to serialize
+     {
+        for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++)
+          *(private_public_key_string+counter)=pub_key->gx[counter-SGX_ECP256_KEY_SIZE];
+
+        for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
+           *(private_public_key_string+counter)=pub_key->gy[counter-2*SGX_ECP256_KEY_SIZE];
+     }*/
+  }
 }
 
 
 // todo: set to private
 void deserialize_string_to_public_private_key_pair(uint8_t* private_public_key_string, sgx_ec256_public_t* pub_key, sgx_ec256_private_t* signing_priv_key)
 {
-  uint32_t counter;
-  for(counter=0;counter<SGX_ECP256_KEY_SIZE; counter++)
-    signing_priv_key->r[counter]=*(private_public_key_string+counter);
+  if(private_public_key_string != NULL) // nowhere to deserialize from 
+  {
+    uint32_t counter;
+    if(signing_priv_key != NULL) 
+    {
+
+     for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
+       signing_priv_key->r[counter-2*SGX_ECP256_KEY_SIZE]=*(private_public_key_string+counter);
+    }
 
-  for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++)
-    pub_key->gx[counter-SGX_ECP256_KEY_SIZE]=*(private_public_key_string+counter);
+    if(pub_key != NULL)
+    {
+      for(counter=0;counter<SGX_ECP256_KEY_SIZE; counter++)
+        	pub_key->gx[counter]=*(private_public_key_string+counter);
 
-  for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
-    pub_key->gy[counter-2*SGX_ECP256_KEY_SIZE]=*(private_public_key_string+counter);
+      for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++)
+  	pub_key->gy[counter-SGX_ECP256_KEY_SIZE]=*(private_public_key_string+counter);
+    }
+  }
 }