OpenVPN 3 Core Library
Loading...
Searching...
No Matches
endian64.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
14#include <cstdint>
15
17
18namespace openvpn::Endian {
19#ifdef __MINGW32__
20inline std::uint64_t mingw_bswap64(const std::uint64_t val)
21{
22 return (((val & (uint64_t)0x00000000000000ffULL) << 56)
23 | ((val & (uint64_t)0x000000000000ff00ULL) << 40)
24 | ((val & (uint64_t)0x0000000000ff0000ULL) << 24)
25 | ((val & (uint64_t)0x00000000ff000000ULL) << 8)
26 | ((val & (uint64_t)0x000000ff00000000ULL) >> 8)
27 | ((val & (uint64_t)0x0000ff0000000000ULL) >> 24)
28 | ((val & (uint64_t)0x00ff000000000000ULL) >> 40)
29 | ((val & (uint64_t)0xff00000000000000ULL) >> 56));
30}
31#endif
32inline std::uint64_t rev64(const std::uint64_t value)
33{
34#ifdef OPENVPN_LITTLE_ENDIAN
35#if defined(_MSC_VER)
36 return _byteswap_uint64(value);
37#elif defined(__MINGW32__)
38 return mingw_bswap64(value);
39#elif defined(__clang__) || !defined(__GLIBC__)
40 return __builtin_bswap64(value);
41#else
42 return __bswap_constant_64(value);
43#endif /* _MSC_VER */
44#else
45 return value;
46#endif /* OPENVPN_LITTLE_ENDIAN */
47}
48} // namespace openvpn::Endian
std::uint64_t rev64(const std::uint64_t value)
Definition endian64.hpp:32