@@ -799,7 +799,7 @@ static int gcmAesAead_loaded = 0;
799799 (defined(LINUXKM_LKCAPI_REGISTER_ALL ) || \
800800 defined(LINUXKM_LKCAPI_REGISTER_AESXTS ))
801801
802- #ifndef WOLFSSL_AESGCM_STREAM
802+ #ifndef WOLFSSL_AESXTS_STREAM
803803 #error LKCAPI registration of AES-XTS requires WOLFSSL_AESXTS_STREAM (--enable-aesxts-stream).
804804#endif
805805
@@ -2022,6 +2022,25 @@ static int aes_xts_128_test(void)
20222022
20232023 XMEMSET (buf , 0 , AES_XTS_128_TEST_BUF_SIZ );
20242024
2025+ XMEMCPY (iv , i2 , sizeof (i2 ));
2026+ ret = wc_AesXtsEncryptInit (aes , iv , sizeof (iv ));
2027+ if (ret != 0 )
2028+ goto out ;
2029+ ret = wc_AesXtsEncryptUpdate (aes , buf , p2 , AES_BLOCK_SIZE , iv );
2030+ if (ret != 0 )
2031+ goto out ;
2032+ ret = wc_AesXtsEncryptUpdate (aes , buf + AES_BLOCK_SIZE ,
2033+ p2 + AES_BLOCK_SIZE ,
2034+ sizeof (p2 ) - AES_BLOCK_SIZE , iv );
2035+ if (ret != 0 )
2036+ goto out ;
2037+ if (XMEMCMP (c2 , buf , sizeof (c2 ))) {
2038+ ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E ;
2039+ goto out ;
2040+ }
2041+
2042+ XMEMSET (buf , 0 , AES_XTS_128_TEST_BUF_SIZ );
2043+
20252044 ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_ENCRYPTION );
20262045 if (ret != 0 )
20272046 goto out ;
@@ -2173,6 +2192,7 @@ static int aes_xts_128_test(void)
21732192 #define LARGE_XTS_SZ 1024
21742193 int i ;
21752194 int j ;
2195+ int k ;
21762196
21772197 large_input = (byte * )XMALLOC (LARGE_XTS_SZ , NULL ,
21782198 DYNAMIC_TYPE_TMP_BUFFER );
@@ -2184,15 +2204,22 @@ static int aes_xts_128_test(void)
21842204 for (i = 0 ; i < (int )LARGE_XTS_SZ ; i ++ )
21852205 large_input [i ] = (byte )i ;
21862206
2207+ /* first, encrypt block by block then decrypt with a one-shot call. */
21872208 for (j = 16 ; j < (int )LARGE_XTS_SZ ; j ++ ) {
21882209 ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_ENCRYPTION );
21892210 if (ret != 0 )
21902211 goto out ;
2191- ret = wc_AesXtsEncrypt ( aes , large_input , large_input , j , i1 ,
2192- sizeof (i1 ));
2212+ XMEMCPY ( iv , i1 , sizeof ( i1 ));
2213+ ret = wc_AesXtsEncryptInit ( aes , iv , sizeof (iv ));
21932214 if (ret != 0 )
21942215 goto out ;
2195-
2216+ for (k = 0 ; k < j ; k += AES_BLOCK_SIZE ) {
2217+ ret = wc_AesXtsEncryptUpdate (aes , large_input + k , large_input + k , (j - k ) < AES_BLOCK_SIZE * 2 ? j - k : AES_BLOCK_SIZE , iv );
2218+ if (ret != 0 )
2219+ goto out ;
2220+ if ((j - k ) < AES_BLOCK_SIZE * 2 )
2221+ break ;
2222+ }
21962223 ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_DECRYPTION );
21972224 if (ret != 0 )
21982225 goto out ;
@@ -2207,6 +2234,37 @@ static int aes_xts_128_test(void)
22072234 }
22082235 }
22092236 }
2237+
2238+ /* second, encrypt with a one-shot call then decrypt block by block. */
2239+ for (j = 16 ; j < (int )LARGE_XTS_SZ ; j ++ ) {
2240+ ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_ENCRYPTION );
2241+ if (ret != 0 )
2242+ goto out ;
2243+ ret = wc_AesXtsEncrypt (aes , large_input , large_input , j , i1 ,
2244+ sizeof (i1 ));
2245+ if (ret != 0 )
2246+ goto out ;
2247+ ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_DECRYPTION );
2248+ if (ret != 0 )
2249+ goto out ;
2250+ XMEMCPY (iv , i1 , sizeof (i1 ));
2251+ ret = wc_AesXtsDecryptInit (aes , iv , sizeof (iv ));
2252+ if (ret != 0 )
2253+ goto out ;
2254+ for (k = 0 ; k < j ; k += AES_BLOCK_SIZE ) {
2255+ ret = wc_AesXtsDecryptUpdate (aes , large_input + k , large_input + k , (j - k ) < AES_BLOCK_SIZE * 2 ? j - k : AES_BLOCK_SIZE , iv );
2256+ if (ret != 0 )
2257+ goto out ;
2258+ if ((j - k ) < AES_BLOCK_SIZE * 2 )
2259+ break ;
2260+ }
2261+ for (i = 0 ; i < j ; i ++ ) {
2262+ if (large_input [i ] != (byte )i ) {
2263+ ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E ;
2264+ goto out ;
2265+ }
2266+ }
2267+ }
22102268 }
22112269
22122270 /* now the kernel crypto part */
@@ -2425,6 +2483,7 @@ static int aes_xts_256_test(void)
24252483 struct crypto_skcipher * tfm = NULL ;
24262484 struct skcipher_request * req = NULL ;
24272485 u8 iv [AES_BLOCK_SIZE ];
2486+ byte * large_input = NULL ;
24282487
24292488 /* 256 key tests */
24302489 static const unsigned char k1 [] = {
@@ -2543,6 +2602,25 @@ static int aes_xts_256_test(void)
25432602 goto out ;
25442603 }
25452604
2605+ XMEMSET (buf , 0 , AES_XTS_256_TEST_BUF_SIZ );
2606+
2607+ XMEMCPY (iv , i2 , sizeof (i2 ));
2608+ ret = wc_AesXtsEncryptInit (aes , iv , sizeof (iv ));
2609+ if (ret != 0 )
2610+ goto out ;
2611+ ret = wc_AesXtsEncryptUpdate (aes , buf , p2 , AES_BLOCK_SIZE , iv );
2612+ if (ret != 0 )
2613+ goto out ;
2614+ ret = wc_AesXtsEncryptUpdate (aes , buf + AES_BLOCK_SIZE ,
2615+ p2 + AES_BLOCK_SIZE ,
2616+ sizeof (p2 ) - AES_BLOCK_SIZE , iv );
2617+ if (ret != 0 )
2618+ goto out ;
2619+ if (XMEMCMP (c2 , buf , sizeof (c2 ))) {
2620+ ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E ;
2621+ goto out ;
2622+ }
2623+
25462624 XMEMSET (buf , 0 , AES_XTS_256_TEST_BUF_SIZ );
25472625 ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_ENCRYPTION );
25482626 if (ret != 0 )
@@ -2596,6 +2674,85 @@ static int aes_xts_256_test(void)
25962674 goto out ;
25972675 }
25982676
2677+ {
2678+ #define LARGE_XTS_SZ 1024
2679+ int i ;
2680+ int j ;
2681+ int k ;
2682+
2683+ large_input = (byte * )XMALLOC (LARGE_XTS_SZ , NULL ,
2684+ DYNAMIC_TYPE_TMP_BUFFER );
2685+ if (large_input == NULL ) {
2686+ ret = MEMORY_E ;
2687+ goto out ;
2688+ }
2689+
2690+ for (i = 0 ; i < (int )LARGE_XTS_SZ ; i ++ )
2691+ large_input [i ] = (byte )i ;
2692+
2693+ /* first, encrypt block by block then decrypt with a one-shot call. */
2694+ for (j = 16 ; j < (int )LARGE_XTS_SZ ; j ++ ) {
2695+ ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_ENCRYPTION );
2696+ if (ret != 0 )
2697+ goto out ;
2698+ XMEMCPY (iv , i1 , sizeof (i1 ));
2699+ ret = wc_AesXtsEncryptInit (aes , iv , sizeof (iv ));
2700+ if (ret != 0 )
2701+ goto out ;
2702+ for (k = 0 ; k < j ; k += AES_BLOCK_SIZE ) {
2703+ ret = wc_AesXtsEncryptUpdate (aes , large_input + k , large_input + k , (j - k ) < AES_BLOCK_SIZE * 2 ? j - k : AES_BLOCK_SIZE , iv );
2704+ if (ret != 0 )
2705+ goto out ;
2706+ if ((j - k ) < AES_BLOCK_SIZE * 2 )
2707+ break ;
2708+ }
2709+ ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_DECRYPTION );
2710+ if (ret != 0 )
2711+ goto out ;
2712+ ret = wc_AesXtsDecrypt (aes , large_input , large_input , j , i1 ,
2713+ sizeof (i1 ));
2714+ if (ret != 0 )
2715+ goto out ;
2716+ for (i = 0 ; i < j ; i ++ ) {
2717+ if (large_input [i ] != (byte )i ) {
2718+ ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E ;
2719+ goto out ;
2720+ }
2721+ }
2722+ }
2723+
2724+ /* second, encrypt with a one-shot call then decrypt block by block. */
2725+ for (j = 16 ; j < (int )LARGE_XTS_SZ ; j ++ ) {
2726+ ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_ENCRYPTION );
2727+ if (ret != 0 )
2728+ goto out ;
2729+ ret = wc_AesXtsEncrypt (aes , large_input , large_input , j , i1 ,
2730+ sizeof (i1 ));
2731+ if (ret != 0 )
2732+ goto out ;
2733+ ret = wc_AesXtsSetKeyNoInit (aes , k1 , sizeof (k1 ), AES_DECRYPTION );
2734+ if (ret != 0 )
2735+ goto out ;
2736+ XMEMCPY (iv , i1 , sizeof (i1 ));
2737+ ret = wc_AesXtsDecryptInit (aes , iv , sizeof (iv ));
2738+ if (ret != 0 )
2739+ goto out ;
2740+ for (k = 0 ; k < j ; k += AES_BLOCK_SIZE ) {
2741+ ret = wc_AesXtsDecryptUpdate (aes , large_input + k , large_input + k , (j - k ) < AES_BLOCK_SIZE * 2 ? j - k : AES_BLOCK_SIZE , iv );
2742+ if (ret != 0 )
2743+ goto out ;
2744+ if ((j - k ) < AES_BLOCK_SIZE * 2 )
2745+ break ;
2746+ }
2747+ for (i = 0 ; i < j ; i ++ ) {
2748+ if (large_input [i ] != (byte )i ) {
2749+ ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E ;
2750+ goto out ;
2751+ }
2752+ }
2753+ }
2754+ }
2755+
25992756 /* now the kernel crypto part */
26002757
26012758 enc2 = XMALLOC (sizeof (p1 ), NULL , DYNAMIC_TYPE_AES );
@@ -2775,6 +2932,9 @@ static int aes_xts_256_test(void)
27752932
27762933 out :
27772934
2935+ if (large_input )
2936+ XFREE (large_input , NULL , DYNAMIC_TYPE_TMP_BUFFER );
2937+
27782938 if (aes_inited )
27792939 wc_AesXtsFree (aes );
27802940
0 commit comments