tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

crypto_ope.h (1673B)


      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"
     14 #include "lib/crypt_ops/crypto_ope.h"
     15 #include "lib/testsupport/testsupport.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);
     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))
     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) */