aboutsummaryrefslogtreecommitdiff
path: root/src/hash/sha2-256.c
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2024-09-16 12:16:29 -0500
committeramelia squires <[email protected]>2024-09-16 12:16:29 -0500
commit602818b895fec710b0534b0b8fa7f5e1f57203c2 (patch)
treed1a5a26af92af8fabf12d5095a2d3745431593b4 /src/hash/sha2-256.c
parent7c757e7ca41cacd1505622dcb48e5657364aa714 (diff)
fix _copy and mem leaks
Diffstat (limited to 'src/hash/sha2-256.c')
-rw-r--r--src/hash/sha2-256.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/hash/sha2-256.c b/src/hash/sha2-256.c
index 7e37d9d..42f6a81 100644
--- a/src/hash/sha2-256.c
+++ b/src/hash/sha2-256.c
@@ -245,7 +245,13 @@ struct iv sha_iv_gen(int i){
return (struct iv){.h0 = a.h0, .h1 = a.h1, .h2 = a.h2, .h3 = a.h3, .h4 = a.h4, .h5 = a.h5, .h6 = a.h6, .h7 = a.h7};
}
-common_hash_clone(sha512);
+//common_hash_clone(sha512);
+lua_common_hash_clone_oargs(sha512, sha512, l_sha512_init(L), {
+ uint8_t* old = b->buffer;
+ *b = *a;
+ b->buffer = old;
+ memcpy(b->buffer, a->buffer, bs * sizeof * b->buffer);
+});
lua_common_hash_init_ni(sha512, sha512, sha512_t_init_l(sha512_iv, L));
lua_common_hash_update(sha512, sha512);
@@ -259,7 +265,13 @@ int l_sha512_final(lua_State* L){
return 1;
}
-common_hash_clone(sha384);
+//common_hash_clone(sha384);
+lua_common_hash_clone_oargs(sha384, sha384, l_sha384_init(L), {
+ uint8_t* old = b->buffer;
+ *b = *a;
+ b->buffer = old;
+ memcpy(b->buffer, a->buffer, bs * sizeof * b->buffer);
+});
lua_common_hash_init_ni(sha384, sha384, sha512_t_init_l(sha384_iv, L));
lua_common_hash_update(sha384, sha384);
@@ -278,7 +290,11 @@ int l_sha512_t_clone(lua_State* L){
lua_pushinteger(L, a->t);
l_sha512_t_init(L);
struct sha512_hash* b = (struct sha512_hash*)lua_touserdata(L, -1);
+
+ uint8_t* old = b->buffer;
*b = *a;
+ b->buffer = old;
+ memcpy(b->buffer, a->buffer, bs * sizeof * b->buffer);
return 1;
}