eliminated multiple of 16 check for AES

pull/72/head
orignal 10 years ago
parent eb44fdf7a8
commit a6cc2e647b

@ -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);

@ -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)

@ -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:

Loading…
Cancel
Save