updated tlibc
This commit is contained in:
parent
992fcf6b98
commit
bce385a4b5
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@ -4,8 +4,9 @@
|
||||
"name": "all",
|
||||
"defines": [],
|
||||
"includePath": [
|
||||
"dependencies",
|
||||
"src",
|
||||
"dependencies",
|
||||
"dependencies/tlibc/include",
|
||||
"${default}"
|
||||
],
|
||||
"cStandard": "c99"
|
||||
|
||||
2
dependencies/tlibc
vendored
2
dependencies/tlibc
vendored
@ -1 +1 @@
|
||||
Subproject commit ebe6e58ef3b777a7e45f10b5552ca95bc96e8cc8
|
||||
Subproject commit 8999fda11c99717b2415c9d351a46d796c46c67b
|
||||
@ -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
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "cryptography.h"
|
||||
#include <BearSSL/inc/bearssl_block.h>
|
||||
#include <BearSSL/inc/bearssl_hash.h>
|
||||
#include <BearSSL/inc/bearssl_rand.h>
|
||||
#include "BearSSL/inc/bearssl_block.h"
|
||||
#include "BearSSL/inc/bearssl_hash.h"
|
||||
#include "BearSSL/inc/bearssl_rand.h"
|
||||
#include <assert.h>
|
||||
|
||||
Array hash_password(str password, i32 iterations){
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <tlibc/include/std.h>
|
||||
#include <tlibc/include/collections/Array.h>
|
||||
#include <tlibc/include/string/str.h>
|
||||
#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
|
||||
|
||||
18
src/main.c
18
src/main.c
@ -1,18 +1,12 @@
|
||||
#include <cryptography.h>
|
||||
#include <tlibc/include/string/StringBuilder.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user