Skip to content

Commit e6381e3

Browse files
committed
prevent zero size data
1 parent 0d9812a commit e6381e3

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/aes256/aes.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, uint32_t length)
461461
{
462462
uintptr_t i;
463463
uint8_t *Iv = ctx->Iv;
464+
464465
for (i = 0; i < length; i += AES_BLOCKLEN)
465466
{
466467
XorWithIv(buf, Iv);
@@ -477,6 +478,7 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
477478
{
478479
uintptr_t i;
479480
uint8_t storeNextIv[AES_BLOCKLEN];
481+
480482
for (i = 0; i < length; i += AES_BLOCKLEN)
481483
{
482484
memcpy(storeNextIv, buf, AES_BLOCKLEN);
@@ -497,9 +499,9 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
497499
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
498500
{
499501
uint8_t buffer[AES_BLOCKLEN];
500-
501502
unsigned i;
502503
int bi;
504+
503505
for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
504506
{
505507
if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */

src/aes256/aes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AES_H_
33

44
/*
5-
-- variable key length each 16, 24, 32 AES variant source,
5+
-- AES for variable key length each 16, 24, 32 ( 128, 192, 256 bit )
66
-- (C)2021 Raphael K,
77
*/
88

src/endetool.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ void EnDeTool::reset()
7575
origintext = NULL;
7676
}
7777

78-
return;
78+
AES_ctx* aesctx = (AES_ctx*)cryptcontext;
79+
if ( aesctx != NULL )
80+
{
81+
memset( aesctx, 0, sizeof( AES_ctx ) );
82+
}
7983
}
8084

8185
void EnDeTool::compress( bool enabled )
@@ -85,7 +89,7 @@ void EnDeTool::compress( bool enabled )
8589

8690
long long EnDeTool::encodebinary( const char* src, unsigned srcsize, char* &out )
8791
{
88-
if ( src == NULL )
92+
if ( ( src == NULL ) || ( srcsize == 0 ) )
8993
return -1;
9094

9195
generateiv();

0 commit comments

Comments
 (0)