[PATCH] Fix too large burn_stack in camellia-glue.c
Jussi Kivilinna
jussi.kivilinna at mbnet.fi
Wed Nov 14 23:30:22 CET 2012
KEY_TABLE_TYPE is array type, and sizeof(KEY_TABLE_TYPE) gives full
size of array. However what is wanted here is size of array argument
in stack, so change sizeof(KEY_TABLE_TYPE) to sizeof(void*). This
gives boost in speed for camellia cipher.
On AMD Phenom II, x86-64:
Before:
$ tests/benchmark --cipher-repetitions 10 cipher camellia128
Running each test 10 times.
ECB/Stream CBC CFB OFB CTR
--------------- --------------- --------------- --------------- ---------------
CAMELLIA128 250ms 240ms 270ms 260ms 250ms 250ms 260ms 250ms 340ms 330ms
After:
$ tests/benchmark --cipher-repetitions 10 cipher camellia128
Running each test 10 times.
ECB/Stream CBC CFB OFB CTR
--------------- --------------- --------------- --------------- ---------------
CAMELLIA128 140ms 130ms 150ms 160ms 150ms 150ms 150ms 140ms 220ms 220ms
Signed-off-by: Jussi Kivilinna <jussi.kivilinna at mbnet.fi>
---
cipher/camellia-glue.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cipher/camellia-glue.c b/cipher/camellia-glue.c
index a263621..c5019d0 100644
--- a/cipher/camellia-glue.c
+++ b/cipher/camellia-glue.c
@@ -111,7 +111,7 @@ camellia_encrypt(void *c, byte *outbuf, const byte *inbuf)
Camellia_EncryptBlock(ctx->keybitlength,inbuf,ctx->keytable,outbuf);
_gcry_burn_stack
- (sizeof(int)+2*sizeof(unsigned char *)+sizeof(KEY_TABLE_TYPE)
+ (sizeof(int)+2*sizeof(unsigned char *)+sizeof(void*/*KEY_TABLE_TYPE*/)
+4*sizeof(u32)
+2*sizeof(u32*)+4*sizeof(u32)
+2*2*sizeof(void*) /* Function calls. */
@@ -125,7 +125,7 @@ camellia_decrypt(void *c, byte *outbuf, const byte *inbuf)
Camellia_DecryptBlock(ctx->keybitlength,inbuf,ctx->keytable,outbuf);
_gcry_burn_stack
- (sizeof(int)+2*sizeof(unsigned char *)+sizeof(KEY_TABLE_TYPE)
+ (sizeof(int)+2*sizeof(unsigned char *)+sizeof(void*/*KEY_TABLE_TYPE*/)
+4*sizeof(u32)
+2*sizeof(u32*)+4*sizeof(u32)
+2*2*sizeof(void*) /* Function calls. */
More information about the Gcrypt-devel
mailing list