From e8236c5fd41f0f64402a43563a7f97aa1fd96a1a Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sun, 22 Apr 2012 22:46:49 -0400 Subject: [PATCH] Use AlignedBuffer stedda posix_memalign(). Should work on PPC OS X 10.5. Fixes #233 github issue. --- src/crypto/crypto.cc | 10 ++-------- src/crypto/crypto.h | 1 + src/crypto/ocb.cc | 23 +---------------------- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index d7f45c4..71b9fcd 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -138,13 +138,9 @@ string Base64Key::printable_key( void ) const } Session::Session( Base64Key s_key ) - : key( s_key ), ctx( NULL ), blocks_encrypted( 0 ) + : key( s_key ), ctx_buf( ae_ctx_sizeof() ), + ctx( (ae_ctx *)ctx_buf.data() ), blocks_encrypted( 0 ) { - ctx = ae_allocate( NULL ); - if ( ctx == NULL ) { - throw CryptoException( "Could not allocate AES-OCB context." ); - } - if ( AE_SUCCESS != ae_init( ctx, key.data(), 16, 12, 16 ) ) { throw CryptoException( "Could not initialize AES-OCB context." ); } @@ -155,8 +151,6 @@ Session::~Session() if ( ae_clear( ctx ) != AE_SUCCESS ) { throw CryptoException( "Could not clear AES-OCB context." ); } - - ae_free( ctx ); } Nonce::Nonce( uint64_t val ) diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 5d7a3af..bbd70b4 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -98,6 +98,7 @@ namespace Crypto { class Session { private: Base64Key key; + AlignedBuffer ctx_buf; ae_ctx *ctx; uint64_t blocks_encrypted; diff --git a/src/crypto/ocb.cc b/src/crypto/ocb.cc index 8176896..1f14fa3 100644 --- a/src/crypto/ocb.cc +++ b/src/crypto/ocb.cc @@ -623,28 +623,7 @@ static block getL(const ae_ctx *ctx, unsigned tz) /* 32-bit SSE2 and Altivec systems need to be forced to allocate memory on 16-byte alignments. (I believe all major 64-bit systems do already.) */ -ae_ctx* ae_allocate(void *misc) -{ - void *p; - (void) misc; /* misc unused in this implementation */ - #if (__SSE2__ && !_M_X64 && !_M_AMD64 && !__amd64__) - p = _mm_malloc(sizeof(ae_ctx),16); - #elif (__ALTIVEC__ && !__PPC64__) - if (posix_memalign(&p,16,sizeof(ae_ctx)) != 0) p = NULL; - #else - p = malloc(sizeof(ae_ctx)); - #endif - return (ae_ctx *)p; -} - -void ae_free(ae_ctx *ctx) -{ - #if (__SSE2__ && !_M_X64 && !_M_AMD64 && !__amd64__) - _mm_free(ctx); - #else - free(ctx); - #endif -} +/* Mosh uses its own AlignedBuffer class, not ae_allocate() or ae_free(). */ /* ----------------------------------------------------------------------- */