crypto_dh.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. /**
  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 "common/util.h"
  14. /** Length of our DH keys. */
  15. #define DH_BYTES (1024/8)
  16. typedef struct crypto_dh_t crypto_dh_t;
  17. /* Key negotiation */
  18. #define DH_TYPE_CIRCUIT 1
  19. #define DH_TYPE_REND 2
  20. #define DH_TYPE_TLS 3
  21. void crypto_set_tls_dh_prime(void);
  22. crypto_dh_t *crypto_dh_new(int dh_type);
  23. crypto_dh_t *crypto_dh_dup(const crypto_dh_t *dh);
  24. int crypto_dh_get_bytes(crypto_dh_t *dh);
  25. int crypto_dh_generate_public(crypto_dh_t *dh);
  26. int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out,
  27. size_t pubkey_out_len);
  28. ssize_t crypto_dh_compute_secret(int severity, crypto_dh_t *dh,
  29. const char *pubkey, size_t pubkey_len,
  30. char *secret_out, size_t secret_out_len);
  31. void crypto_dh_free_(crypto_dh_t *dh);
  32. #define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh_t, crypto_dh_free_, (dh))
  33. /* Crypto DH free */
  34. void crypto_dh_free_all(void);
  35. /* Prototypes for private functions only used by tortls.c, crypto.c, and the
  36. * unit tests. */
  37. struct dh_st;
  38. struct dh_st *crypto_dh_get_dh_(crypto_dh_t *dh);
  39. #endif /* !defined(TOR_CRYPTO_DH_H) */