tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

crypto_primitives.h (1744B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* This file holds useful functions and macros for crypto code. */
      6 
      7 #ifdef FREEBL_NO_DEPEND
      8 #include "stubs.h"
      9 #endif
     10 
     11 #include <stdlib.h>
     12 #include "prtypes.h"
     13 
     14 /* For non-clang platform */
     15 #ifndef __has_builtin
     16 #define __has_builtin(x) 0
     17 #endif
     18 
     19 /* Unfortunately this isn't always set when it should be. */
     20 #if defined(HAVE_LONG_LONG)
     21 
     22 /*
     23 * ROTR64/ROTL64(x, n): rotate a 64-bit integer x by n bites to the right/left.
     24 */
     25 #if defined(_MSC_VER)
     26 #pragma intrinsic(_rotr64, _rotl64)
     27 #define ROTR64(x, n) _rotr64((x), (n))
     28 #define ROTL64(x, n) _rotl64((x), (n))
     29 #else
     30 #define ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
     31 #define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
     32 #endif
     33 
     34 /*
     35 * FREEBL_HTONLL(x): swap bytes in a 64-bit integer.
     36 */
     37 #if defined(IS_LITTLE_ENDIAN)
     38 #if defined(_MSC_VER)
     39 
     40 #pragma intrinsic(_byteswap_uint64)
     41 #define FREEBL_HTONLL(x) _byteswap_uint64(x)
     42 
     43 /* gcc doesn't have __has_builtin, but it does have __builtin_bswap64 */
     44 #elif __has_builtin(__builtin_bswap64) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
     45 
     46 #define FREEBL_HTONLL(x) __builtin_bswap64(x)
     47 
     48 #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__x86_64))
     49 
     50 PRUint64 swap8b(PRUint64 value);
     51 #define FREEBL_HTONLL(x) swap8b(x)
     52 
     53 #else
     54 
     55 #define SHA_MASK16 0x0000FFFF0000FFFFULL
     56 #define SHA_MASK8 0x00FF00FF00FF00FFULL
     57 PRUint64 swap8b(PRUint64 x);
     58 #define FREEBL_HTONLL(x) swap8b(x)
     59 
     60 #endif /* _MSC_VER */
     61 
     62 #else /* IS_LITTLE_ENDIAN */
     63 #define FREEBL_HTONLL(x) (x)
     64 #endif
     65 
     66 #endif /* HAVE_LONG_LONG */