From a309eb9f3cc736a39df7a65a587f80b63d8989b1 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 27 Oct 2018 18:41:05 -0400 Subject: [PATCH] faster CipherBlock XOR implementation for non-AVX --- libi2pd/Crypto.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libi2pd/Crypto.h b/libi2pd/Crypto.h index c2da1f4d..7ec38235 100644 --- a/libi2pd/Crypto.h +++ b/libi2pd/Crypto.h @@ -124,9 +124,17 @@ namespace crypto else #endif { - // TODO: implement it better - for (int i = 0; i < 16; i++) - buf[i] ^= other.buf[i]; + if (((size_t)buf | (size_t)other.buf) & 0x03) // multiple of 4 ? + { + // we are good to cast to uint32_t * + for (int i = 0; i < 4; i++) + ((uint32_t *)buf)[i] ^= ((uint32_t *)other.buf)[i]; + } + else + { + for (int i = 0; i < 16; i++) + buf[i] ^= other.buf[i]; + } } } };