Skip to content

Commit c3b7532

Browse files
authored
Merge pull request #173 from Youw/master
use size_t for buffer size and its indexes
2 parents 7279b02 + 2ca3e81 commit c3b7532

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

aes.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ static void XorWithIv(uint8_t* buf, const uint8_t* Iv)
498498
}
499499
}
500500

501-
void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, uint32_t length)
501+
void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, size_t length)
502502
{
503-
uintptr_t i;
503+
size_t i;
504504
uint8_t *Iv = ctx->Iv;
505505
for (i = 0; i < length; i += AES_BLOCKLEN)
506506
{
@@ -513,9 +513,9 @@ void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, uint32_t length)
513513
memcpy(ctx->Iv, Iv, AES_BLOCKLEN);
514514
}
515515

516-
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
516+
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length)
517517
{
518-
uintptr_t i;
518+
size_t i;
519519
uint8_t storeNextIv[AES_BLOCKLEN];
520520
for (i = 0; i < length; i += AES_BLOCKLEN)
521521
{
@@ -535,11 +535,11 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
535535
#if defined(CTR) && (CTR == 1)
536536

537537
/* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */
538-
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
538+
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length)
539539
{
540540
uint8_t buffer[AES_BLOCKLEN];
541541

542-
unsigned i;
542+
size_t i;
543543
int bi;
544544
for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
545545
{

aes.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
6969
// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
7070
// NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv()
7171
// no IV should ever be reused with the same key
72-
void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
73-
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
72+
void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
73+
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
7474

7575
#endif // #if defined(CBC) && (CBC == 1)
7676

@@ -82,7 +82,7 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
8282
// Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
8383
// NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv()
8484
// no IV should ever be reused with the same key
85-
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
85+
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
8686

8787
#endif // #if defined(CTR) && (CTR == 1)
8888

0 commit comments

Comments
 (0)