|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|