tcp-chat/src/cryptography/hash.c

18 lines
588 B
C
Executable File

#include "cryptography.h"
#include "bearssl_hash.h"
#include "assert.h"
void hash_password(Array(u8) password, u8* out_buffer, i32 iterations){
assert(PASSWORD_HASH_SIZE == br_sha256_SIZE);;
memset(out_buffer, 0, br_sha256_SIZE);
br_sha256_context sha256_ctx;
br_sha256_init(&sha256_ctx);
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_out(&sha256_ctx, out_buffer);
}