hs_ident.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (c) 2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_ident.c
  5. * \brief Contains circuit and connection identifier code for the whole HS
  6. * subsytem.
  7. **/
  8. #include "hs_ident.h"
  9. /* Return a newly allocated circuit identifier. The given public key is copied
  10. * identity_pk into the identifier. */
  11. hs_ident_circuit_t *
  12. hs_ident_circuit_new(const ed25519_public_key_t *identity_pk,
  13. hs_ident_circuit_type_t circuit_type)
  14. {
  15. tor_assert(circuit_type == HS_IDENT_CIRCUIT_INTRO ||
  16. circuit_type == HS_IDENT_CIRCUIT_RENDEZVOUS);
  17. hs_ident_circuit_t *ident = tor_malloc_zero(sizeof(*ident));
  18. ed25519_pubkey_copy(&ident->identity_pk, identity_pk);
  19. ident->circuit_type = circuit_type;
  20. return ident;
  21. }
  22. /* Free the given circuit identifier. */
  23. void
  24. hs_ident_circuit_free(hs_ident_circuit_t *ident)
  25. {
  26. if (ident == NULL) {
  27. return;
  28. }
  29. memwipe(ident, 0, sizeof(hs_ident_circuit_t));
  30. tor_free(ident);
  31. }
  32. /* For a given directory connection identifier src, return a newly allocated
  33. * copy of it. This can't fail. */
  34. hs_ident_dir_conn_t *
  35. hs_ident_dir_conn_dup(const hs_ident_dir_conn_t *src)
  36. {
  37. hs_ident_dir_conn_t *ident = tor_malloc_zero(sizeof(*ident));
  38. memcpy(ident, src, sizeof(*ident));
  39. return ident;
  40. }
  41. /* Free the given directory connection identifier. */
  42. void
  43. hs_ident_dir_conn_free(hs_ident_dir_conn_t *ident)
  44. {
  45. if (ident == NULL) {
  46. return;
  47. }
  48. memwipe(ident, 0, sizeof(hs_ident_dir_conn_t));
  49. tor_free(ident);
  50. }
  51. /* Return a newly allocated edge connection identifier. The given public key
  52. * identity_pk is copied into the identifier. */
  53. hs_ident_edge_conn_t *
  54. hs_ident_edge_conn_new(const ed25519_public_key_t *identity_pk)
  55. {
  56. hs_ident_edge_conn_t *ident = tor_malloc_zero(sizeof(*ident));
  57. ed25519_pubkey_copy(&ident->identity_pk, identity_pk);
  58. return ident;
  59. }
  60. /* Free the given edge connection identifier. */
  61. void
  62. hs_ident_edge_conn_free(hs_ident_edge_conn_t *ident)
  63. {
  64. if (ident == NULL) {
  65. return;
  66. }
  67. memwipe(ident, 0, sizeof(hs_ident_edge_conn_t));
  68. tor_free(ident);
  69. }