utils.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <string>
  6. #include <cstdint>
  7. #include <random>
  8. #include <openssl/ec.h>
  9. #include <openssl/ecdh.h>
  10. #include <openssl/ecdsa.h>
  11. #include <openssl/conf.h>
  12. #include <openssl/evp.h>
  13. #include <openssl/err.h>
  14. #include <openssl/obj_mac.h>
  15. #define HASH_LENGTH 32
  16. #define NONCE_LENGTH 16
  17. #define KEY_LENGTH 16
  18. #define MILLION 1E6
  19. #define IV_LENGTH 12
  20. #define EC_KEY_SIZE 32
  21. #define KEY_LENGTH 16
  22. #define TAG_SIZE 16
  23. #define CLOCKS_PER_MS (CLOCKS_PER_SEC/1000)
  24. #define AES_GCM_BLOCK_SIZE_IN_BYTES 16
  25. #define PRIME256V1_KEY_SIZE 32
  26. #define BLINDED_KEY_SIZE 32
  27. // (Largest value size we have seen so far was 14200)
  28. #define DESCRIPTOR_MAX_SIZE 16384
  29. using namespace std;
  30. int AES_GCM_128_encrypt (unsigned char *plaintext, int plaintext_len, unsigned char *aad,
  31. int aad_len, unsigned char *key, unsigned char *iv, int iv_len,
  32. unsigned char *ciphertext, unsigned char *tag);
  33. int AES_GCM_128_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *aad,
  34. int aad_len, unsigned char *tag, unsigned char *key, unsigned char *iv,
  35. int iv_len, unsigned char *plaintext);
  36. int32_t serializeLSORAMRequest(unsigned char *key, uint32_t key_size,
  37. unsigned char *value, uint32_t value_size, unsigned char** serialized_request);
  38. int ECDH_encrypt(const string &plain_request, uint32_t request_size,const string &params, string &shared_secret, string &encrypted_request);