dirvote: Fix memleak when computing consensus
[tor.git] / src / lib / crypt_ops / crypto_dh.h
blob60835663068cc0180dd22bb021e7f7482fbf4c71
1 /* Copyright (c) 2001, Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file crypto_dh.h
10 * \brief Headers for crypto_dh.c
11 **/
13 #ifndef TOR_CRYPTO_DH_H
14 #define TOR_CRYPTO_DH_H
16 #include "orconfig.h"
17 #include "lib/cc/torint.h"
18 #include "lib/defs/dh_sizes.h"
20 typedef struct crypto_dh_t crypto_dh_t;
22 extern const unsigned DH_GENERATOR;
23 extern const char TLS_DH_PRIME[];
24 extern const char OAKLEY_PRIME_2[];
26 /* Key negotiation */
27 #define DH_TYPE_CIRCUIT 1
28 #define DH_TYPE_REND 2
29 #define DH_TYPE_TLS 3
30 void crypto_dh_init(void);
31 crypto_dh_t *crypto_dh_new(int dh_type);
32 crypto_dh_t *crypto_dh_dup(const crypto_dh_t *dh);
33 int crypto_dh_get_bytes(crypto_dh_t *dh);
34 int crypto_dh_generate_public(crypto_dh_t *dh);
35 int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out,
36 size_t pubkey_out_len);
37 ssize_t crypto_dh_compute_secret(int severity, crypto_dh_t *dh,
38 const char *pubkey, size_t pubkey_len,
39 char *secret_out, size_t secret_out_len);
40 void crypto_dh_free_(crypto_dh_t *dh);
41 #define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh_t, crypto_dh_free_, (dh))
43 ssize_t crypto_dh_handshake(int severity, crypto_dh_t *dh,
44 const char *pubkey, size_t pubkey_len,
45 unsigned char *secret_out,
46 size_t secret_bytes_out);
48 void crypto_dh_free_all(void);
50 /* Prototypes for private functions only used by tortls.c, crypto.c, and the
51 * unit tests. */
52 struct dh_st;
53 struct dh_st *crypto_dh_new_openssl_tls(void);
55 #ifdef ENABLE_OPENSSL
56 void crypto_dh_init_openssl(void);
57 void crypto_dh_free_all_openssl(void);
58 #endif
59 #ifdef ENABLE_NSS
60 void crypto_dh_init_nss(void);
61 void crypto_dh_free_all_nss(void);
62 #endif
64 #endif /* !defined(TOR_CRYPTO_DH_H) */