From a6cc2e647b2c36487b1f076f990eeac311e04600 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 8 Jun 2014 07:56:04 -0400 Subject: [PATCH] eliminated multiple of 16 check for AES --- SSU.cpp | 2 -- aes.cpp | 15 +++++---------- aes.h | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/SSU.cpp b/SSU.cpp index 2b9b888e..cce2ac3b 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -524,7 +524,6 @@ namespace ssu header->time = htobe32 (i2p::util::GetSecondsSinceEpoch ()); uint8_t * encrypted = &header->flag; uint16_t encryptedLen = len - (encrypted - buf); - encryptedLen = (encryptedLen>>4)<<4; // make sure 16 bytes boundary, TODO: do we really need it? m_SessionKeyEncryption.Encrypt (encrypted, encryptedLen, encrypted); // assume actual buffer size is 18 (16 + 2) bytes more memcpy (buf + len, header->iv, 16); @@ -557,7 +556,6 @@ namespace ssu SSUHeader * header = (SSUHeader *)buf; uint8_t * encrypted = &header->flag; uint16_t encryptedLen = len - (encrypted - buf); - encryptedLen = (encryptedLen>>4)<<4; // make sure 16 bytes boundary if (encryptedLen > 0) { m_SessionKeyDecryption.SetIV (header->iv); diff --git a/aes.cpp b/aes.cpp index a2114846..518d5c58 100644 --- a/aes.cpp +++ b/aes.cpp @@ -197,12 +197,10 @@ namespace crypto #endif } - bool CBCEncryption::Encrypt (const uint8_t * in, std::size_t len, uint8_t * out) + void CBCEncryption::Encrypt (const uint8_t * in, std::size_t len, uint8_t * out) { - div_t d = div (len, 16); - if (d.rem) return false; // len is not multipple of 16 - Encrypt (d.quot, (const ChipherBlock *)in, (ChipherBlock *)out); - return true; + // len/16 + Encrypt (len >> 4, (const ChipherBlock *)in, (ChipherBlock *)out); } void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out) @@ -260,12 +258,9 @@ namespace crypto #endif } - bool CBCDecryption::Decrypt (const uint8_t * in, std::size_t len, uint8_t * out) + void CBCDecryption::Decrypt (const uint8_t * in, std::size_t len, uint8_t * out) { - div_t d = div (len, 16); - if (d.rem) return false; // len is not multiple of 16 - Decrypt (d.quot, (const ChipherBlock *)in, (ChipherBlock *)out); - return true; + Decrypt (len >> 4, (const ChipherBlock *)in, (ChipherBlock *)out); } void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out) diff --git a/aes.h b/aes.h index c69764b4..d1f3c254 100644 --- a/aes.h +++ b/aes.h @@ -109,7 +109,7 @@ namespace crypto void SetIV (const uint8_t * iv) { memcpy (m_LastBlock.buf, iv, 16); }; // 16 bytes void Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out); - bool Encrypt (const uint8_t * in, std::size_t len, uint8_t * out); + void Encrypt (const uint8_t * in, std::size_t len, uint8_t * out); void Encrypt (const uint8_t * in, uint8_t * out); // one block private: @@ -129,7 +129,7 @@ namespace crypto void SetIV (const uint8_t * iv) { memcpy (m_IV.buf, iv, 16); }; // 16 bytes void Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out); - bool Decrypt (const uint8_t * in, std::size_t len, uint8_t * out); + void Decrypt (const uint8_t * in, std::size_t len, uint8_t * out); void Decrypt (const uint8_t * in, uint8_t * out); // one block private: