Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

168 linhas
5.4 KiB

  1. #ifndef FIPS202_H
  2. #define FIPS202_H
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #define SHAKE128_RATE 168
  6. #define SHAKE256_RATE 136
  7. #define SHA3_256_RATE 136
  8. #define SHA3_384_RATE 104
  9. #define SHA3_512_RATE 72
  10. #define PQC_SHAKEINCCTX_BYTES (sizeof(uint64_t)*26)
  11. #define PQC_SHAKECTX_BYTES (sizeof(uint64_t)*25)
  12. // Context for incremental API
  13. typedef struct {
  14. uint64_t* ctx;
  15. } shake128incctx;
  16. // Context for non-incremental API
  17. typedef struct {
  18. uint64_t* ctx;
  19. } shake128ctx;
  20. // Context for incremental API
  21. typedef struct {
  22. uint64_t* ctx;
  23. } shake256incctx;
  24. // Context for non-incremental API
  25. typedef struct {
  26. uint64_t* ctx;
  27. } shake256ctx;
  28. // Context for incremental API
  29. typedef struct {
  30. uint64_t* ctx;
  31. } sha3_256incctx;
  32. // Context for incremental API
  33. typedef struct {
  34. uint64_t* ctx;
  35. } sha3_384incctx;
  36. // Context for incremental API
  37. typedef struct {
  38. uint64_t* ctx;
  39. } sha3_512incctx;
  40. /* Initialize the state and absorb the provided input.
  41. *
  42. * This function does not support being called multiple times
  43. * with the same state.
  44. */
  45. void shake128_absorb(shake128ctx *state, const uint8_t *input, size_t inlen);
  46. /* Squeeze output out of the sponge.
  47. *
  48. * Supports being called multiple times
  49. */
  50. void shake128_squeezeblocks(uint8_t *output, size_t nblocks, shake128ctx *state);
  51. /* Free the state */
  52. void shake128_ctx_release(shake128ctx *state);
  53. /* Copy the state. */
  54. void shake128_ctx_clone(shake128ctx *dest, const shake128ctx *src);
  55. /* Initialize incremental hashing API */
  56. void shake128_inc_init(shake128incctx *state);
  57. /* Absorb more information into the XOF.
  58. *
  59. * Can be called multiple times.
  60. */
  61. void shake128_inc_absorb(shake128incctx *state, const uint8_t *input, size_t inlen);
  62. /* Finalize the XOF for squeezing */
  63. void shake128_inc_finalize(shake128incctx *state);
  64. /* Squeeze output out of the sponge.
  65. *
  66. * Supports being called multiple times
  67. */
  68. void shake128_inc_squeeze(uint8_t *output, size_t outlen, shake128incctx *state);
  69. /* Copy the context of the SHAKE128 XOF */
  70. void shake128_inc_ctx_clone(shake128incctx* dest, const shake128incctx *src);
  71. /* Free the context of the SHAKE128 XOF */
  72. void shake128_inc_ctx_release(shake128incctx *state);
  73. /* Initialize the state and absorb the provided input.
  74. *
  75. * This function does not support being called multiple times
  76. * with the same state.
  77. */
  78. void shake256_absorb(shake256ctx *state, const uint8_t *input, size_t inlen);
  79. /* Squeeze output out of the sponge.
  80. *
  81. * Supports being called multiple times
  82. */
  83. void shake256_squeezeblocks(uint8_t *output, size_t nblocks, shake256ctx *state);
  84. /* Free the context held by this XOF */
  85. void shake256_ctx_release(shake256ctx *state);
  86. /* Copy the context held by this XOF */
  87. void shake256_ctx_clone(shake256ctx *dest, const shake256ctx *src);
  88. /* Initialize incremental hashing API */
  89. void shake256_inc_init(shake256incctx *state);
  90. void shake256_inc_absorb(shake256incctx *state, const uint8_t *input, size_t inlen);
  91. /* Prepares for squeeze phase */
  92. void shake256_inc_finalize(shake256incctx *state);
  93. /* Squeeze output out of the sponge.
  94. *
  95. * Supports being called multiple times
  96. */
  97. void shake256_inc_squeeze(uint8_t *output, size_t outlen, shake256incctx *state);
  98. /* Copy the state */
  99. void shake256_inc_ctx_clone(shake256incctx* dest, const shake256incctx *src);
  100. /* Free the state */
  101. void shake256_inc_ctx_release(shake256incctx *state);
  102. /* One-stop SHAKE128 call */
  103. void shake128(uint8_t *output, size_t outlen,
  104. const uint8_t *input, size_t inlen);
  105. /* One-stop SHAKE256 call */
  106. void shake256(uint8_t *output, size_t outlen,
  107. const uint8_t *input, size_t inlen);
  108. /* Initialize the incremental hashing state */
  109. void sha3_256_inc_init(sha3_256incctx *state);
  110. /* Absorb blocks into SHA3 */
  111. void sha3_256_inc_absorb(sha3_256incctx *state, const uint8_t *input, size_t inlen);
  112. /* Obtain the output of the function and free `state` */
  113. void sha3_256_inc_finalize(uint8_t *output, sha3_256incctx *state);
  114. /* Copy the context */
  115. void sha3_256_inc_ctx_clone(sha3_256incctx *dest, const sha3_256incctx *src);
  116. /* Release the state, don't use if `_finalize` has been used */
  117. void sha3_256_inc_ctx_release(sha3_256incctx *state);
  118. void sha3_256(uint8_t *output, const uint8_t *input, size_t inlen);
  119. /* Initialize the incremental hashing state */
  120. void sha3_384_inc_init(sha3_384incctx *state);
  121. /* Absorb blocks into SHA3 */
  122. void sha3_384_inc_absorb(sha3_384incctx *state, const uint8_t *input, size_t inlen);
  123. /* Obtain the output of the function and free `state` */
  124. void sha3_384_inc_finalize(uint8_t *output, sha3_384incctx *state);
  125. /* Copy the context */
  126. void sha3_384_inc_ctx_clone(sha3_384incctx *dest, const sha3_384incctx *src);
  127. /* Release the state, don't use if `_finalize` has been used */
  128. void sha3_384_inc_ctx_release(sha3_384incctx *state);
  129. /* One-stop SHA3-384 shop */
  130. void sha3_384(uint8_t *output, const uint8_t *input, size_t inlen);
  131. /* Initialize the incremental hashing state */
  132. void sha3_512_inc_init(sha3_512incctx *state);
  133. /* Absorb blocks into SHA3 */
  134. void sha3_512_inc_absorb(sha3_512incctx *state, const uint8_t *input, size_t inlen);
  135. /* Obtain the output of the function and free `state` */
  136. void sha3_512_inc_finalize(uint8_t *output, sha3_512incctx *state);
  137. /* Copy the context */
  138. void sha3_512_inc_ctx_clone(sha3_512incctx *dest, const sha3_512incctx *src);
  139. /* Release the state, don't use if `_finalize` has been used */
  140. void sha3_512_inc_ctx_release(sha3_512incctx *state);
  141. /* One-stop SHA3-512 shop */
  142. void sha3_512(uint8_t *output, const uint8_t *input, size_t inlen);
  143. #endif