aboutsummaryrefslogtreecommitdiff
path: root/src/hash
diff options
context:
space:
mode:
authorame <[email protected]>2024-05-01 23:52:54 -0500
committerame <[email protected]>2024-05-01 23:52:54 -0500
commit81b85b557c308ff743b7b83f2b823e508eef54eb (patch)
treefeb939eadc804dfbdcf148c70fa235c36912476b /src/hash
parent22473687abdbf45c86e837d636cde036845e8460 (diff)
fix some hash ub
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/blake.c12
-rw-r--r--src/hash/blake2.c4
-rw-r--r--src/hash/sha2-256.c14
3 files changed, 15 insertions, 15 deletions
diff --git a/src/hash/blake.c b/src/hash/blake.c
index c6d73ad..76b6680 100644
--- a/src/hash/blake.c
+++ b/src/hash/blake.c
@@ -215,7 +215,7 @@ void blake256_final(struct blake256_hash* hash, char* out_stream){
_blake256_final(hash, out_stream);
for(int i = 0; i != 8; i++){
- sprintf(out_stream, "%s%08x",out_stream,(hash->hash)[i]);
+ sprintf(out_stream + i * 8, "%08x",(hash->hash)[i]);
}
memcpy(hash, &old_hash, sizeof * hash);
@@ -234,7 +234,7 @@ void blake224_final(struct blake256_hash* hash, char* out_stream){
_blake256_final(hash, out_stream);
for(int i = 0; i != 7; i++){
- sprintf(out_stream, "%s%08x",out_stream,(hash->hash)[i]);
+ sprintf(out_stream + i * 8, "%08x",(hash->hash)[i]);
}
memcpy(hash, &old_hash, sizeof * hash);
@@ -427,8 +427,8 @@ void blake512_final(struct blake512_hash* hash, char* out_stream){
_blake512_final(hash, out_stream);
for(int i = 0; i != 8; i++){
- sprintf(out_stream, "%s%016llx",out_stream, (hash->hash)[i]);
- }
+ sprintf(out_stream + 16 * i, "%016llx", (hash->hash)[i]);
+ }
memcpy(hash, &old_hash, sizeof * hash);
memcpy(hash->buffer, old, bs_2);
@@ -454,8 +454,8 @@ void blake384_final(struct blake384_hash* hash, char* out_stream){
_blake512_final(hash, out_stream);
for(int i = 0; i != 6; i++){
- sprintf(out_stream, "%s%016llx",out_stream, (hash->hash)[i]);
- }
+ sprintf(out_stream + 16 * i, "%016llx", (hash->hash)[i]);
+ }
memcpy(hash, &old_hash, sizeof * hash);
memcpy(hash->buffer, old, bs_2);
diff --git a/src/hash/blake2.c b/src/hash/blake2.c
index 61c79ca..9507c96 100644
--- a/src/hash/blake2.c
+++ b/src/hash/blake2.c
@@ -231,7 +231,7 @@ void blake2b_final(struct blake2b_hash* hash, char* out_stream){
blake2b_round(hash, 1);
- for(int i = 0; i != hash->digest_len; i++)sprintf(out_stream, "%s%02x", out_stream, (((uint8_t*)hash->hash)[i]));
+ 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);
@@ -363,7 +363,7 @@ void blake2s_final(struct blake2s_hash* hash, char* out_stream){
blake2s_round(hash, 1);
- for(int i = 0; i != hash->digest_len; i++)sprintf(out_stream, "%s%02x", out_stream, (((uint8_t*)hash->hash)[i]));
+ 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);
diff --git a/src/hash/sha2-256.c b/src/hash/sha2-256.c
index 7e37da9..d4a685a 100644
--- a/src/hash/sha2-256.c
+++ b/src/hash/sha2-256.c
@@ -175,14 +175,14 @@ void sha512_final(struct sha512_hash* hash, char* out_stream){
_sha512_t_final(hash);
- sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h0);
- sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h1);
+ sprintf((char*)out_stream, "%016llx%016llx%016llx%016llx%016llx%016llx%016llx%016llx", hash->h0, hash->h1, hash->h2, hash->h3, hash->h4, hash->h5, hash->h6, hash->h7);
+ /*sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h1);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h2);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h3);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h4);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h5);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h6);
- sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h7);
+ sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h7);*/
memcpy(hash, &old_hash, sizeof * hash);
memcpy(hash->buffer, old, bs);
@@ -196,12 +196,12 @@ void sha384_final(struct sha512_hash* hash, char* out_stream){
_sha512_t_final(hash);
- sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h0);
- sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h1);
+ sprintf((char*)out_stream, "%016llx%016llx%016llx%016llx%016llx%016llx", hash->h0, hash->h1, hash->h2, hash->h3, hash->h4, hash->h5);
+ /*sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h1);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h2);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h3);
sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h4);
- sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h5);
+ sprintf((char*)out_stream, "%s%016llx", out_stream, hash->h5);*/
memcpy(hash, &old_hash, sizeof * hash);
memcpy(hash->buffer, old, bs);
@@ -236,7 +236,7 @@ struct iv sha_iv_gen(int i){
uint8_t nh[512] = {0};
uint8_t in[12];
- sprintf((char*)in, "SHA-512/%i",i);
+ sprintf((char*)in, "SHA-512/%i", i);
struct sha512_hash a = sha512_t_init(oh);
sha512_update(in, strlen((char*)in), &a);
_sha512_t_final(&a);