siphash.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_CRYPTO_SIPHASH_H
  10. # define OSSL_CRYPTO_SIPHASH_H
  11. # pragma once
  12. # include <stddef.h>
  13. # define SIPHASH_BLOCK_SIZE 8
  14. # define SIPHASH_KEY_SIZE 16
  15. # define SIPHASH_MIN_DIGEST_SIZE 8
  16. # define SIPHASH_MAX_DIGEST_SIZE 16
  17. typedef struct siphash_st SIPHASH;
  18. size_t SipHash_ctx_size(void);
  19. size_t SipHash_hash_size(SIPHASH *ctx);
  20. int SipHash_set_hash_size(SIPHASH *ctx, size_t hash_size);
  21. int SipHash_Init(SIPHASH *ctx, const unsigned char *k,
  22. int crounds, int drounds);
  23. void SipHash_Update(SIPHASH *ctx, const unsigned char *in, size_t inlen);
  24. int SipHash_Final(SIPHASH *ctx, unsigned char *out, size_t outlen);
  25. /* Based on https://131002.net/siphash C reference implementation */
  26. struct siphash_st {
  27. uint64_t total_inlen;
  28. uint64_t v0;
  29. uint64_t v1;
  30. uint64_t v2;
  31. uint64_t v3;
  32. unsigned int len;
  33. unsigned int hash_size;
  34. unsigned int crounds;
  35. unsigned int drounds;
  36. unsigned char leavings[SIPHASH_BLOCK_SIZE];
  37. };
  38. /* default: SipHash-2-4 */
  39. # define SIPHASH_C_ROUNDS 2
  40. # define SIPHASH_D_ROUNDS 4
  41. #endif