Merge branch 'maint-0.3.5' into maint-0.4.5
[tor.git] / src / lib / crypt_ops / crypto_ope.h
blob7498ea6a2e4d22efef265913b5431d9da41c176b
1 /* Copyright (c) 2018-2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /**
5 * @file crypto_ope.h
6 * @brief header for crypto_ope.c
7 **/
9 #ifndef CRYPTO_OPE_H
10 #define CRYPTO_OPE_H
12 #include "orconfig.h"
13 #include "lib/cc/torint.h"
14 #include "lib/crypt_ops/crypto_ope.h"
15 #include "lib/testsupport/testsupport.h"
17 /** Length of OPE key, in bytes. */
18 #define OPE_KEY_LEN 32
20 /** Largest value that can be passed to crypto_ope_encrypt().
22 * Expressed as 2^18 because the OPE system prefers powers of two.
24 * The current max value stands for about 70 hours. The rationale here is as
25 * follows: The rev counter is the time of seconds since the start of an SRV
26 * period. SRVs are useful for about 48 hours (that's how long they stick
27 * around on the consensus). Let's also add 12 hours of drift for clock skewed
28 * services that might be using an old consensus and we arrive to 60
29 * hours. The max value should be beyond that.
31 #define OPE_INPUT_MAX (1<<18)
33 #define CRYPTO_OPE_ERROR UINT64_MAX
35 typedef struct crypto_ope_t crypto_ope_t;
37 crypto_ope_t *crypto_ope_new(const uint8_t *key);
38 void crypto_ope_free_(crypto_ope_t *ope);
39 #define crypto_ope_free(ope) \
40 FREE_AND_NULL(crypto_ope_t, crypto_ope_free_, (ope))
42 uint64_t crypto_ope_encrypt(const crypto_ope_t *ope, int plaintext);
44 #ifdef CRYPTO_OPE_PRIVATE
45 struct aes_cnt_cipher_t;
46 STATIC struct aes_cnt_cipher_t *ope_get_cipher(const crypto_ope_t *ope,
47 uint32_t initial_idx);
48 STATIC uint64_t sum_values_from_cipher(struct aes_cnt_cipher_t *c, size_t n);
49 #endif /* defined(CRYPTO_OPE_PRIVATE) */
51 #endif /* !defined(CRYPTO_OPE_H) */