Tor  0.4.7.0-alpha-dev
crypto_ope.h
Go to the documentation of this file.
1 /* Copyright (c) 2018-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * @file crypto_ope.h
6  * @brief header for crypto_ope.c
7  **/
8 
9 #ifndef CRYPTO_OPE_H
10 #define CRYPTO_OPE_H
11 
12 #include "orconfig.h"
13 #include "lib/cc/torint.h"
16 
17 /** Length of OPE key, in bytes. */
18 #define OPE_KEY_LEN 32
19 
20 /** Largest value that can be passed to crypto_ope_encrypt().
21  *
22  * Expressed as 2^18 because the OPE system prefers powers of two.
23  *
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.
30  */
31 #define OPE_INPUT_MAX (1<<18)
32 
33 #define CRYPTO_OPE_ERROR UINT64_MAX
34 
35 typedef struct crypto_ope_t crypto_ope_t;
36 
37 crypto_ope_t *crypto_ope_new(const uint8_t *key);
39 #define crypto_ope_free(ope) \
40  FREE_AND_NULL(crypto_ope_t, crypto_ope_free_, (ope))
41 
42 uint64_t crypto_ope_encrypt(const crypto_ope_t *ope, int plaintext);
43 
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) */
50 
51 #endif /* !defined(CRYPTO_OPE_H) */
STATIC crypto_cipher_t * ope_get_cipher(const crypto_ope_t *ope, uint32_t initial_idx)
Definition: crypto_ope.c:73
STATIC uint64_t sum_values_from_cipher(crypto_cipher_t *c, size_t n)
Definition: crypto_ope.c:97
header for crypto_ope.c
crypto_ope_t * crypto_ope_new(const uint8_t *key)
Definition: crypto_ope.c:129
void crypto_ope_free_(crypto_ope_t *ope)
Definition: crypto_ope.c:149
uint64_t crypto_ope_encrypt(const crypto_ope_t *ope, int plaintext)
Definition: crypto_ope.c:165
uint8_t key[OPE_KEY_LEN]
Definition: crypto_ope.c:43
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
Integer definitions used throughout Tor.