Skip to content

Commit 643f472

Browse files
SparkiDevdouzzer
authored andcommitted
AES-XTS ASM x64: Add Intel x64 implementation of streaming
Changed APIs from wc_AesXts*Start -> wc_AesXts*Init. Enabled ASM for x64 in aes.c. AesXtsDecryptStart_sw same as AesXtsEncryptStart_sw so changed them to AesXtsInit_sw.
1 parent f874d87 commit 643f472

4 files changed

Lines changed: 2940 additions & 267 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12530,9 +12530,9 @@ void AES_XTS_encrypt_aesni(const unsigned char *in, unsigned char *out, word32 s
1253012530
const unsigned char* key2, int nr)
1253112531
XASM_LINK("AES_XTS_encrypt_aesni");
1253212532
#ifdef WOLFSSL_AESXTS_STREAM
12533-
void AES_XTS_encrypt_start_aesni(unsigned char* i, const unsigned char* tweak_key,
12533+
void AES_XTS_init_aesni(unsigned char* i, const unsigned char* tweak_key,
1253412534
int tweak_nr)
12535-
XASM_LINK("AES_XTS_encrypt_start_aesni");
12535+
XASM_LINK("AES_XTS_init_aesni");
1253612536
void AES_XTS_encrypt_update_aesni(const unsigned char *in, unsigned char *out, word32 sz,
1253712537
const unsigned char* key, unsigned char *i, int nr)
1253812538
XASM_LINK("AES_XTS_encrypt_update_aesni");
@@ -12544,9 +12544,9 @@ void AES_XTS_encrypt_avx1(const unsigned char *in, unsigned char *out,
1254412544
int nr)
1254512545
XASM_LINK("AES_XTS_encrypt_avx1");
1254612546
#ifdef WOLFSSL_AESXTS_STREAM
12547-
void AES_XTS_encrypt_start_avx1(unsigned char* i, const unsigned char* tweak_key,
12547+
void AES_XTS_init_avx1(unsigned char* i, const unsigned char* tweak_key,
1254812548
int tweak_nr)
12549-
XASM_LINK("AES_XTS_encrypt_start_avx1");
12549+
XASM_LINK("AES_XTS_init_avx1");
1255012550
void AES_XTS_encrypt_update_avx1(const unsigned char *in, unsigned char *out, word32 sz,
1255112551
const unsigned char* key, unsigned char *i, int nr)
1255212552
XASM_LINK("AES_XTS_encrypt_update_avx1");
@@ -12559,9 +12559,6 @@ void AES_XTS_decrypt_aesni(const unsigned char *in, unsigned char *out, word32 s
1255912559
const unsigned char* key2, int nr)
1256012560
XASM_LINK("AES_XTS_decrypt_aesni");
1256112561
#ifdef WOLFSSL_AESXTS_STREAM
12562-
void AES_XTS_decrypt_start_aesni(unsigned char* i, const unsigned char* tweak_key,
12563-
int tweak_nr)
12564-
XASM_LINK("AES_XTS_decrypt_start_aesni");
1256512562
void AES_XTS_decrypt_update_aesni(const unsigned char *in, unsigned char *out, word32 sz,
1256612563
const unsigned char* key, unsigned char *i, int nr)
1256712564
XASM_LINK("AES_XTS_decrypt_update_aesni");
@@ -12573,9 +12570,6 @@ void AES_XTS_decrypt_avx1(const unsigned char *in, unsigned char *out,
1257312570
int nr)
1257412571
XASM_LINK("AES_XTS_decrypt_avx1");
1257512572
#ifdef WOLFSSL_AESXTS_STREAM
12576-
void AES_XTS_decrypt_start_avx1(unsigned char* i, const unsigned char* tweak_key,
12577-
int tweak_nr)
12578-
XASM_LINK("AES_XTS_decrypt_start_avx1");
1257912573
void AES_XTS_decrypt_update_avx1(const unsigned char *in, unsigned char *out, word32 sz,
1258012574
const unsigned char* key, unsigned char *i, int nr)
1258112575
XASM_LINK("AES_XTS_decrypt_update_avx1");
@@ -12732,7 +12726,7 @@ static int AesXtsEncrypt_sw(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1273212726
*
1273312727
* returns 0 on success
1273412728
*/
12735-
static int AesXtsEncryptStart_sw(XtsAes* xaes, byte* i) {
12729+
static int AesXtsInit_sw(XtsAes* xaes, byte* i) {
1273612730
return wc_AesEncryptDirect(&xaes->tweak, i, i);
1273712731
}
1273812732

@@ -12916,7 +12910,7 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1291612910

1291712911
#ifdef WOLFSSL_AESXTS_STREAM
1291812912

12919-
int wc_AesXtsEncryptStart(XtsAes* xaes, byte* i, word32 iSz)
12913+
int wc_AesXtsEncryptInit(XtsAes* xaes, byte* i, word32 iSz)
1292012914
{
1292112915
int ret;
1292212916

@@ -12942,30 +12936,28 @@ int wc_AesXtsEncryptStart(XtsAes* xaes, byte* i, word32 iSz)
1294212936
}
1294312937

1294412938
{
12945-
#if 0 && defined(WOLFSSL_AESNI)
12939+
#ifdef WOLFSSL_AESNI
1294612940
if (aes->use_aesni) {
1294712941
SAVE_VECTOR_REGISTERS(return _svr_ret;);
1294812942
#if defined(HAVE_INTEL_AVX1)
1294912943
if (IS_INTEL_AVX1(intel_flags)) {
12950-
AES_XTS_encrypt_start_avx1(i,
12951-
(const byte*)xaes->tweak.key,
12952-
(int)xaes->tweak.rounds);
12944+
AES_XTS_init_avx1(i, (const byte*)xaes->tweak.key,
12945+
(int)xaes->tweak.rounds);
1295312946
ret = 0;
1295412947
}
1295512948
else
1295612949
#endif
1295712950
{
12958-
AES_XTS_encrypt_start_aesni(i,
12959-
(const byte*)xaes->tweak.key,
12960-
(int)xaes->tweak.rounds);
12951+
AES_XTS_init_aesni(i, (const byte*)xaes->tweak.key,
12952+
(int)xaes->tweak.rounds);
1296112953
ret = 0;
1296212954
}
1296312955
RESTORE_VECTOR_REGISTERS();
1296412956
}
1296512957
else
12966-
#endif /* 0 && defined(WOLFSSL_AESNI) */
12958+
#endif /* WOLFSSL_AESNI */
1296712959
{
12968-
ret = AesXtsEncryptStart_sw(xaes, i);
12960+
ret = AesXtsInit_sw(xaes, i);
1296912961
}
1297012962
}
1297112963

@@ -12989,15 +12981,15 @@ int wc_AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1298912981
{
1299012982
int ret;
1299112983

12992-
#if 0 && defined(WOLFSSL_AESNI)
12984+
#ifdef WOLFSSL_AESNI
1299312985
Aes *aes;
1299412986
#endif
1299512987

1299612988
if (xaes == NULL || out == NULL || in == NULL || i == NULL) {
1299712989
return BAD_FUNC_ARG;
1299812990
}
1299912991

13000-
#if 0 && defined(WOLFSSL_AESNI)
12992+
#ifdef WOLFSSL_AESNI
1300112993
aes = &xaes->aes;
1300212994
#endif
1300312995

@@ -13007,7 +12999,7 @@ int wc_AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1300712999
}
1300813000

1300913001
{
13010-
#if 0 && defined(WOLFSSL_AESNI)
13002+
#ifdef WOLFSSL_AESNI
1301113003
if (aes->use_aesni) {
1301213004
SAVE_VECTOR_REGISTERS(return _svr_ret;);
1301313005
#if defined(HAVE_INTEL_AVX1)
@@ -13030,7 +13022,7 @@ int wc_AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1303013022
RESTORE_VECTOR_REGISTERS();
1303113023
}
1303213024
else
13033-
#endif /* 0 && defined(WOLFSSL_AESNI) */
13025+
#endif /* WOLFSSL_AESNI */
1303413026
{
1303513027
ret = AesXtsEncryptUpdate_sw(xaes, out, in, sz, i);
1303613028
}
@@ -13171,11 +13163,6 @@ static int AesXtsDecrypt_sw(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1317113163

1317213164
#ifdef WOLFSSL_AESXTS_STREAM
1317313165

13174-
static int AesXtsDecryptStart_sw(XtsAes* xaes, byte* i)
13175-
{
13176-
return wc_AesEncryptDirect(&xaes->tweak, i, i);
13177-
}
13178-
1317913166
/* Block-streaming AES-XTS.
1318013167
*
1318113168
* Same process as encryption but use decrypt key.
@@ -13402,7 +13389,7 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1340213389
*
1340313390
* returns 0 on success
1340413391
*/
13405-
int wc_AesXtsDecryptStart(XtsAes* xaes, byte* i, word32 iSz)
13392+
int wc_AesXtsDecryptInit(XtsAes* xaes, byte* i, word32 iSz)
1340613393
{
1340713394
int ret;
1340813395
Aes *aes;
@@ -13427,30 +13414,28 @@ int wc_AesXtsDecryptStart(XtsAes* xaes, byte* i, word32 iSz)
1342713414
}
1342813415

1342913416
{
13430-
#if 0 && defined(WOLFSSL_AESNI)
13417+
#ifdef WOLFSSL_AESNI
1343113418
if (aes->use_aesni) {
1343213419
SAVE_VECTOR_REGISTERS(return _svr_ret;);
1343313420
#if defined(HAVE_INTEL_AVX1)
1343413421
if (IS_INTEL_AVX1(intel_flags)) {
13435-
AES_XTS_decrypt_start_avx1(i,
13436-
(const byte*)xaes->tweak.key,
13437-
(int)xaes->tweak.rounds);
13422+
AES_XTS_init_avx1(i, (const byte*)xaes->tweak.key,
13423+
(int)xaes->tweak.rounds);
1343813424
ret = 0;
1343913425
}
1344013426
else
1344113427
#endif
1344213428
{
13443-
AES_XTS_decrypt_start_aesni(i,
13444-
(const byte*)xaes->tweak.key,
13445-
(int)xaes->tweak.rounds);
13429+
AES_XTS_init_aesni(i, (const byte*)xaes->tweak.key,
13430+
(int)xaes->tweak.rounds);
1344613431
ret = 0;
1344713432
}
1344813433
RESTORE_VECTOR_REGISTERS();
1344913434
}
1345013435
else
13451-
#endif /* 0 && defined(WOLFSSL_AESNI) */
13436+
#endif /* WOLFSSL_AESNI */
1345213437
{
13453-
ret = AesXtsDecryptStart_sw(xaes, i);
13438+
ret = AesXtsInit_sw(xaes, i);
1345413439
}
1345513440

1345613441
}
@@ -13472,15 +13457,15 @@ int wc_AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1347213457
byte *i)
1347313458
{
1347413459
int ret;
13475-
#if 0 && defined(WOLFSSL_AESNI)
13460+
#ifdef WOLFSSL_AESNI
1347613461
Aes *aes;
1347713462
#endif
1347813463

1347913464
if (xaes == NULL || out == NULL || in == NULL) {
1348013465
return BAD_FUNC_ARG;
1348113466
}
1348213467

13483-
#if 0 && defined(WOLFSSL_AESNI)
13468+
#ifdef WOLFSSL_AESNI
1348413469
#ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
1348513470
aes = &xaes->aes_decrypt;
1348613471
#else
@@ -13494,7 +13479,7 @@ int wc_AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1349413479
}
1349513480

1349613481
{
13497-
#if 0 && defined(WOLFSSL_AESNI)
13482+
#ifdef WOLFSSL_AESNI
1349813483
if (aes->use_aesni) {
1349913484
SAVE_VECTOR_REGISTERS(return _svr_ret;);
1350013485
#if defined(HAVE_INTEL_AVX1)
@@ -13517,7 +13502,7 @@ int wc_AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 sz,
1351713502
RESTORE_VECTOR_REGISTERS();
1351813503
}
1351913504
else
13520-
#endif /* 0 && defined(WOLFSSL_AESNI) */
13505+
#endif /* WOLFSSL_AESNI */
1352113506
{
1352213507
ret = AesXtsDecryptUpdate_sw(xaes, out, in, sz, i);
1352313508
}

0 commit comments

Comments
 (0)