tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

byteorder.h (2545B)


      1 /* <MIT License>
      2 Copyright (c) 2013-2014  Marek Majkowski <marek@popcount.org>
      3 
      4 Permission is hereby granted, free of charge, to any person obtaining a copy
      5 of this software and associated documentation files (the "Software"), to deal
      6 in the Software without restriction, including without limitation the rights
      7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      8 copies of the Software, and to permit persons to whom the Software is
      9 furnished to do so, subject to the following conditions:
     10 
     11 The above copyright notice and this permission notice shall be included in
     12 all copies or substantial portions of the Software.
     13 
     14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     20 THE SOFTWARE.
     21 </MIT License>
     22 
     23 Original location:
     24    https://github.com/majek/csiphash/
     25 
     26 Solution inspired by code from:
     27    Samuel Neves (supercop/crypto_auth/siphash24/little)
     28    djb (supercop/crypto_auth/siphash24/little2)
     29    Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c)
     30 */
     31 
     32 #ifdef HAVE_SYS_PARAM_H
     33 #include <sys/param.h>
     34 #endif
     35 
     36 /* This code is extracted from csiphash.h */
     37 
     38 #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) &&      \
     39 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
     40 #  define _le64toh(x) ((uint64_t)(x))
     41 #elif defined(_WIN32)
     42 /* Windows is always little endian, unless you're on xbox360
     43   http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx */
     44 #  define _le64toh(x) ((uint64_t)(x))
     45 #elif defined(__APPLE__)
     46 #  include <libkern/OSByteOrder.h>
     47 #  define _le64toh(x) OSSwapLittleToHostInt64(x)
     48 #elif defined(sun) || defined(__sun)
     49 #  include <sys/byteorder.h>
     50 #  define _le64toh(x) LE_64(x)
     51 
     52 #else
     53 
     54 /* See: http://sourceforge.net/p/predef/wiki/Endianness/ */
     55 #  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(OpenBSD)
     56 #    include <sys/endian.h>
     57 #  else
     58 #    include <endian.h>
     59 #  endif
     60 #  if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
     61 __BYTE_ORDER == __LITTLE_ENDIAN
     62 #    define _le64toh(x) ((uint64_t)(x))
     63 #  else
     64 #    if defined(OpenBSD)
     65 #      define _le64toh(x) letoh64(x)
     66 #    else
     67 #      define _le64toh(x) le64toh(x)
     68 #    endif
     69 #  endif
     70 
     71 #endif