mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-09 00:11:24 +12:00
crypto: implement AES-NI acceleration
This is based off the upstream implementation in mbedTLS as well as an external pull request [1] for MSVC support (using intrinsics). 1: https://github.com/ARMmbed/mbedtls/pull/1355
This commit is contained in:
parent
bd8cbcdb21
commit
b0d0f51d8d
5 changed files with 806 additions and 1 deletions
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
|
||||
#include "aes.h"
|
||||
#include "aesni.h"
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
|
@ -458,6 +459,9 @@ int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int key
|
|||
|
||||
ctx->rk = RK = ctx->buf;
|
||||
|
||||
if( aesni_supports( POLARSSL_AESNI_AES ) )
|
||||
return( aesni_setkey_enc( (unsigned char *) ctx->rk, key, keysize ) );
|
||||
|
||||
for( i = 0; i < (keysize >> 5); i++ )
|
||||
{
|
||||
GET_UINT32_LE( RK[i], key, i << 2 );
|
||||
|
@ -558,6 +562,13 @@ int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int key
|
|||
if( ret != 0 )
|
||||
return( ret );
|
||||
|
||||
if( aesni_supports( POLARSSL_AESNI_AES ) )
|
||||
{
|
||||
aesni_inverse_key( (unsigned char *) ctx->rk,
|
||||
(const unsigned char *) cty.rk, ctx->nr );
|
||||
goto done;
|
||||
}
|
||||
|
||||
SK = cty.rk + cty.nr * 4;
|
||||
|
||||
*RK++ = *SK++;
|
||||
|
@ -581,6 +592,7 @@ int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int key
|
|||
*RK++ = *SK++;
|
||||
*RK++ = *SK++;
|
||||
|
||||
done:
|
||||
memset( &cty, 0, sizeof( aes_context ) );
|
||||
|
||||
return( 0 );
|
||||
|
@ -643,6 +655,9 @@ int aes_crypt_ecb( aes_context *ctx,
|
|||
int i;
|
||||
uint32_t *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
|
||||
|
||||
if( aesni_supports( POLARSSL_AESNI_AES ) )
|
||||
return( aesni_crypt_ecb( ctx, mode, input, output ) );
|
||||
|
||||
RK = ctx->rk;
|
||||
|
||||
GET_UINT32_LE( X0, input, 0 ); X0 ^= *RK++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue