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 */
10 * \brief Headers for crypto_dh.c
13 #ifndef TOR_CRYPTO_DH_H
14 #define TOR_CRYPTO_DH_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
[];
27 #define DH_TYPE_CIRCUIT 1
28 #define DH_TYPE_REND 2
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
53 struct dh_st
*crypto_dh_new_openssl_tls(void);
56 void crypto_dh_init_openssl(void);
57 void crypto_dh_free_all_openssl(void);
60 void crypto_dh_init_nss(void);
61 void crypto_dh_free_all_nss(void);
64 #endif /* !defined(TOR_CRYPTO_DH_H) */