From cf068aafd605d9c5b77c5dfd65b2963a51c145a1 Mon Sep 17 00:00:00 2001 From: mjvk <29380294+mjvk@users.noreply.github.com> Date: Wed, 9 May 2018 11:47:06 +0100 Subject: [PATCH 1/3] Update cast of load16 Bitwise operations promote the cast to uint16_t to int. So to be consistent, first cast to uint to keep unsignedness and prevent implicit promotion. Then cast back to uint16_t after all bitwise operations are completed. This prevents compiler warnings, unneccessary casts and in the case of right shifting (not the case here) unexpected behaviour. --- sse/blake2-impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sse/blake2-impl.h b/sse/blake2-impl.h index 5dff7fc..c1df82e 100644 --- a/sse/blake2-impl.h +++ b/sse/blake2-impl.h @@ -72,8 +72,8 @@ static BLAKE2_INLINE uint16_t load16( const void *src ) return w; #else const uint8_t *p = ( const uint8_t * )src; - return (( uint16_t )( p[0] ) << 0) | - (( uint16_t )( p[1] ) << 8) ; + return ( uint16_t )((( uint32_t )( p[0] ) << 0) | + (( uint32_t )( p[1] ) << 8)); #endif } From 3d6155ab1682e68c30f93064f988247508f55bbe Mon Sep 17 00:00:00 2001 From: mjvk <29380294+mjvk@users.noreply.github.com> Date: Wed, 9 May 2018 11:47:33 +0100 Subject: [PATCH 2/3] Update blake2-impl.h --- ref/blake2-impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ref/blake2-impl.h b/ref/blake2-impl.h index 5dff7fc..c1df82e 100644 --- a/ref/blake2-impl.h +++ b/ref/blake2-impl.h @@ -72,8 +72,8 @@ static BLAKE2_INLINE uint16_t load16( const void *src ) return w; #else const uint8_t *p = ( const uint8_t * )src; - return (( uint16_t )( p[0] ) << 0) | - (( uint16_t )( p[1] ) << 8) ; + return ( uint16_t )((( uint32_t )( p[0] ) << 0) | + (( uint32_t )( p[1] ) << 8)); #endif } From 467c5446ac1cb7105f5b3e035761bdfc2193545c Mon Sep 17 00:00:00 2001 From: mjvk <29380294+mjvk@users.noreply.github.com> Date: Wed, 9 May 2018 11:49:17 +0100 Subject: [PATCH 3/3] Update blake2-impl.h --- neon/blake2-impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neon/blake2-impl.h b/neon/blake2-impl.h index 5dff7fc..c1df82e 100644 --- a/neon/blake2-impl.h +++ b/neon/blake2-impl.h @@ -72,8 +72,8 @@ static BLAKE2_INLINE uint16_t load16( const void *src ) return w; #else const uint8_t *p = ( const uint8_t * )src; - return (( uint16_t )( p[0] ) << 0) | - (( uint16_t )( p[1] ) << 8) ; + return ( uint16_t )((( uint32_t )( p[0] ) << 0) | + (( uint32_t )( p[1] ) << 8)); #endif }