dpf.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef _DPF
  2. #define _DPF
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6. #include <openssl/conf.h>
  7. #include <openssl/evp.h>
  8. #include <openssl/err.h>
  9. #include <string.h>
  10. //defining these here
  11. //so they don't have to be repeated across okv and okvClient
  12. #define MAX_LAYERS 21
  13. #define MAX_DATA_SIZE 10000000
  14. #define MAX_THREADS 1024
  15. //use prime 2^128-159
  16. //so wrapping around involves a gap of size 159
  17. //from https://primes.utm.edu/lists/2small/100bit.html
  18. #define MODP (uint128_t) 159
  19. typedef __int128 int128_t;
  20. typedef unsigned __int128 uint128_t;
  21. void print_block(uint128_t input);
  22. //arithmetic mod P
  23. uint128_t addModP(uint128_t in1, uint128_t in2);
  24. uint128_t subModP(uint128_t in1, uint128_t in2);
  25. uint128_t multModP(uint128_t in1, uint128_t in2);
  26. uint128_t getRandomBlock(void);
  27. //DPF functions
  28. void dpfPRG(EVP_CIPHER_CTX *ctx, uint128_t input, uint128_t* output1, uint128_t* output2, int* bit1, int* bit2);
  29. void genDPF(EVP_CIPHER_CTX *ctx, int domainSize, uint128_t index, int dataSize, uint8_t* data, unsigned char** k0, unsigned char **k1);
  30. uint128_t evalDPF(EVP_CIPHER_CTX *ctx, unsigned char* k, uint128_t x, int dataSize, uint8_t* dataShare);
  31. //DPF checking functions
  32. void PRF(EVP_CIPHER_CTX *ctx, uint128_t seed, int layer, int count, uint128_t* output);
  33. void digest_message(const unsigned char *message, size_t message_len, unsigned char **digest, unsigned int *digest_len);
  34. //new auditing functions
  35. void clientGenProof(EVP_CIPHER_CTX *ctx, uint128_t seed, int index, uint128_t aShare, uint128_t bShare, uint8_t* outputsAIn, uint8_t* outputsBIn);
  36. void serverSetupProof(EVP_CIPHER_CTX *ctx, uint8_t *seedIn, int dbSize, uint8_t* vectorsIn, uint8_t* mIn, uint8_t* cIn);
  37. void serverComputeQuery(EVP_CIPHER_CTX *ctx, uint8_t *seedIn, uint8_t* mIn, uint8_t* cIn, uint8_t* proofIn, uint8_t* ansIn);
  38. int serverVerifyProof(uint8_t* ans1In, uint8_t* ans2In);
  39. uint128_t evalLinearR(uint128_t r, uint128_t p0, uint128_t p1);
  40. uint128_t evalQuadraticR(uint128_t r, uint128_t h0, uint128_t h1, uint128_t h2);
  41. //old auditing functions
  42. //client check inputs
  43. void clientVerify(EVP_CIPHER_CTX *ctx, uint128_t seed, int index, uint128_t aShare, uint128_t bShare, int dbLayers, uint8_t* bits, uint8_t* nonZeroVectorsIn);
  44. void riposteClientVerify(EVP_CIPHER_CTX *ctx, uint128_t seed, int dbSize, uint128_t *va, uint128_t *vb, uint8_t **digestA, uint8_t **digestB);
  45. //server check inputs
  46. void serverVerify(EVP_CIPHER_CTX *ctx, uint8_t *seedIn, int dbLayers, int dbSize, uint8_t* vectorsIn, uint8_t* outVectorsIn);
  47. void riposteServerVerify(EVP_CIPHER_CTX *ctx, uint128_t seed, int dbSize, uint128_t *vector, uint128_t *mVector, uint128_t *cValue);
  48. //auditor functionality
  49. int auditorVerify(int dbLayers, uint8_t* bits, uint8_t* nonZeroVectorsIn, uint8_t* outVectorsAIn, uint8_t* outVectorsBIn);
  50. int riposteAuditorVerify(uint8_t *digestA, uint8_t *digestB, uint8_t *ma, uint8_t *mb, uint128_t ca, uint128_t cb, int dbSize);
  51. #endif