diff --git a/Garlic.cpp b/Garlic.cpp index 13aae1a9..094e1840 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -83,6 +83,7 @@ namespace garlic I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg) { I2NPMessage * m = NewI2NPMessage (); + m->Align (12); // in order to get buf aligned to 16 (12 + 4) size_t len = 0; uint8_t * buf = m->GetPayload () + 4; // 4 bytes for length diff --git a/I2NPProtocol.h b/I2NPProtocol.h index b96ca02e..900b1415 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -118,6 +118,12 @@ namespace tunnel uint8_t * GetBuffer () { return buf + offset; }; const uint8_t * GetBuffer () const { return buf + offset; }; size_t GetLength () const { return len - offset; }; + void Align (size_t alignment) + { + size_t rem = ((size_t)GetBuffer ()) % alignment; + if (rem) + offset += (alignment - rem); + } I2NPMessage& operator=(const I2NPMessage& other) { diff --git a/aes.h b/aes.h index 36964476..95180fd6 100644 --- a/aes.h +++ b/aes.h @@ -45,7 +45,7 @@ namespace crypto AESAlignedBuffer () { m_Buf = m_UnalignedBuffer; - uint8_t rem = ((uint64_t)m_Buf) & 0x0f; + uint8_t rem = ((size_t)m_Buf) & 0x0f; if (rem) m_Buf += (16 - rem); }