hashes.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * List of hashes for the brute force collision tester
  3. * Part of xxHash project
  4. * Copyright (C) 2019-2020 Yann Collet
  5. *
  6. * GPL v2 License
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * You can contact the author at:
  23. * - xxHash homepage: https://www.xxhash.com
  24. * - xxHash source repository: https://github.com/Cyan4973/xxHash
  25. */
  26. #ifndef HASHES_H_1235465
  27. #define HASHES_H_1235465
  28. #include <stddef.h> /* size_t */
  29. #include <stdint.h> /* uint64_t */
  30. #define XXH_INLINE_ALL /* XXH128_hash_t */
  31. #include "xxhash.h"
  32. /* return type */
  33. typedef union {
  34. uint64_t h64;
  35. XXH128_hash_t h128;
  36. } UniHash;
  37. UniHash uniHash32(uint64_t v32)
  38. { UniHash unih;
  39. unih.h64 = v32;
  40. return unih;
  41. }
  42. UniHash uniHash64(uint64_t v64)
  43. { UniHash unih;
  44. unih.h64 = v64;
  45. return unih;
  46. }
  47. UniHash uniHash128(XXH128_hash_t v128)
  48. { UniHash unih;
  49. unih.h128 = v128;
  50. return unih;
  51. }
  52. /* === xxHash === */
  53. UniHash XXH3_wrapper (const void* data, size_t size)
  54. {
  55. return uniHash64( XXH3_64bits(data, size) );
  56. }
  57. UniHash XXH128_wrapper (const void* data, size_t size)
  58. {
  59. return uniHash128( XXH3_128bits(data, size) );
  60. }
  61. UniHash XXH128l_wrapper (const void* data, size_t size)
  62. {
  63. return uniHash64( XXH3_128bits(data, size).low64 );
  64. }
  65. UniHash XXH128h_wrapper (const void* data, size_t size)
  66. {
  67. return uniHash64( XXH3_128bits(data, size).high64 );
  68. }
  69. UniHash XXH64_wrapper (const void* data, size_t size)
  70. {
  71. return uniHash64 ( XXH64(data, size, 0) );
  72. }
  73. UniHash XXH32_wrapper (const void* data, size_t size)
  74. {
  75. return uniHash32( XXH32(data, size, 0) );
  76. }
  77. /* === Dummy integration example === */
  78. #include "dummy.h"
  79. UniHash badsum32_wrapper (const void* data, size_t size)
  80. {
  81. return uniHash32( badsum32(data, size, 0) );
  82. }
  83. /* === Table === */
  84. typedef UniHash (*hashfn) (const void* data, size_t size);
  85. typedef struct {
  86. const char* name;
  87. hashfn fn;
  88. int bits;
  89. } hashDescription;
  90. #define HASH_FN_TOTAL 7
  91. hashDescription hashfnTable[HASH_FN_TOTAL] = {
  92. { "xxh3" , XXH3_wrapper, 64 },
  93. { "xxh64" , XXH64_wrapper, 64 },
  94. { "xxh128", XXH128_wrapper, 128 },
  95. { "xxh128l", XXH128l_wrapper, 64 },
  96. { "xxh128h", XXH128h_wrapper, 64 },
  97. { "xxh32" , XXH32_wrapper, 32 },
  98. { "badsum32",badsum32_wrapper, 32 },
  99. };
  100. #endif /* HASHES_H_1235465 */