tor  0.4.0.0-alpha-dev
crypto_dh.h
Go to the documentation of this file.
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-2018, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
13 #ifndef TOR_CRYPTO_DH_H
14 #define TOR_CRYPTO_DH_H
15 
16 #include "orconfig.h"
17 #include "lib/cc/torint.h"
18 #include "lib/defs/dh_sizes.h"
19 
20 typedef struct crypto_dh_t crypto_dh_t;
21 
22 extern const unsigned DH_GENERATOR;
23 extern const char TLS_DH_PRIME[];
24 extern const char OAKLEY_PRIME_2[];
25 
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);
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);
41 #define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh_t, crypto_dh_free_, (dh))
42 
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);
47 
48 void crypto_dh_free_all(void);
49 
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);
54 
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
63 
64 #endif /* !defined(TOR_CRYPTO_DH_H) */
const char OAKLEY_PRIME_2[]
Definition: crypto_dh.c:39
void crypto_dh_free_(crypto_dh_t *dh)
struct dh_st * crypto_dh_new_openssl_tls(void)
const char TLS_DH_PRIME[]
Definition: crypto_dh.c:28
crypto_dh_t * crypto_dh_dup(const crypto_dh_t *dh)
Definition: crypto_dh_nss.c:81
int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out, size_t pubkey_out_len)
Integer definitions used throughout Tor.
int crypto_dh_generate_public(crypto_dh_t *dh)
Definitions for sizes of Diffie-Hellman groups elements in Z_p.
void crypto_dh_init_openssl(void)
const unsigned DH_GENERATOR
Definition: crypto_dh.c:23
ssize_t crypto_dh_handshake(int severity, crypto_dh_t *dh, const char *pubkey, size_t pubkey_len, unsigned char *secret_out, size_t secret_bytes_out)
crypto_dh_t * crypto_dh_new(int dh_type)
Definition: crypto_dh_nss.c:73
int crypto_dh_get_bytes(crypto_dh_t *dh)
Definition: crypto_dh_nss.c:93
ssize_t crypto_dh_compute_secret(int severity, crypto_dh_t *dh, const char *pubkey, size_t pubkey_len, char *secret_out, size_t secret_out_len)
Definition: crypto_dh.c:79