summaryrefslogtreecommitdiff
path: root/cipher
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2014-12-01 21:10:19 +0200
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2014-12-01 21:10:19 +0200
commitdbf9e95dd3891f6e6ad370e8ab78fec03595687b (patch)
tree037cac9d936d2f88bf02fc6490d5527a2f9ba465 /cipher
parent67d529630e838daeb8cb9c6d7ef660c01ef34fee (diff)
downloadlibgcrypt-dbf9e95dd3891f6e6ad370e8ab78fec03595687b.tar.gz
rijndael: move AES-NI blocks before Padlock
* cipher/rijndael.c (do_setkey, rijndael_encrypt, _gcry_aes_cfb_enc) (rijndael_decrypt, _gcry_aes_cfb_dec): Move USE_AESNI before USE_PADLOCK. (check_decryption_praparation) [USE_PADLOCK]: Move to... (prepare_decryption) [USE_PADLOCK]: ...here. -- Make order of AES-NI and Padlock #ifdefs consistent. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher')
-rw-r--r--cipher/rijndael.c88
1 files changed, 45 insertions, 43 deletions
diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index 4a10a6b3..8a76fad4 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -180,6 +180,12 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
{
;
}
+#ifdef USE_AESNI
+ else if (hwfeatures & HWF_INTEL_AESNI)
+ {
+ ctx->use_aesni = 1;
+ }
+#endif
#ifdef USE_PADLOCK
else if (hwfeatures & HWF_PADLOCK_AES)
{
@@ -187,12 +193,6 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
memcpy (ctx->padlockkey, key, keylen);
}
#endif
-#ifdef USE_AESNI
- else if (hwfeatures & HWF_INTEL_AESNI)
- {
- ctx->use_aesni = 1;
- }
-#endif
}
else if ( keylen == 192/8 )
{
@@ -348,13 +348,21 @@ prepare_decryption( RIJNDAEL_context *ctx )
{
int r;
+ if (0)
+ ;
#ifdef USE_AESNI
- if (ctx->use_aesni)
+ else if (ctx->use_aesni)
{
_gcry_aes_aesni_prepare_decryption (ctx);
}
- else
#endif /*USE_AESNI*/
+#ifdef USE_PADLOCK
+ else if (ctx->use_padlock)
+ {
+ /* Padlock does not need decryption subkeys. */
+ }
+#endif /*USE_PADLOCK*/
+ else
{
union
{
@@ -587,13 +595,6 @@ rijndael_encrypt (void *context, byte *b, const byte *a)
if (0)
;
-#ifdef USE_PADLOCK
- else if (ctx->use_padlock)
- {
- do_padlock (ctx, 0, b, a);
- burn_stack = (48 + 15 /* possible padding for alignment */);
- }
-#endif /*USE_PADLOCK*/
#ifdef USE_AESNI
else if (ctx->use_aesni)
{
@@ -601,6 +602,13 @@ rijndael_encrypt (void *context, byte *b, const byte *a)
burn_stack = 0;
}
#endif /*USE_AESNI*/
+#ifdef USE_PADLOCK
+ else if (ctx->use_padlock)
+ {
+ do_padlock (ctx, 0, b, a);
+ burn_stack = (48 + 15 /* possible padding for alignment */);
+ }
+#endif /*USE_PADLOCK*/
else
{
do_encrypt (ctx, b, a);
@@ -627,6 +635,13 @@ _gcry_aes_cfb_enc (void *context, unsigned char *iv,
if (0)
;
+#ifdef USE_AESNI
+ else if (ctx->use_aesni)
+ {
+ _gcry_aes_aesni_cfb_enc (ctx, outbuf, inbuf, iv, nblocks);
+ burn_depth = 0;
+ }
+#endif /*USE_AESNI*/
#ifdef USE_PADLOCK
else if (ctx->use_padlock)
{
@@ -642,13 +657,6 @@ _gcry_aes_cfb_enc (void *context, unsigned char *iv,
}
}
#endif /*USE_PADLOCK*/
-#ifdef USE_AESNI
- else if (ctx->use_aesni)
- {
- _gcry_aes_aesni_cfb_enc (ctx, outbuf, inbuf, iv, nblocks);
- burn_depth = 0;
- }
-#endif /*USE_AESNI*/
else
{
for ( ;nblocks; nblocks-- )
@@ -909,13 +917,7 @@ do_decrypt (RIJNDAEL_context *ctx, byte *bx, const byte *ax)
static inline void
check_decryption_preparation (RIJNDAEL_context *ctx)
{
- if (0)
- ;
-#ifdef USE_PADLOCK
- else if (ctx->use_padlock)
- { /* Padlock does not need decryption subkeys. */ }
-#endif /*USE_PADLOCK*/
- else if ( !ctx->decryption_prepared )
+ if ( !ctx->decryption_prepared )
{
prepare_decryption ( ctx );
ctx->decryption_prepared = 1;
@@ -933,13 +935,6 @@ rijndael_decrypt (void *context, byte *b, const byte *a)
if (0)
;
-#ifdef USE_PADLOCK
- else if (ctx->use_padlock)
- {
- do_padlock (ctx, 1, b, a);
- burn_stack = (48 + 2*sizeof(int) /* FIXME */);
- }
-#endif /*USE_PADLOCK*/
#ifdef USE_AESNI
else if (ctx->use_aesni)
{
@@ -947,6 +942,13 @@ rijndael_decrypt (void *context, byte *b, const byte *a)
burn_stack = 0;
}
#endif /*USE_AESNI*/
+#ifdef USE_PADLOCK
+ else if (ctx->use_padlock)
+ {
+ do_padlock (ctx, 1, b, a);
+ burn_stack = (48 + 2*sizeof(int) /* FIXME */);
+ }
+#endif /*USE_PADLOCK*/
else
{
do_decrypt (ctx, b, a);
@@ -973,6 +975,13 @@ _gcry_aes_cfb_dec (void *context, unsigned char *iv,
if (0)
;
+#ifdef USE_AESNI
+ else if (ctx->use_aesni)
+ {
+ _gcry_aes_aesni_cfb_dec (ctx, outbuf, inbuf, iv, nblocks);
+ burn_depth = 0;
+ }
+#endif /*USE_AESNI*/
#ifdef USE_PADLOCK
else if (ctx->use_padlock)
{
@@ -986,13 +995,6 @@ _gcry_aes_cfb_dec (void *context, unsigned char *iv,
}
}
#endif /*USE_PADLOCK*/
-#ifdef USE_AESNI
- else if (ctx->use_aesni)
- {
- _gcry_aes_aesni_cfb_dec (ctx, outbuf, inbuf, iv, nblocks);
- burn_depth = 0;
- }
-#endif /*USE_AESNI*/
else
{
for ( ;nblocks; nblocks-- )