From ba6329e5289d08332f688cfd0f879eae3414375a Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sun, 19 Feb 2012 21:50:02 -0500 Subject: [PATCH] Better fix to alignment issue --- src/crypto/crypto.cc | 6 ++---- src/crypto/crypto.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index 49e0852..e5ee202 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -178,14 +178,12 @@ string Session::encrypt( Message plaintext ) memcpy( pt, plaintext.text.data(), plaintext.text.size() ); - Nonce __attribute__((__aligned__ (16))) nonce( plaintext.nonce ); - - if ( (uint64_t( nonce.data() ) & 0xf) != 0 ) { + if ( (uint64_t( plaintext.nonce.data() ) & 0xf) != 0 ) { throw CryptoException( "Bad alignment." ); } if ( ciphertext_len != ae_encrypt( ctx, /* ctx */ - nonce.data(), /* nonce */ + plaintext.nonce.data(), /* nonce */ pt, /* pt */ pt_len, /* pt_len */ NULL, /* ad */ diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 6cbd21e..9337637 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -48,7 +48,7 @@ namespace Crypto { class Nonce { private: - char bytes[ 12 ]; + char bytes[ 12 ] __attribute__((__aligned__ (16))); public: Nonce( uint64_t val );