From 7386b0a5234dc2f632eb0b6eee51ef031d7c500b Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 9 Dec 2016 13:42:00 -0500 Subject: [PATCH 1/3] fixed android build --- BloomFilter.h | 4 ++-- android/jni/Android.mk | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BloomFilter.h b/BloomFilter.h index 1c451454..2745fbf5 100644 --- a/BloomFilter.h +++ b/BloomFilter.h @@ -13,11 +13,11 @@ namespace util { /** @brief destructor */ - virtual ~IBloomFilter(); + virtual ~IBloomFilter() {}; /** @brief add entry to bloom filter, return false if filter hit otherwise return true */ virtual bool Add(const uint8_t * data, std::size_t len) = 0; /** @brief optionally decay old entries */ - virtual void Decay(); + virtual void Decay() = 0; }; typedef std::shared_ptr BloomFilterPtr; diff --git a/android/jni/Android.mk b/android/jni/Android.mk index cc070984..c44594f0 100755 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -59,7 +59,7 @@ LOCAL_SRC_FILES := DaemonAndroid.cpp i2pd_android.cpp \ ../../TunnelPool.cpp \ ../../Timestamp.cpp \ ../../Event.cpp \ - ../../BloomFiler.cpp \ + ../../BloomFilter.cpp \ ../../util.cpp \ ../../i2pd.cpp ../../UPnP.cpp From dca48c7eec1ed27e2feeb3c73adbe9ecd57100eb Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 9 Dec 2016 15:46:21 -0500 Subject: [PATCH 2/3] use AVX for HMAC --- Crypto.cpp | 56 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/Crypto.cpp b/Crypto.cpp index 91b0ad08..b87afbc8 100644 --- a/Crypto.cpp +++ b/Crypto.cpp @@ -386,44 +386,58 @@ namespace crypto // HMAC const uint64_t IPAD = 0x3636363636363636; const uint64_t OPAD = 0x5C5C5C5C5C5C5C5C; - + + static const uint64_t ipads[] = { IPAD, IPAD, IPAD, IPAD }; + static const uint64_t opads[] = { OPAD, OPAD, OPAD, OPAD }; + void HMACMD5Digest (uint8_t * msg, size_t len, const MACKey& key, uint8_t * digest) // key is 32 bytes // digest is 16 bytes // block size is 64 bytes { uint64_t buf[256]; + uint64_t hash[12]; // 96 bytes +#if defined(__AVX__) // for AVX + __asm__ + ( + "vmovups %[key], %%ymm0 \n" + "vmovups %[ipad], %%ymm1 \n" + "vmovups %%ymm1, 32%[buf] \n" + "vxorps %%ymm0, %%ymm1, %%ymm1 \n" + "vmovups %%ymm1, %[buf] \n" + "vmovups %[opad], %%ymm1 \n" + "vmovups %%ymm1, 32%[hash] \n" + "vxorps %%ymm0, %%ymm1, %%ymm1 \n" + "vmovups %%ymm1, %[hash] \n" + : [buf]"=m"(*buf), [hash]"=m"(*hash) + : [key]"m"(*(const uint8_t *)key), [ipad]"m"(*ipads), [opad]"m"(*opads) + : "memory", "%xmm0", "%xmm1" // should be replaced by %ymm0/1 once supported by compiler + ); +#else // ikeypad buf[0] = key.GetLL ()[0] ^ IPAD; buf[1] = key.GetLL ()[1] ^ IPAD; buf[2] = key.GetLL ()[2] ^ IPAD; buf[3] = key.GetLL ()[3] ^ IPAD; - buf[4] = IPAD; - buf[5] = IPAD; - buf[6] = IPAD; - buf[7] = IPAD; + memcpy (buf + 4, ipads, 32); + // okeypad + hash[0] = key.GetLL ()[0] ^ OPAD; + hash[1] = key.GetLL ()[1] ^ OPAD; + hash[2] = key.GetLL ()[2] ^ OPAD; + hash[3] = key.GetLL ()[3] ^ OPAD; + memcpy (hash + 4, opads, 32); +#endif + // concatenate with msg memcpy (buf + 8, msg, len); // calculate first hash - uint8_t hash[16]; // MD5 - MD5((uint8_t *)buf, len + 64, hash); + MD5((uint8_t *)buf, len + 64, (uint8_t *)(hash + 8)); // 16 bytes - // okeypad - buf[0] = key.GetLL ()[0] ^ OPAD; - buf[1] = key.GetLL ()[1] ^ OPAD; - buf[2] = key.GetLL ()[2] ^ OPAD; - buf[3] = key.GetLL ()[3] ^ OPAD; - buf[4] = OPAD; - buf[5] = OPAD; - buf[6] = OPAD; - buf[7] = OPAD; - // copy first hash after okeypad - memcpy (buf + 8, hash, 16); - // fill next 16 bytes with zeros (first hash size assumed 32 bytes in I2P) - memset (buf + 10, 0, 16); + // fill last 16 bytes with zeros (first hash size assumed 32 bytes in I2P) + memset (hash + 10, 0, 16); // calculate digest - MD5((uint8_t *)buf, 96, digest); + MD5((uint8_t *)hash, 96, digest); } // AES From 259baa0e840c7ddbea1925bb06b98b344aae1001 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 10 Dec 2016 20:41:42 -0500 Subject: [PATCH 3/3] use vzeroall to complete AVX mode --- Crypto.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Crypto.cpp b/Crypto.cpp index b87afbc8..5de3a4ee 100644 --- a/Crypto.cpp +++ b/Crypto.cpp @@ -409,9 +409,11 @@ namespace crypto "vmovups %%ymm1, 32%[hash] \n" "vxorps %%ymm0, %%ymm1, %%ymm1 \n" "vmovups %%ymm1, %[hash] \n" + "vzeroall \n" // end of AVX + "movups %%xmm0, 80%[hash] \n" // zero last 16 bytes : [buf]"=m"(*buf), [hash]"=m"(*hash) : [key]"m"(*(const uint8_t *)key), [ipad]"m"(*ipads), [opad]"m"(*opads) - : "memory", "%xmm0", "%xmm1" // should be replaced by %ymm0/1 once supported by compiler + : "memory" ); #else // ikeypad @@ -426,15 +428,14 @@ namespace crypto hash[2] = key.GetLL ()[2] ^ OPAD; hash[3] = key.GetLL ()[3] ^ OPAD; memcpy (hash + 4, opads, 32); + // fill last 16 bytes with zeros (first hash size assumed 32 bytes in I2P) + memset (hash + 10, 0, 16); #endif // concatenate with msg memcpy (buf + 8, msg, len); // calculate first hash - MD5((uint8_t *)buf, len + 64, (uint8_t *)(hash + 8)); // 16 bytes - - // fill last 16 bytes with zeros (first hash size assumed 32 bytes in I2P) - memset (hash + 10, 0, 16); + MD5((uint8_t *)buf, len + 64, (uint8_t *)(hash + 8)); // 16 bytes // calculate digest MD5((uint8_t *)hash, 96, digest);