diff options
author | Martin Willi <martin@revosec.ch> | 2010-08-19 18:49:35 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2010-08-19 19:08:57 +0200 |
commit | 23cf96773a8d73fba1885ce2238f90dd6a3b8af3 (patch) | |
tree | 1c66bf55acaaff9a2b621a527a155a1092da42ff /src | |
parent | 1a64981048088383621fe9c282d8ac981b766026 (diff) | |
download | strongswan-23cf96773a8d73fba1885ce2238f90dd6a3b8af3.tar.bz2 strongswan-23cf96773a8d73fba1885ce2238f90dd6a3b8af3.tar.xz |
Improve GCM performance by factor 2-3 by shifting full 32/64 bit words
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/plugins/gcm/gcm_aead.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/libstrongswan/plugins/gcm/gcm_aead.c b/src/libstrongswan/plugins/gcm/gcm_aead.c index 7c0a2ba23..644852a08 100644 --- a/src/libstrongswan/plugins/gcm/gcm_aead.c +++ b/src/libstrongswan/plugins/gcm/gcm_aead.c @@ -15,7 +15,7 @@ #include "gcm_aead.h" -#include <debug.h> +#include <limits.h> #define BLOCK_SIZE 16 #define NONCE_SIZE 12 @@ -56,20 +56,40 @@ struct private_gcm_aead_t { }; /** + * architecture specific macros to convert a "long" to network order + */ +#if ULONG_MAX == 4294967295UL +#define htobelong htobe32 +#define belongtoh htobe32 +#elif ULONG_MAX == 18446744073709551615UL +#define htobelong htobe64 +#define belongtoh htobe64 +#endif + +/** * Bitshift a block right by one bit */ -static void sr_block(u_char *block) +static void sr_block(char *block) { + u_long *word = (u_long*)block; int i; - for (i = BLOCK_SIZE - 1; i >= 0; i--) + for (i = 0; i < BLOCK_SIZE / sizeof(*word); i++) { - block[i] = block[i] >> 1; + word[i] = htobelong(word[i]); + } + for (i = BLOCK_SIZE / sizeof(*word) - 1; i >= 0; i--) + { + word[i] >>= 1; if (i != 0) { - block[i] |= block[i - 1] << 7; + word[i] |= word[i - 1] << (sizeof(*word) * 8 - 1); } } + for (i = 0; i < BLOCK_SIZE / sizeof(*word); i++) + { + word[i] = belongtoh(word[i]); + } } /** |