Navigation Menu

Skip to content

Commit

Permalink
Use memcpy for possibly-unaligned loads and stores.
Browse files Browse the repository at this point in the history
The core change is ported from
BLAKE2/BLAKE2@b8024d5.

This let's us remove the ALIGNED_ACCESS_REQUIRED configure check. This isn't a
very good thing to check through configure because it requires running an
executable. That doesn't work for cross compiles.
  • Loading branch information
benjaminp committed Jun 21, 2018
1 parent 9b1cc68 commit 4d8616d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 93 deletions.
1 change: 0 additions & 1 deletion configure.ac
Expand Up @@ -17,7 +17,6 @@ AC_CHECK_FUNCS(explicit_memset)
AC_CHECK_FUNCS(memset_s)
AC_CHECK_HEADERS([stddef.h stdint.h stdlib.h string.h])
AC_OPENMP
AX_CHECK_ALIGNED_ACCESS_REQUIRED
# AX_FORCEINLINE()
AC_C_BIGENDIAN(
[],
Expand Down
84 changes: 0 additions & 84 deletions m4/ax_check_aligned_access_required.m4

This file was deleted.

20 changes: 12 additions & 8 deletions src/blake2-impl.h
Expand Up @@ -29,8 +29,10 @@

static inline uint32_t load32( const void *src )
{
#if defined(NATIVE_LITTLE_ENDIAN) && !defined(HAVE_ALIGNED_ACCESS_REQUIRED)
return *( uint32_t * )( src );
#if defined(NATIVE_LITTLE_ENDIAN)
uint32_t w;
memcpy( &w, src, sizeof( w ) );
return w;
#else
const uint8_t *p = ( uint8_t * )src;
uint32_t w = *p++;
Expand All @@ -43,8 +45,10 @@ static inline uint32_t load32( const void *src )

static inline uint64_t load64( const void *src )
{
#if defined(NATIVE_LITTLE_ENDIAN) && !defined(HAVE_ALIGNED_ACCESS_REQUIRED)
return *( uint64_t * )( src );
#if defined(NATIVE_LITTLE_ENDIAN)
uint64_t w;
memcpy( &w, src, sizeof( w ) );
return w;
#else
const uint8_t *p = ( uint8_t * )src;
uint64_t w = *p++;
Expand All @@ -61,8 +65,8 @@ static inline uint64_t load64( const void *src )

static inline void store32( void *dst, uint32_t w )
{
#if defined(NATIVE_LITTLE_ENDIAN) && !defined(HAVE_ALIGNED_ACCESS_REQUIRED)
*( uint32_t * )( dst ) = w;
#if defined(NATIVE_LITTLE_ENDIAN)
memcpy( dst, &w, sizeof( w ) );
#else
uint8_t *p = ( uint8_t * )dst;
*p++ = ( uint8_t )w; w >>= 8;
Expand All @@ -74,8 +78,8 @@ static inline void store32( void *dst, uint32_t w )

static inline void store64( void *dst, uint64_t w )
{
#if defined(NATIVE_LITTLE_ENDIAN) && !defined(HAVE_ALIGNED_ACCESS_REQUIRED)
*( uint64_t * )( dst ) = w;
#if defined(NATIVE_LITTLE_ENDIAN)
memcpy( dst, &w, sizeof( w ) );
#else
uint8_t *p = ( uint8_t * )dst;
*p++ = ( uint8_t )w; w >>= 8;
Expand Down

0 comments on commit 4d8616d

Please sign in to comment.