tor-browser

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

crypto_primitives.c (1004B)


      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 #ifdef FREEBL_NO_DEPEND
      6 #include "stubs.h"
      7 #endif
      8 
      9 /* This file holds useful functions and macros for crypto code. */
     10 #include "crypto_primitives.h"
     11 
     12 /*
     13 * FREEBL_HTONLL(x): swap bytes in a 64-bit integer.
     14 */
     15 #if defined(__GNUC__) && (defined(__x86_64__) || defined(__x86_64))
     16 
     17 __inline__ PRUint64
     18 swap8b(PRUint64 value)
     19 {
     20    __asm__("bswapq %0"
     21            : "+r"(value));
     22    return (value);
     23 }
     24 
     25 #elif defined(IS_LITTLE_ENDIAN) && !defined(_MSC_VER) && !__has_builtin(__builtin_bswap64) && !((defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
     26 
     27 PRUint64
     28 swap8b(PRUint64 x)
     29 {
     30    PRUint64 t1 = x;
     31    t1 = ((t1 & SHA_MASK8) << 8) | ((t1 >> 8) & SHA_MASK8);
     32    t1 = ((t1 & SHA_MASK16) << 16) | ((t1 >> 16) & SHA_MASK16);
     33    return (t1 >> 32) | (t1 << 32);
     34 }
     35 
     36 #endif