You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.7 KiB

  1. /*
  2. * Copyright (C) 2021 - 2022, Stephan Mueller <smueller@chronox.de>
  3. *
  4. * License: see LICENSE file in root directory
  5. *
  6. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  7. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  8. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
  9. * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
  10. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  11. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  12. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  13. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  14. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  16. * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
  17. * DAMAGE.
  18. */
  19. #ifndef JITTERENTROPY_SHA3_H
  20. #define JITTERENTROPY_SHA3_H
  21. #include "jitterentropy.h"
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. #define SHA3_SIZE_BLOCK(bits) ((1600 - 2 * bits) >> 3)
  27. #define SHA3_256_SIZE_BLOCK SHA3_SIZE_BLOCK(SHA3_256_SIZE_DIGEST_BITS)
  28. #define SHA3_MAX_SIZE_BLOCK SHA3_256_SIZE_BLOCK
  29. struct sha_ctx {
  30. uint64_t state[25];
  31. size_t msg_len;
  32. unsigned int r;
  33. unsigned int rword;
  34. unsigned int digestsize;
  35. uint8_t partial[SHA3_MAX_SIZE_BLOCK];
  36. };
  37. #define SHA_MAX_CTX_SIZE (sizeof(struct sha_ctx))
  38. #define HASH_CTX_ON_STACK(name) \
  39. struct sha_ctx name
  40. void sha3_256_init(struct sha_ctx *ctx);
  41. void sha3_update(struct sha_ctx *ctx, const uint8_t *in, size_t inlen);
  42. void sha3_final(struct sha_ctx *ctx, uint8_t *digest);
  43. int sha3_alloc(void **hash_state);
  44. void sha3_dealloc(void *hash_state);
  45. int sha3_tester(void);
  46. #ifdef __cplusplus
  47. }
  48. #endif
  49. #endif /* JITTERENTROPY_SHA3_H */