client.cpp 971 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "Enclave_t.h"
  2. #include "utils.hpp"
  3. #include "client.hpp"
  4. bool authenticateClient(unsigned char *auth_message,
  5. const sgx_aes_gcm_128bit_key_t *ckey)
  6. {
  7. int auth_success = 0;
  8. unsigned long epoch_no = *((unsigned long*) auth_message);
  9. auth_message+=(sizeof(unsigned long));
  10. unsigned char computed_auth[SGX_AESGCM_KEY_SIZE];
  11. unsigned char zeroes[SGX_AESGCM_KEY_SIZE] = {0};
  12. unsigned char iv[SGX_AESGCM_IV_SIZE] = {0};
  13. sgx_aes_gcm_128bit_tag_t mac;
  14. memcpy(iv, &epoch_no, sizeof(epoch_no));
  15. sgx_status_t ret = SGX_SUCCESS;
  16. ret = sgx_rijndael128GCM_encrypt(ckey, zeroes, SGX_AESGCM_KEY_SIZE,
  17. computed_auth, iv, SGX_AESGCM_IV_SIZE, NULL, 0, &mac);
  18. if(ret!=SGX_SUCCESS) {
  19. return false;
  20. }
  21. auth_success = memcmp(auth_message, computed_auth, SGX_AESGCM_KEY_SIZE);
  22. if(auth_success == 0) {
  23. return true;
  24. } else {
  25. printf("authentication FAIL\n");
  26. return false;
  27. }
  28. }