ECDHKeypair.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #include <stdint.h>
  2. #include "ECDHKeypair.h"
  3. #include"Openssl_crypto.h"
  4. uint32_t ECDHKeypair::generate_keypair()
  5. {
  6. return ecdh_key_gen(public_key, public_key+SGX_ECP256_KEY_SIZE, private_key);
  7. }
  8. void ECDHKeypair::get_public_key(uint8_t* op_public_key)
  9. {
  10. uint32_t counter;
  11. for(counter=0 ; counter<ECDH_PUBLIC_KEY_SIZE; counter++)
  12. op_public_key[counter] = public_key[counter];
  13. }
  14. void ECDHKeypair::get_private_key(uint8_t* op_private_key)
  15. {
  16. uint32_t counter;
  17. for(counter=0; counter<ECDH_PRIVATE_KEY_SIZE; counter++)
  18. op_private_key[counter] = private_key[counter];
  19. }
  20. void ECDHKeypair::set_private_public_key(uint8_t* ip_private_key, uint8_t* ip_public_key)
  21. {
  22. // TODO: DO SOME CHECKS HERE - TO MAKE SURE THAT IT IS A VALID KEYPAIR
  23. // IT SHOULD BE AS IT WOULD HAVE BEEN GENERATED BY THIS MODULE AND IF IT HAD BEEN TAMPERED (WHILE BEING SEALED), THEN THE MAC WOULD NOT HAVE WORKED OUT.
  24. // BUT STILL...
  25. uint32_t counter;
  26. for(counter=0; counter<ECDH_PRIVATE_KEY_SIZE; counter++)
  27. private_key[counter] = ip_private_key[counter];
  28. for(counter=0 ; counter<ECDH_PUBLIC_KEY_SIZE; counter++)
  29. public_key[counter] = ip_public_key[counter];
  30. }