okvClient.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "okvClient.h"
  2. #include <openssl/rand.h>
  3. #include <omp.h>
  4. #include <math.h>
  5. //for rand() mb i should not use this
  6. //people on the internet say its not cryptographically secure
  7. #include <stdlib.h>
  8. //cipher for ciphering
  9. EVP_CIPHER_CTX *ctx;
  10. //position where client will write to
  11. uint128_t position;
  12. void initializeCipher() {
  13. if(!(ctx = EVP_CIPHER_CTX_new()))
  14. printf("errors occured in creating context\n");
  15. //should use random key for real world application, this is only for testing
  16. unsigned char *aeskey = (unsigned char*) "0123456789123456";
  17. if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_128_ecb(), NULL, aeskey, NULL))
  18. printf("errors occured in init\n");
  19. EVP_CIPHER_CTX_set_padding(ctx, 0);
  20. }
  21. uint128_t prepQuery(int pos, int dbSize, uint8_t *dataToWrite, int dataSize, int *querySize, uint8_t **dpfQueryA, uint8_t **dpfQueryB){
  22. position = pos;
  23. *querySize = 1 + 16 + 1 + 18 * 128 + dataSize;
  24. genDPF(ctx, 128, position, dataSize, dataToWrite, dpfQueryA, dpfQueryB);
  25. return position;
  26. }
  27. void prepAudit(uint8_t *seed, uint8_t *outputsA, uint8_t *outputsB, uint8_t *dpfQueryA, uint8_t *dpfQueryB){
  28. uint128_t shareA;
  29. uint128_t shareB;
  30. //eval the dpf query at A and B and put results in shareA, shareB
  31. uint8_t temp[16];
  32. shareA = evalDPF(ctx, dpfQueryA, position, 16, temp);
  33. shareB = evalDPF(ctx, dpfQueryB, position, 16, temp);
  34. //call the auditing function
  35. clientGenProof(ctx, *(uint128_t*)seed, 0, shareA, shareB, outputsA, outputsB);
  36. }