Skip to content
Browse files

Use AlignedBuffer stedda posix_memalign(). Should work on PPC OS X 10.5.

Fixes #233 github issue.
  • Loading branch information...
1 parent 9b3845e commit e8236c5fd41f0f64402a43563a7f97aa1fd96a1a @keithw keithw committed Apr 22, 2012
Showing with 4 additions and 30 deletions.
  1. +2 −8 src/crypto/crypto.cc
  2. +1 −0 src/crypto/crypto.h
  3. +1 −22 src/crypto/ocb.cc
View
10 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 )
View
1 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;
View
23 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(). */
/* ----------------------------------------------------------------------- */

0 comments on commit e8236c5

Please sign in to comment.
Something went wrong with that request. Please try again.