Skip to content

Commit 883fcfc

Browse files
Merge pull request #6860 from douzzer/20231012-aes-xts-fixes
20231012-aes-xts-fixes
2 parents 0e35e9c + 3a19556 commit 883fcfc

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11461,9 +11461,9 @@ int wc_AesXtsEncryptConsecutiveSectors(XtsAes* aes, byte* out, const byte* in,
1146111461
word32 sz, word64 sector, word32 sectorSz)
1146211462
{
1146311463
int ret = 0;
11464-
int iter = 0;
11465-
int sectorCount = sz / sectorSz;
11466-
int remainder = sz % sectorSz;
11464+
word32 iter = 0;
11465+
word32 sectorCount;
11466+
word32 remainder;
1146711467

1146811468
if (aes == NULL || out == NULL || in == NULL || sectorSz == 0) {
1146911469
return BAD_FUNC_ARG;
@@ -11474,6 +11474,9 @@ int wc_AesXtsEncryptConsecutiveSectors(XtsAes* aes, byte* out, const byte* in,
1147411474
return BAD_FUNC_ARG;
1147511475
}
1147611476

11477+
sectorCount = sz / sectorSz;
11478+
remainder = sz % sectorSz;
11479+
1147711480
while (sectorCount) {
1147811481
ret = wc_AesXtsEncryptSector(aes, out + (iter * sectorSz),
1147911482
in + (iter * sectorSz), sectorSz, sector);
@@ -11507,9 +11510,9 @@ int wc_AesXtsDecryptConsecutiveSectors(XtsAes* aes, byte* out, const byte* in,
1150711510
word32 sz, word64 sector, word32 sectorSz)
1150811511
{
1150911512
int ret = 0;
11510-
int iter = 0;
11511-
int sectorCount = sz / sectorSz;
11512-
int remainder = sz % sectorSz;
11513+
word32 iter = 0;
11514+
word32 sectorCount;
11515+
word32 remainder;
1151311516

1151411517
if (aes == NULL || out == NULL || in == NULL || sectorSz == 0) {
1151511518
return BAD_FUNC_ARG;
@@ -11520,6 +11523,9 @@ int wc_AesXtsDecryptConsecutiveSectors(XtsAes* aes, byte* out, const byte* in,
1152011523
return BAD_FUNC_ARG;
1152111524
}
1152211525

11526+
sectorCount = sz / sectorSz;
11527+
remainder = sz % sectorSz;
11528+
1152311529
while (sectorCount) {
1152411530
ret = wc_AesXtsDecryptSector(aes, out + (iter * sectorSz),
1152511531
in + (iter * sectorSz), sectorSz, sector);

wolfcrypt/test/test.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9820,10 +9820,6 @@ static wc_test_ret_t aes_xts_sector_test(void)
98209820
int aes_inited = 0;
98219821
wc_test_ret_t ret = 0;
98229822
unsigned char buf[AES_BLOCK_SIZE * 2];
9823-
#ifndef BENCH_EMBEDDED
9824-
/* Sector size for encrypt/decrypt consecutive sectors testcase */
9825-
word32 sectorSz = 512;
9826-
#endif
98279823

98289824
/* 128 key tests */
98299825
WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
@@ -9871,7 +9867,11 @@ static wc_test_ret_t aes_xts_sector_test(void)
98719867
};
98729868
word64 s2 = 187;
98739869

9874-
#ifndef BENCH_EMBEDDED
9870+
#if !defined(BENCH_EMBEDDED) && \
9871+
(!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
9872+
/* Sector size for encrypt/decrypt consecutive sectors testcase */
9873+
word32 sectorSz = 512;
9874+
98759875
unsigned char data[550];
98769876

98779877
WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
@@ -10055,7 +10055,8 @@ static wc_test_ret_t aes_xts_sector_test(void)
1005510055
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
1005610056
wc_AesXtsFree(aes);
1005710057

10058-
#ifndef BENCH_EMBEDDED
10058+
#if !defined(BENCH_EMBEDDED) && \
10059+
(!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
1005910060
/* encrypt consecutive sectors test */
1006010061
XMEMSET(data, 0, sizeof(buf));
1006110062
ret = wc_AesXtsSetKey(aes, k3, sizeof(k3), AES_ENCRYPTION,
@@ -10090,7 +10091,7 @@ static wc_test_ret_t aes_xts_sector_test(void)
1009010091
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
1009110092
wc_AesXtsFree(aes);
1009210093

10093-
#endif
10094+
#endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
1009410095

1009510096
out:
1009610097

0 commit comments

Comments
 (0)