Tor 0.4.9.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-2021, The Tor Project, Inc. */
5/* See LICENSE for licensing information */
6
7/**
8 * \file crypto_dh.h
9 *
10 * \brief Headers for crypto_dh.c
11 **/
12
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
20typedef struct crypto_dh_t crypto_dh_t;
21
22extern const unsigned DH_GENERATOR;
23extern const char TLS_DH_PRIME[];
24extern 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
30void crypto_dh_init(void);
31crypto_dh_t *crypto_dh_new(int dh_type);
35int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out,
36 size_t pubkey_out_len);
37ssize_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
43ssize_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
48void crypto_dh_free_all(void);
49
50/* Prototypes for private functions only used by tortls.c, crypto.c, and the
51 * unit tests. */
52struct dh_st;
53struct dh_st *crypto_dh_new_openssl_tls(void);
54
55#ifdef ENABLE_OPENSSL
56void crypto_dh_init_openssl(void);
57void crypto_dh_free_all_openssl(void);
58#endif
59#ifdef ENABLE_NSS
60void crypto_dh_init_nss(void);
61void crypto_dh_free_all_nss(void);
62#endif
63
64#endif /* !defined(TOR_CRYPTO_DH_H) */
struct dh_st * crypto_dh_new_openssl_tls(void)
int crypto_dh_generate_public(crypto_dh_t *dh)
const char OAKLEY_PRIME_2[]
Definition: crypto_dh.c:39
void crypto_dh_free_(crypto_dh_t *dh)
crypto_dh_t * crypto_dh_new(int dh_type)
Definition: crypto_dh_nss.c:75
int crypto_dh_get_bytes(crypto_dh_t *dh)
Definition: crypto_dh_nss.c:95
const char TLS_DH_PRIME[]
Definition: crypto_dh.c:28
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)
int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out, size_t pubkey_out_len)
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
crypto_dh_t * crypto_dh_dup(const crypto_dh_t *dh)
Definition: crypto_dh_nss.c:83
void crypto_dh_init_openssl(void)
Definitions for sizes of Diffie-Hellman groups elements in Z_p.
Integer definitions used throughout Tor.