Skip to content

Commit a0a7625

Browse files
authored
Merge pull request wolfSSL#9783 from SparkiDev/aes_clang_volatile
AES clang: make x volatile in pre-fetch functions
2 parents 90d0ea1 + 299e7bd commit a0a7625

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

wolfcrypt/src/aes.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,15 +1880,17 @@ static WARN_UNUSED_RESULT word32 inv_col_mul(
18801880
static WARN_UNUSED_RESULT WC_INLINE word32 PreFetchTe(void)
18811881
{
18821882
#ifndef WOLFSSL_AES_TOUCH_LINES
1883-
word32 x = 0;
1884-
int i,j;
1883+
volatile word32 x = 0;
1884+
int i;
1885+
int j;
18851886

18861887
for (i = 0; i < 4; i++) {
18871888
/* 256 elements, each one is 4 bytes */
1888-
for (j = 0; j < 256; j += WC_CACHE_LINE_SZ/4) {
1889+
for (j = 0; j < 256; j += WC_CACHE_LINE_SZ / 4) {
18891890
x &= Te[i][j];
18901891
}
18911892
}
1893+
18921894
return x;
18931895
#else
18941896
return 0;
@@ -1899,12 +1901,13 @@ static WARN_UNUSED_RESULT WC_INLINE word32 PreFetchTe(void)
18991901
static WARN_UNUSED_RESULT WC_INLINE word32 PreFetchSBox(void)
19001902
{
19011903
#ifndef WOLFSSL_AES_TOUCH_LINES
1902-
word32 x = 0;
1904+
volatile word32 x = 0;
19031905
int i;
19041906

19051907
for (i = 0; i < 256; i += WC_CACHE_LINE_SZ/4) {
19061908
x &= Tsbox[i];
19071909
}
1910+
19081911
return x;
19091912
#else
19101913
return 0;
@@ -3168,15 +3171,17 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
31683171
/* load 4 Td Tables into cache by cache line stride */
31693172
static WARN_UNUSED_RESULT WC_INLINE word32 PreFetchTd(void)
31703173
{
3171-
word32 x = 0;
3172-
int i,j;
3174+
volatile word32 x = 0;
3175+
int i;
3176+
int j;
31733177

31743178
for (i = 0; i < 4; i++) {
31753179
/* 256 elements, each one is 4 bytes */
3176-
for (j = 0; j < 256; j += WC_CACHE_LINE_SZ/4) {
3180+
for (j = 0; j < 256; j += WC_CACHE_LINE_SZ / 4) {
31773181
x &= Td[i][j];
31783182
}
31793183
}
3184+
31803185
return x;
31813186
}
31823187
#endif /* !WOLFSSL_AES_SMALL_TABLES */
@@ -3185,12 +3190,13 @@ static WARN_UNUSED_RESULT WC_INLINE word32 PreFetchTd(void)
31853190
static WARN_UNUSED_RESULT WC_INLINE word32 PreFetchTd4(void)
31863191
{
31873192
#ifndef WOLFSSL_AES_TOUCH_LINES
3188-
word32 x = 0;
3193+
volatile word32 x = 0;
31893194
int i;
31903195

31913196
for (i = 0; i < 256; i += WC_CACHE_LINE_SZ) {
31923197
x &= (word32)Td4[i];
31933198
}
3199+
31943200
return x;
31953201
#else
31963202
return 0;

0 commit comments

Comments
 (0)