added flags to socket_recv

This commit is contained in:
2025-10-25 19:08:37 +05:00
parent eea36ec2a3
commit 42702ffbe7
7 changed files with 49 additions and 24 deletions

View File

@@ -26,8 +26,9 @@ void EncryptorAES_construct(EncryptorAES* ptr, Array(u8) key){
rng_init_sha256_seedFromSystem(&ptr->rng_ctx.vtable);
}
void EncryptorAES_encrypt(EncryptorAES* ptr, Array(u8) src, Array(u8) dst){
assert(dst.size >= EncryptorAES_calcDstSize(src.size));
Result(void) EncryptorAES_encrypt(EncryptorAES* ptr, Array(u8) src, Array(u8) dst){
Deferral(4);
try_assert(dst.size >= EncryptorAES_calcDstSize(src.size));
// generate random initial vector
br_hmac_drbg_generate(&ptr->rng_ctx, ptr->iv, __AES_IV_SIZE);
@@ -57,6 +58,8 @@ void EncryptorAES_encrypt(EncryptorAES* ptr, Array(u8) src, Array(u8) dst){
br_aes_ct64_cbcenc_run(&ptr->enc_ctx, ptr->iv, ptr->buf, src_size_padded);
memcpy(dst.data, ptr->buf, src_size_padded);
}
Return RESULT_VOID;
}
@@ -66,10 +69,11 @@ void DecryptorAES_construct(DecryptorAES* ptr, Array(u8) key){
br_aes_ct64_cbcdec_init(&ptr->dec_ctx, key.data, key.size);
}
void DecryptorAES_decrypt(DecryptorAES* ptr, Array(u8) src, Array(u8) dst, u32* decrypted_size){
assert(src.size >= EncryptorAES_calcDstSize(0));
assert(src.size % 16 == 0 && "src must be array of 16-byte blocks");
assert(dst.size >= src.size);
Result(void) DecryptorAES_decrypt(DecryptorAES* ptr, Array(u8) src, Array(u8) dst, u32* decrypted_size){
Deferral(4);
try_assert(src.size >= EncryptorAES_calcDstSize(0));
try_assert(src.size % 16 == 0 && "src must be array of 16-byte blocks");
try_assert(dst.size >= src.size);
// read IV from the beginning of src
__Array_readNext(ptr->iv, &src, __AES_IV_SIZE);
@@ -97,4 +101,6 @@ void DecryptorAES_decrypt(DecryptorAES* ptr, Array(u8) src, Array(u8) dst, u32*
br_aes_ct64_cbcdec_run(&ptr->dec_ctx, ptr->iv, ptr->buf, src_size_padded);
memcpy(dst.data, ptr->buf, src.size);
}
Return RESULT_VOID;
}