crypto_dh.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file crypto_dh.h
  8. *
  9. * \brief Headers for crypto_dh.c
  10. **/
  11. #ifndef TOR_CRYPTO_DH_H
  12. #define TOR_CRYPTO_DH_H
  13. #include "orconfig.h"
  14. #include "lib/cc/torint.h"
  15. #include "lib/defs/dh_sizes.h"
  16. typedef struct crypto_dh_t crypto_dh_t;
  17. extern const unsigned DH_GENERATOR;
  18. extern const char TLS_DH_PRIME[];
  19. extern const char OAKLEY_PRIME_2[];
  20. /* Key negotiation */
  21. #define DH_TYPE_CIRCUIT 1
  22. #define DH_TYPE_REND 2
  23. #define DH_TYPE_TLS 3
  24. void crypto_dh_init(void);
  25. crypto_dh_t *crypto_dh_new(int dh_type);
  26. crypto_dh_t *crypto_dh_dup(const crypto_dh_t *dh);
  27. int crypto_dh_get_bytes(crypto_dh_t *dh);
  28. int crypto_dh_generate_public(crypto_dh_t *dh);
  29. int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out,
  30. size_t pubkey_out_len);
  31. ssize_t crypto_dh_compute_secret(int severity, crypto_dh_t *dh,
  32. const char *pubkey, size_t pubkey_len,
  33. char *secret_out, size_t secret_out_len);
  34. void crypto_dh_free_(crypto_dh_t *dh);
  35. #define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh_t, crypto_dh_free_, (dh))
  36. ssize_t crypto_dh_handshake(int severity, crypto_dh_t *dh,
  37. const char *pubkey, size_t pubkey_len,
  38. unsigned char *secret_out,
  39. size_t secret_bytes_out);
  40. void crypto_dh_free_all(void);
  41. /* Prototypes for private functions only used by tortls.c, crypto.c, and the
  42. * unit tests. */
  43. struct dh_st;
  44. struct dh_st *crypto_dh_new_openssl_tls(void);
  45. #ifdef ENABLE_OPENSSL
  46. void crypto_dh_init_openssl(void);
  47. void crypto_dh_free_all_openssl(void);
  48. #endif
  49. #ifdef ENABLE_NSS
  50. void crypto_dh_init_nss(void);
  51. void crypto_dh_free_all_nss(void);
  52. #endif
  53. #endif /* !defined(TOR_CRYPTO_DH_H) */