diff --git a/sys/contrib/libb2/FREEBSD-Xlist b/sys/contrib/libb2/FREEBSD-Xlist new file mode 100644 --- /dev/null +++ b/sys/contrib/libb2/FREEBSD-Xlist @@ -0,0 +1,11 @@ +.gitignore +COPYING +Makefile.am +autogen.sh +clean.sh +configure.ac +libb2.pc.in +m4 +src/Makefile.am +src/*-test.c +src/blake2-kat.h diff --git a/sys/contrib/libb2/FREEBSD-upgrade b/sys/contrib/libb2/FREEBSD-upgrade new file mode 100755 --- /dev/null +++ b/sys/contrib/libb2/FREEBSD-upgrade @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Usage: cd /usr/src/sys/contrib/libb2 +# ./FREEBSD-upgrade +# +# should be in x.y.z format +# + +set -e + +if [ ! -x "FREEBSD-upgrade" ] ; then + echo "Run from within src/sys/contrib/libb2/" >&2 + exit 1 +fi + +if [ -z "$1" ] + then + echo "No version supplied" >&2 + exit 1 +fi + +curl -LJO https://github.com/BLAKE2/libb2/archive/refs/tags/v$1.tar.gz + +tar -X FREEBSD-Xlist -xzf libb2-$1.tar.gz + +mv libb2-$1/src/* libb2-$1/ + +rm -r libb2-$1/src + +mv libb2-$1/* . + +rm -r libb2-$1 +rm libb2-$1.tar.gz diff --git a/sys/contrib/libb2/README.md b/sys/contrib/libb2/README.md new file mode 100644 --- /dev/null +++ b/sys/contrib/libb2/README.md @@ -0,0 +1,14 @@ +# libb2 + +C library providing BLAKE2b, BLAKE2s, BLAKE2bp, BLAKE2sp + +Installation: + +``` +$ ./autogen.sh +$ ./configure +$ make +$ sudo make install +``` + +Contact: contact@blake2.net diff --git a/sys/contrib/libb2/blake2-impl.h b/sys/contrib/libb2/blake2-impl.h --- a/sys/contrib/libb2/blake2-impl.h +++ b/sys/contrib/libb2/blake2-impl.h @@ -14,6 +14,10 @@ #ifndef __BLAKE2_IMPL_H__ #define __BLAKE2_IMPL_H__ +#if defined(_WIN32) || defined(WIN32) +#include +#endif + #include #include #include @@ -25,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++; @@ -39,8 +45,10 @@ 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++; @@ -57,8 +65,8 @@ 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; @@ -70,8 +78,8 @@ 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;