fixed bug in AESStreamEncryptor_encrypt

This commit is contained in:
Timerix 2025-11-15 15:24:16 +05:00
parent 9942d94c94
commit 0ea241c5db
2 changed files with 5 additions and 4 deletions

View File

@ -172,13 +172,14 @@ Result(u32) AESStreamEncryptor_encrypt(AESStreamEncryptor* ptr,
Array(u8) src, Array(u8) dst)
{
Deferral(4);
u32 encrypted_size = AESStreamEncryptor_calcDstSize(src.size);
try_assert(dst.size >= encrypted_size);
u32 encrypted_size = src.size;
// if it is the beginning of the stream, write IV
if(ptr->block_counter == 0){
__Array_writeNext(&dst, ptr->iv, __AES_STREAM_IV_SIZE);
encrypted_size = AESStreamEncryptor_calcDstSize(encrypted_size);
}
try_assert(dst.size >= encrypted_size);
// encrypt full buffers
while(src.size > __AES_BUFFER_SIZE){

View File

@ -101,7 +101,7 @@ void AESStreamEncryptor_changeKey(AESStreamEncryptor* ptr, Array(u8) key);
/// @brief If ptr->block_counter == 0, writes random IV to `dst`. After that writes encrypted data to dst.
/// @param src array of any size
/// @param dst array of size >= AESStreamEncryptor_calcDstSize(src.size)
/// @param dst array of size >= `AESStreamEncryptor_calcDstSize(src.size)` for first block and `src.size `for other blocks
/// @return size of encrypted data
Result(u32) AESStreamEncryptor_encrypt(AESStreamEncryptor* ptr, Array(u8) src, Array(u8) dst);