Added session key to ServerConnection

This commit is contained in:
2025-10-25 10:47:08 +05:00
parent b1ca05759e
commit 60bc501227
6 changed files with 29 additions and 15 deletions

View File

@@ -13,12 +13,12 @@
/// @brief hashes password multiple times using its own hash as salt
/// @param password some byte array
/// @param out_buffer u8[password_hash_size]
/// @param out_buffer u8[PASSWORD_HASH_SIZE]
/// @param iterations number of iterations
void hash_password(Array(u8) password, u8* out_buffer, i32 iterations);
#define password_hash_size 32
#define PASSWORD_HASH_SIZE 32
#define __passhash_lvl_iter 1e5
#define __PASSWORD_HASH_LVL_ITERATIONS 1e5
//////////////////////////////////////////////////////////////////////////////
// rng.c //
@@ -38,6 +38,9 @@ void rng_init_sha256_seedFromTime(const br_prng_class** rng_vtable_ptr);
// AES.c //
//////////////////////////////////////////////////////////////////////////////
#define __AES_SESSION_KEY_SIZE 32
#define __AES_DB_KEY_SIZE 32
typedef struct EncryptedBlockInfo {
u8 padding_size;
u32 _reserved;
@@ -87,7 +90,7 @@ void DecryptorAES_decrypt(DecryptorAES* ptr, Array(u8) src, Array(u8) dst, u32*
// RSA.c //
//////////////////////////////////////////////////////////////////////////////
#define __rsa_key_size_default 3072
#define __RSA_DEFAULT_KEY_SIZE 3072
/// @brief generate random key pair based on system time
/// @param key_size size of public key in bits (2048/3072/4096)

View File

@@ -3,7 +3,7 @@
#include "assert.h"
void hash_password(Array(u8) password, u8* out_buffer, i32 iterations){
assert(password_hash_size == br_sha256_SIZE);;
assert(PASSWORD_HASH_SIZE == br_sha256_SIZE);;
memset(out_buffer, 0, br_sha256_SIZE);
br_sha256_context sha256_ctx;
br_sha256_init(&sha256_ctx);
@@ -11,7 +11,7 @@ void hash_password(Array(u8) password, u8* out_buffer, i32 iterations){
for(i32 i = 0; i < iterations; i++){
br_sha256_update(&sha256_ctx, password.data, password.size);
br_sha256_out(&sha256_ctx, out_buffer);
br_sha256_update(&sha256_ctx, out_buffer, password_hash_size);
br_sha256_update(&sha256_ctx, out_buffer, PASSWORD_HASH_SIZE);
}
br_sha256_out(&sha256_ctx, out_buffer);
}