Skip to content

Commit

Permalink
Use AlignedBuffer stedda posix_memalign(). Should work on PPC OS X 10.5.
Browse files Browse the repository at this point in the history
Fixes mobile-shell#233 github issue.
  • Loading branch information
keithw committed Apr 23, 2012
1 parent 9b3845e commit e8236c5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
10 changes: 2 additions & 8 deletions src/crypto/crypto.cc
Expand Up @@ -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." );
}
Expand All @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/crypto/crypto.h
Expand Up @@ -98,6 +98,7 @@ namespace Crypto {
class Session {
private:
Base64Key key;
AlignedBuffer ctx_buf;
ae_ctx *ctx;
uint64_t blocks_encrypted;

Expand Down
23 changes: 1 addition & 22 deletions src/crypto/ocb.cc
Expand Up @@ -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(). */

/* ----------------------------------------------------------------------- */

Expand Down

0 comments on commit e8236c5

Please sign in to comment.