Skip to content

Commit b8d989e

Browse files
hacl sha3
1 parent d9921ac commit b8d989e

File tree

6 files changed

+788
-0
lines changed

6 files changed

+788
-0
lines changed

crypto/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,12 @@ config CRYPTO_SHA3
10441044
help
10451045
SHA-3 secure hash algorithms (FIPS 202, ISO/IEC 10118-3)
10461046

1047+
config CRYPTO_SHA3_HACL
1048+
tristate "SHA-3"
1049+
select CRYPTO_HASH
1050+
help
1051+
SHA-3 secure hash algorithms (FIPS 202, ISO/IEC 10118-3) from HACL*
1052+
10471053
config CRYPTO_SM3
10481054
tristate
10491055

crypto/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o
8080
obj-$(CONFIG_CRYPTO_SHA2_HACL) += sha2-hacl-generated.o sha2-hacl.o
8181
obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o
8282
obj-$(CONFIG_CRYPTO_SHA3) += sha3_generic.o
83+
obj-$(CONFIG_CRYPTO_SHA3_HACL) += sha3-hacl-generated.o sha3-hacl.o
8384
obj-$(CONFIG_CRYPTO_SM3) += sm3.o
8485
obj-$(CONFIG_CRYPTO_SM3_GENERIC) += sm3_generic.o
8586
obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o

crypto/hacl_hash.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010
#include "hacl_lib.h"
1111

12+
#define Spec_Hash_Definitions_SHA3_256 8
13+
#define Spec_Hash_Definitions_SHA3_224 9
14+
#define Spec_Hash_Definitions_SHA3_384 10
15+
#define Spec_Hash_Definitions_SHA3_512 11
16+
#define Spec_Hash_Definitions_Shake128 12
17+
#define Spec_Hash_Definitions_Shake256 13
18+
19+
typedef uint8_t Spec_Hash_Definitions_hash_alg;
20+
1221
#define Hacl_Streaming_Types_Success 0
1322
#define Hacl_Streaming_Types_InvalidAlgorithm 1
1423
#define Hacl_Streaming_Types_InvalidLength 2
@@ -222,4 +231,37 @@ void Hacl_Streaming_SHA2_finish_384(struct Hacl_Streaming_MD_state_64_s *p,
222231
void Hacl_Streaming_SHA2_hash_384(uint8_t *input, uint32_t input_len,
223232
uint8_t *dst);
224233

234+
struct Hacl_Streaming_Keccak_hash_buf_s {
235+
Spec_Hash_Definitions_hash_alg fst;
236+
uint64_t *snd;
237+
};
238+
239+
struct Hacl_Streaming_Keccak_state_s {
240+
struct Hacl_Streaming_Keccak_hash_buf_s block_state;
241+
uint8_t *buf;
242+
uint64_t total_len;
243+
};
244+
245+
Hacl_Streaming_Types_error_code
246+
Hacl_Streaming_Keccak_update(struct Hacl_Streaming_Keccak_state_s *p,
247+
uint8_t *data, uint32_t len);
248+
249+
Hacl_Streaming_Types_error_code
250+
Hacl_Streaming_Keccak_finish(struct Hacl_Streaming_Keccak_state_s *p,
251+
uint8_t *out);
252+
253+
void Hacl_SHA3_shake128_hacl(uint32_t inputByteLen, uint8_t *input,
254+
uint32_t outputByteLen, uint8_t *output);
255+
256+
void Hacl_SHA3_shake256_hacl(uint32_t inputByteLen, uint8_t *input,
257+
uint32_t outputByteLen, uint8_t *output);
258+
259+
void Hacl_SHA3_sha3_224(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
260+
261+
void Hacl_SHA3_sha3_256(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
262+
263+
void Hacl_SHA3_sha3_384(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
264+
265+
void Hacl_SHA3_sha3_512(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
266+
225267
#endif // CRYPTO_HACL_HASH_H_

crypto/hacl_lib.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ static inline u128 FStar_UInt128_uint64_to_uint128(u64 x)
4040
#define load64_be(b) (get_unaligned_be64(b))
4141
#define store64_be(b, i) put_unaligned_be64(i, b);
4242

43+
#define load32_le(b) (get_unaligned_le32(b))
44+
#define store32_le(b, i) put_unaligned_le32(i, b);
45+
#define load64_le(b) (get_unaligned_le64(b))
46+
#define store64_le(b, i) put_unaligned_le64(i, b);
47+
4348
static inline void store128_be(u8 *buf, u128 x)
4449
{
4550
store64_be(buf, (u64)(x >> 64));
@@ -230,4 +235,8 @@ static inline void store128_be(u8 *buf, u128 x)
230235
#define KRML_MAYBE_FOR16(i, z, n, k, x) KRML_ACTUAL_FOR(i, z, n, k, x)
231236
#endif
232237

238+
#ifndef KRML_HOST_IGNORE
239+
#define KRML_HOST_IGNORE(x) (void)(x)
240+
#endif
241+
233242
#endif // CRYPTO_HACL_LIB_H_

0 commit comments

Comments
 (0)