AESNI: add macro guard of CIPHER_ENCRYPT_ONLY
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
parent
590c9b7abe
commit
380be5af3a
2 changed files with 27 additions and 8 deletions
|
@ -93,21 +93,32 @@ int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
|
||||||
++rk;
|
++rk;
|
||||||
--nr;
|
--nr;
|
||||||
|
|
||||||
if (mode == 0) {
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
while (nr != 0) {
|
if (mode == MBEDTLS_AES_ENCRYPT) {
|
||||||
state = _mm_aesdec_si128(state, *rk);
|
|
||||||
++rk;
|
|
||||||
--nr;
|
|
||||||
}
|
|
||||||
state = _mm_aesdeclast_si128(state, *rk);
|
|
||||||
} else {
|
|
||||||
while (nr != 0) {
|
while (nr != 0) {
|
||||||
state = _mm_aesenc_si128(state, *rk);
|
state = _mm_aesenc_si128(state, *rk);
|
||||||
++rk;
|
++rk;
|
||||||
--nr;
|
--nr;
|
||||||
}
|
}
|
||||||
state = _mm_aesenclast_si128(state, *rk);
|
state = _mm_aesenclast_si128(state, *rk);
|
||||||
|
} else {
|
||||||
|
while (nr != 0) {
|
||||||
|
state = _mm_aesdec_si128(state, *rk);
|
||||||
|
++rk;
|
||||||
|
--nr;
|
||||||
|
}
|
||||||
|
state = _mm_aesdeclast_si128(state, *rk);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void) mode;
|
||||||
|
while (nr != 0) {
|
||||||
|
|
||||||
|
state = _mm_aesenc_si128(state, *rk);
|
||||||
|
++rk;
|
||||||
|
--nr;
|
||||||
|
}
|
||||||
|
state = _mm_aesenclast_si128(state, *rk);
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
memcpy(output, &state, 16);
|
memcpy(output, &state, 16);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -217,6 +228,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||||
/*
|
/*
|
||||||
* Compute decryption round keys from encryption round keys
|
* Compute decryption round keys from encryption round keys
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||||
const unsigned char *fwdkey, int nr)
|
const unsigned char *fwdkey, int nr)
|
||||||
{
|
{
|
||||||
|
@ -229,6 +241,7 @@ void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||||
}
|
}
|
||||||
*ik = *fk;
|
*ik = *fk;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key expansion, 128-bit case
|
* Key expansion, 128-bit case
|
||||||
|
@ -455,6 +468,7 @@ int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
|
||||||
"jnz 1b \n\t"
|
"jnz 1b \n\t"
|
||||||
"movdqu (%1), %%xmm1 \n\t" // load round key
|
"movdqu (%1), %%xmm1 \n\t" // load round key
|
||||||
AESENCLAST(xmm1_xmm0) // last round
|
AESENCLAST(xmm1_xmm0) // last round
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
"jmp 3f \n\t"
|
"jmp 3f \n\t"
|
||||||
|
|
||||||
"2: \n\t" // decryption loop
|
"2: \n\t" // decryption loop
|
||||||
|
@ -465,6 +479,7 @@ int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
|
||||||
"jnz 2b \n\t"
|
"jnz 2b \n\t"
|
||||||
"movdqu (%1), %%xmm1 \n\t" // load round key
|
"movdqu (%1), %%xmm1 \n\t" // load round key
|
||||||
AESDECLAST(xmm1_xmm0) // last round
|
AESDECLAST(xmm1_xmm0) // last round
|
||||||
|
#endif
|
||||||
|
|
||||||
"3: \n\t"
|
"3: \n\t"
|
||||||
"movdqu %%xmm0, (%4) \n\t" // export output
|
"movdqu %%xmm0, (%4) \n\t" // export output
|
||||||
|
@ -591,6 +606,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||||
/*
|
/*
|
||||||
* Compute decryption round keys from encryption round keys
|
* Compute decryption round keys from encryption round keys
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||||
const unsigned char *fwdkey, int nr)
|
const unsigned char *fwdkey, int nr)
|
||||||
{
|
{
|
||||||
|
@ -610,6 +626,7 @@ void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||||
|
|
||||||
memcpy(ik, fk, 16);
|
memcpy(ik, fk, 16);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key expansion, 128-bit case
|
* Key expansion, 128-bit case
|
||||||
|
|
|
@ -141,6 +141,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||||
const unsigned char a[16],
|
const unsigned char a[16],
|
||||||
const unsigned char b[16]);
|
const unsigned char b[16]);
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
/**
|
/**
|
||||||
* \brief Internal round key inversion. This function computes
|
* \brief Internal round key inversion. This function computes
|
||||||
* decryption round keys from the encryption round keys.
|
* decryption round keys from the encryption round keys.
|
||||||
|
@ -155,6 +156,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||||
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||||
const unsigned char *fwdkey,
|
const unsigned char *fwdkey,
|
||||||
int nr);
|
int nr);
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Internal key expansion for encryption
|
* \brief Internal key expansion for encryption
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue