From bce385a4b5fb4a3dd2b8d0c6971b7ddccf284771 Mon Sep 17 00:00:00 2001 From: Timerix Date: Mon, 21 Jul 2025 16:24:13 +0300 Subject: [PATCH] updated tlibc --- .vscode/c_cpp_properties.json | 3 ++- dependencies/tlibc | 2 +- project.config | 2 +- src/cryptography.c | 6 +++--- src/cryptography.h | 6 +++--- src/main.c | 18 +++++++----------- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 7f0fd13..7cdd1a2 100755 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,8 +4,9 @@ "name": "all", "defines": [], "includePath": [ - "dependencies", "src", + "dependencies", + "dependencies/tlibc/include", "${default}" ], "cStandard": "c99" diff --git a/dependencies/tlibc b/dependencies/tlibc index ebe6e58..8999fda 160000 --- a/dependencies/tlibc +++ b/dependencies/tlibc @@ -1 +1 @@ -Subproject commit ebe6e58ef3b777a7e45f10b5552ca95bc96e8cc8 +Subproject commit 8999fda11c99717b2415c9d351a46d796c46c67b diff --git a/project.config b/project.config index e5ea8c5..5c66362 100644 --- a/project.config +++ b/project.config @@ -26,7 +26,7 @@ OBJDIR="obj" OUTDIR="bin" STATIC_LIB_FILE="lib$PROJECT.a" -INCLUDE="-I./src -I./dependencies" +INCLUDE="-I./src -I./dependencies -I./dependencies/tlibc/include" # OS-specific options case "$OS" in diff --git a/src/cryptography.c b/src/cryptography.c index 83329a3..5e05389 100755 --- a/src/cryptography.c +++ b/src/cryptography.c @@ -1,7 +1,7 @@ #include "cryptography.h" -#include -#include -#include +#include "BearSSL/inc/bearssl_block.h" +#include "BearSSL/inc/bearssl_hash.h" +#include "BearSSL/inc/bearssl_rand.h" #include Array hash_password(str password, i32 iterations){ diff --git a/src/cryptography.h b/src/cryptography.h index 4e06bbb..eed2be5 100755 --- a/src/cryptography.h +++ b/src/cryptography.h @@ -1,7 +1,7 @@ #pragma once -#include -#include -#include +#include "tlibc/std.h" +#include "tlibc/collections/Array.h" +#include "tlibc/string/str.h" /// @brief hashes password multiple times using its own hash as salt /// @param password some byte array diff --git a/src/main.c b/src/main.c index ab409ca..782b243 100755 --- a/src/main.c +++ b/src/main.c @@ -1,18 +1,12 @@ -#include -#include - -str hex_to_str(Array buf) { - StringBuilder sb = StringBuilder_alloc(buf.size * 2 + 1); - StringBuilder_append_memory(&sb, buf); - return StringBuilder_getStr(&sb); -} +#include "cryptography.h" +#include "tlibc/string/StringBuilder.h" int main(){ const str password = STR("abobus"); const Array data = str_castTo_Array(STR("0123456789_hii_")); const Array key_hash = hash_password(password, 1e5); - str hash_str = hex_to_str(key_hash); + str hash_str = hex_to_str(key_hash, true); printf("password hash [%i] %s\n", key_hash.size, hash_str.data); free(hash_str.data); @@ -24,7 +18,8 @@ int main(){ Array buffer = Array_alloc_size(EncryptorAES_calcDstSize(data.size)); EncryptorAES_encrypt(encr, data, buffer); EncryptorAES_destroy(encr); - str encrypted_str = hex_to_str(buffer); + + str encrypted_str = hex_to_str(buffer, true); printf("data encrypted (hex): %s\n", encrypted_str.data); free(encrypted_str.data); @@ -32,9 +27,10 @@ int main(){ u32 decrypted_size = 0; DecryptorAES_decrypt(decr, buffer, buffer, &decrypted_size); DecryptorAES_destroy(decr); + str decrypted_str = str_copy(str_construct(buffer.data, decrypted_size, false)); printf("data decrypted (utf8): %s\n", decrypted_str.data); free(decrypted_str.data); return 0; -} \ No newline at end of file +}