kyber512r3_fips202.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include "kyber512r3_params.h"
  5. #define S2N_KYBER_512_R3_SHAKE128_RATE 168
  6. #define S2N_KYBER_512_R3_SHAKE256_RATE 136
  7. #define S2N_KYBER_512_R3_SHA3_256_RATE 136
  8. #define S2N_KYBER_512_R3_SHA3_384_RATE 104
  9. #define S2N_KYBER_512_R3_SHA3_512_RATE 72
  10. #define S2N_KYBER_512_R3_PQC_SHAKECTX_SIZE 25
  11. /* Context for non-incremental API */
  12. #define shake128ctx S2N_KYBER_512_R3_NAMESPACE(shake128ctx)
  13. typedef struct {
  14. uint64_t ctx[S2N_KYBER_512_R3_PQC_SHAKECTX_SIZE];
  15. } shake128ctx;
  16. /* Context for non-incremental API */
  17. #define shake256ctx S2N_KYBER_512_R3_NAMESPACE(shake256ctx)
  18. typedef struct {
  19. uint64_t ctx[S2N_KYBER_512_R3_PQC_SHAKECTX_SIZE];
  20. } shake256ctx;
  21. /* Initialize the state and absorb the provided input.
  22. *
  23. * This function does not support being called multiple times
  24. * with the same state.
  25. */
  26. #define shake128_absorb S2N_KYBER_512_R3_NAMESPACE(shake128_absorb)
  27. void shake128_absorb(shake128ctx *state, const uint8_t *input, size_t inlen);
  28. /* Squeeze output out of the sponge.
  29. *
  30. * Supports being called multiple times
  31. */
  32. #define shake128_squeezeblocks S2N_KYBER_512_R3_NAMESPACE(shake128_squeezeblocks)
  33. void shake128_squeezeblocks(uint8_t *output, size_t nblocks, shake128ctx *state);
  34. /* Copy the state. */
  35. #define shake128_ctx_clone S2N_KYBER_512_R3_NAMESPACE(shake128_ctx_clone)
  36. void shake128_ctx_clone(shake128ctx *dest, const shake128ctx *src);
  37. /* Initialize the state and absorb the provided input.
  38. *
  39. * This function does not support being called multiple times
  40. * with the same state.
  41. */
  42. #define shake256_absorb S2N_KYBER_512_R3_NAMESPACE(shake256_absorb)
  43. void shake256_absorb(shake256ctx *state, const uint8_t *input, size_t inlen);
  44. /* Squeeze output out of the sponge.
  45. *
  46. * Supports being called multiple times
  47. */
  48. #define shake256_squeezeblocks S2N_KYBER_512_R3_NAMESPACE(shake256_squeezeblocks)
  49. void shake256_squeezeblocks(uint8_t *output, size_t nblocks, shake256ctx *state);
  50. /* One-stop SHAKE256 call */
  51. #define shake256 S2N_KYBER_512_R3_NAMESPACE(shake256)
  52. void shake256(uint8_t *output, size_t outlen, const uint8_t *input, size_t inlen);
  53. #define sha3_256 S2N_KYBER_512_R3_NAMESPACE(sha3_256)
  54. void sha3_256(uint8_t *output, const uint8_t *input, size_t inlen);
  55. /* One-stop SHA3-512 shop */
  56. #define sha3_512 S2N_KYBER_512_R3_NAMESPACE(sha3_512)
  57. void sha3_512(uint8_t *output, const uint8_t *input, size_t inlen);