webmcp

changeset 502:fa902b26589f

Removed endianess detection from moonhash_sha.c and created byteorder.h for that purpose instead
author jbe
date Mon Aug 14 12:07:37 2017 +0200 (2017-08-14)
parents 01f53490f262
children 218219b7a15e
files libraries/moonhash/byteorder.h libraries/moonhash/moonhash_sha3.c
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libraries/moonhash/byteorder.h	Mon Aug 14 12:07:37 2017 +0200
     1.3 @@ -0,0 +1,24 @@
     1.4 +/* Defines LITTLE_ENDIAN_DETECTED if system follows little endian byte order
     1.5 +   scheme. Does not define anything if endianess could not be determined. */
     1.6 +
     1.7 +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
     1.8 +#  include <sys/endian.h>
     1.9 +#  if defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN)
    1.10 +#    if _BYTE_ORDER == _LITTLE_ENDIAN
    1.11 +#      define LITTLE_ENDIAN_DETECTED
    1.12 +#    endif
    1.13 +#  else
    1.14 +#    warning Could not determine endianess on BSD platform, revert to fail safe.
    1.15 +#  endif
    1.16 +#elif defined(__linux__)
    1.17 +#  include <endian.h>
    1.18 +#  if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN)
    1.19 +#    if __BYTE_ORDER == __LITTLE_ENDIAN
    1.20 +#      define LITTLE_ENDIAN_DETECTED
    1.21 +#    endif
    1.22 +#  else
    1.23 +#    warning Could not determine endianess on Linux platform, revert to fail safe.
    1.24 +#  endif
    1.25 +#else
    1.26 +#  warning Could not determine endianess, revert to fail safe.
    1.27 +#endif
     2.1 --- a/libraries/moonhash/moonhash_sha3.c	Sun Aug 13 14:55:50 2017 +0200
     2.2 +++ b/libraries/moonhash/moonhash_sha3.c	Mon Aug 14 12:07:37 2017 +0200
     2.3 @@ -1,20 +1,7 @@
     2.4  /* This file is derived from "Keccak-more-compact.c", which has been downloaded from <https://github.com/gvanas/KeccakCodePackage/blob/10856bc1922a1ee2c4d2822a88b9ef8fb5059932/Standalone/CompactFIPS202/Keccak-more-compact.c>. The original file "Keccak-more-compact.c" has, according to <https://github.com/gvanas/KeccakCodePackage/blob/10856bc1922a1ee2c4d2822a88b9ef8fb5059932/README.markdown>, been put into the public domain. */
     2.5  
     2.6  #include <stdint.h>
     2.7 -
     2.8 -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
     2.9 -#include <sys/endian.h>
    2.10 -#if defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && _BYTE_ORDER == _LITTLE_ENDIAN
    2.11 -#define MOONHASH_LITTLE_ENDIAN
    2.12 -#endif
    2.13 -#elif defined(__linux__)
    2.14 -#include <endian.h>
    2.15 -#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
    2.16 -#define MOONHASH_LITTLE_ENDIAN
    2.17 -#endif
    2.18 -#else
    2.19 -#warning Could not determine endianess, revert to fail safe.
    2.20 -#endif
    2.21 +#include "byteorder.h"
    2.22  
    2.23  #define FOR(i,n) for(i=0; i<n; ++i)
    2.24  typedef uint8_t u8;
    2.25 @@ -31,7 +18,7 @@
    2.26  
    2.27  static int LFSR86540(u8 *R) { (*R)=((*R)<<1)^(((*R)&0x80)?0x71:0); return ((*R)&2)>>1; }
    2.28  #define ROL(a,o) ((((u64)a)<<o)^(((u64)a)>>(64-o)))
    2.29 -#ifdef MOONHASH_LITTLE_ENDIAN
    2.30 +#ifdef LITTLE_ENDIAN_DETECTED
    2.31  #define load64(src) (*(uint64_t *)(src))
    2.32  #define store64(dst, src) do { *(uint64_t *)(dst) = src; } while (0)
    2.33  #define xor64(dst, src) do { *(uint64_t *)(dst) ^= src; } while (0)

Impressum / About Us