Skip to content

Commit

Permalink
16 bytes alignmen of AES block
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Nov 26, 2014
1 parent f7d9064 commit 357a9a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions I2NPProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 357a9a6

Please sign in to comment.