diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-06-09 16:37:38 +0300 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-06-09 16:40:14 +0300 |
commit | ec2f8de409a93c80efa658134df22074a9bca5a4 (patch) | |
tree | 390c5ed048998614e7c336e815c0db44fa627393 | |
parent | d94ec5f5f8a5d40a7d344025aa466f276f9718df (diff) | |
download | libgcrypt-ec2f8de409a93c80efa658134df22074a9bca5a4.tar.gz |
Optimize _gcry_burn_stack for 32-bit and 64-bit architectures
* src/misc.c (_gcry_burn_stack): Add optimization for 32-bit and 64-bit
architectures.
--
Busy looping 'tests/benchmark --cipher-repetitions 10 cipher blowfish' on ARM
Cortex-A8 shows that _gcry_burn_stack takes 21% of CPU time. With this patch,
that number drops to 3.4%.
On AMD64 (Intel i5-4570) CPU usage for _gcry_burn_stack in the same test drops
from 3.5% to 1.1%.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
-rw-r--r-- | src/misc.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -290,9 +290,35 @@ _gcry_log_printhex (const char *text, const void *buffer, size_t length) void _gcry_burn_stack (int bytes) { +#if SIZEOF_UNSIGNED_LONG == 4 || SIZEOF_UNSIGNED_LONG == 8 + /* Optimized burn_stack for 32-bit and 64-bit architectures. In addition + to loop unrolling, compiler sees that writes are within 'buf' and + generation of stack-protection code is avoided. */ + volatile unsigned long buf[64 / SIZEOF_UNSIGNED_LONG]; + + buf[0] = 0; + buf[1] = 0; + buf[2] = 0; + buf[3] = 0; + buf[4] = 0; + buf[5] = 0; + buf[6] = 0; + buf[7] = 0; +# if SIZEOF_UNSIGNED_LONG == 4 + buf[8] = 0; + buf[9] = 0; + buf[10] = 0; + buf[11] = 0; + buf[12] = 0; + buf[13] = 0; + buf[14] = 0; + buf[15] = 0; +# endif +#else char buf[64]; wipememory (buf, sizeof buf); +#endif bytes -= sizeof buf; if (bytes > 0) _gcry_burn_stack (bytes); |