rehash_crypto.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* GNU Guix --- Functional package management for GNU
  2. Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
  3. This file is part of GNU Guix.
  4. GNU Guix is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or (at
  7. your option) any later version.
  8. GNU Guix is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
  14. /**
  15. * @brief Some DHT query encryption
  16. * @author Maxime Devos
  17. */
  18. #ifndef GNUNET_REHASH_CRYPTO_H
  19. #define GNUNET_REHASH_CRYPTO_H
  20. #include "rehash_types.h"
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #if 0
  25. }
  26. #endif
  27. #endif
  28. /**
  29. * Almost calculate the DHT query for finding a hash of type @a out_type
  30. * given the hash @a data of a certain @a in_type, except for the
  31. * final obfuscation step.
  32. *
  33. * The hash types do not have to be known to GNUnet-rehash.
  34. *
  35. * @param out_type hash type to try to find
  36. * @param in_type known hash type
  37. * @param data hash of type @a in_type
  38. * @param length length of @a data
  39. * @param query hash to use for query (output paramater)
  40. * @return #GNUNET_OK in case of success, #GNUNET_NO
  41. * in case no DHT query is defined
  42. */
  43. int
  44. GNUNET_REHASH_cleartext_query_from_hash (
  45. enum GNUNET_REHASH_Hash_Type out_type,
  46. enum GNUNET_REHASH_Hash_Type in_type,
  47. const char *data,
  48. size_t data_size,
  49. struct GNUNET_HashCode *query);
  50. /**
  51. * Calculate the DHT query for finding a hash of type @a out_type
  52. * given the hash @a data of a certain @a in_type
  53. *
  54. * The hash types do not have to be known to GNUnet-rehash.
  55. *
  56. * @param out_type hash type to try to find
  57. * @param in_type known hash type
  58. * @param data hash of type @a in_type
  59. * @param length length of @a data
  60. * @param query hash to use for query (output paramater)
  61. * @return #GNUNET_OK in case of success, #GNUNET_NO
  62. * in case no DHT query is defined
  63. */
  64. int
  65. GNUNET_REHASH_obfuscated_query_from_hash (
  66. enum GNUNET_REHASH_Hash_Type out_type,
  67. enum GNUNET_REHASH_Hash_Type in_type,
  68. const char *data,
  69. size_t data_size,
  70. struct GNUNET_HashCode *query);
  71. /**
  72. * Calculate how many bytes we will need to serialize
  73. * the hash_in -> hash_out mapping into data suitable
  74. * to put ito the DHT.
  75. *
  76. * @param out_size size of hash to find
  77. * @return the required size to serialize the serialized data,
  78. * something strictly negative on error
  79. */
  80. static inline ssize_t
  81. GNUNET_REHASH_data_size_for_mapping (size_t out_size)
  82. {
  83. if (out_size > 64)
  84. return -1;
  85. return out_size;
  86. }
  87. /**
  88. * Serialize the data to put into the DHT into a given destination buffer
  89. *
  90. * @param out_type hash type to search for
  91. * @param in_type hash type of hash to query with
  92. * @param out_data hash of type @a out_type
  93. * @param in_data hash of type @a in_type
  94. * @param out_size size of @a out_data buffer
  95. * @param in_size size of @a in_data buffer
  96. * @param dest where to write output
  97. * @param dest_size size of @a dest buffer
  98. * @return the size of the serialized data,
  99. * -1 if data doesn't fit and in case
  100. * of unreasonable inputs
  101. */
  102. ssize_t
  103. GNUNET_REHASH_data_for_mapping (
  104. enum GNUNET_REHASH_Hash_Type out_type,
  105. enum GNUNET_REHASH_Hash_Type in_type,
  106. const char *out_data,
  107. const char *in_data,
  108. size_t out_size,
  109. size_t in_size,
  110. char *dest,
  111. size_t dest_size);
  112. /**
  113. * Deserialize data put into the DHT
  114. *
  115. * The hash type doesn't have to be known to GNUnet-rehash.
  116. * Corollary: output length may be bogus (even for
  117. * known hash types), even upon ‘successful’ returns.
  118. *
  119. * @param out_type hash type searched for
  120. * @param in_type hash type searched with
  121. * @param in_data hash of type @a in_type
  122. * @param in_size size of @a in_data
  123. * @param dht_data data found in the DHT
  124. * @param dht_size size of @a dht_data and @a cleartext
  125. * @param cleartext (output parameter) hash found in the DHT
  126. * @returns #GNUNET_OK on success, #GNUNET_NO in case of some
  127. * validation error
  128. */
  129. int
  130. GNUNET_REHASH_mapping_for_data (
  131. enum GNUNET_REHASH_Hash_Type out_type,
  132. enum GNUNET_REHASH_Hash_Type in_type,
  133. const char *in_data,
  134. size_t in_size,
  135. const char *dht_data,
  136. size_t dht_size,
  137. char *clearhash);
  138. #if 0
  139. {
  140. #endif
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif