updated tlibc
This commit is contained 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user