testvector.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // testvector.h
  2. //
  3. // The MIT License (MIT)
  4. //
  5. // Copyright (c) 2015 J. Andrew Rogers
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in all
  15. // copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. // SOFTWARE.
  24. //
  25. #ifndef METROHASH_TESTVECTOR_H
  26. #define METROHASH_TESTVECTOR_H
  27. #include "metrohash.h"
  28. typedef void (*HashFunction) (const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * hash);
  29. struct TestVectorData
  30. {
  31. HashFunction function;
  32. uint32_t bits;
  33. const char * key;
  34. uint32_t seed;
  35. uint8_t hash[64];
  36. };
  37. // The test vector string is selected such that it will properly exercise every
  38. // internal branch of the hash function. Currently that requires a string with
  39. // a length of (at least) 63 bytes.
  40. static const char * test_key_63 = "012345678901234567890123456789012345678901234567890123456789012";
  41. // The hash assumes a little-endian architecture. Treating the hash results
  42. // as an array of uint64_t should enable conversion for big-endian implementations.
  43. const TestVectorData TestVector [] =
  44. {
  45. // seed = 0
  46. { metrohash64_1, 64, test_key_63, 0, "658F044F5C730E40" },
  47. { metrohash64_2, 64, test_key_63, 0, "073CAAB960623211" },
  48. { metrohash128_1, 128, test_key_63, 0, "ED9997ED9D0A8B0FF3F266399477788F" },
  49. { metrohash128_2, 128, test_key_63, 0, "7BBA6FE119CF35D45507EDF3505359AB" },
  50. { metrohash128crc_1, 128, test_key_63, 0, "B329ED67831604D3DFAC4E4876D8262F" },
  51. { metrohash128crc_2, 128, test_key_63, 0, "0502A67E257BBD77206BBCA6BBEF2653" },
  52. // seed = 1
  53. { metrohash64_1, 64, test_key_63, 1, "AE49EBB0A856537B" },
  54. { metrohash64_2, 64, test_key_63, 1, "CF518E9CF58402C0" },
  55. { metrohash128_1, 128, test_key_63, 1, "DDA6BA67F7DE755EFDF6BEABECCFD1F4" },
  56. { metrohash128_2, 128, test_key_63, 1, "2DA6AF149A5CDBC12B09DB0846D69EF0" },
  57. { metrohash128crc_1, 128, test_key_63, 1, "E8FAB51AF19F18A7B10D0A57D4276DF2" },
  58. { metrohash128crc_2, 128, test_key_63, 1, "2D54F87181A0CF64B02C50D95692BC19" },
  59. };
  60. #endif // #ifndef METROHASH_TESTVECTOR_H