• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 
26 #ifndef __Hacl_Hash_SHA3_H
27 #define __Hacl_Hash_SHA3_H
28 
29 #if defined(__cplusplus)
30 extern "C" {
31 #endif
32 
33 #include <string.h>
34 #include "python_hacl_namespaces.h"
35 #include "krml/types.h"
36 #include "krml/lowstar_endianness.h"
37 #include "krml/internal/target.h"
38 
39 #include "Hacl_Streaming_Types.h"
40 
41 typedef struct Hacl_Hash_SHA3_hash_buf_s
42 {
43   Spec_Hash_Definitions_hash_alg fst;
44   uint64_t *snd;
45 }
46 Hacl_Hash_SHA3_hash_buf;
47 
48 typedef struct Hacl_Hash_SHA3_state_t_s
49 {
50   Hacl_Hash_SHA3_hash_buf block_state;
51   uint8_t *buf;
52   uint64_t total_len;
53 }
54 Hacl_Hash_SHA3_state_t;
55 
56 Spec_Hash_Definitions_hash_alg Hacl_Hash_SHA3_get_alg(Hacl_Hash_SHA3_state_t *s);
57 
58 Hacl_Hash_SHA3_state_t *Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_hash_alg a);
59 
60 void Hacl_Hash_SHA3_free(Hacl_Hash_SHA3_state_t *state);
61 
62 Hacl_Hash_SHA3_state_t *Hacl_Hash_SHA3_copy(Hacl_Hash_SHA3_state_t *state);
63 
64 void Hacl_Hash_SHA3_reset(Hacl_Hash_SHA3_state_t *state);
65 
66 Hacl_Streaming_Types_error_code
67 Hacl_Hash_SHA3_update(Hacl_Hash_SHA3_state_t *state, uint8_t *chunk, uint32_t chunk_len);
68 
69 Hacl_Streaming_Types_error_code
70 Hacl_Hash_SHA3_digest(Hacl_Hash_SHA3_state_t *state, uint8_t *output);
71 
72 Hacl_Streaming_Types_error_code
73 Hacl_Hash_SHA3_squeeze(Hacl_Hash_SHA3_state_t *s, uint8_t *dst, uint32_t l);
74 
75 uint32_t Hacl_Hash_SHA3_block_len(Hacl_Hash_SHA3_state_t *s);
76 
77 uint32_t Hacl_Hash_SHA3_hash_len(Hacl_Hash_SHA3_state_t *s);
78 
79 bool Hacl_Hash_SHA3_is_shake(Hacl_Hash_SHA3_state_t *s);
80 
81 void
82 Hacl_Hash_SHA3_shake128_hacl(
83   uint32_t inputByteLen,
84   uint8_t *input,
85   uint32_t outputByteLen,
86   uint8_t *output
87 );
88 
89 void
90 Hacl_Hash_SHA3_shake256_hacl(
91   uint32_t inputByteLen,
92   uint8_t *input,
93   uint32_t outputByteLen,
94   uint8_t *output
95 );
96 
97 void Hacl_Hash_SHA3_sha3_224(uint8_t *output, uint8_t *input, uint32_t input_len);
98 
99 void Hacl_Hash_SHA3_sha3_256(uint8_t *output, uint8_t *input, uint32_t input_len);
100 
101 void Hacl_Hash_SHA3_sha3_384(uint8_t *output, uint8_t *input, uint32_t input_len);
102 
103 void Hacl_Hash_SHA3_sha3_512(uint8_t *output, uint8_t *input, uint32_t input_len);
104 
105 void Hacl_Hash_SHA3_absorb_inner(uint32_t rateInBytes, uint8_t *block, uint64_t *s);
106 
107 void
108 Hacl_Hash_SHA3_squeeze0(
109   uint64_t *s,
110   uint32_t rateInBytes,
111   uint32_t outputByteLen,
112   uint8_t *output
113 );
114 
115 void
116 Hacl_Hash_SHA3_keccak(
117   uint32_t rate,
118   uint32_t capacity,
119   uint32_t inputByteLen,
120   uint8_t *input,
121   uint8_t delimitedSuffix,
122   uint32_t outputByteLen,
123   uint8_t *output
124 );
125 
126 #if defined(__cplusplus)
127 }
128 #endif
129 
130 #define __Hacl_Hash_SHA3_H_DEFINED
131 #endif
132