aboutsummaryrefslogtreecommitdiff
path: root/src/hash/sha2xx.c
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2025-04-21 20:43:51 -0500
committeramelia squires <[email protected]>2025-04-21 20:43:51 -0500
commitaf975d63f67e6cc2d17f1804acb66328905f8701 (patch)
treeab23744e784044d29cc73cd1da4070011e7e858c /src/hash/sha2xx.c
parentb2ee662b4621282b137a2a2cf1be13bd60073c5a (diff)
better version support, fixes, and memory saftey
Diffstat (limited to 'src/hash/sha2xx.c')
-rw-r--r--src/hash/sha2xx.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/hash/sha2xx.c b/src/hash/sha2xx.c
index 1ef3f6f..c67e40d 100644
--- a/src/hash/sha2xx.c
+++ b/src/hash/sha2xx.c
@@ -12,10 +12,18 @@ struct sha256_hash sha256_init(){
return a;
}
+int sha256_free_l(lua_State* L){
+ struct sha256_hash* h = lua_touserdata(L, -1);
+ free(h->buffer);
+ return 0;
+}
+
+#define sha224_free_l sha256_free_l
+
struct sha256_hash sha256_init_l(lua_State* L){
struct sha256_hash a = {.h0 = 0x6a09e667, .h1 = 0xbb67ae85, .h2 = 0x3c6ef372, .h3 = 0xa54ff53a, .h4 = 0x510e527f, .h5 = 0x9b05688c, .h6 = 0x1f83d9ab, .h7 = 0x5be0cd19,
.total = 0, .bufflen = 0};
- a.buffer = lua_newuserdata(L, sizeof * a.buffer * bs);
+ a.buffer = calloc(sizeof * a.buffer, bs);
memset(a.buffer, 0, bs);
return a;
}