Hacl_Hash_SHA3.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* MIT License
  2. *
  3. * Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation
  4. * Copyright (c) 2022-2023 HACL* Contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #ifndef __Hacl_Hash_SHA3_H
  25. #define __Hacl_Hash_SHA3_H
  26. #if defined(__cplusplus)
  27. extern "C" {
  28. #endif
  29. #include <string.h>
  30. #include "python_hacl_namespaces.h"
  31. #include "krml/types.h"
  32. #include "krml/lowstar_endianness.h"
  33. #include "krml/internal/target.h"
  34. #include "Hacl_Streaming_Types.h"
  35. typedef struct Hacl_Hash_SHA3_hash_buf_s
  36. {
  37. Spec_Hash_Definitions_hash_alg fst;
  38. uint64_t *snd;
  39. }
  40. Hacl_Hash_SHA3_hash_buf;
  41. typedef struct Hacl_Hash_SHA3_state_t_s
  42. {
  43. Hacl_Hash_SHA3_hash_buf block_state;
  44. uint8_t *buf;
  45. uint64_t total_len;
  46. }
  47. Hacl_Hash_SHA3_state_t;
  48. Spec_Hash_Definitions_hash_alg Hacl_Hash_SHA3_get_alg(Hacl_Hash_SHA3_state_t *s);
  49. Hacl_Hash_SHA3_state_t *Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_hash_alg a);
  50. void Hacl_Hash_SHA3_free(Hacl_Hash_SHA3_state_t *state);
  51. Hacl_Hash_SHA3_state_t *Hacl_Hash_SHA3_copy(Hacl_Hash_SHA3_state_t *state);
  52. void Hacl_Hash_SHA3_reset(Hacl_Hash_SHA3_state_t *state);
  53. Hacl_Streaming_Types_error_code
  54. Hacl_Hash_SHA3_update(Hacl_Hash_SHA3_state_t *state, uint8_t *chunk, uint32_t chunk_len);
  55. Hacl_Streaming_Types_error_code
  56. Hacl_Hash_SHA3_digest(Hacl_Hash_SHA3_state_t *state, uint8_t *output);
  57. Hacl_Streaming_Types_error_code
  58. Hacl_Hash_SHA3_squeeze(Hacl_Hash_SHA3_state_t *s, uint8_t *dst, uint32_t l);
  59. uint32_t Hacl_Hash_SHA3_block_len(Hacl_Hash_SHA3_state_t *s);
  60. uint32_t Hacl_Hash_SHA3_hash_len(Hacl_Hash_SHA3_state_t *s);
  61. bool Hacl_Hash_SHA3_is_shake(Hacl_Hash_SHA3_state_t *s);
  62. void
  63. Hacl_Hash_SHA3_shake128_hacl(
  64. uint32_t inputByteLen,
  65. uint8_t *input,
  66. uint32_t outputByteLen,
  67. uint8_t *output
  68. );
  69. void
  70. Hacl_Hash_SHA3_shake256_hacl(
  71. uint32_t inputByteLen,
  72. uint8_t *input,
  73. uint32_t outputByteLen,
  74. uint8_t *output
  75. );
  76. void Hacl_Hash_SHA3_sha3_224(uint8_t *output, uint8_t *input, uint32_t input_len);
  77. void Hacl_Hash_SHA3_sha3_256(uint8_t *output, uint8_t *input, uint32_t input_len);
  78. void Hacl_Hash_SHA3_sha3_384(uint8_t *output, uint8_t *input, uint32_t input_len);
  79. void Hacl_Hash_SHA3_sha3_512(uint8_t *output, uint8_t *input, uint32_t input_len);
  80. void Hacl_Hash_SHA3_absorb_inner(uint32_t rateInBytes, uint8_t *block, uint64_t *s);
  81. void
  82. Hacl_Hash_SHA3_squeeze0(
  83. uint64_t *s,
  84. uint32_t rateInBytes,
  85. uint32_t outputByteLen,
  86. uint8_t *output
  87. );
  88. void
  89. Hacl_Hash_SHA3_keccak(
  90. uint32_t rate,
  91. uint32_t capacity,
  92. uint32_t inputByteLen,
  93. uint8_t *input,
  94. uint8_t delimitedSuffix,
  95. uint32_t outputByteLen,
  96. uint8_t *output
  97. );
  98. #if defined(__cplusplus)
  99. }
  100. #endif
  101. #define __Hacl_Hash_SHA3_H_DEFINED
  102. #endif