Hacl_Hash_SHA3.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "krml/types.h"
  31. #include "krml/lowstar_endianness.h"
  32. #include "krml/internal/target.h"
  33. #include "Hacl_Streaming_Types.h"
  34. typedef struct Hacl_Streaming_Keccak_hash_buf_s
  35. {
  36. Spec_Hash_Definitions_hash_alg fst;
  37. uint64_t *snd;
  38. }
  39. Hacl_Streaming_Keccak_hash_buf;
  40. typedef struct Hacl_Streaming_Keccak_state_s
  41. {
  42. Hacl_Streaming_Keccak_hash_buf block_state;
  43. uint8_t *buf;
  44. uint64_t total_len;
  45. }
  46. Hacl_Streaming_Keccak_state;
  47. Spec_Hash_Definitions_hash_alg Hacl_Streaming_Keccak_get_alg(Hacl_Streaming_Keccak_state *s);
  48. Hacl_Streaming_Keccak_state *Hacl_Streaming_Keccak_malloc(Spec_Hash_Definitions_hash_alg a);
  49. void Hacl_Streaming_Keccak_free(Hacl_Streaming_Keccak_state *s);
  50. Hacl_Streaming_Keccak_state *Hacl_Streaming_Keccak_copy(Hacl_Streaming_Keccak_state *s0);
  51. void Hacl_Streaming_Keccak_reset(Hacl_Streaming_Keccak_state *s);
  52. Hacl_Streaming_Types_error_code
  53. Hacl_Streaming_Keccak_update(Hacl_Streaming_Keccak_state *p, uint8_t *data, uint32_t len);
  54. Hacl_Streaming_Types_error_code
  55. Hacl_Streaming_Keccak_finish(Hacl_Streaming_Keccak_state *s, uint8_t *dst);
  56. Hacl_Streaming_Types_error_code
  57. Hacl_Streaming_Keccak_squeeze(Hacl_Streaming_Keccak_state *s, uint8_t *dst, uint32_t l);
  58. uint32_t Hacl_Streaming_Keccak_block_len(Hacl_Streaming_Keccak_state *s);
  59. uint32_t Hacl_Streaming_Keccak_hash_len(Hacl_Streaming_Keccak_state *s);
  60. bool Hacl_Streaming_Keccak_is_shake(Hacl_Streaming_Keccak_state *s);
  61. void
  62. Hacl_SHA3_shake128_hacl(
  63. uint32_t inputByteLen,
  64. uint8_t *input,
  65. uint32_t outputByteLen,
  66. uint8_t *output
  67. );
  68. void
  69. Hacl_SHA3_shake256_hacl(
  70. uint32_t inputByteLen,
  71. uint8_t *input,
  72. uint32_t outputByteLen,
  73. uint8_t *output
  74. );
  75. void Hacl_SHA3_sha3_224(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
  76. void Hacl_SHA3_sha3_256(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
  77. void Hacl_SHA3_sha3_384(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
  78. void Hacl_SHA3_sha3_512(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
  79. void Hacl_Impl_SHA3_absorb_inner(uint32_t rateInBytes, uint8_t *block, uint64_t *s);
  80. void
  81. Hacl_Impl_SHA3_squeeze(
  82. uint64_t *s,
  83. uint32_t rateInBytes,
  84. uint32_t outputByteLen,
  85. uint8_t *output
  86. );
  87. void
  88. Hacl_Impl_SHA3_keccak(
  89. uint32_t rate,
  90. uint32_t capacity,
  91. uint32_t inputByteLen,
  92. uint8_t *input,
  93. uint8_t delimitedSuffix,
  94. uint32_t outputByteLen,
  95. uint8_t *output
  96. );
  97. #if defined(__cplusplus)
  98. }
  99. #endif
  100. #define __Hacl_Hash_SHA3_H_DEFINED
  101. #endif