@@ -49,15 +49,15 @@ const struct ltc_cipher_descriptor aes_enc_desc =
4949#endif
5050
5151/* Code partially borrowed from https://software.intel.com/content/www/us/en/develop/articles/intel-sha-extensions.html */
52- #if defined(LTC_HAS_AES_NI )
52+ #if defined(LTC_AES_NI )
5353static LTC_INLINE int s_aesni_is_supported (void )
5454{
5555 static int initialized = 0 , is_supported = 0 ;
5656
5757 if (initialized == 0 ) {
5858 int a , b , c , d ;
5959
60- /* Look for CPUID.1.0.ECX[25]
60+ /* Look for CPUID.1.0.ECX[19] (SSE4.1) and CPUID.1.0.ECX[ 25] (AES-NI)
6161 * EAX = 1, ECX = 0
6262 */
6363 a = 1 ;
@@ -68,7 +68,7 @@ static LTC_INLINE int s_aesni_is_supported(void)
6868 :"a" (a ), "c" (c )
6969 );
7070
71- is_supported = ((c >> 25 ) & 1 );
71+ is_supported = ((c >> 19 ) & 1 ) && (( c >> 25 ) & 1 );
7272 initialized = 1 ;
7373 }
7474
@@ -93,7 +93,7 @@ int aesni_is_supported(void)
9393 */
9494int AES_SETUP (const unsigned char * key , int keylen , int num_rounds , symmetric_key * skey )
9595{
96- #ifdef LTC_HAS_AES_NI
96+ #ifdef LTC_AES_NI
9797 if (s_aesni_is_supported ()) {
9898 return aesni_setup (key , keylen , num_rounds , skey );
9999 }
@@ -111,7 +111,7 @@ int AES_SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
111111*/
112112int AES_ENC (const unsigned char * pt , unsigned char * ct , const symmetric_key * skey )
113113{
114- #ifdef LTC_HAS_AES_NI
114+ #ifdef LTC_AES_NI
115115 if (s_aesni_is_supported ()) {
116116 return aesni_ecb_encrypt (pt , ct , skey );
117117 }
@@ -130,7 +130,7 @@ int AES_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
130130*/
131131int AES_DEC (const unsigned char * ct , unsigned char * pt , const symmetric_key * skey )
132132{
133- #ifdef LTC_HAS_AES_NI
133+ #ifdef LTC_AES_NI
134134 if (s_aesni_is_supported ()) {
135135 return aesni_ecb_decrypt (ct , pt , skey );
136136 }
0 commit comments