siphash.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef CCAN_SIPHASH_H_
  2. #define CCAN_SIPHASH_H_
  3. /* Licensed under GPL v2+ - see LICENSE file for details */
  4. /* Written in 2013 by Ulrik Sverdrup */
  5. #include <stdint.h>
  6. #include <stddef.h>
  7. /**
  8. * siphash - a keyed hash function
  9. *
  10. * SipHash-c-d, where `c` is the number of rounds per message chunk
  11. * and `d` the number of finalization rounds,
  12. * "is a family of pseudorandom functions optimized for speed on short
  13. * messages"
  14. *
  15. * Implemented from the paper https://131002.net/siphash/
  16. * The designers recommend using SipHash-2-4 or SipHash-4-8
  17. *
  18. * SipHash-c-d uses a 16-byte key.
  19. * To defend against hash-flooding, the application needs to use
  20. * a new random key regularly.
  21. *
  22. * The designers of SipHash claim it is cryptographically strong
  23. * to use as MAC with secret key but _not_collision_resistant_.
  24. *
  25. * Returns one 64-bit word as the hash function result.
  26. *
  27. * Example:
  28. * // Outputs cf2794e0277187b7
  29. * #include <stdio.h>
  30. * #include <ccan/siphash/siphash.h>
  31. *
  32. * int main(void)
  33. * {
  34. * unsigned char t_key[16] =
  35. * {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
  36. * unsigned char data[4] = "\0\1\2\3";
  37. * uint64_t hash = siphash_2_4(data, sizeof(data), t_key);
  38. * printf("%llx\n", (unsigned long long)hash);
  39. *
  40. * return 0;
  41. * }
  42. *
  43. */
  44. uint64_t siphash_2_4(const void *in, size_t len, const unsigned char key[16]);
  45. #endif /* CCAN_SIPHASH_H_ */