algorithms.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* algorithms.h - rhash library algorithms */
  2. #ifndef RHASH_ALGORITHMS_H
  3. #define RHASH_ALGORITHMS_H
  4. #include "rhash.h"
  5. #include "byte_order.h"
  6. #include <stddef.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #ifndef RHASH_API
  11. /* modifier for RHash library functions */
  12. # define RHASH_API
  13. #endif
  14. /**
  15. * Bit flag: default hash output format is base32.
  16. */
  17. #define RHASH_INFO_BASE32 1
  18. /**
  19. * Information about a hash function.
  20. */
  21. typedef struct rhash_info
  22. {
  23. /**
  24. * Hash function indentifier.
  25. */
  26. unsigned hash_id;
  27. /**
  28. * Flags bit-mask, including RHASH_INFO_BASE32 bit.
  29. */
  30. unsigned flags;
  31. /**
  32. The size of of the raw message digest in bytes.
  33. */
  34. size_t digest_size;
  35. /**
  36. * The hash function name.
  37. */
  38. const char* name;
  39. /**
  40. * The corresponding paramenter name in a magnet link.
  41. */
  42. const char* magnet_name;
  43. } rhash_info;
  44. typedef void (*pinit_t)(void*);
  45. typedef void (*pupdate_t)(void* ctx, const void* msg, size_t size);
  46. typedef void (*pfinal_t)(void*, unsigned char*);
  47. typedef void (*pcleanup_t)(void*);
  48. /**
  49. * Information about a hash function
  50. */
  51. typedef struct rhash_hash_info
  52. {
  53. rhash_info* info;
  54. size_t context_size;
  55. ptrdiff_t digest_diff;
  56. pinit_t init;
  57. pupdate_t update;
  58. pfinal_t final;
  59. pcleanup_t cleanup;
  60. } rhash_hash_info;
  61. /**
  62. * Information on a hash function and its context
  63. */
  64. typedef struct rhash_vector_item
  65. {
  66. struct rhash_hash_info* hash_info;
  67. void* context;
  68. } rhash_vector_item;
  69. /**
  70. * The rhash context containing contexts for several hash functions
  71. */
  72. typedef struct rhash_context_ext
  73. {
  74. struct rhash_context rc;
  75. unsigned hash_vector_size; /* number of contained hash sums */
  76. unsigned flags;
  77. unsigned state;
  78. void* callback;
  79. void* callback_data;
  80. void* bt_ctx;
  81. rhash_vector_item vector[1]; /* contexts of contained hash sums */
  82. } rhash_context_ext;
  83. extern rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT];
  84. extern rhash_hash_info* rhash_info_table;
  85. extern int rhash_info_size;
  86. extern unsigned rhash_uninitialized_algorithms;
  87. extern rhash_info info_crc32;
  88. extern rhash_info info_crc32c;
  89. extern rhash_info info_md4;
  90. extern rhash_info info_md5;
  91. extern rhash_info info_sha1;
  92. extern rhash_info info_tiger;
  93. extern rhash_info info_tth ;
  94. extern rhash_info info_btih;
  95. extern rhash_info info_ed2k;
  96. extern rhash_info info_aich;
  97. extern rhash_info info_whirlpool;
  98. extern rhash_info info_rmd160;
  99. extern rhash_info info_gost;
  100. extern rhash_info info_gostpro;
  101. extern rhash_info info_has160;
  102. extern rhash_info info_snf128;
  103. extern rhash_info info_snf256;
  104. extern rhash_info info_sha224;
  105. extern rhash_info info_sha256;
  106. extern rhash_info info_sha384;
  107. extern rhash_info info_sha512;
  108. extern rhash_info info_sha3_224;
  109. extern rhash_info info_sha3_256;
  110. extern rhash_info info_sha3_384;
  111. extern rhash_info info_sha3_512;
  112. extern rhash_info info_edr256;
  113. extern rhash_info info_edr512;
  114. /* rhash_info flags */
  115. #define F_BS32 1 /* default output in base32 */
  116. #define F_SWAP32 2 /* Big endian flag */
  117. #define F_SWAP64 4
  118. /* define endianness flags */
  119. #if IS_LITTLE_ENDIAN
  120. #define F_LE32 0
  121. #define F_LE64 0
  122. #define F_BE32 F_SWAP32
  123. #define F_BE64 F_SWAP64
  124. #else
  125. #define F_LE32 F_SWAP32
  126. #define F_LE64 F_SWAP64
  127. #define F_BE32 0
  128. #define F_BE64 0
  129. #endif
  130. void rhash_init_algorithms(unsigned mask);
  131. const rhash_info* rhash_info_by_id(unsigned hash_id); /* get hash sum info by hash id */
  132. #if defined(OPENSSL_RUNTIME) && !defined(USE_OPENSSL)
  133. # define USE_OPENSSL
  134. #endif
  135. #ifdef __cplusplus
  136. } /* extern "C" */
  137. #endif /* __cplusplus */
  138. #endif /* RHASH_ALGORITHMS_H */