Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 95f4c40

Browse filesBrowse files
committed
Refresh from upstream
1 parent 9f5b5a6 commit 95f4c40
Copy full SHA for 95f4c40

File tree

5 files changed

+42
-26
lines changed
Filter options

5 files changed

+42
-26
lines changed

‎Modules/_hacl/Hacl_Hash_SHA3.c

Copy file name to clipboardExpand all lines: Modules/_hacl/Hacl_Hash_SHA3.c
+19-15Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ Hacl_Hash_SHA3_update_multi_sha3(
102102
uint8_t *block = blocks + i * block_len(a);
103103
Hacl_Impl_SHA3_absorb_inner(block_len(a), block, s);
104104
}
105-
uint8_t *last = blocks + n_blocks * block_len(a);
106105
}
107106

108107
void
@@ -487,27 +486,32 @@ finish_(
487486
Hacl_Impl_SHA3_squeeze(s, block_len(a11), hash_len(a11), dst);
488487
}
489488

490-
uint32_t Hacl_Streaming_Keccak_finish(Hacl_Streaming_Keccak_state *s, uint8_t *dst, uint32_t l)
489+
Hacl_Streaming_Keccak_error_code
490+
Hacl_Streaming_Keccak_finish(Hacl_Streaming_Keccak_state *s, uint8_t *dst)
491491
{
492492
Spec_Hash_Definitions_hash_alg a1 = Hacl_Streaming_Keccak_get_alg(s);
493-
if
494-
(
495-
(a1 == Spec_Hash_Definitions_Shake128 || a1 == Spec_Hash_Definitions_Shake256)
496-
&& l == (uint32_t)0U
497-
)
493+
if (a1 == Spec_Hash_Definitions_Shake128 || a1 == Spec_Hash_Definitions_Shake256)
498494
{
499-
return (uint32_t)1U;
495+
return Hacl_Streaming_Keccak_InvalidAlgorithm;
500496
}
501-
if
502-
(
503-
!(a1 == Spec_Hash_Definitions_Shake128 || a1 == Spec_Hash_Definitions_Shake256)
504-
&& l != (uint32_t)0U
505-
)
497+
finish_(a1, s, dst, hash_len(a1));
498+
return Hacl_Streaming_Keccak_Success;
499+
}
500+
501+
Hacl_Streaming_Keccak_error_code
502+
Hacl_Streaming_Keccak_squeeze(Hacl_Streaming_Keccak_state *s, uint8_t *dst, uint32_t l)
503+
{
504+
Spec_Hash_Definitions_hash_alg a1 = Hacl_Streaming_Keccak_get_alg(s);
505+
if (!(a1 == Spec_Hash_Definitions_Shake128 || a1 == Spec_Hash_Definitions_Shake256))
506506
{
507-
return (uint32_t)1U;
507+
return Hacl_Streaming_Keccak_InvalidAlgorithm;
508+
}
509+
if (l == (uint32_t)0U)
510+
{
511+
return Hacl_Streaming_Keccak_InvalidLength;
508512
}
509513
finish_(a1, s, dst, l);
510-
return (uint32_t)0U;
514+
return Hacl_Streaming_Keccak_Success;
511515
}
512516

513517
uint32_t Hacl_Streaming_Keccak_block_len(Hacl_Streaming_Keccak_state *s)

‎Modules/_hacl/Hacl_Hash_SHA3.h

Copy file name to clipboardExpand all lines: Modules/_hacl/Hacl_Hash_SHA3.h
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,17 @@ void Hacl_Streaming_Keccak_reset(Hacl_Streaming_Keccak_state *s);
6565
uint32_t
6666
Hacl_Streaming_Keccak_update(Hacl_Streaming_Keccak_state *p, uint8_t *data, uint32_t len);
6767

68-
uint32_t
69-
Hacl_Streaming_Keccak_finish(Hacl_Streaming_Keccak_state *s, uint8_t *dst, uint32_t l);
68+
#define Hacl_Streaming_Keccak_Success 0
69+
#define Hacl_Streaming_Keccak_InvalidAlgorithm 1
70+
#define Hacl_Streaming_Keccak_InvalidLength 2
71+
72+
typedef uint8_t Hacl_Streaming_Keccak_error_code;
73+
74+
Hacl_Streaming_Keccak_error_code
75+
Hacl_Streaming_Keccak_finish(Hacl_Streaming_Keccak_state *s, uint8_t *dst);
76+
77+
Hacl_Streaming_Keccak_error_code
78+
Hacl_Streaming_Keccak_squeeze(Hacl_Streaming_Keccak_state *s, uint8_t *dst, uint32_t l);
7079

7180
uint32_t Hacl_Streaming_Keccak_block_len(Hacl_Streaming_Keccak_state *s);
7281

‎Modules/_hacl/include/krml/lowstar_endianness.h

Copy file name to clipboardExpand all lines: Modules/_hacl/include/krml/lowstar_endianness.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
# define le64toh(x) (x)
7878

7979
/* ... for Windows (GCC-like, e.g. mingw or clang) */
80-
#elif (defined(_WIN32) || defined(_WIN64)) && \
80+
#elif (defined(_WIN32) || defined(_WIN64) || defined(__EMSCRIPTEN__)) && \
8181
(defined(__GNUC__) || defined(__clang__))
8282

8383
# define htobe16(x) __builtin_bswap16(x)

‎Modules/_hacl/refresh.sh

Copy file name to clipboardExpand all lines: Modules/_hacl/refresh.sh
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fi
2222

2323
# Update this when updating to a new version after verifying that the changes
2424
# the update brings in are good.
25-
expected_hacl_star_rev=a41202dc7378b6e41c609d6b2f8f8b8e10581827
25+
expected_hacl_star_rev=363eae2c2eb60e46f182ddd4bd1cd3f1d00b35c9
2626

2727
hacl_dir="$(realpath "$1")"
2828
cd "$(dirname "$0")"

‎Modules/sha3module.c

Copy file name to clipboardExpand all lines: Modules/sha3module.c
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,9 @@ _sha3_sha3_224_digest_impl(SHA3object *self)
195195
/*[clinic end generated code: output=fd531842e20b2d5b input=5b2a659536bbd248]*/
196196
{
197197
unsigned char digest[SHA3_MAX_DIGESTSIZE];
198-
// The only potential error here is an API misuse, such as trying to specify
199-
// a user-provided length when using a non-Shake algorithm. We thus ignore
200-
// the return code.
201-
Hacl_Streaming_Keccak_finish(self->hash_state, digest, 0);
198+
// This function errors out if the algorithm is Shake. Here, we know this
199+
// not to be the case, and therefore do not perform error checking.
200+
Hacl_Streaming_Keccak_finish(self->hash_state, digest);
202201
return PyBytes_FromStringAndSize((const char *)digest,
203202
Hacl_Streaming_Keccak_hash_len(self->hash_state));
204203
}
@@ -215,7 +214,7 @@ _sha3_sha3_224_hexdigest_impl(SHA3object *self)
215214
/*[clinic end generated code: output=75ad03257906918d input=2d91bb6e0d114ee3]*/
216215
{
217216
unsigned char digest[SHA3_MAX_DIGESTSIZE];
218-
Hacl_Streaming_Keccak_finish(self->hash_state, digest, 0);
217+
Hacl_Streaming_Keccak_finish(self->hash_state, digest);
219218
return _Py_strhex((const char *)digest,
220219
Hacl_Streaming_Keccak_hash_len(self->hash_state));
221220
}
@@ -397,8 +396,12 @@ _SHAKE_digest(SHA3object *self, unsigned long digestlen, int hex)
397396
return PyErr_NoMemory();
398397
}
399398

400-
/* Get the raw (binary) digest value */
401-
Hacl_Streaming_Keccak_finish(self->hash_state, digest, digestlen);
399+
/* Get the raw (binary) digest value. The HACL functions errors out if:
400+
* - the algorith is not shake -- not the case here
401+
* - the output length is zero -- we follow the existing behavior and return
402+
* an empty digest, without raising an error */
403+
if (digestlen > 0)
404+
Hacl_Streaming_Keccak_squeeze(self->hash_state, digest, digestlen);
402405
if (hex) {
403406
result = _Py_strhex((const char *)digest, digestlen);
404407
} else {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.