aboutsummaryrefslogtreecommitdiff
path: root/src/hash/blake2.c
diff options
context:
space:
mode:
authorame <[email protected]>2024-07-11 12:27:06 -0500
committerame <[email protected]>2024-07-11 12:27:06 -0500
commit027c7a7622a4aa4d0ed6483ba495ab91e0c68991 (patch)
tree7d5bc653f6bec52494604ac8c805e311bae080f4 /src/hash/blake2.c
parent90a2acc2f0c9d3904e1dea737e45ef6b10f96a22 (diff)
fixes to ub:33 hashes now safe
Diffstat (limited to 'src/hash/blake2.c')
-rw-r--r--src/hash/blake2.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/hash/blake2.c b/src/hash/blake2.c
index 9507c96..95d878f 100644
--- a/src/hash/blake2.c
+++ b/src/hash/blake2.c
@@ -221,10 +221,11 @@ void blake2b_update(uint8_t* input, size_t len, struct blake2b_hash* hash){
void blake2b_final(struct blake2b_hash* hash, char* out_stream){
uint8_t old[bs_2];
- uint32_t hashh[8];
+ uint64_t hashh[8];
struct blake2b_hash old_hash;
+
memcpy(&old_hash, hash, sizeof * hash);
- memcpy(old, hash->buffer, bs_2);
+ memcpy(old, hash->buffer, bs_2 * sizeof * old);
memcpy(hashh, hash->hash, 8 * sizeof * hashh);
hash->compressed += hash->bufflen;
@@ -234,7 +235,7 @@ void blake2b_final(struct blake2b_hash* hash, char* out_stream){
for(int i = 0; i != hash->digest_len; i++)sprintf(out_stream + i * 2, "%02x", (((uint8_t*)hash->hash)[i]));
memcpy(hash, &old_hash, sizeof * hash);
- memcpy(hash->buffer, old, bs_2);
+ memcpy(hash->buffer, old, bs_2 * sizeof * old);
memcpy(hash->hash, hashh, 8 * sizeof * hashh);
}
@@ -531,4 +532,4 @@ int l_blake2s(lua_State* L){
lua_pushstring(L, digest);
return 1;
-} \ No newline at end of file
+}