crypto_ope.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (c) 2018-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef CRYPTO_OPE_H
  4. #define CRYPTO_OPE_H
  5. #include "orconfig.h"
  6. #include "lib/cc/torint.h"
  7. #include "lib/crypt_ops/crypto_ope.h"
  8. #include "lib/testsupport/testsupport.h"
  9. /** Length of OPE key, in bytes. */
  10. #define OPE_KEY_LEN 32
  11. /** Largest value that can be passed to crypto_ope_encrypt().
  12. *
  13. * Expressed as 2^18 because the OPE system prefers powers of two.
  14. *
  15. * The current max value stands for about 70 hours. The rationale here is as
  16. * follows: The rev counter is the time of seconds since the start of an SRV
  17. * period. SRVs are useful for about 48 hours (that's how long they stick
  18. * around on the consensus). Let's also add 12 hours of drift for clock skewed
  19. * services that might be using an old consensus and we arrive to 60
  20. * hours. The max value should be beyond that.
  21. */
  22. #define OPE_INPUT_MAX (1<<18)
  23. #define CRYPTO_OPE_ERROR UINT64_MAX
  24. typedef struct crypto_ope_t crypto_ope_t;
  25. crypto_ope_t *crypto_ope_new(const uint8_t *key);
  26. void crypto_ope_free_(crypto_ope_t *ope);
  27. #define crypto_ope_free(ope) \
  28. FREE_AND_NULL(crypto_ope_t, crypto_ope_free_, (ope))
  29. uint64_t crypto_ope_encrypt(const crypto_ope_t *ope, int plaintext);
  30. #ifdef CRYPTO_OPE_PRIVATE
  31. struct aes_cnt_cipher;
  32. STATIC struct aes_cnt_cipher *ope_get_cipher(const crypto_ope_t *ope,
  33. uint32_t initial_idx);
  34. STATIC uint64_t sum_values_from_cipher(struct aes_cnt_cipher *c, size_t n);
  35. #endif
  36. #endif