added flags to socket_recv
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ void EncryptorAES_construct(EncryptorAES* ptr, Array(u8) key);
|
||||
/// @brief Encrypts `src` and writes output to `dst`.
|
||||
/// @param src array of any size
|
||||
/// @param dst array of size >= EncryptorAES_calcDstSize(src.size)
|
||||
void EncryptorAES_encrypt(EncryptorAES* ptr, Array(u8) src, Array(u8) dst);
|
||||
Result(void) EncryptorAES_encrypt(EncryptorAES* ptr, Array(u8) src, Array(u8) dst);
|
||||
|
||||
#define EncryptorAES_calcDstSize(SRC_SIZE) (__AES_IV_SIZE + sizeof(EncryptedBlockHeader) + ALIGN_TO(SRC_SIZE, 16))
|
||||
|
||||
@@ -91,7 +91,7 @@ void DecryptorAES_construct(DecryptorAES* ptr, Array(u8) key);
|
||||
/// @param src array of size at least EncryptorAES_calcDstSize(0). Size must be multiple of 16.
|
||||
/// @param dst array of size >= src.size
|
||||
/// @param decrypted_size size of original data without padding added by EncryptorAES_encrypt
|
||||
void DecryptorAES_decrypt(DecryptorAES* ptr, Array(u8) src, Array(u8) dst, u32* decrypted_size);
|
||||
Result(void) DecryptorAES_decrypt(DecryptorAES* ptr, Array(u8) src, Array(u8) dst, u32* decrypted_size);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user