Skip to content

Commit 80b7ea6

Browse files
committed
Aarch64 no harware crypto assembly AES
Implementations of AES-ECB, AES-CBC, AES-CTR, AES-GCM, AES-XTS with base instructions and NEON but not using crypto instructions. Benchmark of AES-ECB added. Updated AES tests.
1 parent 1b7072b commit 80b7ea6

8 files changed

Lines changed: 28421 additions & 270 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ WOLFSSL_ALLOW_TLS_SHA1
663663
WOLFSSL_ALTERNATIVE_DOWNGRADE
664664
WOLFSSL_ALT_NAMES_NO_REV
665665
WOLFSSL_ARM_ARCH_NEON_64BIT
666+
WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP
666667
WOLFSSL_ASCON_UNROLL
667668
WOLFSSL_ASNC_CRYPT
668669
WOLFSSL_ASN_EXTRA

tests/api/test_aes.c

Lines changed: 307 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ int test_wc_AesEncryptDecryptDirect(void)
289289

290290
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
291291
/* Assembly code doing 8 iterations at a time. */
292-
#define ECB_LEN (9 * WC_AES_BLOCK_SIZE)
292+
#define ECB_LEN (15 * WC_AES_BLOCK_SIZE)
293293

294294
static int test_wc_AesEcbEncryptDecrypt_BadArgs(Aes* aes, byte* key,
295295
word32 keyLen)
@@ -1993,7 +1993,7 @@ int test_wc_AesCtrSetKey(void)
19931993

19941994
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
19951995
/* Assembly code doing 8 iterations at a time. */
1996-
#define CTR_LEN (9 * WC_AES_BLOCK_SIZE)
1996+
#define CTR_LEN (15 * WC_AES_BLOCK_SIZE)
19971997

19981998
static int test_wc_AesCtrEncrypt_BadArgs(Aes* aes, byte* key,
19991999
word32 keyLen, byte* iv)
@@ -2237,6 +2237,18 @@ int test_wc_AesCtrEncryptDecrypt(void)
22372237
0x86, 0x8f, 0x83, 0xff, 0x3d, 0xbe, 0x6e, 0xfa,
22382238
0xd2, 0x2b, 0x3e, 0x70, 0x21, 0x1c, 0xe8, 0x7b,
22392239
0xe4, 0x01, 0x2c, 0xd0, 0x82, 0xe2, 0x7a, 0x4a,
2240+
0xcf, 0x67, 0x82, 0x1c, 0x80, 0x79, 0x85, 0x5e,
2241+
0xe5, 0xf9, 0x3a, 0x0d, 0x1a, 0xa7, 0x89, 0x29,
2242+
0xee, 0xe7, 0x2b, 0xd6, 0x29, 0xac, 0xfa, 0xca,
2243+
0xc8, 0xcb, 0x4e, 0x6c, 0x1f, 0x30, 0x5e, 0x95,
2244+
0xa5, 0xa2, 0x17, 0xe2, 0x93, 0xd3, 0xe6, 0xbe,
2245+
0x91, 0x37, 0x84, 0x01, 0xdb, 0x44, 0x4c, 0x60,
2246+
0x1c, 0x2c, 0x64, 0x7d, 0xb7, 0x73, 0x12, 0x11,
2247+
0xc2, 0x6a, 0xfd, 0xac, 0x6d, 0x85, 0xd8, 0xeb,
2248+
0x0e, 0x70, 0xd3, 0x82, 0x93, 0x65, 0xff, 0x18,
2249+
0x4e, 0x22, 0x07, 0x8a, 0xf6, 0xfd, 0x36, 0x9d,
2250+
0x5c, 0x15, 0x1c, 0x84, 0x69, 0x13, 0x68, 0x78,
2251+
0xf1, 0x04, 0x02, 0x66, 0xec, 0x37, 0xcc, 0x0d,
22402252
};
22412253
#elif defined(WOLFSSL_AES_192)
22422254
byte expected24[CTR_LEN] = {
@@ -2258,6 +2270,18 @@ int test_wc_AesCtrEncryptDecrypt(void)
22582270
0x8d, 0x3b, 0xa9, 0x17, 0x4c, 0x2a, 0xc7, 0x97,
22592271
0x99, 0xb7, 0xaf, 0x86, 0x17, 0xf9, 0xe4, 0x2c,
22602272
0x5a, 0x4d, 0x6d, 0x7f, 0xfe, 0xb8, 0xaa, 0x9b,
2273+
0xf8, 0xb6, 0xcb, 0x6f, 0x2f, 0xa4, 0x57, 0x61,
2274+
0x88, 0x6c, 0x94, 0xaa, 0xf7, 0x97, 0xcf, 0xcd,
2275+
0x19, 0x29, 0x9e, 0xf3, 0x30, 0xb8, 0xaa, 0x56,
2276+
0x49, 0xcb, 0xf0, 0x56, 0xdd, 0xac, 0x4b, 0x41,
2277+
0x00, 0xb3, 0x19, 0xdd, 0xef, 0x69, 0xd0, 0x9c,
2278+
0xd1, 0x67, 0x48, 0x62, 0x9f, 0x56, 0x21, 0x2d,
2279+
0x05, 0xb3, 0x4d, 0x0b, 0xac, 0xb6, 0x63, 0xf4,
2280+
0x44, 0xfc, 0x43, 0xc0, 0xa9, 0x8c, 0x37, 0xd6,
2281+
0xc3, 0x8c, 0xa4, 0x42, 0x68, 0x08, 0x2c, 0x1e,
2282+
0xe7, 0xcc, 0xe4, 0x1f, 0x82, 0x9a, 0xe0, 0xfb,
2283+
0x18, 0x84, 0x55, 0xaf, 0x02, 0xcc, 0x55, 0x13,
2284+
0x7e, 0xc7, 0x05, 0xb8, 0xb9, 0x5e, 0x90, 0xc3,
22612285
};
22622286
#else
22632287
byte expected32[CTR_LEN] = {
@@ -2279,6 +2303,18 @@ int test_wc_AesCtrEncryptDecrypt(void)
22792303
0xf1, 0x7b, 0x2b, 0x87, 0xe4, 0xcd, 0x93, 0x22,
22802304
0x07, 0xdc, 0x35, 0x46, 0x8a, 0x1d, 0xf5, 0xe4,
22812305
0x23, 0x01, 0x67, 0x00, 0x66, 0x7b, 0xd6, 0x56,
2306+
0x0d, 0x57, 0x4f, 0x6f, 0x45, 0x82, 0x91, 0x58,
2307+
0x81, 0x37, 0xcc, 0xb4, 0xa4, 0xa3, 0x3c, 0x57,
2308+
0x42, 0x05, 0x95, 0xa3, 0x04, 0x1f, 0xfd, 0x32,
2309+
0xb7, 0xc8, 0xbb, 0x14, 0xe7, 0xf1, 0xc1, 0x1f,
2310+
0xe9, 0x33, 0x6a, 0xb0, 0x10, 0x0d, 0xfb, 0x91,
2311+
0x88, 0xca, 0x20, 0x29, 0xeb, 0xcd, 0x9c, 0x71,
2312+
0x07, 0xfd, 0x3f, 0x6b, 0x1f, 0xb3, 0x76, 0xb7,
2313+
0x6b, 0xa1, 0xad, 0xbe, 0xd3, 0x45, 0xb5, 0xe9,
2314+
0x04, 0x9a, 0xfd, 0x6a, 0x85, 0xa2, 0xbc, 0x4e,
2315+
0xca, 0xdb, 0x84, 0xbc, 0x0e, 0x0c, 0x96, 0x65,
2316+
0xc9, 0x95, 0x2b, 0xcb, 0x98, 0x8c, 0xd2, 0x78,
2317+
0x85, 0x7e, 0x1a, 0xa2, 0x6a, 0x73, 0x90, 0x80,
22822318
};
22832319
#endif
22842320
byte iv[] = "1234567890abcdef";
@@ -3407,6 +3443,275 @@ int test_wc_AesCcmEncryptDecrypt(void)
34073443
return EXPECT_RESULT();
34083444
} /* END test_wc_AesCcmEncryptDecrypt */
34093445

3446+
/*******************************************************************************
3447+
* AES-XTS
3448+
******************************************************************************/
3449+
3450+
/*
3451+
* test function for wc_AesXtsSetKey()
3452+
*/
3453+
int test_wc_AesXtsSetKey(void)
3454+
{
3455+
EXPECT_DECLS;
3456+
#if !defined(NO_AES) && defined(WOLFSSL_AES_XTS)
3457+
XtsAes aes;
3458+
#ifdef WOLFSSL_AES_128
3459+
byte key16[] = {
3460+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3461+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3462+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3463+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3464+
};
3465+
#endif
3466+
#if defined(WOLFSSL_AES_192) && !defined(HAVE_FIPS)
3467+
byte key24[] = {
3468+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3469+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3470+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3471+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3472+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3473+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
3474+
};
3475+
#endif
3476+
#ifdef WOLFSSL_AES_256
3477+
byte key32[] = {
3478+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3479+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3480+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3481+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3482+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3483+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3484+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3485+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
3486+
};
3487+
#endif
3488+
byte badKey16[] = {
3489+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3490+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3491+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3492+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
3493+
};
3494+
byte badKey24[] = {
3495+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3496+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3497+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3498+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3499+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3500+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
3501+
};
3502+
byte badKey32[] = {
3503+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3504+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3505+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3506+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3507+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x37, 0x37,
3508+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3509+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3510+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
3511+
};
3512+
byte* key;
3513+
word32 keyLen;
3514+
3515+
#ifdef WOLFSSL_AES_128
3516+
key = key16;
3517+
keyLen = sizeof(key16)/sizeof(byte);
3518+
#elif defined(WOLFSSL_AES_192)
3519+
key = key24;
3520+
keyLen = sizeof(key24)/sizeof(byte);
3521+
#else
3522+
key = key32;
3523+
keyLen = sizeof(key32)/sizeof(byte);
3524+
#endif
3525+
3526+
#ifdef WOLFSSL_AES_128
3527+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key16, sizeof(key16)/sizeof(byte),
3528+
AES_ENCRYPTION, NULL, INVALID_DEVID), 0);
3529+
wc_AesXtsFree(&aes);
3530+
#endif
3531+
#if defined(WOLFSSL_AES_192) && !defined(HAVE_FIPS)
3532+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key24, sizeof(key24)/sizeof(byte),
3533+
AES_ENCRYPTION, NULL, INVALID_DEVID), 0);
3534+
wc_AesXtsFree(&aes);
3535+
#endif
3536+
#ifdef WOLFSSL_AES_256
3537+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key32, sizeof(key32)/sizeof(byte),
3538+
AES_ENCRYPTION, NULL, INVALID_DEVID), 0);
3539+
wc_AesXtsFree(&aes);
3540+
#endif
3541+
3542+
/* Pass in bad args. */
3543+
ExpectIntEQ(wc_AesXtsSetKey(NULL, NULL, keyLen, AES_ENCRYPTION, NULL,
3544+
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3545+
ExpectIntEQ(wc_AesXtsSetKey(NULL, key, keyLen, AES_ENCRYPTION, NULL,
3546+
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3547+
ExpectIntEQ(wc_AesXtsSetKey(&aes, NULL, keyLen, AES_ENCRYPTION, NULL,
3548+
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3549+
ExpectIntEQ(wc_AesXtsSetKey(&aes, badKey16, sizeof(badKey16)/sizeof(byte),
3550+
AES_ENCRYPTION, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
3551+
ExpectIntEQ(wc_AesXtsSetKey(&aes, badKey24, sizeof(badKey24)/sizeof(byte),
3552+
AES_ENCRYPTION, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
3553+
ExpectIntEQ(wc_AesXtsSetKey(&aes, badKey32, sizeof(badKey32)/sizeof(byte),
3554+
AES_ENCRYPTION, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
3555+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key, keyLen, -2, NULL, INVALID_DEVID),
3556+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3557+
#endif
3558+
return EXPECT_RESULT();
3559+
} /* END test_wc_AesXtsSetKey */
3560+
3561+
int test_wc_AesXtsEncryptDecrypt_Sizes(void)
3562+
{
3563+
EXPECT_DECLS;
3564+
#if !defined(NO_AES) && defined(WOLFSSL_AES_XTS) && \
3565+
defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG) && \
3566+
!defined(WOLFSSL_KCAPI)
3567+
#define XTS_LEN (WC_AES_BLOCK_SIZE * 16)
3568+
byte key32[] = {
3569+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3570+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3571+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3572+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3573+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3574+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3575+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3576+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
3577+
};
3578+
byte tweak[] = {
3579+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3580+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3581+
};
3582+
XtsAes aes;
3583+
word32 tweakLen = (word32)sizeof(tweak)/sizeof(byte);
3584+
int sz;
3585+
WC_DECLARE_VAR(plain, byte, XTS_LEN, NULL);
3586+
WC_DECLARE_VAR(cipher, byte, XTS_LEN, NULL);
3587+
#ifdef HAVE_AES_DECRYPT
3588+
WC_DECLARE_VAR(decrypted, byte, XTS_LEN, NULL);
3589+
#endif
3590+
3591+
WC_ALLOC_VAR(plain, byte, XTS_LEN, NULL);
3592+
WC_ALLOC_VAR(cipher, byte, XTS_LEN, NULL);
3593+
#ifdef HAVE_AES_DECRYPT
3594+
WC_ALLOC_VAR(decrypted, byte, XTS_LEN, NULL);
3595+
#endif
3596+
3597+
#ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
3598+
ExpectNotNull(plain);
3599+
ExpectNotNull(cipher);
3600+
#ifdef HAVE_AES_DECRYPT
3601+
ExpectNotNull(decrypted);
3602+
#endif
3603+
#endif
3604+
3605+
XMEMSET(&aes, 0, sizeof(Aes));
3606+
XMEMSET(plain, 0xa5, XTS_LEN);
3607+
3608+
for (sz = WC_AES_BLOCK_SIZE; sz <= XTS_LEN; sz *= 2) {
3609+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key32, sizeof(key32)/sizeof(byte),
3610+
AES_ENCRYPTION, NULL, INVALID_DEVID), 0);
3611+
XMEMSET(cipher, 0, XTS_LEN);
3612+
ExpectIntEQ(wc_AesXtsEncrypt(&aes, cipher, plain, sz, tweak, tweakLen),
3613+
0);
3614+
wc_AesXtsFree(&aes);
3615+
3616+
#ifdef HAVE_AES_DECRYPT
3617+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key32, sizeof(key32)/sizeof(byte),
3618+
AES_DECRYPTION, NULL, INVALID_DEVID), 0);
3619+
XMEMSET(decrypted, 0xff, XTS_LEN);
3620+
ExpectIntEQ(wc_AesXtsDecrypt(&aes, decrypted, cipher, sz, tweak,
3621+
tweakLen), 0);
3622+
ExpectBufEQ(decrypted, plain, sz);
3623+
wc_AesXtsFree(&aes);
3624+
#endif
3625+
}
3626+
3627+
WC_FREE_VAR(plain, NULL);
3628+
WC_FREE_VAR(cipher, NULL);
3629+
#ifdef HAVE_AES_DECRYPT
3630+
WC_FREE_VAR(decrypted, NULL);
3631+
#endif
3632+
#endif
3633+
return EXPECT_RESULT();
3634+
}
3635+
3636+
/*
3637+
* test function for wc_AesXtsEncrypt and wc_AesXtsDecrypt
3638+
*/
3639+
int test_wc_AesXtsEncryptDecrypt(void)
3640+
{
3641+
EXPECT_DECLS;
3642+
#if !defined(NO_AES) && defined(WOLFSSL_AES_XTS) && \
3643+
defined(WOLFSSL_AES_256)
3644+
XtsAes aes;
3645+
byte key32[] = {
3646+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3647+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3648+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3649+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3650+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3651+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3652+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3653+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
3654+
};
3655+
byte vector[] = { /* Now is the time for all w/o trailing 0 */
3656+
0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
3657+
0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
3658+
0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
3659+
};
3660+
byte tweak[] = {
3661+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3662+
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
3663+
};
3664+
word32 tweakLen = (word32)sizeof(tweak)/sizeof(byte);
3665+
byte enc[sizeof(vector)];
3666+
byte resultT[WC_AES_BLOCK_SIZE];
3667+
byte dec[sizeof(vector)];
3668+
3669+
/* Init stack variables. */
3670+
XMEMSET(&aes, 0, sizeof(Aes));
3671+
XMEMSET(enc, 0, sizeof(vector));
3672+
XMEMSET(dec, 0, sizeof(vector));
3673+
XMEMSET(resultT, 0, WC_AES_BLOCK_SIZE);
3674+
3675+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key32, sizeof(key32)/sizeof(byte),
3676+
AES_ENCRYPTION, NULL, INVALID_DEVID), 0);
3677+
ExpectIntEQ(wc_AesXtsEncrypt(&aes, enc, vector, sizeof(vector), tweak,
3678+
tweakLen), 0);
3679+
wc_AesXtsFree(&aes);
3680+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key32, sizeof(key32)/sizeof(byte),
3681+
AES_DECRYPTION, NULL, INVALID_DEVID), 0);
3682+
ExpectIntEQ(wc_AesXtsDecrypt(&aes, dec, enc, sizeof(vector), tweak,
3683+
tweakLen), 0);
3684+
ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
3685+
wc_AesXtsFree(&aes);
3686+
3687+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key32, sizeof(key32)/sizeof(byte),
3688+
AES_ENCRYPTION, NULL, INVALID_DEVID), 0);
3689+
/* Test bad args for wc_AesXtsEncrypt and wc_AesXtsDecrypt */
3690+
ExpectIntEQ(wc_AesXtsEncrypt(NULL, enc, vector, sizeof(vector), tweak,
3691+
tweakLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3692+
ExpectIntEQ(wc_AesXtsEncrypt(&aes, NULL, vector, sizeof(vector), tweak,
3693+
tweakLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3694+
ExpectIntEQ(wc_AesXtsEncrypt(&aes, enc, NULL, sizeof(vector), tweak,
3695+
tweakLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3696+
wc_AesXtsFree(&aes);
3697+
/* END wc_AesXtsEncrypt */
3698+
3699+
#ifdef HAVE_AES_DECRYPT
3700+
ExpectIntEQ(wc_AesXtsSetKey(&aes, key32, sizeof(key32)/sizeof(byte),
3701+
AES_DECRYPTION, NULL, INVALID_DEVID), 0);
3702+
ExpectIntEQ(wc_AesXtsDecrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte),
3703+
tweak, tweakLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3704+
ExpectIntEQ(wc_AesXtsDecrypt(&aes, NULL, enc, sizeof(enc)/sizeof(byte),
3705+
tweak, tweakLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3706+
ExpectIntEQ(wc_AesXtsDecrypt(&aes, dec, NULL, sizeof(enc)/sizeof(byte),
3707+
tweak, tweakLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3708+
wc_AesXtsFree(&aes);
3709+
#endif /* HAVE_AES_DECRYPT */
3710+
#endif
3711+
3712+
return EXPECT_RESULT();
3713+
} /* END test_wc_AesXtsEncryptDecrypt */
3714+
34103715
#if defined(WOLFSSL_AES_EAX) && defined(WOLFSSL_AES_256) && \
34113716
(!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
34123717

tests/api/test_aes.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ int test_wc_AesGcmMixedEncDecLongIV(void);
4141
int test_wc_AesGcmStream(void);
4242
int test_wc_AesCcmSetKey(void);
4343
int test_wc_AesCcmEncryptDecrypt(void);
44+
int test_wc_AesXtsSetKey(void);
45+
int test_wc_AesXtsEncryptDecrypt_Sizes(void);
46+
int test_wc_AesXtsEncryptDecrypt(void);
4447
#if defined(WOLFSSL_AES_EAX) && defined(WOLFSSL_AES_256) && \
4548
(!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
4649
int test_wc_AesEaxVectors(void);
@@ -68,7 +71,10 @@ int test_wc_GmacUpdate(void);
6871
TEST_DECL_GROUP("aes", test_wc_AesGcmMixedEncDecLongIV), \
6972
TEST_DECL_GROUP("aes", test_wc_AesGcmStream), \
7073
TEST_DECL_GROUP("aes", test_wc_AesCcmSetKey), \
71-
TEST_DECL_GROUP("aes", test_wc_AesCcmEncryptDecrypt)
74+
TEST_DECL_GROUP("aes", test_wc_AesCcmEncryptDecrypt), \
75+
TEST_DECL_GROUP("aes", test_wc_AesXtsSetKey), \
76+
TEST_DECL_GROUP("aes", test_wc_AesXtsEncryptDecrypt_Sizes), \
77+
TEST_DECL_GROUP("aes", test_wc_AesXtsEncryptDecrypt)
7278

7379
#if defined(WOLFSSL_AES_EAX) && defined(WOLFSSL_AES_256) && \
7480
(!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)

0 commit comments

Comments
 (0)