├── .editorconfig ├── .github ├── action.sh ├── build-cmake.sh ├── build.sh ├── install-post.sh ├── install.sh ├── install │ ├── alpine.sh │ ├── archlinux.sh │ ├── debian.sh │ ├── fedora.sh │ ├── opensuse.sh │ └── ubuntu.sh ├── preinstall.sh ├── update-packages.sh ├── update-packages │ ├── alpine.sh │ ├── archlinux.sh │ ├── debian.sh │ ├── fedora.sh │ ├── opensuse.sh │ └── ubuntu.sh └── workflows │ ├── build.yml │ ├── linux-flavors.yml │ └── macos.yml ├── .gitignore ├── .gitmodules ├── .travis-run-local.py ├── .travis.yml ├── BUILDING.md ├── BUILDING_WINDOWS_MANUAL.md ├── CMakeLists.txt ├── GameNetworkingSockets.code-workspace ├── LICENSE ├── README.md ├── README_P2P.md ├── SECURITY.md ├── cmake ├── DefaultBuildType.cmake ├── FindASan.cmake ├── FindMSan.cmake ├── FindSanitizers.cmake ├── FindTSan.cmake ├── FindUBSan.cmake ├── Findsodium.cmake ├── FlagsMSVC.cmake ├── GameNetworkingSocketsConfig.cmake.in ├── asan-wrapper ├── sanitize-helpers.cmake └── tryCompileTestBCrypt.cpp ├── examples ├── CMakeLists.txt ├── example_chat.cpp ├── trivial_signaling_client.cpp ├── trivial_signaling_client.h ├── trivial_signaling_server.go └── vcpkg_example_chat │ ├── CMakeLists.txt │ ├── README.md │ └── vcpkg.json ├── include └── steam │ ├── isteamnetworkingmessages.h │ ├── isteamnetworkingsockets.h │ ├── isteamnetworkingutils.h │ ├── steam_api_common.h │ ├── steamclientpublic.h │ ├── steamnetworkingcustomsignaling.h │ ├── steamnetworkingsockets.h │ ├── steamnetworkingsockets_flat.h │ ├── steamnetworkingtypes.h │ ├── steamtypes.h │ └── steamuniverse.h ├── src ├── CMakeLists.txt ├── common │ ├── crypto.cpp │ ├── crypto.h │ ├── crypto_25519.h │ ├── crypto_25519_donna.cpp │ ├── crypto_25519_libsodium.cpp │ ├── crypto_25519_openssl.cpp │ ├── crypto_bcrypt.cpp │ ├── crypto_constants.h │ ├── crypto_digest_opensslevp.cpp │ ├── crypto_libsodium.cpp │ ├── crypto_openssl.cpp │ ├── crypto_sha1_wpa.cpp │ ├── crypto_symmetric_opensslevp.cpp │ ├── crypto_textencode.cpp │ ├── keypair.cpp │ ├── keypair.h │ ├── opensslwrapper.cpp │ ├── opensslwrapper.h │ ├── percentile_generator.h │ ├── steamid.cpp │ ├── steamid.h │ ├── steamnetworkingsockets_messages.proto │ ├── steamnetworkingsockets_messages_certs.proto │ └── steamnetworkingsockets_messages_udp.proto ├── external │ ├── curve25519-donna │ │ ├── README.md │ │ ├── curve25519-donna-32bit.h │ │ ├── curve25519-donna-64bit.h │ │ ├── curve25519-donna-common.h │ │ ├── curve25519-donna-portable-identify.h │ │ ├── curve25519-donna-portable.h │ │ ├── curve25519-donna-scalarmult-base.h │ │ ├── curve25519-donna-scalarmult-sse2.h │ │ ├── curve25519-donna-sse2.h │ │ ├── curve25519-donna.h │ │ ├── curve25519-optimizations-32bit.md │ │ ├── curve25519.c │ │ ├── curve25519.h │ │ ├── curve25519_VALVE_sse2.c │ │ ├── readme_VALVE.txt │ │ ├── test-ticks.h │ │ └── test.c │ ├── ed25519-donna │ │ ├── README.md │ │ ├── curve25519-donna-32bit.h │ │ ├── curve25519-donna-64bit.h │ │ ├── curve25519-donna-helpers.h │ │ ├── curve25519-donna-sse2.h │ │ ├── ed25519-donna-32bit-sse2.h │ │ ├── ed25519-donna-32bit-tables.h │ │ ├── ed25519-donna-64bit-sse2.h │ │ ├── ed25519-donna-64bit-tables.h │ │ ├── ed25519-donna-64bit-x86-32bit.h │ │ ├── ed25519-donna-64bit-x86.h │ │ ├── ed25519-donna-basepoint-table.h │ │ ├── ed25519-donna-batchverify.h │ │ ├── ed25519-donna-impl-base.h │ │ ├── ed25519-donna-impl-sse2.h │ │ ├── ed25519-donna-portable-identify.h │ │ ├── ed25519-donna-portable.h │ │ ├── ed25519-donna.h │ │ ├── ed25519-hash-bcrypt.h │ │ ├── ed25519-hash-custom.h │ │ ├── ed25519-hash-openssl.h │ │ ├── ed25519-hash-ref.h │ │ ├── ed25519-hash.h │ │ ├── ed25519-randombytes-custom.h │ │ ├── ed25519-randombytes.h │ │ ├── ed25519.c │ │ ├── ed25519.h │ │ ├── ed25519_VALVE.c │ │ ├── ed25519_VALVE_sse2.c │ │ ├── fuzz │ │ │ ├── README.md │ │ │ ├── build-nix.php │ │ │ ├── curve25519-ref10.c │ │ │ ├── curve25519-ref10.h │ │ │ ├── ed25519-donna-sse2.c │ │ │ ├── ed25519-donna.c │ │ │ ├── ed25519-donna.h │ │ │ ├── ed25519-ref10.c │ │ │ ├── ed25519-ref10.h │ │ │ ├── fuzz-curve25519.c │ │ │ └── fuzz-ed25519.c │ │ ├── modm-donna-32bit.h │ │ ├── modm-donna-64bit.h │ │ ├── readme_VALVE.txt │ │ ├── regression.h │ │ ├── test-internals.c │ │ ├── test-ticks.h │ │ └── test.c │ ├── sha1-wpa │ │ ├── README │ │ ├── sha1-internal.c │ │ ├── sha1.c │ │ ├── sha1.h │ │ └── sha1_i.h │ └── steamwebrtc │ │ ├── CMakeLists.txt │ │ ├── ice_session.cpp │ │ ├── ice_session.h │ │ ├── steamwebrtc_internal.h │ │ └── webrtc_sdp.cc ├── public │ ├── minbase │ │ ├── minbase_annotations.h │ │ ├── minbase_decls.h │ │ ├── minbase_endian.h │ │ ├── minbase_identify.h │ │ ├── minbase_limits.h │ │ ├── minbase_macros.h │ │ ├── minbase_securezeromemory_impl.h │ │ ├── minbase_types.h │ │ └── minbase_warnings.h │ ├── tier0 │ │ ├── basetypes.h │ │ ├── dbg.h │ │ ├── memdbgoff.h │ │ ├── memdbgon.h │ │ ├── platform.h │ │ ├── platform_sockets.h │ │ ├── platformtime.h │ │ ├── t0constants.h │ │ ├── valve_off.h │ │ ├── valve_on.h │ │ ├── valve_tracelogging.h │ │ ├── vprof.h │ │ └── wchartypes.h │ ├── tier1 │ │ ├── fmtstr.h │ │ ├── netadr.h │ │ ├── utlbuffer.h │ │ ├── utlhashmap.h │ │ ├── utliterator.h │ │ ├── utllinkedlist.h │ │ ├── utlmemory.h │ │ ├── utlpriorityqueue.h │ │ └── utlvector.h │ ├── vstdlib │ │ ├── random.h │ │ └── strtools.h │ └── winlite.h ├── steamnetworkingsockets │ ├── certtool │ │ └── steamnetworkingsockets_certtool.cpp │ ├── clientlib │ │ ├── SNP_WIRE_FORMAT.md │ │ ├── csteamnetworkingmessages.cpp │ │ ├── csteamnetworkingmessages.h │ │ ├── csteamnetworkingsockets.cpp │ │ ├── csteamnetworkingsockets.h │ │ ├── ice_client_types.h │ │ ├── steamnetworkingsockets_connections.cpp │ │ ├── steamnetworkingsockets_connections.h │ │ ├── steamnetworkingsockets_flat.cpp │ │ ├── steamnetworkingsockets_lowlevel.cpp │ │ ├── steamnetworkingsockets_lowlevel.h │ │ ├── steamnetworkingsockets_p2p.cpp │ │ ├── steamnetworkingsockets_p2p.h │ │ ├── steamnetworkingsockets_p2p_ice.cpp │ │ ├── steamnetworkingsockets_p2p_ice.h │ │ ├── steamnetworkingsockets_p2p_webrtc.cpp │ │ ├── steamnetworkingsockets_p2p_webrtc.h │ │ ├── steamnetworkingsockets_snp.cpp │ │ ├── steamnetworkingsockets_snp.h │ │ ├── steamnetworkingsockets_stun.cpp │ │ ├── steamnetworkingsockets_stun.h │ │ ├── steamnetworkingsockets_udp.cpp │ │ └── steamnetworkingsockets_udp.h │ ├── steamnetworking_stats.h │ ├── steamnetworking_statsutils.h │ ├── steamnetworkingsockets_certs.cpp │ ├── steamnetworkingsockets_certstore.cpp │ ├── steamnetworkingsockets_certstore.h │ ├── steamnetworkingsockets_internal.h │ ├── steamnetworkingsockets_shared.cpp │ ├── steamnetworkingsockets_stats.cpp │ ├── steamnetworkingsockets_thinker.cpp │ └── steamnetworkingsockets_thinker.h ├── tier0 │ ├── dbg.cpp │ ├── platformtime.cpp │ └── valve_tracelogging.cpp ├── tier1 │ ├── ipv6text.c │ ├── ipv6text.h │ ├── netadr.cpp │ ├── utlbuffer.cpp │ └── utlmemory.cpp └── vstdlib │ └── strtools.cpp ├── tests ├── CMakeLists.txt ├── aesgcmtestvectors │ ├── gcmDecrypt128.rsp │ ├── gcmDecrypt192.rsp │ ├── gcmDecrypt256.rsp │ ├── gcmEncryptExtIV128.rsp │ ├── gcmEncryptExtIV192.rsp │ ├── gcmEncryptExtIV256.rsp │ └── readme.txt ├── make_test_certs.py ├── test_common.cpp ├── test_common.h ├── test_connection.cpp ├── test_crypto.cpp ├── test_flat.c ├── test_p2p.cpp ├── test_p2p.py └── test_pki.cpp ├── vcpkg.json └── vcpkg_ports └── gamenetworkingsockets └── portfile.cmake /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | 7 | [*.py] 8 | indent_style = space 9 | indent_size = 4 10 | 11 | [CMakeLists.txt,*.{cpp,h}] 12 | indent_style = tab 13 | indent_size = 4 14 | -------------------------------------------------------------------------------- /.github/action.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -o pipefail 5 | 6 | ACTION="$(basename "$0")" 7 | ACTION="${ACTION%.sh}" 8 | 9 | SCRIPT_CANDIDATES=( 10 | "$PWD/.github/${ACTION}/${IMAGE//\//-}.sh" 11 | "$PWD/.github/${ACTION}/${IMAGE%/*}.sh" 12 | ) 13 | 14 | for SCRIPT in "${SCRIPT_CANDIDATES[@]}"; do 15 | if [[ -f "${SCRIPT}" ]]; then 16 | bash "${SCRIPT}" | cat 17 | exit $? 18 | fi 19 | done 20 | 21 | echo "Could not find script in any of these paths:" 22 | for SCRIPT in "${SCRIPT_CANDIDATES[@]}"; do 23 | echo " ${SCRIPT}" 24 | done 25 | echo "" 26 | echo "Don't know how to do step '${ACTION}' for ${IMAGE}!" 27 | echo "" 28 | exit 1 29 | -------------------------------------------------------------------------------- /.github/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is a distribution-agnostic build script. Do not use "apt-get", "dnf", or 4 | # similar in here. Add any package installation gunk into the appropriate 5 | # install script instead. 6 | # 7 | set -e 8 | 9 | has() { 10 | if type -P "$@" &>/dev/null; then 11 | return 0 12 | fi 13 | return 1 14 | } 15 | 16 | has_clang() { 17 | has clang && has clang++ 18 | } 19 | 20 | has_gcc() { 21 | has gcc && has g++ 22 | } 23 | 24 | msg() { 25 | echo "$1" >&2 26 | } 27 | 28 | die() { 29 | msg "$1" 30 | exit 1 31 | } 32 | 33 | CI_BUILD=${CI_BUILD:-0} 34 | export BUILD_SANITIZERS=0 35 | 36 | # Only run sanitizers on a couple of the builder types. 37 | if [[ "$IMAGE" == "ubuntu" ]] && [[ "$IMAGE_TAG" == "rolling" ]]; then 38 | export BUILD_SANITIZERS=1 39 | fi 40 | if [[ "$IMAGE" == "fedora" ]] && [[ "$IMAGE_TAG" == "rawhide" ]]; then 41 | export BUILD_SANITIZERS=1 42 | fi 43 | if [[ "$CI_BUILD" -eq 0 ]]; then 44 | # If we're doing a non-CI build, we should build the sanitizers for our 45 | # own debugging. 46 | export BUILD_SANITIZERS=1 47 | fi 48 | 49 | msg "Image is $IMAGE:$IMAGE_TAG, sanitizers enabled: $BUILD_SANITIZERS" 50 | 51 | # Make sure cmake is installed 52 | has cmake || die "cmake required" 53 | 54 | # We also need at least one compiler 55 | has_clang || has_gcc || die "No compiler available" 56 | 57 | export CCACHE_DIR=$PWD/build-ci-ccache 58 | ccache -M4G 59 | 60 | # Mark all directories as safe so checkouts performed in CMakeLists.txt don't cause "unsafe repository" errors. 61 | # See https://github.com/actions/checkout/issues/766 62 | git config --global --add safe.directory '*' 63 | 64 | # Use shallow clones of submodules for space/time efficiency. 65 | #git submodule update --init --depth=1 2>&1 | cat 66 | 67 | if has_clang; then 68 | msg "Beginning build tests with Clang" 69 | export CC=clang CXX=clang++ 70 | has cmake && bash .github/build-cmake.sh 71 | fi 72 | 73 | if has_gcc; then 74 | msg "Beginning build tests with GCC" 75 | export CC=gcc CXX=g++ 76 | has cmake && bash .github/build-cmake.sh 77 | fi 78 | 79 | msg "All builds and tests executed successfully." 80 | 81 | exit 0 82 | -------------------------------------------------------------------------------- /.github/install-post.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is a post-install script common to all Docker images. 4 | # 5 | 6 | cmake --version 7 | g++ --version 8 | clang++ --version 9 | uname -a 10 | 11 | echo "=====================" 12 | echo "GCC predefined macros" 13 | echo "=====================" 14 | g++ -E -dM -xc /dev/null | sort 15 | 16 | echo "=======================" 17 | echo "Clang predefined macros" 18 | echo "=======================" 19 | clang++ -E -dM -xc /dev/null | sort 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /.github/install.sh: -------------------------------------------------------------------------------- 1 | action.sh -------------------------------------------------------------------------------- /.github/install/alpine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Alpine-specific packages. 4 | # 5 | set -ex 6 | 7 | # Base build packages 8 | PACKAGES=( 9 | clang 10 | clang-dev 11 | gcc 12 | g++ 13 | ccache 14 | cmake 15 | ninja 16 | pkgconf 17 | git 18 | linux-headers 19 | go 20 | ) 21 | 22 | PACKAGES+=(protobuf-dev) 23 | PACKAGES+=(openssl-dev) 24 | PACKAGES+=(libsodium-dev) 25 | 26 | apk add "${PACKAGES[@]}" 27 | 28 | exit 0 29 | -------------------------------------------------------------------------------- /.github/install/archlinux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Arch Linux-specific packages. 4 | # 5 | set -ex 6 | 7 | # Base build packages 8 | PACKAGES=( 9 | base-devel 10 | ccache 11 | clang 12 | cmake 13 | git 14 | go 15 | ninja 16 | ) 17 | 18 | PACKAGES+=(protobuf) 19 | PACKAGES+=(openssl) 20 | PACKAGES+=(libsodium) 21 | 22 | pacman --noconfirm -Sy "${PACKAGES[@]}" 23 | 24 | exit 0 25 | -------------------------------------------------------------------------------- /.github/install/debian.sh: -------------------------------------------------------------------------------- 1 | ubuntu.sh -------------------------------------------------------------------------------- /.github/install/fedora.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Fedora-specific packages. 4 | # 5 | set -ex 6 | 7 | # Base build packages 8 | PACKAGES=( 9 | gcc-c++ 10 | libasan 11 | libubsan 12 | ccache 13 | clang 14 | cmake 15 | ninja-build 16 | pkgconf-pkg-config 17 | git 18 | make 19 | golang 20 | ) 21 | 22 | PACKAGES+=(protobuf-compiler protobuf-devel) 23 | PACKAGES+=(openssl-devel) 24 | PACKAGES+=(libsodium-devel) 25 | 26 | dnf install -y "${PACKAGES[@]}" 27 | 28 | exit 0 29 | -------------------------------------------------------------------------------- /.github/install/opensuse.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for OpenSuSE-specific packages. 4 | # 5 | set -ex 6 | 7 | # Base build packages 8 | PACKAGES=( 9 | gcc-c++ 10 | ccache 11 | clang 12 | cmake 13 | ninja 14 | pkgconf-pkg-config 15 | git 16 | make 17 | go 18 | ) 19 | 20 | PACKAGES+=(protobuf-devel) 21 | PACKAGES+=(libopenssl-devel) 22 | PACKAGES+=(libsodium-devel) 23 | 24 | zypper install -y "${PACKAGES[@]}" 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /.github/install/ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Ubuntu-specific packages. 4 | # 5 | set -ex 6 | 7 | APT_FLAGS=(-q -oDpkg::Use-Pty=0) 8 | 9 | export DEBIAN_FRONTEND=noninteractive 10 | 11 | apt-get ${APT_FLAGS[@]} install -y locales 12 | locale-gen en_US.UTF-8 13 | 14 | PACKAGES=( 15 | build-essential 16 | pkg-config 17 | ccache 18 | cmake 19 | ninja-build 20 | clang 21 | git 22 | golang 23 | ) 24 | 25 | PACKAGES+=(libprotobuf-dev protobuf-compiler) 26 | PACKAGES+=(libssl-dev) 27 | PACKAGES+=(libsodium-dev) 28 | 29 | apt-get ${APT_FLAGS[@]} install -y "${PACKAGES[@]}" 30 | 31 | exit 0 32 | -------------------------------------------------------------------------------- /.github/preinstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$IMAGE" = "alpine" ] 4 | then 5 | apk update 6 | apk add bash 7 | fi 8 | 9 | exit 0 10 | -------------------------------------------------------------------------------- /.github/update-packages.sh: -------------------------------------------------------------------------------- 1 | action.sh -------------------------------------------------------------------------------- /.github/update-packages/alpine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Alpine-specific package updates. 4 | # 5 | set -ex 6 | 7 | apk update 8 | 9 | exit 0 10 | -------------------------------------------------------------------------------- /.github/update-packages/archlinux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Arch Linux-specific package updates. 4 | # 5 | set -ex 6 | 7 | pacman --noconfirm -Syu 8 | 9 | exit 0 10 | -------------------------------------------------------------------------------- /.github/update-packages/debian.sh: -------------------------------------------------------------------------------- 1 | ubuntu.sh -------------------------------------------------------------------------------- /.github/update-packages/fedora.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Fedora-specific package updates. 4 | # 5 | set -ex 6 | 7 | if ! grep '^fastestmirror' /etc/dnf/dnf.conf; then 8 | echo 'fastestmirror=1' >> /etc/dnf/dnf.conf 9 | fi 10 | 11 | dnf clean all 12 | dnf update -y 13 | 14 | exit 0 15 | -------------------------------------------------------------------------------- /.github/update-packages/opensuse.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for OpenSuSE-specific package updates. 4 | # 5 | set -ex 6 | 7 | zypper update -y 8 | 9 | exit 0 10 | -------------------------------------------------------------------------------- /.github/update-packages/ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an install script for Debian/Ubuntu-specific package updates. 4 | # 5 | set -ex 6 | 7 | APT_FLAGS=(-q -oDpkg::Use-Pty=0) 8 | 9 | export DEBIAN_FRONTEND=noninteractive 10 | 11 | apt-get ${APT_FLAGS[@]} update 12 | apt-get ${APT_FLAGS[@]} dist-upgrade -y 13 | 14 | exit 0 15 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | 6 | build-and-test-ubuntu: 7 | #if: false # Temporarily disable 8 | name: Build And Test Ubuntu 9 | runs-on: ubuntu-latest 10 | env: 11 | CI_BUILD: 1 12 | IMAGE: ubuntu 13 | IMAGE_TAG: latest 14 | steps: 15 | - uses: actions/checkout@main 16 | # Note only alpine needs "preinstall" step 17 | - name: Update packages 18 | run: sudo -E bash .github/update-packages.sh 19 | - name: Install dependencies 20 | run: | 21 | sudo -E bash .github/install.sh 22 | sudo -E bash .github/install-post.sh 23 | - name: Build and run tests 24 | run: bash .github/build.sh 25 | 26 | # Don't do it this way. This causes the main badge to 27 | # go red if one of the flavors fails. 28 | ## Trigger testing of more linux flavors 29 | #- name: Trigger linux flavors build 30 | # uses: peter-evans/repository-dispatch@v2 31 | # with: 32 | # event-type: build-linux-flavors 33 | 34 | build-and-test-windows: 35 | #if: false # Temporarily disable 36 | name: Build And Test Windows ${{ matrix.os-version }} ${{ matrix.crypto }} 37 | runs-on: windows-${{ matrix.os-version }} 38 | strategy: 39 | fail-fast: false 40 | matrix: 41 | os-version: [2019, 2022] 42 | crypto: [OpenSSL, BCrypt] 43 | env: 44 | VCPKG_ROOT: ${{ github.workspace }}/vcpkg 45 | steps: 46 | - uses: actions/checkout@main 47 | 48 | - uses: lukka/get-cmake@latest 49 | 50 | # Setup MSVC command prompt environment vars. 51 | # We must do this before sedtting up our local vcpkg, 52 | # Because it will set VCPKG_ROOT to point to some global 53 | # install of vcpkg, and we don't want that 54 | - uses: ilammy/msvc-dev-cmd@v1 55 | 56 | - name: Restore artifacts, setup vcpkg 57 | uses: lukka/run-vcpkg@v11 58 | with: 59 | vcpkgGitCommitId: fba75d09065fcc76a25dcf386b1d00d33f5175af 60 | vcpkgDirectory: '${{ github.workspace }}/vcpkg' 61 | vcpkgJsonGlob: vcpkg.json 62 | runVcpkgInstall: false 63 | 64 | - name: vcpkg check / install dependencies 65 | working-directory: '${{ github.workspace }}' 66 | run: '"${{env.VCPKG_ROOT}}\\vcpkg" install --triplet=x64-windows' 67 | shell: cmd 68 | 69 | - name: Install dependencies and generate project files 70 | run: | 71 | mkdir build 72 | cd build 73 | cmake -S .. -G Ninja -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_TOOLS=ON -DCMAKE_TOOLCHAIN_FILE=${{env.VCPKG_ROOT}}/scripts/buildsystems/vcpkg.cmake -DUSE_CRYPTO=${{matrix.crypto}} 74 | shell: cmd 75 | 76 | # Mark all directories as safe so checkouts performed in CMakeLists.txt don't cause "unsafe repository" errors. 77 | # See https://github.com/actions/checkout/issues/766 78 | - name: Configure Git 79 | run: git config --global --add safe.directory '*' 80 | shell: cmd 81 | 82 | - name: Build projects 83 | working-directory: '${{ github.workspace }}/build' 84 | run: ninja 85 | shell: cmd 86 | 87 | - name: Test crypto 88 | working-directory: '${{ github.workspace }}/build/bin' 89 | run: test_crypto.exe 90 | shell: cmd 91 | 92 | - name: Test connection 93 | working-directory: '${{ github.workspace }}/build/bin' 94 | #run: test_connection.exe suite-quick # Loopback throughput test not performing on github hosted runners for some reason 95 | 96 | run: test_connection.exe identity quick lane_quick_queueanddrain lane_quick_priority_and_background 97 | shell: cmd 98 | 99 | -------------------------------------------------------------------------------- /.github/workflows/linux-flavors.yml: -------------------------------------------------------------------------------- 1 | # We put all of the different linux flavors in a separate workflow, 2 | # so that we can have a different status badge for them. 3 | name: Linux flavors 4 | 5 | # Triggered from the main CI build workflow 6 | on: 7 | workflow_run: 8 | workflows: ["CI"] 9 | types: 10 | - completed 11 | #workflow_call: 12 | #workflow_dispatch: 13 | #repository_dispatch: 14 | # types: [ build-linux-flavors ] 15 | 16 | jobs: 17 | 18 | build-and-test-flavors: 19 | #if: false # Temporarily disable 20 | name: Build And Test Unix Flavors 21 | runs-on: ${{ matrix.os }} 22 | strategy: 23 | matrix: 24 | include: 25 | - build: ubuntu-bionic 26 | os: ubuntu-latest 27 | docker_image: ubuntu 28 | docker_tag: bionic 29 | #- build: ubuntu-latest 30 | # os: ubuntu-latest 31 | # docker_image: ubuntu 32 | # docker_tag: latest 33 | - build: ubuntu-rolling 34 | os: ubuntu-latest 35 | docker_image: ubuntu 36 | docker_tag: rolling 37 | #- build: ubuntu-devel 38 | # os: ubuntu-latest 39 | # docker_image: ubuntu 40 | # docker_tag: devel 41 | - build: fedora-latest 42 | os: ubuntu-latest 43 | docker_image: fedora 44 | docker_tag: latest 45 | - build: archlinux-latest 46 | os: ubuntu-latest 47 | docker_image: archlinux 48 | docker_tag: latest 49 | - build: alpine-latest 50 | os: ubuntu-latest 51 | docker_image: alpine 52 | docker_tag: latest 53 | steps: 54 | - uses: actions/checkout@main 55 | - name: Launch container 56 | run: | 57 | docker run -d --rm --name github-docker-builder -e LC_ALL="C" -e LANG="C" -v ${{ github.workspace }}:/build -w /build ${{ matrix.docker_image }}:${{ matrix.docker_tag }} tail -f /dev/null 58 | docker ps 59 | docker exec -e CI_BUILD=1 -e IMAGE=${{ matrix.docker_image }} -e IMAGE_TAG=${{ matrix.docker_tag }} -t github-docker-builder sh .github/preinstall.sh 60 | - name: Update packages 61 | run: | 62 | docker exec -e CI_BUILD=1 -e IMAGE=${{ matrix.docker_image }} -e IMAGE_TAG=${{ matrix.docker_tag }} -t github-docker-builder bash .github/update-packages.sh 63 | - name: Install dependencies 64 | run: | 65 | docker exec -e CI_BUILD=1 -e IMAGE=${{ matrix.docker_image }} -e IMAGE_TAG=${{ matrix.docker_tag }} -t github-docker-builder bash .github/install.sh 66 | docker exec -e CI_BUILD=1 -e IMAGE=${{ matrix.docker_image }} -e IMAGE_TAG=${{ matrix.docker_tag }} -t github-docker-builder bash .github/install-post.sh 67 | - name: Build and run project 68 | run: | 69 | docker exec -e CI_BUILD=1 -e IMAGE=${{ matrix.docker_image }} -e IMAGE_TAG=${{ matrix.docker_tag }} -t github-docker-builder bash .github/build.sh 70 | -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: MacOS 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | 6 | build-and-test-macos: 7 | name: Build And Test MacOS 8 | runs-on: macos-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | - name: Install Vcpkg 12 | run: | 13 | git clone https://github.com/Microsoft/vcpkg.git 14 | cd vcpkg 15 | ./bootstrap-vcpkg.sh 16 | ./vcpkg integrate install 17 | 18 | - name: Configure CMake 19 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 20 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 21 | run: cmake -B ${{github.workspace}}/build 22 | -DCMAKE_BUILD_TYPE=Release 23 | -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake 24 | -DBUILD_TESTS=ON 25 | 26 | - name: Build 27 | # Build the program with the given configuration 28 | run: cmake --build ${{github.workspace}}/build --config Release 29 | 30 | #- name: Test 31 | # working-directory: ${{github.workspace}}/build 32 | # # Execute tests defined by the CMake configuration. 33 | # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 34 | # run: ctest -C Release 35 | 36 | - name: Test crypto 37 | working-directory: ${{github.workspace}}/build/bin 38 | run: ./test_crypto 39 | shell: bash 40 | 41 | - name: Test connection 42 | working-directory: ${{github.workspace}}/build/bin 43 | run: ./test_connection identity quick lane_quick_queueanddrain lane_quick_priority_and_background 44 | shell: bash 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | obj 10 | 11 | # Precompiled Headers 12 | *.gch 13 | *.pch 14 | 15 | /bin 16 | 17 | # Ignore CMake outputs 18 | compile_commands.json 19 | CMakeCache.txt 20 | CMakeFiles 21 | Makefile 22 | cmake_install.cmake 23 | 24 | # Ignore outputs from "perf record" 25 | perf.data 26 | perf.data.old 27 | 28 | # Default/recommended install directory for vcpkg 29 | **/vcpkg 30 | 31 | # Other misc stuff 32 | *.VC.* 33 | **/.vscode 34 | **/build 35 | **/build-* 36 | **/build.bat 37 | **/log.txt 38 | **/.vs 39 | /src/steamnetworkingsockets/Messageswin64Debug/* 40 | /src/steamnetworkingsockets/certtool/win64/* 41 | /src/steamnetworkingsockets/clientlib/win64/* 42 | *.swp 43 | /.github/build-ci-ccache 44 | *.log 45 | *build-ci-ccache* 46 | vcpkg_installed 47 | .p4config 48 | P4CONFIG 49 | 50 | # We use cmake, so no Visual studio project files should be in git 51 | *.sln 52 | *.vcxproj 53 | *.vcxproj.filters 54 | *.vcxproj.user 55 | *.vpc_crc 56 | *.vpc.sentinel 57 | *_from_partner.bat 58 | src/mp.bat 59 | *_changes.html 60 | 61 | # Unfortunately, in the partner branch we compile our generated protobufs 62 | # directly into the common folder 63 | src/common/*.pb.cc 64 | src/common/*.pb.h 65 | 66 | # Protobuf has some test scripts and we get warnings about line endings 67 | src/external/protobuf-3.15.3/**/*.sh 68 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/external/abseil"] 2 | path = src/external/abseil 3 | url = https://github.com/abseil/abseil-cpp 4 | branch = lts_2020_02_25 5 | [submodule "src/external/webrtc"] 6 | path = src/external/webrtc 7 | url = https://webrtc.googlesource.com/src 8 | [submodule "src/external/picojson"] 9 | path = src/external/picojson 10 | url = https://github.com/kazuho/picojson.git 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: minimal 2 | 3 | dist: bionic 4 | 5 | os: linux 6 | 7 | services: 8 | - docker 9 | 10 | arch: amd64 11 | 12 | env: 13 | global: 14 | - CONTAINER_NAME=github-docker-builder 15 | jobs: 16 | - IMAGE=alpine IMAGE_TAG=latest 17 | - IMAGE=archlinux IMAGE_TAG=latest 18 | # 18.04 (Bionic) is the oldest one we want to attempt builds with. 19 | - IMAGE=ubuntu IMAGE_TAG=bionic 20 | - IMAGE=ubuntu IMAGE_TAG=latest 21 | - IMAGE=ubuntu IMAGE_TAG=rolling 22 | # Something broke here. Commenting it out to see if it's just broken at the head. 23 | #- IMAGE=ubuntu IMAGE_TAG=devel 24 | - IMAGE=fedora IMAGE_TAG=latest 25 | - IMAGE=fedora IMAGE_TAG=rawhide 26 | 27 | jobs: 28 | include: 29 | - arch: i386 30 | env: IMAGE=debian IMAGE_TAG=stable 31 | - arch: arm64 32 | env: IMAGE=ubuntu IMAGE_TAG=rolling 33 | # Disabled - the docker is failing to boot ver early with this output: 34 | # Unpacking locales (2.31-0ubuntu9) ... 35 | # dpkg: error processing archive /var/cache/apt/archives/locales_2.31-0ubuntu9_all.deb (--unpack): 36 | # unable to install new version of './usr/share/doc/locales': Invalid cross-device link 37 | # dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) 38 | # Errors were encountered while processing: 39 | # /var/cache/apt/archives/locales_2.31-0ubuntu9_all.deb 40 | #- arch: ppc64le 41 | # env: IMAGE=ubuntu IMAGE_TAG=rolling 42 | - arch: s390x 43 | env: IMAGE=ubuntu IMAGE_TAG=rolling 44 | 45 | before_install: 46 | - docker run -d --rm --cap-add SYS_PTRACE --name $CONTAINER_NAME -e LC_ALL="C" -e LANG="C" -v $(pwd):/build -w /build $IMAGE_PREFIX$IMAGE:$IMAGE_TAG tail -f /dev/null 47 | - docker ps 48 | - docker exec -e CI_BUILD=1 -e IMAGE=$IMAGE -e IMAGE_TAG=$IMAGE_TAG -t $CONTAINER_NAME sh .github/preinstall.sh 49 | - docker exec -e CI_BUILD=1 -e IMAGE=$IMAGE -e IMAGE_TAG=$IMAGE_TAG -t $CONTAINER_NAME bash .github/update-packages.sh 50 | 51 | install: 52 | - docker exec -e CI_BUILD=1 -e IMAGE=$IMAGE -e IMAGE_TAG=$IMAGE_TAG -t $CONTAINER_NAME bash .github/install.sh 53 | - docker exec -e CI_BUILD=1 -e IMAGE=$IMAGE -e IMAGE_TAG=$IMAGE_TAG -t $CONTAINER_NAME bash .github/install-post.sh 54 | 55 | script: 56 | - docker exec -e CI_BUILD=1 -e IMAGE=$IMAGE -e IMAGE_TAG=$IMAGE_TAG -t $CONTAINER_NAME bash .github/build.sh 57 | - docker kill $CONTAINER_NAME 58 | 59 | # vim: set ts=2 sts=2 sw=2 et: 60 | -------------------------------------------------------------------------------- /GameNetworkingSockets.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": { 8 | "cmake.buildDirectory": "${workspaceFolder}/build", 9 | "C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json", 10 | "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Valve Corporation 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | If you believe you have found a security vulnerability, please do not file a 4 | public issue or pull request. Instead, disclose it responsibly through 5 | [hacker one](https://hackerone.com/valve). 6 | 7 | Because most of the code in this library is used in the Steamworks SDK and our 8 | games, it is in scope for hackerone reports. Note that to be eligible 9 | for a bounty, the vulnerability needs to be in a part of the code that is used 10 | by Steam players. 11 | -------------------------------------------------------------------------------- /cmake/DefaultBuildType.cmake: -------------------------------------------------------------------------------- 1 | # Set a default build type if none was specified 2 | set(default_build_type "RelWithDebInfo") 3 | 4 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 5 | message(STATUS "Setting CMAKE_BUILD_TYPE to '${default_build_type}' as none was specified.") 6 | set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) 7 | 8 | # Set the possible values of build type for cmake-gui 9 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 10 | else() 11 | message(STATUS "CMAKE_BUILD_TYPE='${CMAKE_BUILD_TYPE}'") 12 | endif() 13 | -------------------------------------------------------------------------------- /cmake/FindASan.cmake: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 4 | # 2013 Matthew Arsenault 5 | # 2015-2016 RWTH Aachen University, Federal Republic of Germany 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | option(SANITIZE_ADDRESS "Enable AddressSanitizer for sanitized targets." Off) 26 | 27 | set(FLAG_CANDIDATES 28 | # Clang 3.2+ use this version. The no-omit-frame-pointer option is optional. 29 | "-g -fsanitize=address -fno-omit-frame-pointer" 30 | "-g -fsanitize=address" 31 | 32 | # Older deprecated flag for ASan 33 | "-g -faddress-sanitizer" 34 | ) 35 | 36 | 37 | if (SANITIZE_ADDRESS AND (SANITIZE_THREAD OR SANITIZE_MEMORY)) 38 | message(FATAL_ERROR "AddressSanitizer is not compatible with " 39 | "ThreadSanitizer or MemorySanitizer.") 40 | endif () 41 | 42 | 43 | include(sanitize-helpers) 44 | 45 | if (SANITIZE_ADDRESS) 46 | sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "AddressSanitizer" 47 | "ASan") 48 | 49 | find_program(ASan_WRAPPER "asan-wrapper" PATHS ${CMAKE_MODULE_PATH}) 50 | mark_as_advanced(ASan_WRAPPER) 51 | endif () 52 | 53 | function (add_sanitize_address TARGET) 54 | if (NOT SANITIZE_ADDRESS) 55 | return() 56 | endif () 57 | 58 | sanitizer_add_flags(${TARGET} "AddressSanitizer" "ASan") 59 | endfunction () 60 | -------------------------------------------------------------------------------- /cmake/FindMSan.cmake: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 4 | # 2013 Matthew Arsenault 5 | # 2015-2016 RWTH Aachen University, Federal Republic of Germany 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | option(SANITIZE_MEMORY "Enable MemorySanitizer for sanitized targets." Off) 26 | 27 | set(FLAG_CANDIDATES 28 | "-g -fsanitize=memory" 29 | ) 30 | 31 | 32 | include(sanitize-helpers) 33 | 34 | if (SANITIZE_MEMORY) 35 | if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 36 | message(WARNING "MemorySanitizer disabled for target ${TARGET} because " 37 | "MemorySanitizer is supported for Linux systems only.") 38 | set(SANITIZE_MEMORY Off CACHE BOOL 39 | "Enable MemorySanitizer for sanitized targets." FORCE) 40 | elseif (NOT ${CMAKE_SIZEOF_VOID_P} EQUAL 8) 41 | message(WARNING "MemorySanitizer disabled for target ${TARGET} because " 42 | "MemorySanitizer is supported for 64bit systems only.") 43 | set(SANITIZE_MEMORY Off CACHE BOOL 44 | "Enable MemorySanitizer for sanitized targets." FORCE) 45 | else () 46 | sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "MemorySanitizer" 47 | "MSan") 48 | endif () 49 | endif () 50 | 51 | function (add_sanitize_memory TARGET) 52 | if (NOT SANITIZE_MEMORY) 53 | return() 54 | endif () 55 | 56 | sanitizer_add_flags(${TARGET} "MemorySanitizer" "MSan") 57 | endfunction () 58 | -------------------------------------------------------------------------------- /cmake/FindSanitizers.cmake: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 4 | # 2013 Matthew Arsenault 5 | # 2015-2016 RWTH Aachen University, Federal Republic of Germany 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | # If any of the used compiler is a GNU compiler, add a second option to static 26 | # link against the sanitizers. 27 | option(SANITIZE_LINK_STATIC "Try to link static against sanitizers." Off) 28 | 29 | 30 | 31 | 32 | set(FIND_QUIETLY_FLAG "") 33 | if (DEFINED Sanitizers_FIND_QUIETLY) 34 | set(FIND_QUIETLY_FLAG "QUIET") 35 | endif () 36 | 37 | find_package(ASan ${FIND_QUIETLY_FLAG}) 38 | find_package(TSan ${FIND_QUIETLY_FLAG}) 39 | find_package(MSan ${FIND_QUIETLY_FLAG}) 40 | find_package(UBSan ${FIND_QUIETLY_FLAG}) 41 | 42 | 43 | 44 | 45 | function(sanitizer_add_blacklist_file FILE) 46 | if(NOT IS_ABSOLUTE ${FILE}) 47 | set(FILE "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}") 48 | endif() 49 | get_filename_component(FILE "${FILE}" REALPATH) 50 | 51 | sanitizer_check_compiler_flags("-fsanitize-blacklist=${FILE}" 52 | "SanitizerBlacklist" "SanBlist") 53 | endfunction() 54 | 55 | function(add_sanitizers ...) 56 | # If no sanitizer is enabled, return immediately. 57 | if (NOT (SANITIZE_ADDRESS OR SANITIZE_MEMORY OR SANITIZE_THREAD OR 58 | SANITIZE_UNDEFINED)) 59 | return() 60 | endif () 61 | 62 | foreach (TARGET ${ARGV}) 63 | # Check if this target will be compiled by exactly one compiler. Other- 64 | # wise sanitizers can't be used and a warning should be printed once. 65 | get_target_property(TARGET_TYPE ${TARGET} TYPE) 66 | if (TARGET_TYPE STREQUAL "INTERFACE_LIBRARY") 67 | message(WARNING "Can't use any sanitizers for target ${TARGET}, " 68 | "because it is an interface library and cannot be " 69 | "compiled directly.") 70 | return() 71 | endif () 72 | sanitizer_target_compilers(${TARGET} TARGET_COMPILER) 73 | list(LENGTH TARGET_COMPILER NUM_COMPILERS) 74 | if (NUM_COMPILERS GREATER 1) 75 | message(WARNING "Can't use any sanitizers for target ${TARGET}, " 76 | "because it will be compiled by incompatible compilers. " 77 | "Target will be compiled without sanitizers.") 78 | return() 79 | 80 | # If the target is compiled by no or no known compiler, give a warning. 81 | elseif (NUM_COMPILERS EQUAL 0) 82 | message(WARNING "Sanitizers for target ${TARGET} may not be" 83 | " usable, because it uses no or an unknown compiler. " 84 | "This is a false warning for targets using only " 85 | "object lib(s) as input.") 86 | endif () 87 | 88 | # Add sanitizers for target. 89 | add_sanitize_address(${TARGET}) 90 | add_sanitize_thread(${TARGET}) 91 | add_sanitize_memory(${TARGET}) 92 | add_sanitize_undefined(${TARGET}) 93 | endforeach () 94 | endfunction(add_sanitizers) 95 | -------------------------------------------------------------------------------- /cmake/FindTSan.cmake: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 4 | # 2013 Matthew Arsenault 5 | # 2015-2016 RWTH Aachen University, Federal Republic of Germany 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | option(SANITIZE_THREAD "Enable ThreadSanitizer for sanitized targets." Off) 26 | 27 | set(FLAG_CANDIDATES 28 | "-g -fsanitize=thread" 29 | ) 30 | 31 | 32 | # ThreadSanitizer is not compatible with MemorySanitizer. 33 | if (SANITIZE_THREAD AND SANITIZE_MEMORY) 34 | message(FATAL_ERROR "ThreadSanitizer is not compatible with " 35 | "MemorySanitizer.") 36 | endif () 37 | 38 | 39 | include(sanitize-helpers) 40 | 41 | if (SANITIZE_THREAD) 42 | if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND 43 | NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") 44 | message(WARNING "ThreadSanitizer disabled for target ${TARGET} because " 45 | "ThreadSanitizer is supported for Linux systems and macOS only.") 46 | set(SANITIZE_THREAD Off CACHE BOOL 47 | "Enable ThreadSanitizer for sanitized targets." FORCE) 48 | elseif (NOT ${CMAKE_SIZEOF_VOID_P} EQUAL 8) 49 | message(WARNING "ThreadSanitizer disabled for target ${TARGET} because " 50 | "ThreadSanitizer is supported for 64bit systems only.") 51 | set(SANITIZE_THREAD Off CACHE BOOL 52 | "Enable ThreadSanitizer for sanitized targets." FORCE) 53 | else () 54 | sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "ThreadSanitizer" 55 | "TSan") 56 | endif () 57 | endif () 58 | 59 | function (add_sanitize_thread TARGET) 60 | if (NOT SANITIZE_THREAD) 61 | return() 62 | endif () 63 | 64 | sanitizer_add_flags(${TARGET} "ThreadSanitizer" "TSan") 65 | endfunction () 66 | -------------------------------------------------------------------------------- /cmake/FindUBSan.cmake: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 4 | # 2013 Matthew Arsenault 5 | # 2015-2016 RWTH Aachen University, Federal Republic of Germany 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | option(SANITIZE_UNDEFINED 26 | "Enable UndefinedBehaviorSanitizer for sanitized targets." Off) 27 | 28 | set(FLAG_CANDIDATES 29 | "-g -fsanitize=undefined -fno-sanitize=alignment" 30 | ) 31 | 32 | 33 | include(sanitize-helpers) 34 | 35 | if (SANITIZE_UNDEFINED) 36 | sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" 37 | "UndefinedBehaviorSanitizer" "UBSan") 38 | endif () 39 | 40 | function (add_sanitize_undefined TARGET) 41 | if (NOT SANITIZE_UNDEFINED) 42 | return() 43 | endif () 44 | 45 | sanitizer_add_flags(${TARGET} "UndefinedBehaviorSanitizer" "UBSan") 46 | endfunction () 47 | -------------------------------------------------------------------------------- /cmake/FlagsMSVC.cmake: -------------------------------------------------------------------------------- 1 | macro(configure_msvc_runtime) 2 | if(MSVC) 3 | # Set compiler options. 4 | set(variables 5 | CMAKE_C_FLAGS_DEBUG 6 | CMAKE_C_FLAGS_MINSIZEREL 7 | CMAKE_C_FLAGS_RELEASE 8 | CMAKE_C_FLAGS_RELWITHDEBINFO 9 | CMAKE_CXX_FLAGS_DEBUG 10 | CMAKE_CXX_FLAGS_MINSIZEREL 11 | CMAKE_CXX_FLAGS_RELEASE 12 | CMAKE_CXX_FLAGS_RELWITHDEBINFO 13 | ) 14 | if(MSVC_CRT_STATIC) 15 | message(STATUS "MSVC -> forcing use of statically-linked runtime.") 16 | foreach(variable ${variables}) 17 | if(${variable} MATCHES "/MD") 18 | string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") 19 | endif() 20 | endforeach() 21 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") 22 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") 23 | else() 24 | message(STATUS "MSVC -> forcing use of dynamically-linked runtime.") 25 | foreach(variable ${variables}) 26 | if(${variable} MATCHES "/MT") 27 | string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}") 28 | endif() 29 | endforeach() 30 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") 31 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") 32 | endif() 33 | endif() 34 | endmacro() 35 | macro(print_default_msvc_flags) 36 | if(MSVC) 37 | set(variables 38 | CMAKE_C_FLAGS_DEBUG 39 | CMAKE_C_FLAGS_MINSIZEREL 40 | CMAKE_C_FLAGS_RELEASE 41 | CMAKE_C_FLAGS_RELWITHDEBINFO 42 | CMAKE_CXX_FLAGS_DEBUG 43 | CMAKE_CXX_FLAGS_MINSIZEREL 44 | CMAKE_CXX_FLAGS_RELEASE 45 | CMAKE_CXX_FLAGS_RELWITHDEBINFO 46 | ) 47 | message(STATUS "Initial build flags:") 48 | foreach(variable ${variables}) 49 | message(STATUS " '${variable}': ${${variable}}") 50 | endforeach() 51 | message(STATUS "") 52 | endif() 53 | endmacro() -------------------------------------------------------------------------------- /cmake/GameNetworkingSocketsConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include(CMakeFindDependencyMacro) 4 | 5 | find_dependency(Threads) 6 | find_dependency(Protobuf) 7 | 8 | if(@USE_CRYPTO@ STREQUAL "OpenSSL") 9 | find_dependency(OpenSSL) 10 | endif() 11 | 12 | if(@USE_CRYPTO@ STREQUAL "libsodium") 13 | find_dependency(sodium) 14 | endif() 15 | 16 | if(@STEAMWEBRTC_ABSL_SOURCE@ STREQUAL "package") 17 | find_dependency(absl REQUIRED) 18 | endif() 19 | 20 | if(@USE_STEAMWEBRTC@) 21 | include(${CMAKE_CURRENT_LIST_DIR}/steamwebrtc.cmake) 22 | endif() 23 | 24 | include(${CMAKE_CURRENT_LIST_DIR}/GameNetworkingSockets.cmake) 25 | 26 | if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0") 27 | # Need to set IMPORTED_GLOBAL in order to create the aliases 28 | # However, IMPORTED_GLOBAL only exists in 3.11 and up 29 | # Also, setting IMPORTED_GLOBAL from another directory from where it was first set blows up 30 | # so we can only set it once. 31 | 32 | if(@BUILD_SHARED_LIB@) 33 | get_target_property(GNS_IMPORTED_GLOBAL_SET GameNetworkingSockets::GameNetworkingSockets IMPORTED_GLOBAL) 34 | 35 | if(NOT ${GNS_IMPORTED_GLOBAL_SET}) 36 | set_target_properties( 37 | GameNetworkingSockets::GameNetworkingSockets 38 | PROPERTIES IMPORTED_GLOBAL True 39 | ) 40 | endif() 41 | 42 | unset(GNS_IMPORTED_GLOBAL_SET) 43 | 44 | add_library(GameNetworkingSockets::shared ALIAS GameNetworkingSockets::GameNetworkingSockets) 45 | endif() 46 | 47 | if(@BUILD_STATIC_LIB@) 48 | get_target_property(GNS_IMPORTED_GLOBAL_SET GameNetworkingSockets::GameNetworkingSockets_s IMPORTED_GLOBAL) 49 | 50 | if(NOT ${GNS_IMPORTED_GLOBAL_SET}) 51 | set_target_properties( 52 | GameNetworkingSockets::GameNetworkingSockets_s 53 | PROPERTIES IMPORTED_GLOBAL True 54 | ) 55 | endif() 56 | 57 | unset(GNS_IMPORTED_GLOBAL_SET) 58 | 59 | add_library(GameNetworkingSockets::static ALIAS GameNetworkingSockets::GameNetworkingSockets_s) 60 | endif() 61 | endif() 62 | 63 | check_required_components(GameNetworkingSockets) 64 | set(GameNetworkingSockets_FOUND 1) 65 | -------------------------------------------------------------------------------- /cmake/asan-wrapper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # The MIT License (MIT) 4 | # 5 | # Copyright (c) 6 | # 2013 Matthew Arsenault 7 | # 2015-2016 RWTH Aachen University, Federal Republic of Germany 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining a copy 10 | # of this software and associated documentation files (the "Software"), to deal 11 | # in the Software without restriction, including without limitation the rights 12 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | # copies of the Software, and to permit persons to whom the Software is 14 | # furnished to do so, subject to the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be included in all 17 | # copies or substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | # SOFTWARE. 26 | 27 | # This script is a wrapper for AddressSanitizer. In some special cases you need 28 | # to preload AddressSanitizer to avoid error messages - e.g. if you're 29 | # preloading another library to your application. At the moment this script will 30 | # only do something, if we're running on a Linux platform. OSX might not be 31 | # affected. 32 | 33 | 34 | # Exit immediately, if platform is not Linux. 35 | if [ "$(uname)" != "Linux" ] 36 | then 37 | exec $@ 38 | fi 39 | 40 | 41 | # Get the used libasan of the application ($1). If a libasan was found, it will 42 | # be prepended to LD_PRELOAD. 43 | libasan=$(ldd $1 | grep libasan | sed "s/^[[:space:]]//" | cut -d' ' -f1) 44 | if [ -n "$libasan" ] 45 | then 46 | if [ -n "$LD_PRELOAD" ] 47 | then 48 | export LD_PRELOAD="$libasan:$LD_PRELOAD" 49 | else 50 | export LD_PRELOAD="$libasan" 51 | fi 52 | fi 53 | 54 | # Execute the application. 55 | exec $@ 56 | -------------------------------------------------------------------------------- /cmake/tryCompileTestBCrypt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int, char **) 6 | { 7 | printf("%p\n", &BCryptEncrypt); 8 | } 9 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Trivial signaling server, written in go 3 | # 4 | if( ENABLE_ICE AND ( BUILD_EXAMPLES OR BUILD_TESTS ) ) 5 | find_program( GO go ) 6 | if ( NOT GO ) 7 | message(WARNING "Could not find 'go' binary, will not build signaling server example program") 8 | else() 9 | set(SIGNAL_SERVER_TARGET trivial_signaling_server) 10 | 11 | if ( WIN32 ) 12 | set(SIGNAL_SERVER_OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/trivial_signaling_server.exe) 13 | else() 14 | set(SIGNAL_SERVER_OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/trivial_signaling_server) 15 | endif() 16 | set(SIGNAL_SERVER_SRCS 17 | trivial_signaling_server.go 18 | ) 19 | add_custom_command( 20 | OUTPUT ${SIGNAL_SERVER_OUTPUT} 21 | DEPENDS ${SIGNAL_SERVER_SRCS} 22 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 23 | COMMENT "Building GO Trivial signaling server" 24 | COMMAND ${GO} build -o "${SIGNAL_SERVER_OUTPUT}" ${CMAKE_GO_FLAGS} ${SIGNAL_SERVER_SRCS} 25 | ) 26 | add_custom_target(${SIGNAL_SERVER_TARGET} ALL DEPENDS ${SIGNAL_SERVER_OUTPUT}) 27 | endif() 28 | endif() 29 | 30 | # 31 | # Examples 32 | # 33 | if( BUILD_EXAMPLES ) 34 | 35 | # 36 | # Really simple client/server chat 37 | # 38 | 39 | add_executable( 40 | example_chat 41 | example_chat.cpp) 42 | 43 | target_link_libraries(example_chat GameNetworkingSockets::shared) 44 | 45 | add_sanitizers(example_chat) 46 | 47 | endif() 48 | -------------------------------------------------------------------------------- /examples/trivial_signaling_client.h: -------------------------------------------------------------------------------- 1 | // Client of our dummy trivial signaling server service. 2 | // Serves as an example of you how to hook up signaling server 3 | // to SteamNetworkingSockets P2P connections 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | class ISteamNetworkingSockets; 10 | 11 | /// Interface to our client. 12 | class ITrivialSignalingClient 13 | { 14 | public: 15 | 16 | /// Create signaling object for a connection to peer 17 | virtual ISteamNetworkingConnectionSignaling *CreateSignalingForConnection( 18 | const SteamNetworkingIdentity &identityPeer, 19 | SteamNetworkingErrMsg &errMsg ) = 0; 20 | 21 | /// Poll the server for incoming signals and dispatch them. 22 | /// We use polling in this example just to keep it simple. 23 | /// You could use a service thread. 24 | virtual void Poll() = 0; 25 | 26 | /// Disconnect from the server and close down our polling thread. 27 | virtual void Release() = 0; 28 | }; 29 | 30 | // Start connecting to the signaling server. 31 | ITrivialSignalingClient *CreateTrivialSignalingClient( 32 | const char *address, // Address:port 33 | ISteamNetworkingSockets *pSteamNetworkingSockets, // Where should we send signals when we get them? 34 | SteamNetworkingErrMsg &errMsg // Error message is retjrned here if we fail 35 | ); 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/vcpkg_example_chat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Example porject that uses GameNetworkingSockets, obtaining 3 | # dependencies, etc entirely through vcpkg. 4 | # 5 | cmake_minimum_required(VERSION 3.9) 6 | project( example_chat_vcpkg ) 7 | 8 | # Ask vcpkg to fetch gamenetworkingsockets and all 9 | # its dependencies and build it 10 | find_package(GameNetworkingSockets CONFIG REQUIRED) 11 | 12 | # Our program only has one cpp file 13 | add_executable( 14 | example_chat 15 | ../example_chat.cpp) 16 | 17 | # This example links GameNetworkingSockets as a shared lib. 18 | target_link_libraries(example_chat GameNetworkingSockets::shared) 19 | -------------------------------------------------------------------------------- /examples/vcpkg_example_chat/README.md: -------------------------------------------------------------------------------- 1 | The purpose of this project is to demonstrate/test a project that pulls in 2 | GameNetworkingSockets and its dependencies entirely using vcpkg. 3 | 4 | # TL;DR 5 | 6 | We assume that your project defines its dependences in a `vcpkg.json` file, and 7 | you are pulling in vcpkg's cmake toolchain file. Then all you need to do is: 8 | 9 | * Add `gamenetworkingsockets` as a dependency in your project's `vcpkg.json` 10 | * In your cmake file, add `find_package( GameNetworkingSockets )` 11 | * Link your targets with the appropriate library: 12 | * `target_link_libraries( GameNetworkingSockets::shared)` 13 | * or `target_link_libraries( GameNetworkingSockets::static)` 14 | 15 | # Building the example project using vcpkg in manifest mode 16 | 17 | Here are some specific instructions that build the example project using vcpkg in 18 | ["manifest mode"](https://vcpkg.readthedocs.io/en/latest/users/manifests/). 19 | This example assumes Windows, and also it's recommended to run this from a 20 | Visual Studio command prompt so we know what compiler to use. 21 | 22 | First, we bootstrap a project-specific installation of vcpkg ("manifest mode") 23 | in the default location, `/vcpkg`. From the project root, run these 24 | commands: 25 | 26 | ``` 27 | > git clone https://github.com/microsoft/vcpkg 28 | > .\vcpkg\bootstrap-vcpkg.bat 29 | ``` 30 | 31 | Now we ask vcpkg to install of the dependencies for our project, which are described by 32 | the file `/vcpkg.json`. Note that this step is optional, as cmake will 33 | automatically do this. But here we are doing it in a separate step so that we can isolate 34 | any problems, because if problems happen here don't have anything to do with your 35 | cmake files. 36 | 37 | ``` 38 | > .\vcpkg\vcpkg install --triplet=x64-windows 39 | ``` 40 | 41 | Next build the project files. There are different options for telling cmake how 42 | to integrate with vcpkg; here we use `CMAKE_TOOLCHAIN_FILE` on the command line. 43 | Also we select Ninja project generator. 44 | 45 | ``` 46 | > cmake -S . -B build -G Ninja -DCMAKE_TOOLCHAIN_FILE=vcpkg\scripts\buildsystems\vcpkg.cmake 47 | ``` 48 | 49 | Finally, build the project: 50 | 51 | ``` 52 | > cd build 53 | > ninja 54 | ``` 55 | -------------------------------------------------------------------------------- /examples/vcpkg_example_chat/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", 3 | "name": "gamenetworkingsockets-vcpkg-example", 4 | "version-string": "1.0", 5 | "description": "Example app that uses vcpkg to declare dependencies and fetch gamenetworkingsockets", 6 | "dependencies": [ "gamenetworkingsockets" ] 7 | } 8 | -------------------------------------------------------------------------------- /include/steam/steam_api_common.h: -------------------------------------------------------------------------------- 1 | #ifndef STEAM_API_COMMON 2 | #define STEAM_API_COMMON 3 | #pragma once 4 | 5 | // When using the SteamWorks SDK, this header contains declarations 6 | // for callbacks, etc. In the OpenSource version, it's a stub with 7 | // just a few things. 8 | 9 | #include "steamtypes.h" 10 | #include "steamclientpublic.h" 11 | 12 | enum { k_iSteamNetworkingSocketsCallbacks = 1220 }; 13 | enum { k_iSteamNetworkingMessagesCallbacks = 1250 }; 14 | enum { k_iSteamNetworkingUtilsCallbacks = 1280 }; 15 | 16 | // handle to a communication pipe to the Steam client 17 | typedef int32 HSteamPipe; 18 | // handle to single instance of a steam user 19 | typedef int32 HSteamUser; 20 | 21 | #ifdef API_GEN 22 | # define STEAM_CLANG_ATTR(ATTR) __attribute__((annotate( ATTR ))) 23 | #else 24 | # define STEAM_CLANG_ATTR(ATTR) 25 | #endif 26 | 27 | #define STEAM_METHOD_DESC(DESC) STEAM_CLANG_ATTR( "desc:" #DESC ";" ) 28 | #define STEAM_IGNOREATTR() STEAM_CLANG_ATTR( "ignore" ) 29 | #define STEAM_OUT_STRUCT() STEAM_CLANG_ATTR( "out_struct: ;" ) 30 | #define STEAM_OUT_STRING() STEAM_CLANG_ATTR( "out_string: ;" ) 31 | #define STEAM_OUT_ARRAY_CALL(COUNTER,FUNCTION,PARAMS) STEAM_CLANG_ATTR( "out_array_call:" #COUNTER "," #FUNCTION "," #PARAMS ";" ) 32 | #define STEAM_OUT_ARRAY_COUNT(COUNTER, DESC) STEAM_CLANG_ATTR( "out_array_count:" #COUNTER ";desc:" #DESC ) 33 | #define STEAM_ARRAY_COUNT(COUNTER) STEAM_CLANG_ATTR( "array_count:" #COUNTER ";" ) 34 | #define STEAM_ARRAY_COUNT_D(COUNTER, DESC) STEAM_CLANG_ATTR( "array_count:" #COUNTER ";desc:" #DESC ) 35 | #define STEAM_BUFFER_COUNT(COUNTER) STEAM_CLANG_ATTR( "buffer_count:" #COUNTER ";" ) 36 | #define STEAM_OUT_BUFFER_COUNT(COUNTER) STEAM_CLANG_ATTR( "out_buffer_count:" #COUNTER ";" ) 37 | #define STEAM_OUT_STRING_COUNT(COUNTER) STEAM_CLANG_ATTR( "out_string_count:" #COUNTER ";" ) 38 | #define STEAM_DESC(DESC) STEAM_CLANG_ATTR("desc:" #DESC ";") 39 | #define STEAM_CALL_RESULT(RESULT_TYPE) STEAM_CLANG_ATTR("callresult:" #RESULT_TYPE ";") 40 | #define STEAM_CALL_BACK(RESULT_TYPE) STEAM_CLANG_ATTR("callback:" #RESULT_TYPE ";") 41 | 42 | #endif // STEAM_API_COMMON 43 | -------------------------------------------------------------------------------- /include/steam/steamnetworkingsockets.h: -------------------------------------------------------------------------------- 1 | //====== Copyright Valve Corporation, All rights reserved. ==================== 2 | // 3 | // High level interface to GameNetworkingSockets library. 4 | // 5 | //============================================================================= 6 | 7 | #ifndef STEAMNETWORKINGSOCKETS_H 8 | #define STEAMNETWORKINGSOCKETS_H 9 | #ifdef _WIN32 10 | #pragma once 11 | #endif 12 | 13 | #include "isteamnetworkingsockets.h" 14 | 15 | extern "C" { 16 | 17 | // Initialize the library. Optionally, you can set an initial identity for the default 18 | // interface that is returned by SteamNetworkingSockets(). 19 | // 20 | // On failure, false is returned, and a non-localized diagnostic message is returned. 21 | STEAMNETWORKINGSOCKETS_INTERFACE bool GameNetworkingSockets_Init( const SteamNetworkingIdentity *pIdentity, SteamNetworkingErrMsg &errMsg ); 22 | 23 | // Close all connections and listen sockets and free all resources 24 | STEAMNETWORKINGSOCKETS_INTERFACE void GameNetworkingSockets_Kill(); 25 | 26 | /// Custom memory allocation methods. If you call this, you MUST call it exactly once, 27 | /// before calling any other API function. *Most* allocations will pass through these, 28 | /// especially all allocations that are per-connection. A few allocations 29 | /// might still go to the default CRT malloc and operator new. 30 | /// To use this, you must compile the library with STEAMNETWORKINGSOCKETS_ENABLE_MEM_OVERRIDE 31 | STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetCustomMemoryAllocator( 32 | void* (*pfn_malloc)( size_t s ), 33 | void (*pfn_free)( void *p ), 34 | void* (*pfn_realloc)( void *p, size_t s ) 35 | ); 36 | 37 | 38 | // 39 | // Statistics about the global lock. 40 | // 41 | STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockWaitWarningThreshold( SteamNetworkingMicroseconds usecThreshold ); 42 | STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockAcquiredCallback( void (*callback)( const char *tags, SteamNetworkingMicroseconds usecWaited ) ); 43 | STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetLockHeldCallback( void (*callback)( const char *tags, SteamNetworkingMicroseconds usecWaited ) ); 44 | 45 | /// Called from the service thread at initialization time. 46 | /// Use this to customize its priority / affinity, etc 47 | STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingSockets_SetServiceThreadInitCallback( void (*callback)() ); 48 | 49 | } 50 | 51 | #endif // STEAMNETWORKINGSOCKETS_H 52 | -------------------------------------------------------------------------------- /include/steam/steamuniverse.h: -------------------------------------------------------------------------------- 1 | //========= Copyright � 1996-2008, Valve LLC, All rights reserved. ============ 2 | // 3 | // Purpose: 4 | // 5 | //============================================================================= 6 | 7 | #ifndef STEAMUNIVERSE_H 8 | #define STEAMUNIVERSE_H 9 | #ifdef _WIN32 10 | #pragma once 11 | #endif 12 | 13 | 14 | // Steam universes. Each universe is a self-contained Steam instance. 15 | enum EUniverse 16 | { 17 | k_EUniverseInvalid = 0, 18 | k_EUniversePublic = 1, 19 | k_EUniverseBeta = 2, 20 | k_EUniverseInternal = 3, 21 | k_EUniverseDev = 4, 22 | // k_EUniverseRC = 5, // no such universe anymore 23 | k_EUniverseMax 24 | }; 25 | 26 | 27 | #endif // STEAMUNIVERSE_H 28 | -------------------------------------------------------------------------------- /src/common/crypto.cpp: -------------------------------------------------------------------------------- 1 | //========= Copyright Valve LLC, All rights reserved. ======================== 2 | 3 | #include "crypto.h" 4 | 5 | /////////////////////////////////////////////////////////////////////////////// 6 | // 7 | // SipHash, used for challenge generation 8 | // 9 | // http://en.wikipedia.org/wiki/SipHash 10 | // 11 | // Code was copied from here: 12 | // https://github.com/veorq/SipHash/blob/1b85a33b71f0fdd49942037a503b6798d67ef765/siphash24.c 13 | // 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | /* default: SipHash-2-4 */ 17 | #define cROUNDS 2 18 | #define dROUNDS 4 19 | 20 | #define ROTL(x,b) (uint64_t)( ((x) << (b)) | ( (x) >> (64 - (b))) ) 21 | #define U8TO64_LE(p) LittleQWord( *(const uint64*)(p) ); 22 | 23 | #define SIPROUND \ 24 | do { \ 25 | v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \ 26 | v2 += v3; v3=ROTL(v3,16); v3 ^= v2; \ 27 | v0 += v3; v3=ROTL(v3,21); v3 ^= v0; \ 28 | v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \ 29 | } while(0) 30 | 31 | uint64_t CCrypto::SipHash( const void *data, size_t inlen, const CCrypto::SipHashKey_t &k ) 32 | { 33 | const uint8_t *in = (const uint8_t *)data; 34 | 35 | /* "somepseudorandomlygeneratedbytes" */ 36 | uint64_t v0 = 0x736f6d6570736575ULL; 37 | uint64_t v1 = 0x646f72616e646f6dULL; 38 | uint64_t v2 = 0x6c7967656e657261ULL; 39 | uint64_t v3 = 0x7465646279746573ULL; 40 | uint64_t b; 41 | uint64_t k0 = k[0]; 42 | uint64_t k1 = k[1]; 43 | uint64_t m; 44 | int i; 45 | const uint8_t *end = in + inlen - ( inlen % sizeof( uint64_t ) ); 46 | const int left = inlen & 7; 47 | b = ( ( uint64_t )inlen ) << 56; 48 | v3 ^= k1; 49 | v2 ^= k0; 50 | v1 ^= k1; 51 | v0 ^= k0; 52 | 53 | for ( ; in != end; in += 8 ) 54 | { 55 | m = U8TO64_LE( in ); 56 | v3 ^= m; 57 | 58 | //TRACE; 59 | for( i=0; i 8 | 9 | const int k_nSymmetricBlockSize = 16; // AES block size (128 bits) 10 | const int k_nSymmetricIVSize = 12; // length of the IV (must be 12 for BCryptEncrypt/BCryptDecrypt, but OpenSSL is more flexible) 11 | const int k_nSymmetricGCMTagSize = 16; // length in GCM tag (must be 16 for BCryptEncrypt/BCryptDecrypt, but OpenSSL is more flexible) 12 | const int k_nSymmetricKeyLen = 32; // length in bytes of keys used for symmetric encryption 13 | const int k_nSymmetricKeyLen128 = 16; // 128 bits, in bytes 14 | const int k_nSymmetricKeyLen256 = 32; // 256 bits, in bytes 15 | 16 | const int k_nRSAKeyLenMax = 1024; // max length in bytes of keys used for RSA encryption (includes DER encoding) 17 | const int k_nRSAKeyLenMaxEncoded = k_nRSAKeyLenMax*2; // max length in bytes of hex-encoded key (hex encoding exactly doubles size) 18 | const int k_nRSAKeyBits = 1024; // length in bits of keys used for RSA encryption 19 | const int k_cubRSAEncryptedBlockSize = 128; 20 | const int k_cubRSAPlaintextBlockSize = 86 + 1; // assume plaintext is text, so add a byte for the trailing \0 21 | const uint32 k_cubRSASignature = k_cubRSAEncryptedBlockSize; 22 | 23 | const uint32 k_cubRSA2048Signature = 256; // Signature length when using a 2048-bit RSA key 24 | 25 | const int k_nAESKeyLenMax = k_nSymmetricKeyLen; 26 | const int k_nAESKeyLenMaxEncoded = k_nAESKeyLenMax*2; 27 | const int k_nAESKeyBits = k_nSymmetricKeyLen*8; // normal size of AES keys 28 | const int k_cchMaxPassphrase = 128; // maximum size of a license passphrase 29 | 30 | const int k_nSHAHashStringLen = 40; // length of SHA1 hash when stored as a hex string 31 | 32 | const unsigned int k_cubSHA1Hash = 20; 33 | const unsigned int k_cubSHAHash = 20; 34 | typedef unsigned char SHADigest_t[ k_cubSHAHash ]; 35 | 36 | const unsigned int k_cubMD5Hash = 16; 37 | typedef unsigned char MD5Digest_t[k_cubMD5Hash]; 38 | 39 | const unsigned int k_cubSHA256Hash = 32; 40 | typedef unsigned char SHA256Digest_t[ k_cubSHA256Hash ]; 41 | 42 | const unsigned int k_cubSHA512Hash = 64; 43 | typedef unsigned char SHA512Digest_t[ k_cubSHA512Hash ]; 44 | 45 | #endif // CRYPTO_CONSTANTS_H 46 | -------------------------------------------------------------------------------- /src/common/crypto_digest_opensslevp.cpp: -------------------------------------------------------------------------------- 1 | //========= Copyright Valve LLC, All rights reserved. ======================== 2 | 3 | #include "crypto.h" 4 | #ifdef VALVE_CRYPTO_OPENSSL 5 | 6 | #include 7 | #include 8 | 9 | #include "tier0/memdbgoff.h" 10 | #include 11 | #include 12 | #include "tier0/memdbgon.h" 13 | 14 | #if OPENSSL_VERSION_NUMBER < 0x10100000 15 | inline void EVP_MD_CTX_free( EVP_MD_CTX *ctx ) 16 | { 17 | EVP_MD_CTX_destroy( ctx ); 18 | } 19 | #endif 20 | 21 | template < typename CTXType, void(*CleanupFunc)(CTXType)> 22 | class EVPCTXPointer 23 | { 24 | public: 25 | CTXType ctx; 26 | 27 | EVPCTXPointer() { this->ctx = NULL; } 28 | EVPCTXPointer(CTXType ctx) { this->ctx = ctx; } 29 | ~EVPCTXPointer() { CleanupFunc(ctx); } 30 | }; 31 | 32 | //----------------------------------------------------------------------------- 33 | // Generate a SHA256 hash 34 | //----------------------------------------------------------------------------- 35 | void CCrypto::GenerateSHA256Digest( const void *pInput, size_t cbInput, SHA256Digest_t *pOutDigest ) 36 | { 37 | VPROF_BUDGET( "CCrypto::GenerateSHA256Digest", VPROF_BUDGETGROUP_ENCRYPTION ); 38 | //Assert( pubInput ); 39 | Assert( pOutDigest ); 40 | 41 | EVPCTXPointer ctx(EVP_MD_CTX_create()); 42 | 43 | unsigned int digest_len = sizeof(SHA256Digest_t); 44 | VerifyFatal(ctx.ctx != NULL); 45 | VerifyFatal(EVP_DigestInit_ex(ctx.ctx, EVP_sha256(), NULL) == 1); 46 | VerifyFatal(EVP_DigestUpdate(ctx.ctx, pInput, cbInput) == 1); 47 | VerifyFatal(EVP_DigestFinal(ctx.ctx, *pOutDigest, &digest_len) == 1); 48 | } 49 | 50 | //----------------------------------------------------------------------------- 51 | // Purpose: Generate a keyed-hash MAC using SHA-256 52 | //----------------------------------------------------------------------------- 53 | void CCrypto::GenerateHMAC256( const uint8 *pubData, uint32 cubData, const uint8 *pubKey, uint32 cubKey, SHA256Digest_t *pOutputDigest ) 54 | { 55 | VPROF_BUDGET( "CCrypto::GenerateHMAC256", VPROF_BUDGETGROUP_ENCRYPTION ); 56 | Assert( pubData ); 57 | Assert( cubData > 0 ); 58 | Assert( pubKey ); 59 | Assert( cubKey > 0 ); 60 | Assert( pOutputDigest ); 61 | 62 | EVPCTXPointer mdctx(EVP_MD_CTX_create()); 63 | EVPCTXPointer pkey(EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pubKey, cubKey)); 64 | const EVP_MD *digest = EVP_sha256(); 65 | 66 | VerifyFatal(mdctx.ctx != NULL && pkey.ctx != NULL); 67 | VerifyFatal(EVP_DigestInit_ex(mdctx.ctx, digest, NULL) == 1); 68 | VerifyFatal(EVP_DigestSignInit(mdctx.ctx, NULL, digest, NULL, pkey.ctx) == 1); 69 | VerifyFatal(EVP_DigestSignUpdate(mdctx.ctx, pubData, cubData) == 1); 70 | 71 | size_t needed = sizeof(SHA256Digest_t); 72 | VerifyFatal(EVP_DigestSignFinal(mdctx.ctx, *pOutputDigest, &needed) == 1); 73 | } 74 | 75 | //----------------------------------------------------------------------------- 76 | // Purpose: Generate a keyed-hash MAC using SHA1 77 | //----------------------------------------------------------------------------- 78 | void CCrypto::GenerateHMAC( const uint8 *pubData, uint32 cubData, const uint8 *pubKey, uint32 cubKey, SHADigest_t *pOutputDigest ) 79 | { 80 | VPROF_BUDGET( "CCrypto::GenerateHMAC", VPROF_BUDGETGROUP_ENCRYPTION ); 81 | Assert( pubData ); 82 | Assert( cubData > 0 ); 83 | Assert( pubKey ); 84 | Assert( cubKey > 0 ); 85 | Assert( pOutputDigest ); 86 | 87 | unsigned int needed = (unsigned int)sizeof(SHADigest_t); 88 | HMAC( EVP_sha1(), pubKey, cubKey, pubData, cubData, (unsigned char*)pOutputDigest, &needed ); 89 | } 90 | 91 | #endif // VALVE_CRYPTO_OPENSSL 92 | -------------------------------------------------------------------------------- /src/common/crypto_openssl.cpp: -------------------------------------------------------------------------------- 1 | //========= Copyright Valve LLC, All rights reserved. ======================== 2 | 3 | #include "crypto.h" 4 | #ifdef VALVE_CRYPTO_OPENSSL 5 | 6 | #if defined(_WIN32) 7 | #ifdef __MINGW32__ 8 | // x86intrin.h gets included by MinGW's winnt.h, so defining this avoids 9 | // redefinition of AES-NI intrinsics below 10 | #define _X86INTRIN_H_INCLUDED 11 | #endif 12 | #include "winlite.h" 13 | #elif IsPosix() 14 | #include 15 | #include 16 | #include 17 | #include 18 | #endif 19 | 20 | #include 21 | #include 22 | 23 | #include "opensslwrapper.h" 24 | 25 | void OneTimeCryptoInitOpenSSL() 26 | { 27 | static bool once; 28 | if ( !once ) 29 | { 30 | once = true; // Not thread-safe 31 | COpenSSLWrapper::Initialize(); 32 | atexit( &COpenSSLWrapper::Shutdown ); 33 | } 34 | } 35 | 36 | void CCrypto::Init() 37 | { 38 | OneTimeCryptoInitOpenSSL(); 39 | } 40 | 41 | 42 | //----------------------------------------------------------------------------- 43 | // Purpose: Generates a cryptographiacally random block of data fit for any use. 44 | // NOTE: Function terminates process on failure rather than returning false! 45 | //----------------------------------------------------------------------------- 46 | void CCrypto::GenerateRandomBlock( void *pvDest, int cubDest ) 47 | { 48 | VPROF_BUDGET( "CCrypto::GenerateRandomBlock", VPROF_BUDGETGROUP_ENCRYPTION ); 49 | AssertFatal( cubDest >= 0 ); 50 | uint8 *pubDest = (uint8 *)pvDest; 51 | 52 | #if defined(_WIN32) 53 | 54 | // NOTE: assume that this cannot fail. MS has baked this function name into 55 | // static CRT runtime libraries for years; changing the export would break 56 | // millions of applications. Available from Windows XP onward. -henryg 57 | typedef BYTE ( NTAPI *PfnRtlGenRandom_t )( PVOID RandomBuffer, ULONG RandomBufferLength ); 58 | static PfnRtlGenRandom_t s_pfnRtlGenRandom; 59 | if ( !s_pfnRtlGenRandom ) 60 | { 61 | s_pfnRtlGenRandom = (PfnRtlGenRandom_t) (void*) GetProcAddress( LoadLibraryA( "advapi32.dll" ), "SystemFunction036" ); 62 | } 63 | 64 | bool bRtlGenRandomOK = s_pfnRtlGenRandom && ( s_pfnRtlGenRandom( pubDest, (unsigned long)cubDest ) == TRUE ); 65 | AssertFatal( bRtlGenRandomOK ); 66 | 67 | #elif IsPosix() 68 | 69 | // Reading from /dev/urandom is threadsafe, but possibly slow due to a kernel 70 | // spinlock or mutex protecting access to the internal PRNG state. In theory, 71 | // we could use bytes from /dev/urandom to initialize a user-space PRNG (like 72 | // OpenSSL does), but this introduces a security risk: if our process memory 73 | // is compromised and an attacker gains read access, the PRNG state could be 74 | // dumped and an attacker might be able to predict future or past outputs! 75 | // The risk of the kernel's internal PRNG state being exposed is much lower. 76 | // (We can revisit this if performance becomes an issue. -henryg 4/26/2016) 77 | static int s_dev_urandom_fd = open( "/dev/urandom", O_RDONLY | O_CLOEXEC ); 78 | AssertFatal( s_dev_urandom_fd >= 0 ); 79 | size_t remaining = (size_t)cubDest; 80 | while ( remaining ) 81 | { 82 | ssize_t urandom_result = read( s_dev_urandom_fd, pubDest + cubDest - remaining, remaining ); 83 | AssertFatal( urandom_result > 0 || ( urandom_result < 0 && errno == EINTR ) ); 84 | if ( urandom_result > 0 ) 85 | { 86 | remaining -= urandom_result; 87 | } 88 | } 89 | 90 | #else 91 | 92 | OneTimeCryptoInitOpenSSL(); 93 | AssertFatal( RAND_bytes( pubDest, cubDest ) > 0 ); 94 | 95 | #endif 96 | } 97 | 98 | #endif // VALVE_CRYPTO_OPENSSL 99 | -------------------------------------------------------------------------------- /src/common/crypto_sha1_wpa.cpp: -------------------------------------------------------------------------------- 1 | #include "crypto.h" 2 | #include 3 | #include 4 | 5 | #ifdef VALVE_CRYPTO_SHA1_WPA 6 | 7 | extern "C" { 8 | // external headers for sha1 and hmac-sha1 support 9 | #include "../external/sha1-wpa/sha1.h" 10 | } 11 | 12 | //----------------------------------------------------------------------------- 13 | // Purpose: Generate a keyed-hash MAC using SHA1 14 | // Input: pubData - Plaintext data to digest 15 | // cubData - length of data 16 | // pubKey - key to use in HMAC 17 | // cubKey - length of key 18 | // pOutDigest - Pointer to receive hashed digest output 19 | //----------------------------------------------------------------------------- 20 | void CCrypto::GenerateHMAC( const uint8 *pubData, uint32 cubData, const uint8 *pubKey, uint32 cubKey, SHADigest_t *pOutputDigest ) 21 | { 22 | VPROF_BUDGET( "CCrypto::GenerateHMAC", VPROF_BUDGETGROUP_ENCRYPTION ); 23 | Assert( pubData ); 24 | Assert( cubData > 0 ); 25 | Assert( pubKey ); 26 | Assert( cubKey > 0 ); 27 | Assert( pOutputDigest ); 28 | 29 | int status = hmac_sha1(pubKey, cubKey, pubData, cubData, (uint8_t*)pOutputDigest); 30 | AssertFatal(status == 0); 31 | } 32 | 33 | #endif // #ifdef VALVE_CRYPTO_SHA1_WPA 34 | 35 | -------------------------------------------------------------------------------- /src/common/opensslwrapper.h: -------------------------------------------------------------------------------- 1 | //====== Copyright 1996-2010, Valve Corporation, All rights reserved. ======= 2 | // 3 | // Purpose: Code for dealing with OpenSSL library 4 | // 5 | //============================================================================= 6 | 7 | #ifndef OPENSSLWRAPPER_H 8 | #define OPENSSLWRAPPER_H 9 | #ifdef _WIN32 10 | #pragma once 11 | #endif 12 | 13 | // Locking structure for OpenSSL usage 14 | struct CRYPTO_dynlock_value; 15 | 16 | 17 | //----------------------------------------------------------------------------- 18 | // Purpose: Wrapper for OpenSSL 19 | //----------------------------------------------------------------------------- 20 | class COpenSSLWrapper 21 | { 22 | public: 23 | static void Initialize(); 24 | static void Shutdown(); 25 | static bool BIsOpenSSLInitialized() { return m_nInstances > 0; } 26 | static int GetContextDataIndex() { return s_nContextDataIndex; } 27 | static int GetConnectionDataIndex() { return s_nConnectionDataIndex; } 28 | 29 | 30 | // OpenSSL callback functions for threading 31 | static void OpenSSLLockingCallback( int mode, int type, const char *file, int line ); 32 | static unsigned long OpenSSLThreadIDCallback( void ); 33 | static CRYPTO_dynlock_value* OpenSSLDynLockCreateCallback( const char* file, int line ); 34 | static void OpenSSLDynLockDestroyCallback( CRYPTO_dynlock_value * l, const char *file, int line ); 35 | static void OpenSSLDynLockLockCallback( int mode, CRYPTO_dynlock_value *l, const char* file, int line ); 36 | 37 | #ifdef _DEBUG 38 | // In debug we track OpenSSL memory usage via it's internal mechanism for this 39 | static void *OpenSSLMemLeakCallback( unsigned long order, const char *file, int line, int num_bytes, void * addr ); 40 | static int m_nBytesLeaked; 41 | #endif 42 | 43 | #ifdef DBGFLAG_VALIDATE 44 | static void ValidateStatics( CValidator &validator, const char *pchName ); 45 | #endif 46 | 47 | 48 | private: 49 | // Some statics to track how many context objects exist and to perform one time OpenSSL library initialization 50 | // when needed. 51 | static int m_nInstances; 52 | // VOID to avoid include on engine.h, as it can lead to some conflicts in places we need to include this header 53 | static void *s_pAESNIEngine; 54 | static int s_nContextDataIndex; 55 | static int s_nConnectionDataIndex; 56 | 57 | }; 58 | 59 | 60 | #endif // OPENSSLWRAPPER_H 61 | 62 | -------------------------------------------------------------------------------- /src/common/steamid.h: -------------------------------------------------------------------------------- 1 | //========= Copyright 1996-2022, Valve LLC, All rights reserved. ============ 2 | 3 | #ifndef STEAMID_H 4 | #define STEAMID_H 5 | #pragma once 6 | 7 | #include "steam/steamclientpublic.h" 8 | 9 | #ifdef GENERICHASH_H 10 | inline uint32 HashItem( const CSteamID &item ) 11 | { 12 | return HashItemAsBytes(item); 13 | } 14 | #endif 15 | 16 | #endif // _H 17 | -------------------------------------------------------------------------------- /src/common/steamnetworkingsockets_messages_certs.proto: -------------------------------------------------------------------------------- 1 | //====== Copyright Valve Corporation, All rights reserved. ==================== 2 | // 3 | // Wire format messages for Steam networking authentication structures 4 | // 5 | //============================================================================= 6 | syntax = "proto2"; 7 | 8 | option optimize_for = SPEED; 9 | 10 | // We don't use the service generation functionality 11 | option cc_generic_services = false; 12 | 13 | // Legacy binary format. Now the string format is always used, even over 14 | // the wire. This is a bit wasteful. But the benefit of the string format 15 | // is that it's must easier to make forward comaptible. So we can add new 16 | // identity types without updating all old clients that may possibly interact 17 | // with the new identity type. In many cases, the old client doesn't really 18 | // need to "understand" the type, and the string format actually works great. 19 | message CMsgSteamNetworkingIdentityLegacyBinary 20 | { 21 | 22 | // We don't use a seperate "type" field, we just use the 23 | // presence of the appropriate fields. (On the wire, we 24 | // really do have a type field.) 25 | 26 | optional fixed64 steam_id = 16; 27 | 28 | optional bytes generic_bytes = 2; 29 | optional string generic_string = 3; 30 | optional bytes ipv6_and_port = 4; 31 | }; 32 | 33 | // A public key used for crypto key exchange and identity. 34 | // This is basically the portion of a certificate over which 35 | // the signature is generated. (It is broken into a separate 36 | // message to make it easy to keep the exact bytes that were 37 | // signed intact during transport.) 38 | message CMsgSteamDatagramCertificate 39 | { 40 | enum EKeyType 41 | { 42 | INVALID = 0; 43 | ED25519 = 1; 44 | }; 45 | optional EKeyType key_type = 1; 46 | optional bytes key_data = 2; 47 | 48 | // 49 | // Who is allowed to use this key? This is the set of people who we assume 50 | // will have access to the corresponding private key. 51 | // 52 | 53 | // Single user key? This might not be set if the key is shared! 54 | optional fixed64 legacy_steam_id = 4; 55 | optional CMsgSteamNetworkingIdentityLegacyBinary legacy_identity_binary = 11; 56 | optional string identity_string = 12; 57 | 58 | // Allow any server in particular data centers to use it? 59 | repeated fixed32 gameserver_datacenter_ids = 5; 60 | 61 | // 62 | // Key restrictions 63 | // 64 | 65 | // Restricted time range? 66 | optional fixed32 time_created = 8; 67 | optional fixed32 time_expiry = 9; 68 | 69 | // Restrict key to be used for a particular AppID(s)? 70 | repeated uint32 app_ids = 10; 71 | 72 | // Restrict key to be used for a particular IP address ranges? 73 | // This is a list of strings. At the time of this writing, 74 | // each string must be a single IPv4 or a single IPv6. 75 | repeated string ip_addresses = 13; 76 | }; 77 | 78 | // Certificate signed by a certificate authority. 79 | message CMsgSteamDatagramCertificateSigned 80 | { 81 | // The public key associated with my identity. This is a longer standing key 82 | // that can be used for multiple connections. It's a serialized 83 | // version of CMsgSteamDatagramCertificate, but because the signature 84 | // is based on a particular serialization of that message, we keep the 85 | // original serialization here. 86 | optional bytes cert = 4; 87 | 88 | /// The key that was used by the certificate authority to sign 89 | /// my public key. This might be empty if the key is unsigned. 90 | // (It's up to the endpoint to decide if they want to accept that 91 | // or not.) 92 | optional fixed64 ca_key_id = 5; 93 | 94 | /// Signature over the certificate, using the key identified 95 | /// by ca_key_id. 96 | optional bytes ca_signature = 6; 97 | 98 | /// In a few instances, we want to use the same message to include the private 99 | /// key and the corresponding cert. Most of the time this field should not be 100 | /// present! 101 | optional bytes private_key_data = 1; 102 | } 103 | 104 | // A request by a client to a CA to issue a cert. 105 | message CMsgSteamDatagramCertificateRequest 106 | { 107 | // An unsigned cert. The requestor will populate the fields 108 | // appropriate to the request. (Who do you thin you are, 109 | // what app(s) would you like access for, etc) Most importantly, 110 | // the caller must fill in the public key they want to use 111 | optional CMsgSteamDatagramCertificate cert = 1; 112 | } 113 | 114 | // Do not remove this comment due to a bug on the Mac OS X protobuf compiler 115 | 116 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/README.md: -------------------------------------------------------------------------------- 1 | [curve25519](http://cr.yp.to/ecdh.html) is an elliptic curve, developed by 2 | [Dan Bernstein](http://cr.yp.to/djb.html), for fast 3 | [Diffie-Hellman](http://en.wikipedia.org/wiki/Diffie-Hellman) key agreement. 4 | DJB's [original implementation](http://cr.yp.to/ecdh.html) was written in a 5 | language of his own devising called [qhasm](http://cr.yp.to/qhasm.html). 6 | The original qhasm source isn't available, only the x86 32-bit assembly output. 7 | 8 | This project provides performant, portable 32-bit & 64-bit implementations. 9 | All implementations are of course constant time in regard to secret data. 10 | 11 | #### Performance 12 | 13 | Compilers versions are gcc 4.6.3, icc 13.1.1, clang 3.4-1~exp1. 14 | 15 | Counts are in thousands of cycles. 16 | 17 | Note that SSE2 performance may be less impressive on AMD & older CPUs with slower SSE ops! 18 | 19 | ##### E5200 @ 2.5ghz, march=core2 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
Versiongcciccclang
64-bit SSE2 278k 265k 302k
64-bit 273k 271k 377k
32-bit SSE2 304k 289k 317k
32-bit 1417k 845k 981k
30 | 31 | ##### E3-1270 @ 3.4ghz, march=corei7-avx 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
Versiongcciccclang
64-bit 201k 192k 233k
64-bit SSE2 201k 201k 261k
32-bit SSE2 238k 225k 250k
32-bit 1293k 822k 848k
42 | 43 | #### Compilation 44 | 45 | No configuration is needed. 46 | 47 | ##### 32-bit 48 | 49 | gcc curve25519.c -m32 -O3 -c 50 | 51 | ##### 64-bit 52 | 53 | gcc curve25519.c -m64 -O3 -c 54 | 55 | ##### SSE2 56 | 57 | gcc curve25519.c -m32 -O3 -c -DCURVE25519_SSE2 -msse2 58 | gcc curve25519.c -m64 -O3 -c -DCURVE25519_SSE2 59 | 60 | clang, icc, and msvc are also supported 61 | 62 | ##### Named Versions 63 | 64 | Define CURVE25519_SUFFIX to append a suffix to public functions, e.g. 65 | `-DCURVE25519_SUFFIX=_sse2` to create curve25519_donna_sse2 and 66 | curve25519_donna_basepoint_sse2. 67 | 68 | #### Usage 69 | 70 | To use the code, link against `curve25519.o` and: 71 | 72 | #include "curve25519.h" 73 | 74 | To generate a private/secret key, generate 32 cryptographically random bytes: 75 | 76 | curve25519_key sk; 77 | randombytes(sk, sizeof(curve25519_key)); 78 | 79 | Manual clamping is not needed, and it is actually not possible to use unclamped 80 | keys due to the code taking advantage of the clamped bits internally. 81 | 82 | To generate the public key from the private/secret key: 83 | 84 | curve25519_key pk; 85 | curve25519_donna_basepoint(pk, sk); 86 | 87 | To generate a shared key with your private/secret key and someone elses public key: 88 | 89 | curve25519_key shared; 90 | curve25519_donna(shared, mysk, yourpk); 91 | 92 | And hash `shared` with a cryptographic hash before using, or e.g. pass `shared` through 93 | HSalsa20/HChacha as NaCl does. 94 | 95 | #### Testing 96 | 97 | Fuzzing against a reference implemenation is now available. See [fuzz/README](fuzz/README.md). 98 | 99 | Building `curve25519.c` and linking with `test.c` will run basic sanity tests and benchmark curve25519_donna. 100 | 101 | #### Papers 102 | 103 | [djb's curve25519 paper](http://cr.yp.to/ecdh/curve25519-20060209.pdf) 104 | 105 | #### License 106 | 107 | Public Domain, or MIT -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519-donna-common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * In: b = 2^5 - 2^0 3 | * Out: b = 2^250 - 2^0 4 | */ 5 | static void 6 | curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) { 7 | bignum25519 ALIGN(16) t0,c; 8 | 9 | /* 2^5 - 2^0 */ /* b */ 10 | /* 2^10 - 2^5 */ curve25519_square_times(t0, b, 5); 11 | /* 2^10 - 2^0 */ curve25519_mul(b, t0, b); 12 | /* 2^20 - 2^10 */ curve25519_square_times(t0, b, 10); 13 | /* 2^20 - 2^0 */ curve25519_mul(c, t0, b); 14 | /* 2^40 - 2^20 */ curve25519_square_times(t0, c, 20); 15 | /* 2^40 - 2^0 */ curve25519_mul(t0, t0, c); 16 | /* 2^50 - 2^10 */ curve25519_square_times(t0, t0, 10); 17 | /* 2^50 - 2^0 */ curve25519_mul(b, t0, b); 18 | /* 2^100 - 2^50 */ curve25519_square_times(t0, b, 50); 19 | /* 2^100 - 2^0 */ curve25519_mul(c, t0, b); 20 | /* 2^200 - 2^100 */ curve25519_square_times(t0, c, 100); 21 | /* 2^200 - 2^0 */ curve25519_mul(t0, t0, c); 22 | /* 2^250 - 2^50 */ curve25519_square_times(t0, t0, 50); 23 | /* 2^250 - 2^0 */ curve25519_mul(b, t0, b); 24 | } 25 | 26 | /* 27 | * z^(p - 2) = z(2^255 - 21) 28 | */ 29 | static void 30 | curve25519_recip(bignum25519 out, const bignum25519 z) { 31 | bignum25519 ALIGN(16) a,t0,b; 32 | 33 | /* 2 */ curve25519_square(a, z); /* a = 2 */ 34 | /* 8 */ curve25519_square_times(t0, a, 2); 35 | /* 9 */ curve25519_mul(b, t0, z); /* b = 9 */ 36 | /* 11 */ curve25519_mul(a, b, a); /* a = 11 */ 37 | /* 22 */ curve25519_square(t0, a); 38 | /* 2^5 - 2^0 = 31 */ curve25519_mul(b, t0, b); 39 | /* 2^250 - 2^0 */ curve25519_pow_two5mtwo0_two250mtwo0(b); 40 | /* 2^255 - 2^5 */ curve25519_square_times(b, b, 5); 41 | /* 2^255 - 21 */ curve25519_mul(out, b, a); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519-donna-portable-identify.h: -------------------------------------------------------------------------------- 1 | /* os */ 2 | #if defined(_WIN32) || defined(_WIN64) || defined(__TOS_WIN__) || defined(__WINDOWS__) 3 | #define OS_WINDOWS 4 | #elif defined(sun) || defined(__sun) || defined(__SVR4) || defined(__svr4__) 5 | #define OS_SOLARIS 6 | #else 7 | #include /* need this to define BSD */ 8 | #define OS_NIX 9 | #if defined(__linux__) 10 | #define OS_LINUX 11 | #elif defined(BSD) 12 | #define OS_BSD 13 | #if defined(MACOS_X) || (defined(__APPLE__) & defined(__MACH__)) 14 | #define OS_OSX 15 | #elif defined(macintosh) || defined(Macintosh) 16 | #define OS_MAC 17 | #elif defined(__OpenBSD__) 18 | #define OS_OPENBSD 19 | #endif 20 | #endif 21 | #endif 22 | 23 | 24 | /* compiler */ 25 | #if defined(_MSC_VER) 26 | #define COMPILER_MSVC 27 | #endif 28 | #if defined(__ICC) 29 | #define COMPILER_INTEL 30 | #endif 31 | #if defined(__GNUC__) 32 | #if (__GNUC__ >= 3) 33 | #define COMPILER_GCC ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + (__GNUC_PATCHLEVEL__)) 34 | #else 35 | #define COMPILER_GCC ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) ) 36 | #endif 37 | #endif 38 | #if defined(__PATHCC__) 39 | #define COMPILER_PATHCC 40 | #endif 41 | #if defined(__clang__) 42 | #define COMPILER_CLANG ((__clang_major__ * 10000) + (__clang_minor__ * 100) + (__clang_patchlevel__)) 43 | #endif 44 | 45 | 46 | 47 | /* cpu */ 48 | #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__ ) || defined(_M_X64) 49 | #define CPU_X86_64 50 | #elif defined(__i586__) || defined(__i686__) || (defined(_M_IX86) && (_M_IX86 >= 500)) 51 | #define CPU_X86 500 52 | #elif defined(__i486__) || (defined(_M_IX86) && (_M_IX86 >= 400)) 53 | #define CPU_X86 400 54 | #elif defined(__i386__) || (defined(_M_IX86) && (_M_IX86 >= 300)) || defined(__X86__) || defined(_X86_) || defined(__I86__) 55 | #define CPU_X86 300 56 | #elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(_M_IA64) || defined(__ia64) 57 | #define CPU_IA64 58 | #endif 59 | 60 | #if defined(__sparc__) || defined(__sparc) || defined(__sparcv9) 61 | #define CPU_SPARC 62 | #if defined(__sparcv9) 63 | #define CPU_SPARC64 64 | #endif 65 | #endif 66 | 67 | #if defined(powerpc) || defined(__PPC__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(POWERPC) || defined(_M_PPC) 68 | #define CPU_PPC 69 | #if defined(_ARCH_PWR7) 70 | #define CPU_POWER7 71 | #elif defined(__64BIT__) 72 | #define CPU_PPC64 73 | #else 74 | #define CPU_PPC32 75 | #endif 76 | #endif 77 | 78 | #if defined(__hppa__) || defined(__hppa) 79 | #define CPU_HPPA 80 | #endif 81 | 82 | #if defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) 83 | #define CPU_ALPHA 84 | #endif 85 | 86 | /* 64 bit cpu */ 87 | #if defined(CPU_X86_64) || defined(CPU_IA64) || defined(CPU_SPARC64) || defined(__64BIT__) || defined(__LP64__) || defined(_LP64) || (defined(_MIPS_SZLONG) && (_MIPS_SZLONG == 64)) 88 | #define CPU_64BITS 89 | #endif 90 | 91 | #if defined(COMPILER_MSVC) 92 | typedef signed char int8_t; 93 | typedef unsigned char uint8_t; 94 | typedef signed short int16_t; 95 | typedef unsigned short uint16_t; 96 | typedef signed int int32_t; 97 | typedef unsigned int uint32_t; 98 | typedef signed __int64 int64_t; 99 | typedef unsigned __int64 uint64_t; 100 | #else 101 | #include 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519-donna-portable.h: -------------------------------------------------------------------------------- 1 | #include "curve25519-donna-portable-identify.h" 2 | 3 | #define mul32x32_64(a,b) (((uint64_t)(a))*(b)) 4 | 5 | #ifdef ALIGN 6 | #undef ALIGN 7 | #endif 8 | 9 | /* platform */ 10 | #if defined(COMPILER_MSVC) 11 | #include 12 | #if !defined(_DEBUG) 13 | #undef mul32x32_64 14 | #define mul32x32_64(a,b) __emulu(a,b) 15 | #endif 16 | #undef inline 17 | #define inline __forceinline 18 | #define DONNA_INLINE __forceinline 19 | #define DONNA_NOINLINE __declspec(noinline) 20 | #define ALIGN(x) __declspec(align(x)) 21 | #define ROTL32(a,b) _rotl(a,b) 22 | #define ROTR32(a,b) _rotr(a,b) 23 | #else 24 | #include 25 | #define DONNA_INLINE inline __attribute__((always_inline)) 26 | #define DONNA_NOINLINE __attribute__((noinline)) 27 | #define ALIGN(x) __attribute__((aligned(x))) 28 | #define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b))) 29 | #define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b))) 30 | #endif 31 | 32 | /* uint128_t */ 33 | #if defined(CPU_64BITS) && !defined(ED25519_FORCE_32BIT) 34 | #if defined(COMPILER_CLANG) && (COMPILER_CLANG >= 30100) 35 | #define HAVE_NATIVE_UINT128 36 | typedef unsigned __int128 uint128_t; 37 | #elif defined(COMPILER_MSVC) 38 | #define HAVE_UINT128 39 | typedef struct uint128_t { 40 | uint64_t lo, hi; 41 | } uint128_t; 42 | #define mul64x64_128(out,a,b) out.lo = _umul128(a,b,&out.hi); 43 | #define shr128_pair(out,hi,lo,shift) out = __shiftright128(lo, hi, shift); 44 | #define shl128_pair(out,hi,lo,shift) out = __shiftleft128(lo, hi, shift); 45 | #define shr128(out,in,shift) shr128_pair(out, in.hi, in.lo, shift) 46 | #define shl128(out,in,shift) shl128_pair(out, in.hi, in.lo, shift) 47 | #define add128(a,b) { uint64_t p = a.lo; a.lo += b.lo; a.hi += b.hi + (a.lo < p); } 48 | #define add128_64(a,b) { uint64_t p = a.lo; a.lo += b; a.hi += (a.lo < p); } 49 | #define lo128(a) (a.lo) 50 | #define hi128(a) (a.hi) 51 | #elif defined(COMPILER_GCC) && !defined(HAVE_NATIVE_UINT128) 52 | #if defined(__SIZEOF_INT128__) 53 | #define HAVE_NATIVE_UINT128 54 | typedef unsigned __int128 uint128_t; 55 | #elif (COMPILER_GCC >= 40400) 56 | #define HAVE_NATIVE_UINT128 57 | typedef unsigned uint128_t __attribute__((mode(TI))); 58 | #elif defined(CPU_X86_64) 59 | #define HAVE_UINT128 60 | typedef struct uint128_t { 61 | uint64_t lo, hi; 62 | } uint128_t; 63 | #define mul64x64_128(out,a,b) __asm__ ("mulq %3" : "=a" (out.lo), "=d" (out.hi) : "a" (a), "rm" (b)); 64 | #define shr128_pair(out,hi,lo,shift) __asm__ ("shrdq %2,%1,%0" : "+r" (lo) : "r" (hi), "J" (shift)); out = lo; 65 | #define shl128_pair(out,hi,lo,shift) __asm__ ("shldq %2,%1,%0" : "+r" (hi) : "r" (lo), "J" (shift)); out = hi; 66 | #define shr128(out,in,shift) shr128_pair(out,in.hi, in.lo, shift) 67 | #define shl128(out,in,shift) shl128_pair(out,in.hi, in.lo, shift) 68 | #define add128(a,b) __asm__ ("addq %4,%2; adcq %5,%3" : "=r" (a.hi), "=r" (a.lo) : "1" (a.lo), "0" (a.hi), "rm" (b.lo), "rm" (b.hi) : "cc"); 69 | #define add128_64(a,b) __asm__ ("addq %4,%2; adcq $0,%3" : "=r" (a.hi), "=r" (a.lo) : "1" (a.lo), "0" (a.hi), "rm" (b) : "cc"); 70 | #define lo128(a) (a.lo) 71 | #define hi128(a) (a.hi) 72 | #endif 73 | #endif 74 | 75 | #if defined(HAVE_NATIVE_UINT128) 76 | #define HAVE_UINT128 77 | #define mul64x64_128(out,a,b) out = (uint128_t)a * b; 78 | #define shr128_pair(out,hi,lo,shift) out = (uint64_t)((((uint128_t)hi << 64) | lo) >> (shift)); 79 | #define shl128_pair(out,hi,lo,shift) out = (uint64_t)(((((uint128_t)hi << 64) | lo) << (shift)) >> 64); 80 | #define shr128(out,in,shift) out = (uint64_t)(in >> (shift)); 81 | #define shl128(out,in,shift) out = (uint64_t)((in << shift) >> 64); 82 | #define add128(a,b) a += b; 83 | #define add128_64(a,b) a += (uint64_t)b; 84 | #define lo128(a) ((uint64_t)a) 85 | #define hi128(a) ((uint64_t)(a >> 64)) 86 | #endif 87 | 88 | #if !defined(HAVE_UINT128) 89 | #error Need a uint128_t implementation! 90 | #endif 91 | #endif 92 | 93 | #include 94 | #include 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519-donna-scalarmult-base.h: -------------------------------------------------------------------------------- 1 | /* Calculates nQ where Q is the x-coordinate of a point on the curve 2 | * 3 | * mypublic: the packed little endian x coordinate of the resulting curve point 4 | * n: a little endian, 32-byte number 5 | * basepoint: a packed little endian point of the curve 6 | */ 7 | 8 | static void 9 | curve25519_scalarmult_donna(curve25519_key mypublic, const curve25519_key n, const curve25519_key basepoint) { 10 | bignum25519 nqpqx = {1}, nqpqz = {0}, nqz = {1}, nqx; 11 | bignum25519 q, qx, qpqx, qqx, zzz, zmone; 12 | size_t bit, lastbit; 13 | int32_t i; 14 | 15 | curve25519_expand(q, basepoint); 16 | curve25519_copy(nqx, q); 17 | 18 | /* bit 255 is always 0, and bit 254 is always 1, so skip bit 255 and 19 | start pre-swapped on bit 254 */ 20 | lastbit = 1; 21 | 22 | /* we are doing bits 254..3 in the loop, but are swapping in bits 253..2 */ 23 | for (i = 253; i >= 2; i--) { 24 | curve25519_add(qx, nqx, nqz); 25 | curve25519_sub(nqz, nqx, nqz); 26 | curve25519_add(qpqx, nqpqx, nqpqz); 27 | curve25519_sub(nqpqz, nqpqx, nqpqz); 28 | curve25519_mul(nqpqx, qpqx, nqz); 29 | curve25519_mul(nqpqz, qx, nqpqz); 30 | curve25519_add(qqx, nqpqx, nqpqz); 31 | curve25519_sub(nqpqz, nqpqx, nqpqz); 32 | curve25519_square(nqpqz, nqpqz); 33 | curve25519_square(nqpqx, qqx); 34 | curve25519_mul(nqpqz, nqpqz, q); 35 | curve25519_square(qx, qx); 36 | curve25519_square(nqz, nqz); 37 | curve25519_mul(nqx, qx, nqz); 38 | curve25519_sub(nqz, qx, nqz); 39 | curve25519_scalar_product(zzz, nqz, 121665); 40 | curve25519_add(zzz, zzz, qx); 41 | curve25519_mul(nqz, nqz, zzz); 42 | 43 | bit = (n[i/8] >> (i & 7)) & 1; 44 | curve25519_swap_conditional(nqx, nqpqx, bit ^ lastbit); 45 | curve25519_swap_conditional(nqz, nqpqz, bit ^ lastbit); 46 | lastbit = bit; 47 | } 48 | 49 | /* the final 3 bits are always zero, so we only need to double */ 50 | for (i = 0; i < 3; i++) { 51 | curve25519_add(qx, nqx, nqz); 52 | curve25519_sub(nqz, nqx, nqz); 53 | curve25519_square(qx, qx); 54 | curve25519_square(nqz, nqz); 55 | curve25519_mul(nqx, qx, nqz); 56 | curve25519_sub(nqz, qx, nqz); 57 | curve25519_scalar_product(zzz, nqz, 121665); 58 | curve25519_add(zzz, zzz, qx); 59 | curve25519_mul(nqz, nqz, zzz); 60 | } 61 | 62 | curve25519_recip(zmone, nqz); 63 | curve25519_mul(nqz, nqx, zmone); 64 | curve25519_contract(mypublic, nqz); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519-donna-scalarmult-sse2.h: -------------------------------------------------------------------------------- 1 | 2 | /* Calculates nQ where Q is the x-coordinate of a point on the curve 3 | * 4 | * mypublic: the packed little endian x coordinate of the resulting curve point 5 | * n: a little endian, 32-byte number 6 | * basepoint: a packed little endian point of the curve 7 | */ 8 | static void 9 | curve25519_scalarmult_donna(curve25519_key mypublic, const curve25519_key n, const curve25519_key basepoint) { 10 | bignum25519 ALIGN(16) nqx = {1}, nqpqz = {1}, nqz = {0}, nqpqx, zmone; 11 | packed32bignum25519 qx, qz, pqz, pqx; 12 | packed64bignum25519 nq, sq, sqscalar, prime, primex, primez, nqpq; 13 | bignum25519mulprecomp preq; 14 | uint32_t bit, lastbit, i; 15 | 16 | curve25519_expand(nqpqx, basepoint); 17 | curve25519_mul_precompute(&preq, nqpqx); 18 | 19 | /* do bits 254..3 */ 20 | for (i = 254, lastbit = 0; i >= 3; i--) { 21 | bit = (n[i/8] >> (i & 7)) & 1; 22 | curve25519_swap_conditional(nqx, nqpqx, bit ^ lastbit); 23 | curve25519_swap_conditional(nqz, nqpqz, bit ^ lastbit); 24 | lastbit = bit; 25 | 26 | curve25519_tangle32(qx, nqx, nqpqx); /* qx = [nqx,nqpqx] */ 27 | curve25519_tangle32(qz, nqz, nqpqz); /* qz = [nqz,nqpqz] */ 28 | 29 | curve25519_add_packed32(pqx, qx, qz); /* pqx = [nqx+nqz,nqpqx+nqpqz] */ 30 | curve25519_sub_packed32(pqz, qx, qz); /* pqz = [nqx-nqz,nqpqx-nqpqz] */ 31 | 32 | curve25519_make_nqpq(primex, primez, pqx, pqz); /* primex = [nqx+nqz,nqpqx+nqpqz], primez = [nqpqx-nqpqz,nqx-nqz] */ 33 | curve25519_mul_packed64(prime, primex, primez); /* prime = [nqx+nqz,nqpqx+nqpqz] * [nqpqx-nqpqz,nqx-nqz] */ 34 | curve25519_addsub_packed64(prime); /* prime = [prime.x+prime.z,prime.x-prime.z] */ 35 | curve25519_square_packed64(nqpq, prime); /* nqpq = prime^2 */ 36 | curve25519_untangle64(nqpqx, nqpqz, nqpq); 37 | curve25519_mul_precomputed(nqpqz, nqpqz, &preq); /* nqpqz = nqpqz * q */ 38 | 39 | /* (((sq.x-sq.z)*121665)+sq.x) * (sq.x-sq.z) is equivalent to (sq.x*121666-sq.z*121665) * (sq.x-sq.z) */ 40 | curve25519_make_nq(nq, pqx, pqz); /* nq = [nqx+nqz,nqx-nqz] */ 41 | curve25519_square_packed64(sq, nq); /* sq = nq^2 */ 42 | curve25519_121665_packed64(sqscalar, sq); /* sqscalar = sq * [121666,121665] */ 43 | curve25519_final_nq(nq, sq, sqscalar); /* nq = [sq.x,sqscalar.x-sqscalar.z] * [sq.z,sq.x-sq.z] */ 44 | curve25519_untangle64(nqx, nqz, nq); 45 | }; 46 | 47 | /* it's possible to get rid of this swap with the swap in the above loop 48 | at the bottom instead of the top, but compilers seem to optimize better this way */ 49 | curve25519_swap_conditional(nqx, nqpqx, bit); 50 | curve25519_swap_conditional(nqz, nqpqz, bit); 51 | 52 | /* do bits 2..0 */ 53 | for (i = 0; i < 3; i++) { 54 | curve25519_compute_nq(nq, nqx, nqz); 55 | curve25519_square_packed64(sq, nq); /* sq = nq^2 */ 56 | curve25519_121665_packed64(sqscalar, sq); /* sqscalar = sq * [121666,121665] */ 57 | curve25519_final_nq(nq, sq, sqscalar); /* nq = [sq.x,sqscalar.x-sqscalar.z] * [sq.z,sq.x-sq.z] */ 58 | curve25519_untangle64(nqx, nqz, nq); 59 | } 60 | 61 | curve25519_recip(zmone, nqz); 62 | curve25519_mul(nqz, nqx, zmone); 63 | curve25519_contract(mypublic, nqz); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519-donna.h: -------------------------------------------------------------------------------- 1 | #include "curve25519.h" 2 | #include "curve25519-donna-portable.h" 3 | 4 | #if defined(CURVE25519_SSE2) 5 | #else 6 | #if defined(HAVE_UINT128) && !defined(CURVE25519_FORCE_32BIT) 7 | #define CURVE25519_64BIT 8 | #else 9 | #define CURVE25519_32BIT 10 | #endif 11 | #endif 12 | 13 | #if !defined(CURVE25519_NO_INLINE_ASM) 14 | #endif 15 | 16 | 17 | #if defined(CURVE25519_SSE2) 18 | #include "curve25519-donna-sse2.h" 19 | #elif defined(CURVE25519_64BIT) 20 | #include "curve25519-donna-64bit.h" 21 | #else 22 | #include "curve25519-donna-32bit.h" 23 | #endif 24 | 25 | #include "curve25519-donna-common.h" 26 | 27 | #if defined(CURVE25519_SSE2) 28 | #include "curve25519-donna-scalarmult-sse2.h" 29 | #else 30 | #include "curve25519-donna-scalarmult-base.h" 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519-optimizations-32bit.md: -------------------------------------------------------------------------------- 1 | Partial Reductions for multiplications 2 | -------------------------------------- 3 | 4 | It is possible to get away with partial reductions for multiplications 5 | instead of fully reducing everything. The largest input to square/mult 6 | will come from an unreduced add, which will double the element values. 7 | Test values are 1 bit larger than actual maximum values. 8 | 9 | max27 = (1 << 27) - 1 10 | max26 = (1 << 26) - 1 11 | 12 | Largest values from an add of full bit values (max27,max26,max27,max26..) 13 | 14 | m0 0x1f1fffea8000042c 15 | m1 0x133ffff190000268 16 | m2 0x185fffef00000354 17 | m3 0x0ebffff4f00001d8 18 | m4 0x119ffff38000027c 19 | m5 0x0a3ffff850000148 20 | m6 0x0adffff8000001a4 21 | m7 0x05bffffbb00000b8 22 | m8 0x041ffffc800000cc 23 | m9 0x013fffff10000028 24 | 25 | Carry values from reducing sums 26 | 27 | c0 0x00000007c7fffaa0 28 | c1 0x000000099ffffcab 29 | c2 0x0000000617fffe27 30 | c3 0x000000075ffffd83 31 | c4 0x0000000467fffeb7 32 | c5 0x000000051ffffe5b 33 | c6 0x00000002b7ffff47 34 | c7 0x00000002dfffff33 35 | c8 0x0000000107ffffd7 36 | c9 0xa000000b 37 | c0 0x000002f8 38 | 39 | 40 | The largest carried value r1 could receive is 0x2f8, with everything else 41 | fitting in 25 or 26 bits. Assuming full values for everything, with 0x2f8 42 | added to r1 (max27,maxr1,max27,max26..): 43 | 44 | max27 = (1 << 27) - 1 45 | max26 = (1 << 26) - 1 46 | maxr1 = (((1 << 25) - 1) + 0x2f8) * 2 47 | 48 | m0 0x1f2006f77ffc7dac 49 | m1 0x134000508fffeaa8 50 | m2 0x1860004e004655d4 51 | m3 0x0ec00053efffea18 52 | m4 0x11a000527fffd2fc 53 | m5 0x0a4000574fffe988 54 | m6 0x0ae00056ffffd224 55 | m7 0x05c0005aafffe8f8 56 | m8 0x0420005b7fffd14c 57 | m9 0x0140005e0fffe868 58 | 59 | Carry values 60 | 61 | c0 0x00000007c801bddf 62 | c1 0x00000009a0002c2c 63 | c2 0x00000006180015e8 64 | c3 0x0000000760002d04 65 | c4 0x0000000468001678 66 | c5 0x0000000520002ddc 67 | c6 0x00000002b8001708 68 | c7 0x00000002e0002eb4 69 | c8 0x0000000108001798 70 | c9 0xa0002f8c 71 | c0 0x000002f9 72 | 73 | The largest carried value is now 0x2f9 (max27,maxr1b,max27,max26..) 74 | 75 | max27 = (1 << 27) - 1 76 | max26 = (1 << 26) - 1 77 | maxr1b = (((1 << 25) - 1) + 0x2f9) * 2 78 | 79 | m0 0x1f2006f9dffc7c7c 80 | m1 0x13400050afffeaa0 81 | m2 0x1860004e2046854c 82 | m3 0x0ec000540fffea10 83 | m4 0x11a000529fffd2ec 84 | m5 0x0a4000576fffe980 85 | m6 0x0ae000571fffd214 86 | m7 0x05c0005acfffe8f0 87 | m8 0x0420005b9fffd13c 88 | m9 0x0140005e2fffe860 89 | 90 | Carry values 91 | 92 | c0 0x00000007c801be77 93 | c1 0x00000009a0002c3c 94 | c2 0x00000006180015f0 95 | c3 0x0000000760002d14 96 | c4 0x0000000468001680 97 | c5 0x0000000520002dec 98 | c6 0x00000002b8001710 99 | c7 0x00000002e0002ec4 100 | c8 0x00000001080017a0 101 | c9 0xa0002f9c 102 | c0 0x000002f9 103 | 104 | The largest carried value is fixed at 0x2f9. Subtracting the largest values 105 | from 0 will result in r0 exceeding 26 bits, but r0-r4 are safe for 106 | multiplications up to 30 bits, so partial reductions throughout the entire 107 | calculation should be safe to chain. This especially helps with speeding up 108 | the SSE2 version by freeing it from large serial carry chains. Testing of 109 | course continues, but no problems as of yet have shown up. 110 | 111 | 112 | Subtraction 113 | ----------- 114 | Subtraction with unsigned elements is done using Emilia Kasper's trick, via 115 | agl: http://www.imperialviolet.org/2010/12/04/ecc.html 116 | 117 | Adding a large enough value that is equivalent to 0 mod p before subracting 118 | ensures no elements underflow. 119 | 120 | Compiler 121 | -------- 122 | gcc (as of 4.4.5) has a difficult time optimizing the 32 bit C version properly. 123 | icc produces code that is roughly 40% faster. -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519.c: -------------------------------------------------------------------------------- 1 | #include "curve25519-donna.h" 2 | 3 | #if !defined(CURVE25519_SUFFIX) 4 | #define CURVE25519_SUFFIX 5 | #endif 6 | 7 | #define CURVE25519_FN3(fn,suffix) fn##suffix 8 | #define CURVE25519_FN2(fn,suffix) CURVE25519_FN3(fn,suffix) 9 | #define CURVE25519_FN(fn) CURVE25519_FN2(fn,CURVE25519_SUFFIX) 10 | 11 | void 12 | CURVE25519_FN(curve25519_donna) (curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint) { 13 | curve25519_key e; 14 | size_t i; 15 | 16 | for (i = 0;i < 32;++i) e[i] = secret[i]; 17 | e[0] &= 0xf8; 18 | e[31] &= 0x7f; 19 | e[31] |= 0x40; 20 | curve25519_scalarmult_donna(mypublic, e, basepoint); 21 | } 22 | 23 | void 24 | CURVE25519_FN(curve25519_donna_basepoint) (curve25519_key mypublic, const curve25519_key secret) { 25 | static const curve25519_key basepoint = {9}; 26 | CURVE25519_FN(curve25519_donna)(mypublic, secret, basepoint); 27 | } 28 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519.h: -------------------------------------------------------------------------------- 1 | #ifndef CURVE25519_H 2 | #define CURVE25519_H 3 | 4 | typedef unsigned char curve25519_key[32]; 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | void curve25519_donna(curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint); 11 | void curve25519_donna_basepoint(curve25519_key mypublic, const curve25519_key secret); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* CURVE25519_H */ 18 | 19 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/curve25519_VALVE_sse2.c: -------------------------------------------------------------------------------- 1 | /* The code for curve25519-donna comes from https://github.com/floodyberry/curve25519-donna 2 | where it is explicitly placed in the public domain. This wrapper compiles it with the _sse2 3 | function suffix to be distinguished from the native C version. */ 4 | 5 | #if defined( _M_IX86 ) || defined( _M_X64 ) || defined(__SSE2__) 6 | 7 | #define CURVE25519_SUFFIX _sse2 8 | #define CURVE25519_SSE2 9 | 10 | #include "curve25519.c" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/readme_VALVE.txt: -------------------------------------------------------------------------------- 1 | curve25519-donna is an implementation of the Curve25519 ECDH key-exchange algorithm by Dan J Bernstein. 2 | 3 | curve25519 is a "256-bit strength" elliptical curve (equivalent to NIST P-256) with 32-byte secret/public keys. 4 | 5 | It is very fast, easy to implement securely in software, and fully public-domain. 6 | 7 | 8 | Downloaded 2/10/2016 from https://github.com/floodyberry/curve25519-donna 9 | 10 | 11 | 12 | Filenames containing VALVE are *not* entirely public domain - see individual files for details. 13 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/test-ticks.h: -------------------------------------------------------------------------------- 1 | #include "curve25519-donna-portable-identify.h" 2 | 3 | /* ticks - not tested on anything other than x86 */ 4 | static uint64_t 5 | get_ticks(void) { 6 | #if defined(CPU_X86) || defined(CPU_X86_64) 7 | #if defined(COMPILER_INTEL) 8 | return _rdtsc(); 9 | #elif defined(COMPILER_MSVC) 10 | return __rdtsc(); 11 | #elif defined(COMPILER_GCC) 12 | uint32_t lo, hi; 13 | __asm__ __volatile__("rdtsc" : "=a" (lo), "=d" (hi)); 14 | return ((uint64_t)lo | ((uint64_t)hi << 32)); 15 | #else 16 | need rdtsc for this compiler 17 | #endif 18 | #elif defined(OS_SOLARIS) 19 | return (uint64_t)gethrtime(); 20 | #elif defined(CPU_SPARC) && !defined(OS_OPENBSD) 21 | uint64_t t; 22 | __asm__ __volatile__("rd %%tick, %0" : "=r" (t)); 23 | return t; 24 | #elif defined(CPU_PPC) 25 | uint32_t lo = 0, hi = 0; 26 | __asm__ __volatile__("mftbu %0; mftb %1" : "=r" (hi), "=r" (lo)); 27 | return ((uint64_t)lo | ((uint64_t)hi << 32)); 28 | #elif defined(CPU_IA64) 29 | uint64_t t; 30 | __asm__ __volatile__("mov %0=ar.itc" : "=r" (t)); 31 | return t; 32 | #elif defined(OS_NIX) 33 | timeval t2; 34 | gettimeofday(&t2, NULL); 35 | t = ((uint64_t)t2.tv_usec << 32) | (uint64_t)t2.tv_sec; 36 | return t; 37 | #else 38 | need ticks for this platform 39 | #endif 40 | } 41 | 42 | #define timeit(x,minvar) \ 43 | ticks = get_ticks(); \ 44 | x; \ 45 | ticks = get_ticks() - ticks; \ 46 | if (ticks < minvar) \ 47 | minvar = ticks; 48 | 49 | #define maxticks 0xffffffffffffffffull 50 | 51 | -------------------------------------------------------------------------------- /src/external/curve25519-donna/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "curve25519.h" 9 | 10 | #include "test-ticks.h" 11 | 12 | static void 13 | curveassert_die(const unsigned char *a, const unsigned char *b, size_t len, int round, const char *failreason) { 14 | size_t i; 15 | if (round > 0) 16 | printf("round %d, %s\n", round, failreason); 17 | else 18 | printf("%s\n", failreason); 19 | printf("want: "); for (i = 0; i < len; i++) printf("%02x,", a[i]); printf("\n"); 20 | printf("got : "); for (i = 0; i < len; i++) printf("%02x,", b[i]); printf("\n"); 21 | printf("diff: "); for (i = 0; i < len; i++) if (a[i] ^ b[i]) printf("%02x,", a[i] ^ b[i]); else printf(" ,"); printf("\n\n"); 22 | exit(1); 23 | } 24 | 25 | static void 26 | curveassert_equal(const unsigned char *a, const unsigned char *b, size_t len, const char *failreason) { 27 | if (memcmp(a, b, len) == 0) 28 | return; 29 | curveassert_die(a, b, len, -1, failreason); 30 | } 31 | 32 | /* result of the curve25519 scalarmult |((|max| * |max|) * |max|)... 1024 times| * basepoint */ 33 | 34 | /* 35 | static const curve25519_key curve25519_expected = { 36 | 0x8e,0x74,0xac,0x44,0x38,0xa6,0x87,0x54, 37 | 0xc8,0xc6,0x1b,0xa0,0x8b,0xd2,0xf7,0x7b, 38 | 0xbb,0xc6,0x26,0xd5,0x24,0xb3,0xbe,0xa0, 39 | 0x38,0x30,0x1d,0xec,0x2d,0x92,0xe7,0x51 40 | }; 41 | */ 42 | 43 | /* this is the result if the 256th bit of a point is ignored:*/ 44 | const curve25519_key curve25519_expected = { 45 | 0x1e,0x61,0x8e,0xc0,0x2f,0x25,0x1b,0x8d, 46 | 0x62,0xed,0x0e,0x57,0x3c,0x83,0x11,0x49, 47 | 0x7b,0xa5,0x85,0x40,0x1a,0xcf,0xd4,0x3e, 48 | 0x5b,0xeb,0xa8,0xb5,0xae,0x75,0x96,0x2d 49 | }; 50 | 51 | 52 | /* shared key resulting from the private keys |max| and |mid| */ 53 | static const curve25519_key curve25519_shared = { 54 | 0x78,0x0e,0x63,0xa6,0x58,0x5c,0x6d,0x56, 55 | 0xf1,0xa0,0x18,0x2d,0xec,0xe6,0x96,0x3b, 56 | 0x5b,0x4d,0x63,0x08,0x7b,0xf9,0x19,0x0e, 57 | 0x3a,0x77,0xf5,0x27,0x9c,0xd7,0x8b,0x44 58 | }; 59 | 60 | 61 | static void 62 | test_main(void) { 63 | int i; 64 | static const curve25519_key max = { 65 | 255,255,255,255,255,255,255,255, 66 | 255,255,255,255,255,255,255,255, 67 | 255,255,255,255,255,255,255,255, 68 | 255,255,255,255,255,255,255,255 69 | }; 70 | static const curve25519_key mid = { 71 | 127,127,127,127,127,127,127,127, 72 | 127,127,127,127,127,127,127,127, 73 | 127,127,127,127,127,127,127,127, 74 | 127,127,127,127,127,127,127,127 75 | }; 76 | curve25519_key pk[2]; 77 | curve25519_key shared[2]; 78 | uint64_t ticks, curveticks = maxticks; 79 | 80 | curve25519_donna(pk[0], max, max); 81 | for (i = 0; i < 1023; i++) 82 | curve25519_donna(pk[(i & 1) ^ 1], pk[i & 1], max); 83 | curve25519_donna_basepoint(pk[0], pk[1]); 84 | curveassert_equal(curve25519_expected, pk[0], sizeof(curve25519_key), "curve25519 sanity test failed to generate correct value"); 85 | 86 | curve25519_donna_basepoint(pk[0], max); 87 | curve25519_donna_basepoint(pk[1], mid); 88 | curve25519_donna(shared[0], max, pk[1]); 89 | curve25519_donna(shared[1], mid, pk[0]); 90 | curveassert_equal(curve25519_shared, shared[0], sizeof(curve25519_key), "curve25519 failed to generate the same shared key (1)"); 91 | curveassert_equal(curve25519_shared, shared[1], sizeof(curve25519_key), "curve25519 failed to generate the same shared key (2)"); 92 | 93 | for (i = 0; i < 2048; i++) { 94 | timeit(curve25519_donna(pk[1], pk[0], max), curveticks); 95 | } 96 | 97 | printf("%.0f ticks/curve25519 scalarmult\n", (double)curveticks); 98 | } 99 | 100 | int 101 | main(void) { 102 | test_main(); 103 | return 0; 104 | } 105 | 106 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/curve25519-donna-helpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Public domain by Andrew M. 3 | See: https://github.com/floodyberry/curve25519-donna 4 | 5 | Curve25519 implementation agnostic helpers 6 | */ 7 | 8 | /* 9 | * In: b = 2^5 - 2^0 10 | * Out: b = 2^250 - 2^0 11 | */ 12 | static void 13 | curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) { 14 | bignum25519 ALIGN(16) t0,c; 15 | 16 | /* 2^5 - 2^0 */ /* b */ 17 | /* 2^10 - 2^5 */ curve25519_square_times(t0, b, 5); 18 | /* 2^10 - 2^0 */ curve25519_mul_noinline(b, t0, b); 19 | /* 2^20 - 2^10 */ curve25519_square_times(t0, b, 10); 20 | /* 2^20 - 2^0 */ curve25519_mul_noinline(c, t0, b); 21 | /* 2^40 - 2^20 */ curve25519_square_times(t0, c, 20); 22 | /* 2^40 - 2^0 */ curve25519_mul_noinline(t0, t0, c); 23 | /* 2^50 - 2^10 */ curve25519_square_times(t0, t0, 10); 24 | /* 2^50 - 2^0 */ curve25519_mul_noinline(b, t0, b); 25 | /* 2^100 - 2^50 */ curve25519_square_times(t0, b, 50); 26 | /* 2^100 - 2^0 */ curve25519_mul_noinline(c, t0, b); 27 | /* 2^200 - 2^100 */ curve25519_square_times(t0, c, 100); 28 | /* 2^200 - 2^0 */ curve25519_mul_noinline(t0, t0, c); 29 | /* 2^250 - 2^50 */ curve25519_square_times(t0, t0, 50); 30 | /* 2^250 - 2^0 */ curve25519_mul_noinline(b, t0, b); 31 | } 32 | 33 | /* 34 | * z^(p - 2) = z(2^255 - 21) 35 | */ 36 | static void 37 | curve25519_recip(bignum25519 out, const bignum25519 z) { 38 | bignum25519 ALIGN(16) a,t0,b; 39 | 40 | /* 2 */ curve25519_square_times(a, z, 1); /* a = 2 */ 41 | /* 8 */ curve25519_square_times(t0, a, 2); 42 | /* 9 */ curve25519_mul_noinline(b, t0, z); /* b = 9 */ 43 | /* 11 */ curve25519_mul_noinline(a, b, a); /* a = 11 */ 44 | /* 22 */ curve25519_square_times(t0, a, 1); 45 | /* 2^5 - 2^0 = 31 */ curve25519_mul_noinline(b, t0, b); 46 | /* 2^250 - 2^0 */ curve25519_pow_two5mtwo0_two250mtwo0(b); 47 | /* 2^255 - 2^5 */ curve25519_square_times(b, b, 5); 48 | /* 2^255 - 21 */ curve25519_mul_noinline(out, b, a); 49 | } 50 | 51 | /* 52 | * z^((p-5)/8) = z^(2^252 - 3) 53 | */ 54 | static void 55 | curve25519_pow_two252m3(bignum25519 two252m3, const bignum25519 z) { 56 | bignum25519 ALIGN(16) b,c,t0; 57 | 58 | /* 2 */ curve25519_square_times(c, z, 1); /* c = 2 */ 59 | /* 8 */ curve25519_square_times(t0, c, 2); /* t0 = 8 */ 60 | /* 9 */ curve25519_mul_noinline(b, t0, z); /* b = 9 */ 61 | /* 11 */ curve25519_mul_noinline(c, b, c); /* c = 11 */ 62 | /* 22 */ curve25519_square_times(t0, c, 1); 63 | /* 2^5 - 2^0 = 31 */ curve25519_mul_noinline(b, t0, b); 64 | /* 2^250 - 2^0 */ curve25519_pow_two5mtwo0_two250mtwo0(b); 65 | /* 2^252 - 2^2 */ curve25519_square_times(b, b, 2); 66 | /* 2^252 - 3 */ curve25519_mul_noinline(two252m3, b, z); 67 | } 68 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-donna-portable-identify.h: -------------------------------------------------------------------------------- 1 | /* os */ 2 | #if defined(_WIN32) || defined(_WIN64) || defined(__TOS_WIN__) || defined(__WINDOWS__) 3 | #define OS_WINDOWS 4 | #elif defined(sun) || defined(__sun) || defined(__SVR4) || defined(__svr4__) 5 | #define OS_SOLARIS 6 | #else 7 | #include /* need this to define BSD */ 8 | #define OS_NIX 9 | #if defined(__linux__) 10 | #define OS_LINUX 11 | #elif defined(BSD) 12 | #define OS_BSD 13 | #if defined(MACOS_X) || (defined(__APPLE__) & defined(__MACH__)) 14 | #define OS_OSX 15 | #elif defined(macintosh) || defined(Macintosh) 16 | #define OS_MAC 17 | #elif defined(__OpenBSD__) 18 | #define OS_OPENBSD 19 | #endif 20 | #endif 21 | #endif 22 | 23 | 24 | /* compiler */ 25 | #if defined(_MSC_VER) 26 | #define COMPILER_MSVC 27 | #endif 28 | #if defined(__ICC) 29 | #define COMPILER_INTEL 30 | #endif 31 | #if defined(__GNUC__) 32 | #if (__GNUC__ >= 3) 33 | #define COMPILER_GCC ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + (__GNUC_PATCHLEVEL__)) 34 | #else 35 | #define COMPILER_GCC ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) ) 36 | #endif 37 | #endif 38 | #if defined(__PATHCC__) 39 | #define COMPILER_PATHCC 40 | #endif 41 | #if defined(__clang__) 42 | #define COMPILER_CLANG ((__clang_major__ * 10000) + (__clang_minor__ * 100) + (__clang_patchlevel__)) 43 | #endif 44 | 45 | 46 | 47 | /* cpu */ 48 | #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__ ) || defined(_M_X64) 49 | #define CPU_X86_64 50 | #elif defined(__i586__) || defined(__i686__) || (defined(_M_IX86) && (_M_IX86 >= 500)) 51 | #define CPU_X86 500 52 | #elif defined(__i486__) || (defined(_M_IX86) && (_M_IX86 >= 400)) 53 | #define CPU_X86 400 54 | #elif defined(__i386__) || (defined(_M_IX86) && (_M_IX86 >= 300)) || defined(__X86__) || defined(_X86_) || defined(__I86__) 55 | #define CPU_X86 300 56 | #elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(_M_IA64) || defined(__ia64) 57 | #define CPU_IA64 58 | #endif 59 | 60 | #if defined(__sparc__) || defined(__sparc) || defined(__sparcv9) 61 | #define CPU_SPARC 62 | #if defined(__sparcv9) 63 | #define CPU_SPARC64 64 | #endif 65 | #endif 66 | 67 | #if defined(powerpc) || defined(__PPC__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(POWERPC) || defined(_M_PPC) 68 | #define CPU_PPC 69 | #if defined(_ARCH_PWR7) 70 | #define CPU_POWER7 71 | #elif defined(__64BIT__) 72 | #define CPU_PPC64 73 | #else 74 | #define CPU_PPC32 75 | #endif 76 | #endif 77 | 78 | #if defined(__hppa__) || defined(__hppa) 79 | #define CPU_HPPA 80 | #endif 81 | 82 | #if defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) 83 | #define CPU_ALPHA 84 | #endif 85 | 86 | /* 64 bit cpu */ 87 | #if defined(CPU_X86_64) || defined(CPU_IA64) || defined(CPU_SPARC64) || defined(__64BIT__) || defined(__LP64__) || defined(_LP64) || (defined(_MIPS_SZLONG) && (_MIPS_SZLONG == 64)) 88 | #define CPU_64BITS 89 | #endif 90 | 91 | #if defined(COMPILER_MSVC) 92 | typedef signed char int8_t; 93 | typedef unsigned char uint8_t; 94 | typedef signed short int16_t; 95 | typedef unsigned short uint16_t; 96 | typedef signed int int32_t; 97 | typedef unsigned int uint32_t; 98 | typedef signed __int64 int64_t; 99 | typedef unsigned __int64 uint64_t; 100 | #else 101 | #include 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-donna.h: -------------------------------------------------------------------------------- 1 | /* 2 | Public domain by Andrew M. 3 | Modified from the amd64-51-30k implementation by 4 | Daniel J. Bernstein 5 | Niels Duif 6 | Tanja Lange 7 | Peter Schwabe 8 | Bo-Yin Yang 9 | */ 10 | 11 | 12 | #include "ed25519-donna-portable.h" 13 | 14 | #if defined(ED25519_SSE2) 15 | #else 16 | #if defined(HAVE_UINT128) && !defined(ED25519_FORCE_32BIT) 17 | #define ED25519_64BIT 18 | #else 19 | #define ED25519_32BIT 20 | #endif 21 | #endif 22 | 23 | #if !defined(ED25519_NO_INLINE_ASM) 24 | /* detect extra features first so un-needed functions can be disabled throughout */ 25 | #if defined(ED25519_SSE2) 26 | #if defined(COMPILER_GCC) && defined(CPU_X86) 27 | #define ED25519_GCC_32BIT_SSE_CHOOSE 28 | #elif defined(COMPILER_GCC) && defined(CPU_X86_64) 29 | #define ED25519_GCC_64BIT_SSE_CHOOSE 30 | #endif 31 | #else 32 | #if defined(CPU_X86_64) 33 | #if defined(COMPILER_GCC) 34 | #if defined(ED25519_64BIT) 35 | #define ED25519_GCC_64BIT_X86_CHOOSE 36 | #else 37 | #define ED25519_GCC_64BIT_32BIT_CHOOSE 38 | #endif 39 | #endif 40 | #endif 41 | #endif 42 | #endif 43 | 44 | #if defined(ED25519_SSE2) 45 | #include "curve25519-donna-sse2.h" 46 | #elif defined(ED25519_64BIT) 47 | #include "curve25519-donna-64bit.h" 48 | #else 49 | #include "curve25519-donna-32bit.h" 50 | #endif 51 | 52 | #include "curve25519-donna-helpers.h" 53 | 54 | /* separate uint128 check for 64 bit sse2 */ 55 | #if defined(HAVE_UINT128) && !defined(ED25519_FORCE_32BIT) 56 | #include "modm-donna-64bit.h" 57 | #else 58 | #include "modm-donna-32bit.h" 59 | #endif 60 | 61 | typedef unsigned char hash_512bits[64]; 62 | 63 | /* 64 | Timing safe memory compare 65 | */ 66 | static int 67 | ed25519_verify(const unsigned char *x, const unsigned char *y, size_t len) { 68 | size_t differentbits = 0; 69 | while (len--) 70 | differentbits |= (*x++ ^ *y++); 71 | return (int) (1 & ((differentbits - 1) >> 8)); 72 | } 73 | 74 | 75 | /* 76 | * Arithmetic on the twisted Edwards curve -x^2 + y^2 = 1 + dx^2y^2 77 | * with d = -(121665/121666) = 37095705934669439343138083508754565189542113879843219016388785533085940283555 78 | * Base point: (15112221349535400772501151409588531511454012693041857206046113283949847762202,46316835694926478169428394003475163141307993866256225615783033603165251855960); 79 | */ 80 | 81 | typedef struct ge25519_t { 82 | bignum25519 x, y, z, t; 83 | } ge25519; 84 | 85 | typedef struct ge25519_p1p1_t { 86 | bignum25519 x, y, z, t; 87 | } ge25519_p1p1; 88 | 89 | typedef struct ge25519_niels_t { 90 | bignum25519 ysubx, xaddy, t2d; 91 | } ge25519_niels; 92 | 93 | typedef struct ge25519_pniels_t { 94 | bignum25519 ysubx, xaddy, z, t2d; 95 | } ge25519_pniels; 96 | 97 | #include "ed25519-donna-basepoint-table.h" 98 | 99 | #if defined(ED25519_64BIT) 100 | #include "ed25519-donna-64bit-tables.h" 101 | #include "ed25519-donna-64bit-x86.h" 102 | #else 103 | #include "ed25519-donna-32bit-tables.h" 104 | #include "ed25519-donna-64bit-x86-32bit.h" 105 | #endif 106 | 107 | 108 | #if defined(ED25519_SSE2) 109 | #include "ed25519-donna-32bit-sse2.h" 110 | #include "ed25519-donna-64bit-sse2.h" 111 | #include "ed25519-donna-impl-sse2.h" 112 | #else 113 | #include "ed25519-donna-impl-base.h" 114 | #endif 115 | 116 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-hash-bcrypt.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct { 5 | BCRYPT_ALG_HANDLE algorithm; 6 | BCRYPT_HASH_HANDLE hash; 7 | PUCHAR pbBlock; 8 | ULONG cbBlock; 9 | } ed25519_hash_context; 10 | 11 | static void 12 | ed25519_hash_init(ed25519_hash_context *ctx) 13 | { 14 | ULONG junk; 15 | memset( ctx, 0, sizeof( ed25519_hash_context ) ); 16 | BCryptOpenAlgorithmProvider( &ctx->algorithm, BCRYPT_SHA512_ALGORITHM, NULL, 0 ); 17 | BCryptGetProperty( ctx->algorithm, BCRYPT_OBJECT_LENGTH, ( PUCHAR )&ctx->cbBlock, sizeof( ctx->cbBlock ), &junk, 0 ); 18 | ctx->pbBlock = HeapAlloc( GetProcessHeap(), 0, ctx->cbBlock ); 19 | BCryptCreateHash( ctx->algorithm, &ctx->hash, ctx->pbBlock, ctx->cbBlock, NULL, 0, 0 ); 20 | } 21 | 22 | static void 23 | ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen) 24 | { 25 | BCryptHashData( ctx->hash, (PUCHAR)in, (ULONG)inlen, 0 ); 26 | } 27 | 28 | static void 29 | ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash) 30 | { 31 | BCryptFinishHash( ctx->hash, hash, 64, 0 ); 32 | BCryptCloseAlgorithmProvider( ctx->algorithm, 0 ); 33 | HeapFree( GetProcessHeap(), 0, ctx->pbBlock ); 34 | memset(ctx, 0, sizeof(ed25519_hash_context)); 35 | } 36 | 37 | static void 38 | ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen) 39 | { 40 | ed25519_hash_context ctx; 41 | ed25519_hash_init(&ctx); 42 | ed25519_hash_update(&ctx, in, inlen); 43 | ed25519_hash_final(&ctx, hash); 44 | } 45 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-hash-custom.h: -------------------------------------------------------------------------------- 1 | /* 2 | a custom hash must have a 512bit digest and implement: 3 | 4 | struct ed25519_hash_context; 5 | 6 | void ed25519_hash_init(ed25519_hash_context *ctx); 7 | void ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen); 8 | void ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash); 9 | void ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen); 10 | */ 11 | 12 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-hash-openssl.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef SHA512_CTX ed25519_hash_context; 4 | 5 | static void 6 | ed25519_hash_init(ed25519_hash_context *ctx) { 7 | SHA512_Init(ctx); 8 | } 9 | 10 | static void 11 | ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen) { 12 | SHA512_Update(ctx, in, inlen); 13 | } 14 | 15 | static void 16 | ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash) { 17 | SHA512_Final(hash, ctx); 18 | } 19 | 20 | static void 21 | ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen) { 22 | SHA512(in, inlen, hash); 23 | } -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-hash.h: -------------------------------------------------------------------------------- 1 | #if defined(ED25519_REFHASH) 2 | #include "ed25519-hash-ref.h" 3 | #elif defined(ED25519_CUSTOMHASH) 4 | #include "ed25519-hash-custom.h" 5 | #elif defined(ED25519_HASH_BCRYPT) 6 | #include "ed25519-hash-bcrypt.h" 7 | #else 8 | #include "ed25519-hash-openssl.h" 9 | #endif 10 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-randombytes-custom.h: -------------------------------------------------------------------------------- 1 | /* 2 | a custom randombytes must implement: 3 | 4 | void ED25519_FN(ed25519_randombytes_unsafe) (void *p, size_t len); 5 | 6 | ed25519_randombytes_unsafe is used by the batch verification function 7 | to create random scalars 8 | */ 9 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519-randombytes.h: -------------------------------------------------------------------------------- 1 | #if defined(ED25519_TEST) 2 | /* 3 | ISAAC+ "variant", the paper is not clear on operator precedence and other 4 | things. This is the "first in, first out" option! 5 | 6 | Not threadsafe or securely initialized, only for deterministic testing 7 | */ 8 | typedef struct isaacp_state_t { 9 | uint32_t state[256]; 10 | unsigned char buffer[1024]; 11 | uint32_t a, b, c; 12 | size_t left; 13 | } isaacp_state; 14 | 15 | #define isaacp_step(offset, mix) \ 16 | x = mm[i + offset]; \ 17 | a = (a ^ (mix)) + (mm[(i + offset + 128) & 0xff]); \ 18 | y = (a ^ b) + mm[(x >> 2) & 0xff]; \ 19 | mm[i + offset] = y; \ 20 | b = (x + a) ^ mm[(y >> 10) & 0xff]; \ 21 | U32TO8_LE(out + (i + offset) * 4, b); 22 | 23 | static void 24 | isaacp_mix(isaacp_state *st) { 25 | uint32_t i, x, y; 26 | uint32_t a = st->a, b = st->b, c = st->c; 27 | uint32_t *mm = st->state; 28 | unsigned char *out = st->buffer; 29 | 30 | c = c + 1; 31 | b = b + c; 32 | 33 | for (i = 0; i < 256; i += 4) { 34 | isaacp_step(0, ROTL32(a,13)) 35 | isaacp_step(1, ROTR32(a, 6)) 36 | isaacp_step(2, ROTL32(a, 2)) 37 | isaacp_step(3, ROTR32(a,16)) 38 | } 39 | 40 | st->a = a; 41 | st->b = b; 42 | st->c = c; 43 | st->left = 1024; 44 | } 45 | 46 | static void 47 | isaacp_random(isaacp_state *st, void *p, size_t len) { 48 | size_t use; 49 | unsigned char *c = (unsigned char *)p; 50 | while (len) { 51 | use = (len > st->left) ? st->left : len; 52 | memcpy(c, st->buffer + (sizeof(st->buffer) - st->left), use); 53 | 54 | st->left -= use; 55 | c += use; 56 | len -= use; 57 | 58 | if (!st->left) 59 | isaacp_mix(st); 60 | } 61 | } 62 | 63 | void 64 | ED25519_FN(ed25519_randombytes_unsafe) (void *p, size_t len) { 65 | static int initialized = 0; 66 | static isaacp_state rng; 67 | 68 | if (!initialized) { 69 | memset(&rng, 0, sizeof(rng)); 70 | isaacp_mix(&rng); 71 | isaacp_mix(&rng); 72 | initialized = 1; 73 | } 74 | 75 | isaacp_random(&rng, p, len); 76 | } 77 | #elif defined(ED25519_CUSTOMRNG) 78 | 79 | #include "ed25519-randombytes-custom.h" 80 | 81 | #else 82 | 83 | #include 84 | 85 | void 86 | ED25519_FN(ed25519_randombytes_unsafe) (void *p, size_t len) { 87 | 88 | RAND_bytes(p, (int) len); 89 | 90 | } 91 | #endif 92 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519.c: -------------------------------------------------------------------------------- 1 | /* 2 | Public domain by Andrew M. 3 | 4 | Ed25519 reference implementation using Ed25519-donna 5 | */ 6 | 7 | 8 | /* define ED25519_SUFFIX to have it appended to the end of each public function */ 9 | #if !defined(ED25519_SUFFIX) 10 | #define ED25519_SUFFIX 11 | #endif 12 | 13 | #define ED25519_FN3(fn,suffix) fn##suffix 14 | #define ED25519_FN2(fn,suffix) ED25519_FN3(fn,suffix) 15 | #define ED25519_FN(fn) ED25519_FN2(fn,ED25519_SUFFIX) 16 | 17 | #include "ed25519-donna.h" 18 | #include "ed25519.h" 19 | #include "ed25519-randombytes.h" 20 | #include "ed25519-hash.h" 21 | 22 | /* 23 | Generates a (extsk[0..31]) and aExt (extsk[32..63]) 24 | */ 25 | 26 | DONNA_INLINE static void 27 | ed25519_extsk(hash_512bits extsk, const ed25519_secret_key sk) { 28 | ed25519_hash(extsk, sk, 32); 29 | extsk[0] &= 248; 30 | extsk[31] &= 127; 31 | extsk[31] |= 64; 32 | } 33 | 34 | static void 35 | ed25519_hram(hash_512bits hram, const ed25519_signature RS, const ed25519_public_key pk, const unsigned char *m, size_t mlen) { 36 | ed25519_hash_context ctx; 37 | ed25519_hash_init(&ctx); 38 | ed25519_hash_update(&ctx, RS, 32); 39 | ed25519_hash_update(&ctx, pk, 32); 40 | ed25519_hash_update(&ctx, m, mlen); 41 | ed25519_hash_final(&ctx, hram); 42 | } 43 | 44 | void 45 | ED25519_FN(ed25519_publickey) (const ed25519_secret_key sk, ed25519_public_key pk) { 46 | bignum256modm a; 47 | ge25519 ALIGN(16) A; 48 | hash_512bits extsk; 49 | 50 | /* A = aB */ 51 | ed25519_extsk(extsk, sk); 52 | expand256_modm(a, extsk, 32); 53 | ge25519_scalarmult_base_niels(&A, ge25519_niels_base_multiples, a); 54 | ge25519_pack(pk, &A); 55 | } 56 | 57 | 58 | void 59 | ED25519_FN(ed25519_sign) (const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS) { 60 | ed25519_hash_context ctx; 61 | bignum256modm r, S, a; 62 | ge25519 ALIGN(16) R; 63 | hash_512bits extsk, hashr, hram; 64 | 65 | ed25519_extsk(extsk, sk); 66 | 67 | /* r = H(aExt[32..64], m) */ 68 | ed25519_hash_init(&ctx); 69 | ed25519_hash_update(&ctx, extsk + 32, 32); 70 | ed25519_hash_update(&ctx, m, mlen); 71 | ed25519_hash_final(&ctx, hashr); 72 | expand256_modm(r, hashr, 64); 73 | 74 | /* R = rB */ 75 | ge25519_scalarmult_base_niels(&R, ge25519_niels_base_multiples, r); 76 | ge25519_pack(RS, &R); 77 | 78 | /* S = H(R,A,m).. */ 79 | ed25519_hram(hram, RS, pk, m, mlen); 80 | expand256_modm(S, hram, 64); 81 | 82 | /* S = H(R,A,m)a */ 83 | expand256_modm(a, extsk, 32); 84 | mul256_modm(S, S, a); 85 | 86 | /* S = (r + H(R,A,m)a) */ 87 | add256_modm(S, S, r); 88 | 89 | /* S = (r + H(R,A,m)a) mod L */ 90 | contract256_modm(RS + 32, S); 91 | } 92 | 93 | int 94 | ED25519_FN(ed25519_sign_open) (const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS) { 95 | ge25519 ALIGN(16) R, A; 96 | hash_512bits hash; 97 | bignum256modm hram, S; 98 | unsigned char checkR[32]; 99 | 100 | if ((RS[63] & 224) || !ge25519_unpack_negative_vartime(&A, pk)) 101 | return -1; 102 | 103 | /* hram = H(R,A,m) */ 104 | ed25519_hram(hash, RS, pk, m, mlen); 105 | expand256_modm(hram, hash, 64); 106 | 107 | /* S */ 108 | expand256_modm(S, RS + 32, 32); 109 | 110 | /* SB - H(R,A,m)A */ 111 | ge25519_double_scalarmult_vartime(&R, &A, hram, S); 112 | ge25519_pack(checkR, &R); 113 | 114 | /* check that R = SB - H(R,A,m)A */ 115 | return ed25519_verify(RS, checkR, 32) ? 0 : -1; 116 | } 117 | 118 | #include "ed25519-donna-batchverify.h" 119 | 120 | /* 121 | Fast Curve25519 basepoint scalar multiplication 122 | */ 123 | 124 | void 125 | ED25519_FN(curved25519_scalarmult_basepoint) (curved25519_key pk, const curved25519_key e) { 126 | curved25519_key ec; 127 | bignum256modm s; 128 | bignum25519 ALIGN(16) yplusz, zminusy; 129 | ge25519 ALIGN(16) p; 130 | size_t i; 131 | 132 | /* clamp */ 133 | for (i = 0; i < 32; i++) ec[i] = e[i]; 134 | ec[0] &= 248; 135 | ec[31] &= 127; 136 | ec[31] |= 64; 137 | 138 | expand_raw256_modm(s, ec); 139 | 140 | /* scalar * basepoint */ 141 | ge25519_scalarmult_base_niels(&p, ge25519_niels_base_multiples, s); 142 | 143 | /* u = (y + z) / (z - y) */ 144 | curve25519_add(yplusz, p.y, p.z); 145 | curve25519_sub(zminusy, p.z, p.y); 146 | curve25519_recip(zminusy, zminusy); 147 | curve25519_mul(yplusz, yplusz, zminusy); 148 | curve25519_contract(pk, yplusz); 149 | } 150 | 151 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519.h: -------------------------------------------------------------------------------- 1 | #ifndef ED25519_H 2 | #define ED25519_H 3 | 4 | #include 5 | 6 | typedef unsigned char ed25519_signature[64]; 7 | typedef unsigned char ed25519_public_key[32]; 8 | typedef unsigned char ed25519_secret_key[32]; 9 | 10 | typedef unsigned char curved25519_key[32]; 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | void ed25519_publickey(const ed25519_secret_key sk, ed25519_public_key pk); 17 | int ed25519_sign_open(const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS); 18 | void ed25519_sign(const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS); 19 | 20 | int ed25519_sign_open_batch(const unsigned char **m, size_t *mlen, const unsigned char **pk, const unsigned char **RS, size_t num, int *valid); 21 | 22 | void ed25519_randombytes_unsafe(void *out, size_t count); 23 | 24 | void curved25519_scalarmult_basepoint(curved25519_key pk, const curved25519_key e); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif // ED25519_H 31 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/ed25519_VALVE_sse2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValveSoftware/GameNetworkingSockets/725e273c7442bac7a8bc903c0b210b1c15c34d92/src/external/ed25519-donna/ed25519_VALVE_sse2.c -------------------------------------------------------------------------------- /src/external/ed25519-donna/fuzz/build-nix.php: -------------------------------------------------------------------------------- 1 | set = false; 46 | 47 | $map = array(); 48 | foreach($legal_values as $value) 49 | $map[$value] = true; 50 | 51 | for ($i = 1; $i < $argc; $i++) { 52 | if (!preg_match("!--".$flag."=(.*)!", $argv[$i], $m)) 53 | continue; 54 | if (isset($map[$m[1]])) { 55 | $this->value = $m[1]; 56 | $this->set = true; 57 | return; 58 | } else { 59 | usage("{$m[1]} is not a valid parameter to --{$flag}!"); 60 | exit(1); 61 | } 62 | } 63 | } 64 | } 65 | 66 | class flag extends argument { 67 | function flag($flag) { 68 | global $argc, $argv; 69 | 70 | $this->set = false; 71 | 72 | $flag = "--{$flag}"; 73 | for ($i = 1; $i < $argc; $i++) { 74 | if ($argv[$i] !== $flag) 75 | continue; 76 | $this->value = true; 77 | $this->set = true; 78 | return; 79 | } 80 | } 81 | } 82 | 83 | $bits = new multiargument("bits", array("32", "64")); 84 | $function = new multiargument("function", array("curve25519", "ed25519")); 85 | $compiler = new multiargument("compiler", array("gcc", "clang", "icc")); 86 | $with_sse2 = new flag("with-sse2"); 87 | $with_openssl = new flag("with-openssl"); 88 | $no_asm = new flag("no-asm"); 89 | 90 | $err = ""; 91 | if (!$bits->set) 92 | $err .= "--bits not set\n"; 93 | if (!$function->set) 94 | $err .= "--function not set\n"; 95 | 96 | if ($err !== "") { 97 | usage($err); 98 | exit; 99 | } 100 | 101 | $compile = ($compiler->set) ? $compiler->value : "gcc"; 102 | $link = ""; 103 | $flags = "-O3 -m{$bits->value}"; 104 | $ret = 0; 105 | 106 | if ($with_openssl->set) $link .= " -lssl -lcrypto"; 107 | if (!$with_openssl->set) $flags .= " -DED25519_REFHASH -DED25519_TEST"; 108 | if ($no_asm->set) $flags .= " -DED25519_NO_INLINE_ASM"; 109 | 110 | if ($function->value === "curve25519") { 111 | runcmd("building ref10..", "{$compile} {$flags} curve25519-ref10.c -c -o curve25519-ref10.o"); 112 | runcmd("building ed25519..", "{$compile} {$flags} ed25519-donna.c -c -o ed25519.o"); 113 | if ($with_sse2->set) { 114 | runcmd("building ed25519-sse2..", "{$compile} {$flags} ed25519-donna-sse2.c -c -o ed25519-sse2.o -msse2"); 115 | $flags .= " -DED25519_SSE2"; 116 | $link .= " ed25519-sse2.o"; 117 | } 118 | runcmd("linking..", "{$compile} {$flags} {$link} fuzz-curve25519.c ed25519.o curve25519-ref10.o -o fuzz-curve25519"); 119 | echoln("fuzz-curve25519 built."); 120 | } else if ($function->value === "ed25519") { 121 | runcmd("building ref10..", "{$compile} {$flags} ed25519-ref10.c -c -o ed25519-ref10.o"); 122 | runcmd("building ed25519..", "{$compile} {$flags} ed25519-donna.c -c -o ed25519.o"); 123 | if ($with_sse2->set) { 124 | runcmd("building ed25519-sse2..", "{$compile} {$flags} ed25519-donna-sse2.c -c -o ed25519-sse2.o -msse2"); 125 | $flags .= " -DED25519_SSE2"; 126 | $link .= " ed25519-sse2.o"; 127 | } 128 | runcmd("linking..", "{$compile} {$flags} {$link} fuzz-ed25519.c ed25519.o ed25519-ref10.o -o fuzz-ed25519"); 129 | echoln("fuzz-ed25519 built."); 130 | } 131 | 132 | 133 | cleanup(); 134 | ?> 135 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/fuzz/curve25519-ref10.h: -------------------------------------------------------------------------------- 1 | #ifndef CURVE25519_REF10_H 2 | #define CURVE25519_REF10_H 3 | 4 | int crypto_scalarmult_base_ref10(unsigned char *q,const unsigned char *n); 5 | int crypto_scalarmult_ref10(unsigned char *q, const unsigned char *n, const unsigned char *p); 6 | 7 | #endif /* CURVE25519_REF10_H */ 8 | 9 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/fuzz/ed25519-donna-sse2.c: -------------------------------------------------------------------------------- 1 | #define ED25519_SUFFIX _sse2 2 | #define ED25519_SSE2 3 | #include "../ed25519.c" 4 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/fuzz/ed25519-donna.c: -------------------------------------------------------------------------------- 1 | #include "../ed25519.c" 2 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/fuzz/ed25519-donna.h: -------------------------------------------------------------------------------- 1 | #ifndef ED25519_H 2 | #define ED25519_H 3 | 4 | #include 5 | 6 | typedef unsigned char ed25519_signature[64]; 7 | typedef unsigned char ed25519_public_key[32]; 8 | typedef unsigned char ed25519_secret_key[32]; 9 | 10 | typedef unsigned char curved25519_key[32]; 11 | 12 | void ed25519_publickey(const ed25519_secret_key sk, ed25519_public_key pk); 13 | int ed25519_sign_open(const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS); 14 | void ed25519_sign(const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS); 15 | 16 | int ed25519_sign_open_batch(const unsigned char **m, size_t *mlen, const unsigned char **pk, const unsigned char **RS, size_t num, int *valid); 17 | 18 | void ed25519_randombytes_unsafe(void *out, size_t count); 19 | 20 | void curved25519_scalarmult_basepoint(curved25519_key pk, const curved25519_key e); 21 | 22 | #if defined(ED25519_SSE2) 23 | void ed25519_publickey_sse2(const ed25519_secret_key sk, ed25519_public_key pk); 24 | int ed25519_sign_open_sse2(const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS); 25 | void ed25519_sign_sse2(const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS); 26 | 27 | int ed25519_sign_open_batch_sse2(const unsigned char **m, size_t *mlen, const unsigned char **pk, const unsigned char **RS, size_t num, int *valid); 28 | 29 | void ed25519_randombytes_unsafe_sse2(void *out, size_t count); 30 | 31 | void curved25519_scalarmult_basepoint_sse2(curved25519_key pk, const curved25519_key e); 32 | #endif 33 | 34 | #endif // ED25519_H 35 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/fuzz/ed25519-ref10.h: -------------------------------------------------------------------------------- 1 | #ifndef ED25519_REF10_H 2 | #define ED25519_REF10_H 3 | 4 | int crypto_sign_pk_ref10(unsigned char *pk,unsigned char *sk); 5 | int crypto_sign_ref10(unsigned char *sm,unsigned long long *smlen,const unsigned char *m,unsigned long long mlen,const unsigned char *sk); 6 | int crypto_sign_open_ref10(unsigned char *m,unsigned long long *mlen,const unsigned char *sm,unsigned long long smlen,const unsigned char *pk); 7 | 8 | #endif /* ED25519_REF10_H */ 9 | 10 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/fuzz/fuzz-curve25519.c: -------------------------------------------------------------------------------- 1 | #if defined(_WIN32) 2 | #include 3 | #include 4 | typedef unsigned int uint32_t; 5 | typedef unsigned __int64 uint64_t; 6 | #else 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include "ed25519-donna.h" 14 | #include "curve25519-ref10.h" 15 | 16 | static void 17 | print_diff(const char *desc, const unsigned char *a, const unsigned char *b, size_t len) { 18 | size_t p = 0; 19 | unsigned char diff; 20 | printf("%s diff:\n", desc); 21 | while (len--) { 22 | diff = *a++ ^ *b++; 23 | if (!diff) 24 | printf("____,"); 25 | else 26 | printf("0x%02x,", diff); 27 | if ((++p & 15) == 0) 28 | printf("\n"); 29 | } 30 | printf("\n\n"); 31 | } 32 | 33 | static void 34 | print_bytes(const char *desc, const unsigned char *bytes, size_t len) { 35 | size_t p = 0; 36 | printf("%s:\n", desc); 37 | while (len--) { 38 | printf("0x%02x,", *bytes++); 39 | if ((++p & 15) == 0) 40 | printf("\n"); 41 | } 42 | printf("\n\n"); 43 | } 44 | 45 | 46 | /* chacha20/12 prng */ 47 | void 48 | prng(unsigned char *out, size_t bytes) { 49 | static uint32_t state[16]; 50 | static int init = 0; 51 | uint32_t x[16], t; 52 | size_t i; 53 | 54 | if (!init) { 55 | #if defined(_WIN32) 56 | HCRYPTPROV csp; 57 | if (!CryptAcquireContext(&csp, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { 58 | printf("CryptAcquireContext failed\n"); 59 | exit(1); 60 | } 61 | if (!CryptGenRandom(csp, (DWORD)sizeof(state), (BYTE*)state)) { 62 | printf("CryptGenRandom failed\n"); 63 | exit(1); 64 | } 65 | CryptReleaseContext(csp, 0); 66 | #else 67 | FILE *f = NULL; 68 | f = fopen("/dev/urandom", "rb"); 69 | if (!f) { 70 | printf("failed to open /dev/urandom\n"); 71 | exit(1); 72 | } 73 | if (fread(state, sizeof(state), 1, f) != 1) { 74 | printf("read error on /dev/urandom\n"); 75 | exit(1); 76 | } 77 | #endif 78 | init = 1; 79 | } 80 | 81 | while (bytes) { 82 | for (i = 0; i < 16; i++) x[i] = state[i]; 83 | 84 | #define rotl32(x,k) ((x << k) | (x >> (32 - k))) 85 | #define quarter(a,b,c,d) \ 86 | x[a] += x[b]; t = x[d]^x[a]; x[d] = rotl32(t,16); \ 87 | x[c] += x[d]; t = x[b]^x[c]; x[b] = rotl32(t,12); \ 88 | x[a] += x[b]; t = x[d]^x[a]; x[d] = rotl32(t, 8); \ 89 | x[c] += x[d]; t = x[b]^x[c]; x[b] = rotl32(t, 7); 90 | 91 | for (i = 0; i < 12; i += 2) { 92 | quarter( 0, 4, 8,12) 93 | quarter( 1, 5, 9,13) 94 | quarter( 2, 6,10,14) 95 | quarter( 3, 7,11,15) 96 | quarter( 0, 5,10,15) 97 | quarter( 1, 6,11,12) 98 | quarter( 2, 7, 8,13) 99 | quarter( 3, 4, 9,14) 100 | }; 101 | 102 | if (bytes <= 64) { 103 | memcpy(out, x, bytes); 104 | bytes = 0; 105 | } else { 106 | memcpy(out, x, 64); 107 | bytes -= 64; 108 | out += 64; 109 | } 110 | 111 | /* don't need a nonce, so last 4 words are the counter. 2^136 bytes can be generated */ 112 | if (!++state[12]) if (!++state[13]) if (!++state[14]) ++state[15]; 113 | } 114 | } 115 | 116 | 117 | 118 | int main() { 119 | const size_t skmax = 1024; 120 | static unsigned char sk[1024][32]; 121 | unsigned char pk[3][32]; 122 | unsigned char *skp; 123 | size_t ski, pki, i; 124 | uint64_t ctr; 125 | 126 | printf("fuzzing: "); 127 | printf(" ref10"); 128 | printf(" curved25519"); 129 | #if defined(ED25519_SSE2) 130 | printf(" curved25519-sse2"); 131 | #endif 132 | printf("\n\n"); 133 | 134 | for (ctr = 0, ski = skmax;;ctr++) { 135 | if (ski == skmax) { 136 | prng((unsigned char *)sk, sizeof(sk)); 137 | ski = 0; 138 | } 139 | skp = sk[ski++]; 140 | 141 | pki = 0; 142 | crypto_scalarmult_base_ref10(pk[pki++], skp); 143 | curved25519_scalarmult_basepoint(pk[pki++], skp); 144 | #if defined(ED25519_SSE2) 145 | curved25519_scalarmult_basepoint_sse2(pk[pki++], skp); 146 | #endif 147 | 148 | for (i = 1; i < pki; i++) { 149 | if (memcmp(pk[0], pk[i], 32) != 0) { 150 | printf("\n\n"); 151 | print_bytes("sk", skp, 32); 152 | print_bytes("ref10", pk[0], 32); 153 | print_diff("curved25519", pk[0], pk[1], 32); 154 | #if defined(ED25519_SSE2) 155 | print_diff("curved25519-sse2", pk[0], pk[2], 32); 156 | #endif 157 | exit(1); 158 | } 159 | } 160 | 161 | if (ctr && (ctr % 0x1000 == 0)) { 162 | printf("."); 163 | if ((ctr % 0x20000) == 0) { 164 | printf(" ["); 165 | for (i = 0; i < 8; i++) 166 | printf("%02x", (unsigned char)(ctr >> ((7 - i) * 8))); 167 | printf("]\n"); 168 | } 169 | } 170 | } 171 | } 172 | 173 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/readme_VALVE.txt: -------------------------------------------------------------------------------- 1 | ed25519-donna is an implementation of the Ed25519 public-key signature algorithm by Dan J Bernstein. 2 | 3 | Ed25519 is a 256-bit strength elliptical curve with 32-byte secret/public keys and 64-byte signatures. 4 | 5 | It is very fast, easy to implement securely in software, and fully public-domain. 6 | 7 | 8 | Downloaded 12/12/2013 from https://github.com/floodyberry/ed25519-donna 9 | 10 | 11 | 12 | Filenames containing VALVE are *not* entirely public domain - see individual files for details. 13 | -------------------------------------------------------------------------------- /src/external/ed25519-donna/test-ticks.h: -------------------------------------------------------------------------------- 1 | #include "ed25519-donna-portable-identify.h" 2 | 3 | /* ticks - not tested on anything other than x86 */ 4 | static uint64_t 5 | get_ticks(void) { 6 | #if defined(CPU_X86) || defined(CPU_X86_64) 7 | #if defined(COMPILER_INTEL) 8 | return _rdtsc(); 9 | #elif defined(COMPILER_MSVC) 10 | return __rdtsc(); 11 | #elif defined(COMPILER_GCC) 12 | uint32_t lo, hi; 13 | __asm__ __volatile__("rdtsc" : "=a" (lo), "=d" (hi)); 14 | return ((uint64_t)lo | ((uint64_t)hi << 32)); 15 | #else 16 | need rdtsc for this compiler 17 | #endif 18 | #elif defined(OS_SOLARIS) 19 | return (uint64_t)gethrtime(); 20 | #elif defined(CPU_SPARC) && !defined(OS_OPENBSD) 21 | uint64_t t; 22 | __asm__ __volatile__("rd %%tick, %0" : "=r" (t)); 23 | return t; 24 | #elif defined(CPU_PPC) 25 | uint32_t lo = 0, hi = 0; 26 | __asm__ __volatile__("mftbu %0; mftb %1" : "=r" (hi), "=r" (lo)); 27 | return ((uint64_t)lo | ((uint64_t)hi << 32)); 28 | #elif defined(CPU_IA64) 29 | uint64_t t; 30 | __asm__ __volatile__("mov %0=ar.itc" : "=r" (t)); 31 | return t; 32 | #elif defined(OS_NIX) 33 | timeval t2; 34 | gettimeofday(&t2, NULL); 35 | t = ((uint64_t)t2.tv_usec << 32) | (uint64_t)t2.tv_sec; 36 | return t; 37 | #else 38 | need ticks for this platform 39 | #endif 40 | } 41 | 42 | #define timeit(x,minvar) \ 43 | ticks = get_ticks(); \ 44 | x; \ 45 | ticks = get_ticks() - ticks; \ 46 | if (ticks < minvar) \ 47 | minvar = ticks; 48 | 49 | #define maxticks 0xffffffffffffffffull 50 | 51 | -------------------------------------------------------------------------------- /src/external/sha1-wpa/README: -------------------------------------------------------------------------------- 1 | wpa_supplicant and hostapd 2 | -------------------------- 3 | 4 | Copyright (c) 2002-2012, Jouni Malinen and contributors 5 | All Rights Reserved. 6 | 7 | These programs are licensed under the BSD license (the one with 8 | advertisement clause removed). 9 | 10 | If you are submitting changes to the project, please see CONTRIBUTIONS 11 | file for more instructions. 12 | 13 | 14 | This package may include either wpa_supplicant, hostapd, or both. See 15 | README file respective subdirectories (wpa_supplicant/README or 16 | hostapd/README) for more details. 17 | 18 | Source code files were moved around in v0.6.x releases and compared to 19 | earlier releases, the programs are now built by first going to a 20 | subdirectory (wpa_supplicant or hostapd) and creating build 21 | configuration (.config) and running 'make' there (for Linux/BSD/cygwin 22 | builds). 23 | 24 | 25 | License 26 | ------- 27 | 28 | This software may be distributed, used, and modified under the terms of 29 | BSD license: 30 | 31 | Redistribution and use in source and binary forms, with or without 32 | modification, are permitted provided that the following conditions are 33 | met: 34 | 35 | 1. Redistributions of source code must retain the above copyright 36 | notice, this list of conditions and the following disclaimer. 37 | 38 | 2. Redistributions in binary form must reproduce the above copyright 39 | notice, this list of conditions and the following disclaimer in the 40 | documentation and/or other materials provided with the distribution. 41 | 42 | 3. Neither the name(s) of the above-listed copyright holder(s) nor the 43 | names of its contributors may be used to endorse or promote products 44 | derived from this software without specific prior written permission. 45 | 46 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 47 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 48 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 49 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 50 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 51 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 52 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 53 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 54 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 55 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | -------------------------------------------------------------------------------- /src/external/sha1-wpa/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SHA1 hash implementation and interface functions 3 | * Copyright (c) 2003-2005, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #include "sha1.h" 10 | 11 | /** 12 | * hmac_sha1_vector - HMAC-SHA1 over data vector (RFC 2104) 13 | * @key: Key for HMAC operations 14 | * @key_len: Length of the key in bytes 15 | * @num_elem: Number of elements in the data vector 16 | * @addr: Pointers to the data areas 17 | * @len: Lengths of the data blocks 18 | * @mac: Buffer for the hash (20 bytes) 19 | * Returns: 0 on success, -1 on failure 20 | */ 21 | int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem, 22 | const u8 *addr[], const size_t *len, u8 *mac) 23 | { 24 | unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */ 25 | unsigned char tk[20]; 26 | const u8 *_addr[6]; 27 | size_t _len[6], i; 28 | 29 | if (num_elem > 5) { 30 | /* 31 | * Fixed limit on the number of fragments to avoid having to 32 | * allocate memory (which could fail). 33 | */ 34 | return -1; 35 | } 36 | 37 | /* if key is longer than 64 bytes reset it to key = SHA1(key) */ 38 | if (key_len > 64) { 39 | if (sha1_vector(1, &key, &key_len, tk)) 40 | return -1; 41 | key = tk; 42 | key_len = 20; 43 | } 44 | 45 | /* the HMAC_SHA1 transform looks like: 46 | * 47 | * SHA1(K XOR opad, SHA1(K XOR ipad, text)) 48 | * 49 | * where K is an n byte key 50 | * ipad is the byte 0x36 repeated 64 times 51 | * opad is the byte 0x5c repeated 64 times 52 | * and text is the data being protected */ 53 | 54 | /* start out by storing key in ipad */ 55 | os_memset(k_pad, 0, sizeof(k_pad)); 56 | os_memcpy(k_pad, key, key_len); 57 | /* XOR key with ipad values */ 58 | for (i = 0; i < 64; i++) 59 | k_pad[i] ^= 0x36; 60 | 61 | /* perform inner SHA1 */ 62 | _addr[0] = k_pad; 63 | _len[0] = 64; 64 | for (i = 0; i < num_elem; i++) { 65 | _addr[i + 1] = addr[i]; 66 | _len[i + 1] = len[i]; 67 | } 68 | if (sha1_vector(1 + num_elem, _addr, _len, mac)) 69 | return -1; 70 | 71 | os_memset(k_pad, 0, sizeof(k_pad)); 72 | os_memcpy(k_pad, key, key_len); 73 | /* XOR key with opad values */ 74 | for (i = 0; i < 64; i++) 75 | k_pad[i] ^= 0x5c; 76 | 77 | /* perform outer SHA1 */ 78 | _addr[0] = k_pad; 79 | _len[0] = 64; 80 | _addr[1] = mac; 81 | _len[1] = SHA1_MAC_LEN; 82 | return sha1_vector(2, _addr, _len, mac); 83 | } 84 | 85 | 86 | /** 87 | * hmac_sha1 - HMAC-SHA1 over data buffer (RFC 2104) 88 | * @key: Key for HMAC operations 89 | * @key_len: Length of the key in bytes 90 | * @data: Pointers to the data area 91 | * @data_len: Length of the data area 92 | * @mac: Buffer for the hash (20 bytes) 93 | * Returns: 0 on success, -1 of failure 94 | */ 95 | int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len, 96 | u8 *mac) 97 | { 98 | return hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac); 99 | } 100 | -------------------------------------------------------------------------------- /src/external/sha1-wpa/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SHA1 hash implementation and interface functions 3 | * Copyright (c) 2003-2009, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #ifndef SHA1_H 10 | #define SHA1_H 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #define os_memcpy memcpy 17 | #define os_memset memset 18 | 19 | #define SHA1_MAC_LEN 20 20 | 21 | typedef uint8_t u8; 22 | typedef uint32_t u32; 23 | 24 | 25 | int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem, 26 | const u8 *addr[], const size_t *len, u8 *mac); 27 | int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len, 28 | u8 *mac); 29 | 30 | /** 31 | * sha1_vector - SHA-1 hash for data vector 32 | * @num_elem: Number of elements in the data vector 33 | * @addr: Pointers to the data areas 34 | * @len: Lengths of the data blocks 35 | * @mac: Buffer for the hash 36 | * Returns: 0 on success, -1 on failure 37 | */ 38 | int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, 39 | u8 *mac); 40 | 41 | #endif /* SHA1_H */ 42 | -------------------------------------------------------------------------------- /src/external/sha1-wpa/sha1_i.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SHA1 internal definitions 3 | * Copyright (c) 2003-2005, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #ifndef SHA1_I_H 10 | #define SHA1_I_H 11 | 12 | struct SHA1Context { 13 | u32 state[5]; 14 | u32 count[2]; 15 | unsigned char buffer[64]; 16 | }; 17 | 18 | void SHA1Init(struct SHA1Context *context); 19 | void SHA1Update(struct SHA1Context *context, const void *data, u32 len); 20 | void SHA1Final(unsigned char digest[20], struct SHA1Context *context); 21 | void SHA1Transform(u32 state[5], const unsigned char buffer[64]); 22 | 23 | #endif /* SHA1_I_H */ 24 | -------------------------------------------------------------------------------- /src/external/steamwebrtc/ice_session.h: -------------------------------------------------------------------------------- 1 | //===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== 2 | // 3 | // Simplified interface to a ICE session 4 | // 5 | // This wrapper is designed to provide the ICE peer connection functionality in a separate 6 | // shared library to encapsulate the build environment and C++ runtime requirements of WebRTC. 7 | // 8 | //================================================================================================== 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | // Yes, this is janky 15 | #include "../../steamnetworkingsockets/clientlib/ice_client_types.h" 16 | 17 | //----------------------------------------------------------------------------- 18 | // Increment this if the delegate classes below change interfaces 19 | //----------------------------------------------------------------------------- 20 | #define ICESESSION_INTERFACE_VERSION 3 21 | 22 | 23 | /// You implement this class, which will receive callbacks frim the ICE session 24 | class IICESessionDelegate 25 | { 26 | public: 27 | enum ELogPriority 28 | { 29 | k_ELogPriorityDebug, 30 | k_ELogPriorityVerbose, 31 | k_ELogPriorityInfo, 32 | k_ELogPriorityWarning, 33 | k_ELogPriorityError 34 | }; 35 | 36 | public: 37 | virtual void Log( ELogPriority ePriority, const char *pszMessageFormat, ... ) = 0; 38 | 39 | // 40 | // Callbacks that happen during operation 41 | // 42 | 43 | // Called when a local ICE candidate becomes available 44 | virtual void OnLocalCandidateGathered( EICECandidateType eType, const char *pszCandidate ) { } 45 | 46 | // Called when the writable state changes. 47 | // Use IICESession::IsWritable to get current state, and IICESession::GetPing for a RTT estimate 48 | virtual void OnWritableStateChanged() { } 49 | 50 | // Called when data is received on the data channel 51 | virtual void OnData( const void *pData, size_t nSize ) { } 52 | 53 | // Called when the route has changed. Use GetRoute to get more info 54 | virtual void OnRouteChanged() { } 55 | }; 56 | 57 | /// An ICE session with a peer 58 | class IICESession 59 | { 60 | public: 61 | virtual void Destroy() = 0; 62 | 63 | /// Return true if it looks like we are connected and we think you could send data 64 | virtual bool GetWritableState() = 0; 65 | 66 | /// Get RTT estimate, in ms. Returns -1 if we don't know 67 | virtual int GetPing() = 0; 68 | 69 | /// Return the route being used. 70 | typedef char CandidateAddressString[64]; 71 | virtual bool GetRoute( EICECandidateType &eLocalCandidate, EICECandidateType &eRemoteCandidate, CandidateAddressString &szRemoteAddress ) = 0; 72 | 73 | /// Set credentials of the peer 74 | virtual void SetRemoteAuth( const char *pszUserFrag, const char *pszPwd ) = 0; 75 | 76 | /// Called when we get a signal with a candidate of the other guy, 77 | /// Returns the type of the candidate, or k_EICECandidate_Invalid if we failed 78 | virtual EICECandidateType AddRemoteIceCandidate( const char *pszCandidate ) = 0; 79 | 80 | /// Send a datagram to the peer. Returns false if we know that we failed 81 | virtual bool BSendData( const void *pData, size_t nSize ) = 0; 82 | 83 | // !TEST! ETW callbacks 84 | virtual void SetWriteEvent_setsockopt( void (*fn)( int slevel, int sopt, int value ) ) = 0; 85 | virtual void SetWriteEvent_send( void (*fn)( int length ) ) = 0; 86 | virtual void SetWriteEvent_sendto( void (*fn)( void *addr, int length ) ) = 0; 87 | }; 88 | 89 | /// Factory function prototype. How you get this factory will depend on how you are linking with 90 | /// this code. 91 | typedef IICESession *( *CreateICESession_t )( const ICESessionConfig &cfg, IICESessionDelegate *pDelegate, int nInterfaceVersion ); 92 | -------------------------------------------------------------------------------- /src/external/steamwebrtc/steamwebrtc_internal.h: -------------------------------------------------------------------------------- 1 | //===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== 2 | #pragma once 3 | 4 | #if defined(STEAMWEBRTC_USE_STATIC_LIBS) 5 | # define STEAMWEBRTC_DECLSPEC 6 | #else 7 | # if defined(_WIN32) 8 | # define STEAMWEBRTC_DECLSPEC __declspec(dllexport) 9 | # else 10 | # if defined(__GNUC__) && __GNUC__ >= 4 11 | # define STEAMWEBRTC_DECLSPEC __attribute__ ((visibility("default"))) 12 | # else 13 | # define STEAMWEBRTC_DECLSPEC 14 | # endif 15 | # endif 16 | #endif 17 | 18 | #ifdef WIN32 19 | # define WEBRTC_WIN 1 20 | #elif __linux__ 21 | # define WEBRTC_LINUX 1 22 | # define WEBRTC_POSIX 1 23 | #elif __APPLE__ 24 | # include "TargetConditionals.h" 25 | # if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR 26 | # define WEBRTC_MAC 1 27 | # elif TARGET_OS_IPHONE 28 | # define WEBRTC_MAC 1 29 | # else 30 | # define WEBRTC_MAC 1 31 | # endif 32 | #endif 33 | -------------------------------------------------------------------------------- /src/public/minbase/minbase_limits.h: -------------------------------------------------------------------------------- 1 | //====== Copyright 1996-2012, Valve Corporation, All rights reserved. ======// 2 | // 3 | // Limit values for portable types. 4 | // 5 | //==========================================================================// 6 | 7 | #ifndef MINBASE_LIMITS_H 8 | #define MINBASE_LIMITS_H 9 | #pragma once 10 | 11 | // Identification is needed everywhere but we don't want to include 12 | // it over and over again so just make sure it was already included. 13 | #ifndef MINBASE_IDENTIFY_H 14 | #error Must include minbase_identify.h 15 | #endif 16 | 17 | // Avoid collisions with other people including the regular CRT limits.h. 18 | #ifdef _MSC_VER 19 | #include 20 | #if _MSC_VER >= 1800 // VS 2013 21 | // Avoid collisions with other people including the regular CRT stdint.h. 22 | #include 23 | #endif 24 | #endif 25 | 26 | #undef INT8_MAX 27 | #undef INT8_MIN 28 | #define INT8_MAX ((int8)0x7f) 29 | #define INT8_MIN ((int8)0x80) 30 | 31 | #undef UINT8_MAX 32 | #define UINT8_MAX ((uint8)0xff) 33 | 34 | #undef INT16_MAX 35 | #undef INT16_MIN 36 | #define INT16_MAX ((int16)0x7fff) 37 | #define INT16_MIN ((int16)0x8000) 38 | 39 | #undef UINT16_MAX 40 | #define UINT16_MAX ((uint16)0xffff) 41 | 42 | #undef INT32_MAX 43 | #undef INT32_MIN 44 | #define INT32_MAX ((int32)0x7fffffff) 45 | #define INT32_MIN ((int32)0x80000000) 46 | 47 | #undef UINT32_MAX 48 | #define UINT32_MAX ((uint32)0xffffffff) 49 | 50 | #undef INT64_MAX 51 | #undef INT64_MIN 52 | #define INT64_MAX ((int64)0x7fffffffffffffff) 53 | #define INT64_MIN ((int64)0x8000000000000000) 54 | 55 | #undef UINT64_MAX 56 | #define UINT64_MAX ((uint64)0xffffffffffffffff) 57 | 58 | #undef SIZE_MAX 59 | #if defined(PLATFORM_64BITS) 60 | #define SIZE_MAX ((size_t)UINT64_MAX) 61 | #else 62 | #define SIZE_MAX ((size_t)UINT32_MAX) 63 | #endif 64 | 65 | #undef UINT_MAX 66 | #define UINT_MAX ((uint)-1) 67 | 68 | #endif // #ifndef MINBASE_LIMITS_H 69 | -------------------------------------------------------------------------------- /src/public/minbase/minbase_securezeromemory_impl.h: -------------------------------------------------------------------------------- 1 | //======== Copyright 2013, Valve Corporation, All rights reserved. ============// 2 | // 3 | // Purpose: Implementation of SecureZeroMemory for platforms that don't have one. 4 | // 5 | // $NoKeywords: $ 6 | // 7 | //=============================================================================// 8 | 9 | #ifndef SECUREZEROMEMORY_H 10 | #define SECUREZEROMEMORY_H 11 | #pragma once 12 | 13 | #if !defined(SecureZeroMemory) 14 | inline void SecureZeroMemory( void* pMemory, size_t nBytes ) 15 | { 16 | // The intent of this routine is to avoid being optimized away 17 | // by a compiler that sees that the buffer is no longer used, 18 | // so cast to volatile to indicate we want the accesses to occur. 19 | volatile unsigned char *pMem = (volatile unsigned char *)pMemory; 20 | while ( nBytes > 0 ) 21 | { 22 | *pMem++ = 0; 23 | nBytes--; 24 | } 25 | } 26 | #endif 27 | 28 | #endif /* SECUREZEROMEMORY_H */ 29 | -------------------------------------------------------------------------------- /src/public/minbase/minbase_types.h: -------------------------------------------------------------------------------- 1 | //====== Copyright 1996-2012, Valve Corporation, All rights reserved. ======// 2 | // 3 | // Portable type definitions. 4 | // 5 | //==========================================================================// 6 | 7 | #ifndef MINBASE_TYPES_H 8 | #define MINBASE_TYPES_H 9 | #pragma once 10 | 11 | // Identification is needed everywhere but we don't want to include 12 | // it over and over again so just make sure it was already included. 13 | #ifndef MINBASE_IDENTIFY_H 14 | #error Must include minbase_identify.h 15 | #endif 16 | 17 | typedef unsigned char uint8; 18 | typedef signed char int8; 19 | 20 | // for when we don't care about how many bits we use 21 | typedef unsigned int uint; 22 | 23 | typedef float float32; 24 | typedef double float64; 25 | 26 | #if defined( _WIN32 ) && !defined(__GNUC__) 27 | 28 | typedef __int16 int16; 29 | typedef unsigned __int16 uint16; 30 | typedef __int32 int32; 31 | typedef unsigned __int32 uint32; 32 | typedef __int64 int64; 33 | typedef unsigned __int64 uint64; 34 | 35 | typedef int socklen_t; 36 | 37 | #else // _WIN32 38 | 39 | typedef short int16; 40 | typedef unsigned short uint16; 41 | typedef int int32; 42 | typedef unsigned int uint32; 43 | // NOTE: We always use 'long long int' for 64-bit integers 44 | // even though that is not always the system definition. 45 | // For example, gcc 64-bit uses 'long int', which is a distinct 46 | // type even though it's also a 64-bit integer. 47 | // Always using 'long long int' makes life simpler for us because 48 | // 'll' number suffixes and format string directives always match 49 | // the number type, but be aware that our int64 may not always 50 | // be the same type as the system int64_t. There are typedefs 51 | // below to handle that and ideally you should never have to think about it. 52 | typedef long long int int64; 53 | typedef unsigned long long int uint64; 54 | 55 | #endif // else _WIN32 56 | 57 | #ifdef PLATFORM_64BITS 58 | typedef int64 intp; 59 | typedef uint64 uintp; 60 | #else 61 | typedef int intp; 62 | typedef uint uintp; 63 | #endif 64 | 65 | // We include code that uses the stdint.h types so define 66 | // them also to make it easier to use such code without 67 | // actually including stdint.h (which can get messy because of 68 | // different MIN/MAX definitions). 69 | typedef int8 int8_t; 70 | typedef uint8 uint8_t; 71 | typedef int16 int16_t; 72 | typedef uint16 uint16_t; 73 | typedef int32 int32_t; 74 | typedef uint32 uint32_t; 75 | // NOTE: int64_t must match the compiler stdint.h definition 76 | // and so may not match the Steam int64. Mixing the two is 77 | // error-prone so always use the Steam non-_t types in Steam code. 78 | #if defined(COMPILER_GCC) && defined(PLATFORM_64BITS) && !defined(__MINGW32__) && !IsOSX() && !(defined(IOS) || defined(TVOS)) 79 | #define INT64_DIFFERENT_FROM_INT64_T 1 80 | typedef long int int64_t; 81 | typedef unsigned long int uint64_t; 82 | #else 83 | typedef int64 int64_t; 84 | typedef uint64 uint64_t; 85 | #endif 86 | 87 | #endif // #ifndef MINBASE_TYPES_H 88 | -------------------------------------------------------------------------------- /src/public/minbase/minbase_warnings.h: -------------------------------------------------------------------------------- 1 | //====== Copyright 1996-2012, Valve Corporation, All rights reserved. ======// 2 | // 3 | // Enable and disable specific warnings. 4 | // 5 | //==========================================================================// 6 | 7 | #ifndef MINBASE_WARNINGS_H 8 | #define MINBASE_WARNINGS_H 9 | #pragma once 10 | 11 | // Identification is needed everywhere but we don't want to include 12 | // it over and over again so just make sure it was already included. 13 | #ifndef MINBASE_IDENTIFY_H 14 | #error Must include minbase_identify.h 15 | #endif 16 | 17 | #if defined( COMPILER_GCC ) 18 | 19 | // disable warning: comparing floating point with == or != is unsafe [-Wfloat-equal] 20 | #pragma GCC diagnostic ignored "-Wfloat-equal" 21 | // disable warning: enumeration value 'kMouseRestoreNone' not handled in switch [-Wswitch] 22 | #pragma GCC diagnostic ignored "-Wswitch" 23 | // disable warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] 24 | #pragma GCC diagnostic ignored "-Wwrite-strings" 25 | 26 | #if __GNUC__ >= 4 && __GNUC_MINOR__ > 2 27 | // disable warning: type qualifiers ignored on function return type [-Wignored-qualifiers] 28 | #pragma GCC diagnostic ignored "-Wignored-qualifiers" 29 | // disable warning: warning: comparison is always true due to limited range of data type [-Wtype-limits] 30 | #pragma GCC diagnostic ignored "-Wtype-limits" 31 | #endif 32 | 33 | #if defined( __PROSPERO__ ) || defined( __ORBIS__ ) /* This is the wrong way to detect this. HALP */ 34 | #pragma GCC diagnostic ignored "-Wunused-function" 35 | #pragma GCC diagnostic ignored "-Wreorder-ctor" 36 | #endif 37 | 38 | #endif // #if defined( COMPILER_GCC ) 39 | 40 | #if defined( COMPILER_SNC ) 41 | 42 | #pragma diag_suppress=1700 // warning 1700: class "%s" has virtual functions but non-virtual destructor 43 | #pragma diag_suppress=187 // warning 187: pointless comparison of unsigned integer with zero 44 | 45 | #endif // #if defined( COMPILER_SNC ) 46 | 47 | #if defined( COMPILER_MSVC32 ) 48 | 49 | // Remove warnings from warning level 4. 50 | #pragma warning(disable : 4514) // warning C4514: 'acosl' : unreferenced inline function has been removed 51 | #pragma warning(disable : 4100) // warning C4100: 'hwnd' : unreferenced formal parameter 52 | #pragma warning(disable : 4127) // warning C4127: conditional expression is constant 53 | #pragma warning(disable : 4512) // warning C4512: 'InFileRIFF' : assignment operator could not be generated 54 | #pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable 55 | #pragma warning(disable : 4710) // warning C4710: function 'x' not inlined 56 | #pragma warning(disable : 4505) // unreferenced local function has been removed 57 | #pragma warning(disable : 4239) // nonstandard extension used : 'argument' ( conversion from class Vector to class Vector& ) 58 | #pragma warning(disable : 4097) // typedef-name 'BaseClass' used as synonym for class-name 'CFlexCycler::CBaseFlex' 59 | #pragma warning(disable : 4324) // Padding was added at the end of a structure 60 | #pragma warning(disable : 4244) // type conversion warning. 61 | #pragma warning(disable : 4786) // Disable warnings about long symbol names 62 | #pragma warning(disable : 4250) // 'X' : inherits 'Y::Z' via dominance 63 | #pragma warning(disable : 4748) // warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 64 | 65 | #if _MSC_VER >= 1300 66 | #pragma warning(disable : 4511) // Disable warnings about private copy constructors 67 | #pragma warning(disable : 4121) // warning C4121: 'symbol' : alignment of a member was sensitive to packing 68 | #pragma warning(disable : 4530) // warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc (disabled due to std headers having exception syntax) 69 | #endif 70 | 71 | // When we port to 64 bit, we'll have to resolve the int, ptr vs size_t 32/64 bit problems... 72 | #if !defined( _WIN64 ) 73 | #pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data 74 | #pragma warning( disable : 4311 ) // pointer truncation from 'char *' to 'int' 75 | #pragma warning( disable : 4312 ) // conversion from 'unsigned int' to 'memhandle_t' of greater size 76 | #endif 77 | 78 | #if _MSC_VER >= 1600 // VS 2010 and above. 79 | //----------------------------------------------------------------------------- 80 | // Upgrading important helpful warnings to errors 81 | //----------------------------------------------------------------------------- 82 | #pragma warning(error : 4789 ) // warning C4789: destination of memory copy is too small 83 | #endif // _MSC_VER >= 1600 // VS 2010 and above. 84 | 85 | #endif // #if defined( COMPILER_MSVC32 ) 86 | 87 | #endif // #ifndef MINBASE_WARNINGS_H 88 | -------------------------------------------------------------------------------- /src/public/tier0/memdbgoff.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValveSoftware/GameNetworkingSockets/725e273c7442bac7a8bc903c0b210b1c15c34d92/src/public/tier0/memdbgoff.h -------------------------------------------------------------------------------- /src/public/tier0/memdbgon.h: -------------------------------------------------------------------------------- 1 | //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============// 2 | 3 | // This file should be included before any code that calls malloc, free, and realloc, 4 | // so that those calls will be redirected to the custom allocator, if 5 | // STEAMNETWORKINGSOCKETS_ENABLE_MEM_OVERRIDE is defined. 6 | 7 | #if defined(STEAMNETWORKINGSOCKETS_ENABLE_MEM_OVERRIDE) && !defined(MEM_OVERRIDE_ON) 8 | #define MEM_OVERRIDE_ON 9 | 10 | #define malloc( s ) SteamNetworkingSockets_Malloc( s ) 11 | #define realloc( p, s ) SteamNetworkingSockets_Realloc( p, s ) 12 | #define free( p ) SteamNetworkingSockets_Free( p ) 13 | 14 | #define calloc DO_NOT_USE_CALLOC 15 | #define strdup DO_NOT_USE_STRDUP 16 | #endif // #ifdef STEAMNETWORKINGSOCKETS_ENABLE_MEM_OVERRIDE 17 | 18 | // One-time declarations 19 | #ifndef MEMDBG_ON_INCLUDED 20 | #define MEMDBG_ON_INCLUDED 21 | 22 | #ifdef STEAMNETWORKINGSOCKETS_ENABLE_MEM_OVERRIDE 23 | extern void *SteamNetworkingSockets_Malloc( size_t s ); 24 | extern void *SteamNetworkingSockets_Realloc( void *p, size_t s ); 25 | extern void SteamNetworkingSockets_Free( void *p ); 26 | #endif 27 | #endif 28 | 29 | // Misc Steam codebase compatibility stuff. Not used in the standalone library 30 | #ifndef PvAlloc 31 | #define PvAlloc( cub ) malloc( cub ) 32 | #endif 33 | #ifndef PvRealloc 34 | #define PvRealloc( pv, cub ) realloc( pv, cub ) 35 | #endif 36 | #ifndef FreePv 37 | #define FreePv( pv ) free( pv ) 38 | #endif 39 | #ifndef MEM_ALLOC_CREDIT_CLASS 40 | #define MEM_ALLOC_CREDIT_CLASS() 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /src/public/tier0/platform.h: -------------------------------------------------------------------------------- 1 | //========= Copyright Valve Corporation, All rights reserved. ============// 2 | // 3 | // Misc platform compatibility wrappers. This file is a grab bag of junk, 4 | // stripped out from the version in Steam branch, just so we can compile. 5 | // 6 | //========================================================================// 7 | 8 | #ifndef PLATFORM_H 9 | #define PLATFORM_H 10 | #pragma once 11 | 12 | #include "wchartypes.h" 13 | #include "tier0/memdbgoff.h" 14 | #include "tier0/valve_off.h" 15 | 16 | #include "minbase/minbase_identify.h" 17 | #include "minbase/minbase_securezeromemory_impl.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "minbase/minbase_types.h" 29 | #include "minbase/minbase_decls.h" 30 | #include "minbase/minbase_macros.h" 31 | #include "minbase/minbase_endian.h" 32 | 33 | #if IsPosix() 34 | typedef int SOCKET; 35 | #define INVALID_SOCKET (-1) 36 | #else 37 | typedef uintp SOCKET; 38 | #define INVALID_SOCKET (SOCKET)(~0) // must exactly match winsock2.h to avoid warnings 39 | #endif 40 | 41 | // Marks the codepath from here until the next branch entry point as unreachable, 42 | // and asserts if any attempt is made to execute it. 43 | #define UNREACHABLE() { Assert(0); HINT(0); } 44 | 45 | // In cases where no default is present or appropriate, this causes MSVC to generate 46 | // as little code as possible, and throw an assertion in debug. 47 | #define NO_DEFAULT default: UNREACHABLE(); 48 | 49 | // Enable/disable warnings. 50 | #include "minbase/minbase_warnings.h" 51 | // Pull in the /analyze code annotations. 52 | #include "minbase/minbase_annotations.h" 53 | 54 | #include "platformtime.h" 55 | 56 | #if IsPosix() 57 | 58 | // handle mapping windows names used in tier0 to posix names in one place 59 | #define _snprintf snprintf //validator.cpp 60 | #if !defined( stricmp ) 61 | #define stricmp strcasecmp // assert_dialog.cpp 62 | #endif 63 | 64 | #if !defined( _stricmp ) 65 | #define _stricmp strcasecmp // validator.cpp 66 | #endif 67 | #define _strcmpi strcasecmp // vprof.cpp 68 | 69 | #include 70 | inline int GetLastError() { return errno; } 71 | 72 | #endif 73 | 74 | #define PLATFORM_INTERFACE extern "C" 75 | 76 | PLATFORM_INTERFACE bool Plat_IsInDebugSession(); 77 | 78 | //----------------------------------------------------------------------------- 79 | // Methods to invoke the constructor, copy constructor, and destructor 80 | //----------------------------------------------------------------------------- 81 | 82 | // Placement new, using "default initialization". 83 | // THIS DOES NOT INITIALIZE PODS! 84 | template 85 | inline void Construct( T* pMemory ) 86 | { 87 | HINT( pMemory != 0 ); 88 | ::new( pMemory ) T; 89 | } 90 | 91 | // Placement new, using "value initialization". 92 | // This will zero-initialize PODs 93 | template 94 | inline T* ValueInitializeConstruct( T* pMemory ) 95 | { 96 | HINT( pMemory != 0 ); 97 | return ::new( pMemory ) T{}; 98 | } 99 | 100 | template 101 | inline T* Construct( T* pMemory, ConstructorArgs&&... args ) 102 | { 103 | HINT( pMemory != 0 ); 104 | return ::new( pMemory ) T( std::forward(args)... ); 105 | } 106 | 107 | template 108 | inline void Destruct( T* pMemory ) 109 | { 110 | pMemory->~T(); 111 | 112 | #ifdef _DEBUG 113 | memset( (void*)pMemory, 0xDD, sizeof(T) ); 114 | #endif 115 | } 116 | 117 | #endif /* PLATFORM_H */ 118 | -------------------------------------------------------------------------------- /src/public/tier0/platform_sockets.h: -------------------------------------------------------------------------------- 1 | //====== Copyright Valve Corporation, All rights reserved. ==================== 2 | // 3 | // Include the relevant platform-specific headers for socket-related 4 | // stuff, and declare some functions make them look as similar to 5 | // plain BSD sockets as possible. 6 | // 7 | // This includes a bunch of stuff. DO NOT INCLUDE THIS FROM A HEADER 8 | // 9 | // Some things that will be defined by this file: 10 | // 11 | // closesocket() 12 | // GetLastSocketError() 13 | // SetSocketNonBlocking() 14 | // 15 | // USE_EPOLL or USE_POLL 16 | // If USE_EPOLL: 17 | // EPollHandle, INVALID_EPOLL_HANDLE, EPollCreate() 18 | // 19 | // WAKE_THREAD_USING_EVENT or WAKE_THREAD_USING_SOCKET_PAIR 20 | // If WAKE_THREAD_USING_EVENT: 21 | // ThreadWakeEvent, INVALID_THREAD_WAKE_EVENT, SetWakeThreadEvent() 22 | 23 | #ifndef TIER0_PLATFORM_SOCKETS_H 24 | #define TIER0_PLATFORM_SOCKETS_H 25 | #pragma once 26 | 27 | #include "platform.h" 28 | #include 29 | 30 | // !KLUDGE! 31 | typedef char SteamNetworkingErrMsg[ 1024 ]; 32 | 33 | // Socket headers 34 | #ifdef _WIN32 35 | //#include 36 | #include 37 | #include 38 | #ifndef _XBOX_ONE 39 | #include 40 | #endif 41 | 42 | // Windows is the worst 43 | #undef min 44 | #undef max 45 | #undef SetPort 46 | 47 | #define MSG_NOSIGNAL 0 48 | 49 | inline bool SetSocketNonBlocking( SOCKET s ) 50 | { 51 | unsigned long opt = 1; 52 | return ioctlsocket( s, FIONBIO, &opt ) == 0; 53 | } 54 | 55 | #define WAKE_THREAD_USING_EVENT 56 | typedef HANDLE ThreadWakeEvent; 57 | #define INVALID_THREAD_WAKE_EVENT INVALID_HANDLE_VALUE 58 | inline void SetWakeThreadEvent( ThreadWakeEvent hEvent ) 59 | { 60 | ::SetEvent( hEvent ); 61 | } 62 | 63 | inline int GetLastSocketError() 64 | { 65 | return (int)WSAGetLastError(); 66 | } 67 | 68 | #if !IsXboxOne() 69 | #include 70 | #define PlatformSupportsRecvMsg() true 71 | #endif 72 | 73 | #elif IsNintendoSwitch() 74 | // NDA-protected material, so all this is in a separate file 75 | #include "platform_sockets_nswitch.h" 76 | #elif IsPlaystation() 77 | // NDA-protected material, so all this is in a separate file 78 | #include "platform_sockets_playstation.h" 79 | #elif IsPosix() 80 | 81 | // POSIX-ish platform (Linux, OSX, Android, IOS) 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | #include 89 | 90 | #if !IsAndroid() 91 | #include 92 | #endif 93 | #include 94 | 95 | #ifndef closesocket 96 | #define closesocket close 97 | #endif 98 | #define WSAEWOULDBLOCK EWOULDBLOCK 99 | 100 | #define WAKE_THREAD_USING_SOCKET_PAIR 101 | 102 | inline bool SetSocketNonBlocking( SOCKET s ) 103 | { 104 | unsigned long opt = 1; 105 | return ioctl( s, FIONBIO, &opt ) == 0; 106 | } 107 | 108 | inline int GetLastSocketError() 109 | { 110 | return errno; 111 | } 112 | 113 | #define PlatformSupportsRecvMsg() true 114 | 115 | #ifdef __APPLE__ 116 | #define USE_POLL 117 | 118 | // I can't get this to work on MacOS. If someboddy believes that 119 | // it should work, I would appreciate the help. 120 | #define PlatformSupportsRecvTOS() false 121 | 122 | #else 123 | #define USE_EPOLL 124 | #include 125 | 126 | typedef int EPollHandle; 127 | constexpr EPollHandle INVALID_EPOLL_HANDLE = -1; 128 | inline EPollHandle EPollCreate( SteamNetworkingErrMsg &errMsg ) 129 | { 130 | int flags = 0; 131 | #if IsLinux() 132 | flags |= EPOLL_CLOEXEC; 133 | #endif 134 | EPollHandle e = epoll_create1( flags ); 135 | if ( e == -1 ) 136 | { 137 | V_sprintf_safe( errMsg, "epoll_create1() failed, errno=%d", errno ); 138 | return INVALID_EPOLL_HANDLE; 139 | } 140 | return e; 141 | } 142 | 143 | #define EPollClose(x) close(x) 144 | 145 | // FIXME - should we try to use eventfd() here 146 | // instead of a socket pair? 147 | 148 | #endif 149 | #else 150 | #error "How do?" 151 | #endif 152 | 153 | #ifndef PlatformSupportsRecvMsg 154 | #define PlatformSupportsRecvMsg() false 155 | #endif 156 | 157 | #ifndef PlatformSupportsRecvTOS 158 | #if PlatformSupportsRecvMsg() && defined( IP_RECVTOS ) 159 | #define PlatformSupportsRecvTOS() true 160 | #else 161 | #define PlatformSupportsRecvTOS() false 162 | #endif 163 | #endif 164 | 165 | #endif // _H 166 | -------------------------------------------------------------------------------- /src/public/tier0/platformtime.h: -------------------------------------------------------------------------------- 1 | //========= Copyright Valve Corporation, All rights reserved. ============// 2 | #ifndef PLATFORMTIME_H 3 | #define PLATFORMTIME_H 4 | #pragma once 5 | 6 | #include "minbase/minbase_identify.h" 7 | #include "minbase/minbase_types.h" 8 | #include "minbase/minbase_decls.h" 9 | 10 | // SDR_PUBLIC - Stripped out all of the stuff we don't need 11 | #define PLATFORMTIME_INTERFACE extern "C" 12 | 13 | BEGIN_TIER0_NAMESPACE 14 | 15 | PLATFORMTIME_INTERFACE uint64 Plat_RelativeTicks(); // Returns time in raw ticks since an arbitrary start point. 16 | PLATFORMTIME_INTERFACE double Plat_FloatTime(); // Relative ticks to seconds (double). 17 | PLATFORMTIME_INTERFACE uint64 Plat_USTime(); // Relative ticks to microseconds 18 | 19 | END_TIER0_NAMESPACE 20 | 21 | #endif /* PLATFORMTIME_H */ 22 | -------------------------------------------------------------------------------- /src/public/tier0/t0constants.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValveSoftware/GameNetworkingSockets/725e273c7442bac7a8bc903c0b210b1c15c34d92/src/public/tier0/t0constants.h -------------------------------------------------------------------------------- /src/public/tier0/valve_off.h: -------------------------------------------------------------------------------- 1 | // Stub -------------------------------------------------------------------------------- /src/public/tier0/valve_on.h: -------------------------------------------------------------------------------- 1 | // Stub 2 | -------------------------------------------------------------------------------- /src/public/tier0/vprof.h: -------------------------------------------------------------------------------- 1 | #ifndef VPROF_H 2 | #define VPROF_H 3 | 4 | #define VPROF( name ) ((void)0) 5 | #define VPROF_ASSERT_ACCOUNTED( name ) ((void)0) 6 | #define VPROF_( name, detail, group, bAssertAccounted ) ((void)0) 7 | #define VPROF_BUDGET( name, group ) ((void)0) 8 | #define VPROF_BUDGET_FLAGS( name, group, flags ) ((void)0) 9 | 10 | #define VPROF_SCOPE_BEGIN( tag ) do { 11 | #define VPROF_SCOPE_END() } while (0) 12 | 13 | #define VPROF_ONLY( expression ) ((void)0) 14 | 15 | #define VPROF_INCREMENT_COUNTER(name,amount) ((void)0) 16 | #define VPROF_INCREMENT_GROUP_COUNTER(name,group,amount) ((void)0) 17 | 18 | #endif // VPROF_H 19 | -------------------------------------------------------------------------------- /src/public/tier0/wchartypes.h: -------------------------------------------------------------------------------- 1 | //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============// 2 | // 3 | // Purpose: All of our code is completely Unicode. Instead of char, you should 4 | // use char, uint8, or char8, as explained below. 5 | // 6 | // $NoKeywords: $ 7 | //=============================================================================// 8 | 9 | 10 | #ifndef WCHARTYPES_H 11 | #define WCHARTYPES_H 12 | #pragma once 13 | 14 | #ifdef _INC_TCHAR 15 | #error ("Must include tier0 type headers before tchar.h") 16 | #endif 17 | 18 | // Temporarily turn off Valve defines 19 | #include "tier0/valve_off.h" 20 | 21 | // char8 22 | // char8 is equivalent to char, and should be used when you really need a char 23 | // (for example, when calling an external function that's declared to take 24 | // chars). 25 | typedef char char8; 26 | 27 | // uint8 28 | // uint8 is equivalent to byte (but is preferred over byte for clarity). Use this 29 | // whenever you mean a byte (for example, one byte of a network packet). 30 | typedef unsigned char uint8; 31 | typedef unsigned char BYTE; 32 | typedef unsigned char byte; 33 | 34 | #ifdef _WIN32 35 | #include 36 | #include 37 | #elif defined( _PS3 ) 38 | #define _tcsstr strstr 39 | #define _tcsicmp stricmp 40 | #define _tcscmp strcmp 41 | #define _tcscpy strcpy 42 | #define _tcsncpy strncpy 43 | #define _tcsrchr strrchr 44 | #define _tcslen strlen 45 | #define _tfopen fopen 46 | #define _stprintf sprintf 47 | #define _ftprintf fprintf 48 | #define _vsntprintf vsnprintf 49 | #define _tprintf printf 50 | #define _sntprintf _snprintf 51 | #define _T(s) s 52 | #else 53 | #include 54 | #include 55 | #define _tcsstr strstr 56 | #define _tcsicmp stricmp 57 | #define _tcscmp strcmp 58 | #define _tcscpy strcpy 59 | #define _tcsncpy strncpy 60 | #define _tcsrchr strrchr 61 | #define _tcslen strlen 62 | #define _tfopen fopen 63 | #define _stprintf sprintf 64 | #define _ftprintf fprintf 65 | #define _vsntprintf vsnprintf 66 | #define _tprintf printf 67 | #define _sntprintf snprintf 68 | #define _T(s) s 69 | #endif 70 | 71 | #if defined(_UNICODE) 72 | typedef wchar_t tchar; 73 | #define tstring wstring 74 | #define __TFILE__ __WFILE__ 75 | #define TCHAR_IS_WCHAR 76 | #else 77 | typedef char tchar; 78 | #define tstring string 79 | #define __TFILE__ __FILE__ 80 | #define TCHAR_IS_CHAR 81 | #endif 82 | 83 | #ifdef FORCED_UNICODE 84 | #undef _UNICODE 85 | #endif 86 | 87 | 88 | #if defined( _MSC_VER ) || defined( _WIN32 ) 89 | typedef wchar_t uchar16; 90 | typedef unsigned int uchar32; 91 | #else 92 | typedef unsigned short uchar16; 93 | typedef wchar_t uchar32; 94 | #endif 95 | 96 | // Turn valve defines back on 97 | #include "tier0/valve_on.h" 98 | 99 | 100 | #endif // WCHARTYPES 101 | 102 | 103 | -------------------------------------------------------------------------------- /src/public/tier1/netadr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValveSoftware/GameNetworkingSockets/725e273c7442bac7a8bc903c0b210b1c15c34d92/src/public/tier1/netadr.h -------------------------------------------------------------------------------- /src/public/tier1/utlpriorityqueue.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValveSoftware/GameNetworkingSockets/725e273c7442bac7a8bc903c0b210b1c15c34d92/src/public/tier1/utlpriorityqueue.h -------------------------------------------------------------------------------- /src/public/vstdlib/random.h: -------------------------------------------------------------------------------- 1 | // Stub for just what we need 2 | 3 | #ifndef VSTDLIB_RANDOM_H 4 | #define VSTDLIB_RANDOM_H 5 | 6 | #include 7 | 8 | inline void WeakRandomSeed( int x ) { srand(x); } 9 | inline float WeakRandomFloat( float flMin, float flMax ) 10 | { 11 | return flMin + ( (float)rand() / (float)RAND_MAX ) * ( flMax - flMin ); 12 | } 13 | inline int WeakRandomInt( int nMin, int nMax ) 14 | { 15 | return nMin + rand() % ( nMax - nMin + 1 ); 16 | } 17 | 18 | #endif // VSTDLIB_RANDOM_H 19 | 20 | -------------------------------------------------------------------------------- /src/public/winlite.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValveSoftware/GameNetworkingSockets/725e273c7442bac7a8bc903c0b210b1c15c34d92/src/public/winlite.h -------------------------------------------------------------------------------- /src/steamnetworkingsockets/clientlib/ice_client_types.h: -------------------------------------------------------------------------------- 1 | //===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== 2 | // 3 | // Some types used to interface with different ICE client implementations 4 | 5 | #ifndef ICE_CLIENT_TYPES_H 6 | #define ICE_CLIENT_TYPES_H 7 | 8 | #include 9 | #include 10 | 11 | enum EICERole 12 | { 13 | k_EICERole_Controlling, // usually the "client" who initiated the connection 14 | k_EICERole_Controlled, // usually the "server" who accepted the connection 15 | k_EICERole_Unknown, 16 | }; 17 | 18 | enum EICECandidateType : int 19 | { 20 | k_EICECandidate_Invalid = 0, 21 | 22 | k_EICECandidate_IPv4_Relay = 0x01, 23 | k_EICECandidate_IPv4_HostPrivate = 0x02, 24 | k_EICECandidate_IPv4_HostPublic = 0x04, 25 | k_EICECandidate_IPv4_Reflexive = 0x08, 26 | 27 | k_EICECandidate_IPv6_Relay = 0x100, 28 | k_EICECandidate_IPv6_HostPrivate_Unsupported = 0x200, // NOTE: Not currently used. All IPv6 addresses (even fc00::/7) are considered "public" 29 | k_EICECandidate_IPv6_HostPublic = 0x400, 30 | k_EICECandidate_IPv6_Reflexive = 0x800, 31 | }; 32 | 33 | constexpr int k_EICECandidate_Any_Relay = k_EICECandidate_IPv4_Relay | k_EICECandidate_IPv6_Relay; 34 | constexpr int k_EICECandidate_Any_HostPrivate = k_EICECandidate_IPv4_HostPrivate | k_EICECandidate_IPv6_HostPrivate_Unsupported; 35 | constexpr int k_EICECandidate_Any_HostPublic = k_EICECandidate_IPv4_HostPublic | k_EICECandidate_IPv6_HostPublic; 36 | constexpr int k_EICECandidate_Any_Reflexive = k_EICECandidate_IPv4_Reflexive | k_EICECandidate_IPv6_Reflexive; 37 | constexpr int k_EICECandidate_Any_IPv4 = 0x00ff; 38 | constexpr int k_EICECandidate_Any_IPv6 = 0xff00; 39 | constexpr int k_EICECandidate_Any = 0xffff; 40 | 41 | // Different protocols that may be used to talk to TURN server. 42 | // FIXME - rename this with more specific name 43 | enum EProtocolType { 44 | k_EProtocolTypeUDP, 45 | k_EProtocolTypeTCP, 46 | k_EProtocolTypeSSLTCP, // Pseudo-TLS. 47 | k_EProtocolTypeTLS, 48 | }; 49 | 50 | struct ICESessionConfig 51 | { 52 | typedef const char *StunServer; 53 | struct TurnServer 54 | { 55 | const char *m_pszHost = nullptr; 56 | const char *m_pszUsername = nullptr; 57 | const char *m_pszPwd = nullptr; 58 | const EProtocolType m_protocolType = k_EProtocolTypeUDP; 59 | }; 60 | 61 | EICERole m_eRole = k_EICERole_Unknown; 62 | int m_nStunServers = 0; 63 | const StunServer *m_pStunServers = nullptr; 64 | int m_nTurnServers = 0; 65 | const TurnServer *m_pTurnServers = nullptr; 66 | int m_nCandidateTypes = k_EICECandidate_Any; 67 | const char *m_pszLocalUserFrag; 68 | const char *m_pszLocalPwd; 69 | }; 70 | 71 | 72 | #endif // _H 73 | -------------------------------------------------------------------------------- /src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p_ice.h: -------------------------------------------------------------------------------- 1 | //====== Copyright Valve Corporation, All rights reserved. ==================== 2 | 3 | #ifndef STEAMNETWORKINGSOCKETS_P2P_ICE_H 4 | #define STEAMNETWORKINGSOCKETS_P2P_ICE_H 5 | #pragma once 6 | 7 | #include "steamnetworkingsockets_p2p.h" 8 | #include "steamnetworkingsockets_udp.h" 9 | 10 | #ifdef STEAMNETWORKINGSOCKETS_ENABLE_ICE 11 | 12 | #include "ice_client_types.h" 13 | 14 | namespace SteamNetworkingSocketsLib { 15 | 16 | constexpr int k_nMinPingTimeLocalTolerance = 5; 17 | 18 | class CSteamNetworkConnectionP2P; 19 | struct UDPSendPacketContext_t; 20 | 21 | /// Base transport for peer-to-peer connection using ICE 22 | class CConnectionTransportP2PICE 23 | : public CConnectionTransportUDPBase 24 | , public CConnectionTransportP2PBase 25 | , public CTaskTarget // Should we promote this to a base class? 26 | { 27 | public: 28 | virtual ~CConnectionTransportP2PICE(); 29 | 30 | inline CSteamNetworkConnectionP2P &Connection() const { return *assert_cast< CSteamNetworkConnectionP2P *>( &m_connection ); } 31 | inline ISteamNetworkingConnectionSignaling *Signaling() const { return Connection().m_pSignaling; } 32 | 33 | // CConnectionTransport overrides 34 | virtual void TransportPopulateConnectionInfo( SteamNetConnectionInfo_t &info ) const override; 35 | virtual void GetDetailedConnectionStatus( SteamNetworkingDetailedConnectionStatus &stats, SteamNetworkingMicroseconds usecNow ) override; 36 | 37 | // CConnectionTransportP2PBase 38 | virtual void P2PTransportUpdateRouteMetrics( SteamNetworkingMicroseconds usecNow ) override; 39 | 40 | /// Fill in SDR-specific fields to signal 41 | void PopulateRendezvousMsg( CMsgSteamNetworkingP2PRendezvous &msg, SteamNetworkingMicroseconds usecNow ); 42 | virtual void RecvRendezvous( const CMsgICERendezvous &msg, SteamNetworkingMicroseconds usecNow ) = 0; 43 | 44 | inline int LogLevel_P2PRendezvous() const { return m_connection.m_connectionConfig.LogLevel_P2PRendezvous.Get(); } 45 | 46 | void LocalCandidateGathered( EICECandidateType eType, CMsgICECandidate &&msgCandidate ); 47 | 48 | //EICECandidateType m_eCurrentRouteLocalCandidateType; 49 | //EICECandidateType m_eCurrentRouteRemoteCandidateType; 50 | SteamNetworkingIPAddr m_currentRouteRemoteAddress; 51 | ESteamNetTransportKind m_eCurrentRouteKind; 52 | 53 | protected: 54 | CConnectionTransportP2PICE( CSteamNetworkConnectionP2P &connection ); 55 | 56 | void ProcessPacket( const uint8_t *pData, int cbPkt, SteamNetworkingMicroseconds usecNow ); 57 | 58 | // Implements CConnectionTransportUDPBase 59 | virtual bool SendPacket( const void *pkt, int cbPkt ) override = 0; 60 | virtual bool SendPacketGather( int nChunks, const iovec *pChunks, int cbSendTotal ) override = 0; 61 | virtual void TrackSentStats( UDPSendPacketContext_t &ctx ) override; 62 | virtual void RecvValidUDPDataPacket( UDPRecvPacketContext_t &ctx ) override; 63 | }; 64 | 65 | extern std::string Base64EncodeLower30Bits( uint32 nNum ); 66 | 67 | } // namespace SteamNetworkingSocketsLib 68 | 69 | #endif // #ifdef STEAMNETWORKINGSOCKETS_ENABLE_ICE 70 | 71 | #endif // STEAMNETWORKINGSOCKETS_P2P_ICE_H 72 | -------------------------------------------------------------------------------- /src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p_webrtc.h: -------------------------------------------------------------------------------- 1 | //====== Copyright Valve Corporation, All rights reserved. ==================== 2 | 3 | #ifndef STEAMNETWORKINGSOCKETS_P2P_WEBRTC_H 4 | #define STEAMNETWORKINGSOCKETS_P2P_WEBRTC_H 5 | #pragma once 6 | 7 | #include "steamnetworkingsockets_p2p_ice.h" 8 | 9 | #ifdef STEAMNETWORKINGSOCKETS_ENABLE_WEBRTC 10 | 11 | #include "ice_client_types.h" 12 | #include "../../external/steamwebrtc/ice_session.h" 13 | 14 | class IICESession; 15 | class IICESessionDelegate; 16 | struct ICESessionConfig; 17 | typedef IICESession *( *CreateICESession_t )( const ICESessionConfig &cfg, IICESessionDelegate *pDelegate, int nInterfaceVersion ); 18 | extern "C" CreateICESession_t g_SteamNetworkingSockets_CreateICESessionFunc; 19 | 20 | namespace SteamNetworkingSocketsLib { 21 | 22 | class CConnectionTransportP2PICE_WebRTC final 23 | : public CConnectionTransportP2PICE 24 | , private IICESessionDelegate 25 | { 26 | public: 27 | CConnectionTransportP2PICE_WebRTC( CSteamNetworkConnectionP2P &connection ); 28 | virtual ~CConnectionTransportP2PICE_WebRTC(); 29 | 30 | // In certain circumstances we may need to buffer packets 31 | ShortDurationLock m_mutexPacketQueue; 32 | CUtlBuffer m_bufPacketQueue; 33 | 34 | void Init( const ICESessionConfig &cfg ); 35 | 36 | private: 37 | IICESession *m_pICESession; 38 | 39 | void RouteOrWritableStateChanged(); 40 | void UpdateRoute(); 41 | 42 | void DrainPacketQueue( SteamNetworkingMicroseconds usecNow ); 43 | 44 | // CConnectionTransport overrides 45 | virtual bool BCanSendEndToEndData() const override; 46 | virtual void TransportFreeResources() override; 47 | 48 | // CConnectionTransportP2PBase 49 | virtual void P2PTransportThink( SteamNetworkingMicroseconds usecNow ) override; 50 | 51 | // CConnectionTransportP2PICE overrides 52 | virtual void RecvRendezvous( const CMsgICERendezvous &msg, SteamNetworkingMicroseconds usecNow ) override; 53 | 54 | // CConnectionTransportUDPBase overrides 55 | virtual bool SendPacket( const void *pkt, int cbPkt ) override; 56 | virtual bool SendPacketGather( int nChunks, const iovec *pChunks, int cbSendTotal ) override; 57 | 58 | // Implements IICESessionDelegate 59 | virtual void Log( IICESessionDelegate::ELogPriority ePriority, const char *pszMessageFormat, ... ) override; 60 | virtual void OnData( const void *pData, size_t nSize ) override; 61 | virtual void OnLocalCandidateGathered( EICECandidateType eType, const char *pszCandidate ) override; 62 | virtual void OnWritableStateChanged() override; 63 | virtual void OnRouteChanged() override; 64 | }; 65 | 66 | } // namespace SteamNetworkingSocketsLib 67 | 68 | #endif // #ifdef STEAMNETWORKINGSOCKETS_ENABLE_WEBRTC 69 | 70 | #endif // _H 71 | -------------------------------------------------------------------------------- /src/tier0/platformtime.cpp: -------------------------------------------------------------------------------- 1 | //========= Copyright Valve Corporation, All rights reserved. ============// 2 | #include "../public/tier0/platformtime.h" 3 | 4 | #include 5 | 6 | #ifdef _WIN32 7 | #include "winlite.h" 8 | #include 9 | #else 10 | #include 11 | #include 12 | #if IsOSX() 13 | #include 14 | #include 15 | #endif 16 | 17 | #endif 18 | 19 | #if IsNintendoSwitch() 20 | #include "platformtime_nswitch.h" 21 | #endif 22 | 23 | BEGIN_TIER0_NAMESPACE 24 | 25 | #if defined( _WIN32 ) || IsOSX() || IsNintendoSwitch() 26 | static uint64 g_TickFrequency; 27 | static double g_TickFrequencyDouble; 28 | static double g_TicksToUS; 29 | #else 30 | //static constexpr uint64 g_TickFrequency = 1000000000; 31 | static constexpr double g_TickFrequencyDouble = 1.0e9; 32 | static constexpr double g_TicksToUS = 1.0e6 / g_TickFrequencyDouble; 33 | #endif 34 | 35 | // NOTE: 36 | // If Plat_RelativeTicks, Plat_MSTime, etc. are called by a 37 | // global constructor in another file then g_TickBase may be 38 | // already initialized before executing the following line! 39 | // InitTicks returns existing value of g_TickBase, if set. 40 | static uint64 InitTicks(); 41 | static uint64 g_TickBase = InitTicks(); 42 | 43 | #ifdef _WIN32 44 | static uint64 g_TickLastReturned_XPWorkaround; 45 | #endif 46 | 47 | static uint64 InitTicks() 48 | { 49 | if ( g_TickBase != 0 ) 50 | return g_TickBase; 51 | 52 | #if defined(_WIN32) 53 | LARGE_INTEGER Large; 54 | QueryPerformanceFrequency(&Large); 55 | g_TickFrequency = Large.QuadPart; 56 | g_TickFrequencyDouble = (double)g_TickFrequency; 57 | // Before Windows Vista, multicore system QPC can be non-monotonic 58 | QueryPerformanceCounter( &Large ); 59 | g_TickBase = g_TickLastReturned_XPWorkaround = Large.QuadPart; 60 | #elif IsOSX() 61 | mach_timebase_info_data_t TimebaseInfo; 62 | mach_timebase_info(&TimebaseInfo); 63 | g_TickFrequencyDouble = (double) TimebaseInfo.denom / (double) TimebaseInfo.numer * 1.0e9; 64 | g_TickFrequency = (uint64)( g_TickFrequencyDouble + 0.5 ); 65 | g_TickBase = mach_absolute_time(); 66 | #elif IsNintendoSwitch() 67 | g_TickBase = PlatformTime_GetRawTickCounter(); 68 | g_TickFrequency = PlatformTime_GetRawTickFrequency(); 69 | g_TickFrequencyDouble = g_TickFrequency; 70 | #elif IsPosix() 71 | // TickFrequency is constant since clock_gettime always returns nanoseconds 72 | timespec TimeSpec; 73 | clock_gettime( CLOCK_MONOTONIC, &TimeSpec ); 74 | g_TickBase = (uint64)TimeSpec.tv_sec * 1000000000 + TimeSpec.tv_nsec; 75 | #else 76 | #error Unknown platform 77 | #endif 78 | 79 | #if defined( _WIN32 ) || IsOSX() || IsNintendoSwitch() 80 | g_TicksToUS = 1.0e6 / g_TickFrequencyDouble; 81 | #endif 82 | 83 | return g_TickBase; 84 | } 85 | 86 | uint64 Plat_RelativeTicks() 87 | { 88 | if ( g_TickBase == 0 ) 89 | InitTicks(); 90 | 91 | uint64 Ticks; 92 | 93 | #if defined(_WIN32) 94 | LARGE_INTEGER Large; 95 | QueryPerformanceCounter(&Large); 96 | Ticks = Large.QuadPart; 97 | // On WinXP w/ multi-core CPU, ticks can go slightly backwards. Fixed in Vista+ 98 | if ( Ticks < g_TickLastReturned_XPWorkaround ) 99 | { 100 | Ticks = g_TickLastReturned_XPWorkaround; 101 | } 102 | else 103 | { 104 | g_TickLastReturned_XPWorkaround = Ticks; 105 | } 106 | #elif IsOSX() 107 | Ticks = mach_absolute_time(); 108 | #elif IsNintendoSwitch() 109 | Ticks = PlatformTime_GetRawTickCounter(); 110 | #elif IsPosix() 111 | timespec TimeSpec; 112 | clock_gettime( CLOCK_MONOTONIC, &TimeSpec ); 113 | Ticks = (uint64)TimeSpec.tv_sec * 1000000000 + TimeSpec.tv_nsec; 114 | #else 115 | #error Unknown platform 116 | #endif 117 | 118 | return Ticks; 119 | } 120 | 121 | double Plat_FloatTime() 122 | { 123 | // We subtract off the tick base to keep the diff as small 124 | // as possible so that our conversion math is more accurate. 125 | uint64 Ticks = Plat_RelativeTicks(); // NOTE: inits globals 126 | return ((double)(int64)(Ticks - g_TickBase)) / g_TickFrequencyDouble; 127 | } 128 | 129 | uint64 Plat_USTime() 130 | { 131 | // We subtract off the tick base to keep the diff as small 132 | // as possible so that our conversion math is more accurate. 133 | uint64 Ticks = Plat_RelativeTicks(); // NOTE: inits globals 134 | return (uint64)( (Ticks - g_TickBase) * g_TicksToUS ); 135 | } 136 | 137 | END_TIER0_NAMESPACE 138 | -------------------------------------------------------------------------------- /src/tier0/valve_tracelogging.cpp: -------------------------------------------------------------------------------- 1 | //====== Copyright Valve Corporation, All rights reserved. ==================== 2 | 3 | #include 4 | #if IsTraceLoggingEnabled() 5 | 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Hacks to avoid linking with an import lib and forcing a dependency 9 | // on a certain version of Windows 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | // Typedefs for use with GetProcAddress 14 | typedef ULONG (__stdcall *tEventRegister)( LPCGUID ProviderId, PENABLECALLBACK EnableCallback, PVOID CallbackContext, PREGHANDLE RegHandle ); 15 | static tEventRegister s_pEventRegister; 16 | 17 | typedef ULONG (__stdcall *tEventUnregister)( REGHANDLE RegHandle ); 18 | static tEventUnregister s_pEventUnregister; 19 | 20 | //typedef ULONG (__stdcall *tEventWrite)( REGHANDLE RegHandle, PCEVENT_DESCRIPTOR EventDescriptor, ULONG UserDataCount, PEVENT_DATA_DESCRIPTOR UserData ); 21 | //static ULONG __stdcall Dummy_EventWrite( REGHANDLE RegHandle, PCEVENT_DESCRIPTOR EventDescriptor, ULONG UserDataCount, PEVENT_DATA_DESCRIPTOR UserData ) { return 0; } 22 | //static tEventWrite s_pEventWrite = Dummy_EventWrite; // Always non-NULL 23 | 24 | typedef ULONG (__stdcall *tEventWriteTransfer)( REGHANDLE RegHandle, PCEVENT_DESCRIPTOR EventDescriptor, LPCGUID ActivityId, LPCGUID RelatedActivityId, ULONG UserDataCount, PEVENT_DATA_DESCRIPTOR UserData ); 25 | static ULONG __stdcall Dummy_EventWriteTransfer( REGHANDLE RegHandle, PCEVENT_DESCRIPTOR EventDescriptor, LPCGUID ActivityId, LPCGUID RelatedActivityId, ULONG UserDataCount, PEVENT_DATA_DESCRIPTOR UserData ) { return 0; } 26 | static tEventWriteTransfer s_pEventWriteTransfer = Dummy_EventWriteTransfer; // Always non-NULL 27 | 28 | typedef ULONG (__stdcall *tEventActivityIdControl)( ULONG ControlCode, LPGUID ActivityId ); 29 | static ULONG __stdcall Dummy_EventActivityIdControl( ULONG ControlCode, LPGUID ActivityId ) { return ERROR_NOT_SUPPORTED; } 30 | static tEventActivityIdControl s_pEventActivityIdControl = Dummy_EventActivityIdControl; // Always non-NULL 31 | 32 | PLATFORM_INTERFACE ULONG Plat_EventRegister( LPCGUID ProviderId, PENABLECALLBACK EnableCallback, PVOID CallbackContext, PREGHANDLE RegHandle ) 33 | { 34 | 35 | // One time init 36 | static bool once = [](){ 37 | 38 | // Find Advapi32.dll. This should always succeed. 39 | HMODULE pAdvapiDLL = ::LoadLibraryA( "advapi32.dll" ); 40 | if ( pAdvapiDLL ) 41 | { 42 | 43 | // EventWriteTransfer is the newest function we require. Don't check for the others if it's missing 44 | tEventWriteTransfer pEventWriteTranfer = ( tEventWriteTransfer )GetProcAddress( pAdvapiDLL, "EventWriteTransfer" ); 45 | tEventActivityIdControl pEventActivityIdControl = ( tEventActivityIdControl )GetProcAddress( pAdvapiDLL, "EventActivityIdControl" ); 46 | if ( pEventWriteTranfer && pEventActivityIdControl ) 47 | { 48 | 49 | s_pEventRegister = ( tEventRegister )GetProcAddress( pAdvapiDLL, "EventRegister" ); 50 | s_pEventUnregister = ( tEventUnregister )GetProcAddress( pAdvapiDLL, "EventUnregister" ); 51 | s_pEventWriteTransfer = pEventWriteTranfer; 52 | s_pEventActivityIdControl = pEventActivityIdControl; 53 | } 54 | } 55 | 56 | return true; 57 | }(); 58 | 59 | if ( s_pEventRegister ) 60 | return s_pEventRegister( ProviderId, EnableCallback, CallbackContext, RegHandle ); 61 | 62 | // We are contractually obliged to initialize this. 63 | *RegHandle = 0; 64 | return 0; 65 | } 66 | 67 | PLATFORM_INTERFACE ULONG Plat_EventUnregister( REGHANDLE RegHandle ) 68 | { 69 | if ( s_pEventUnregister ) 70 | return s_pEventUnregister( RegHandle ); 71 | return 0; 72 | } 73 | 74 | // These wrappers are the most perf-sensitive. So we make their function pointer 75 | // always be non-NULL. Because the function signature matches (including __stdcall), 76 | // these should be implemented with a single 'jmp [blah]' instruction. At the time 77 | // this comment was written, I examined the assembly of a release build, and it was 78 | // optimal 79 | 80 | //PLATFORM_INTERFACE ULONG __stdcall Plat_EventWrite( REGHANDLE RegHandle, PCEVENT_DESCRIPTOR EventDescriptor, ULONG UserDataCount, PEVENT_DATA_DESCRIPTOR UserData ) 81 | //{ 82 | // return (*s_pEventWrite)( RegHandle, EventDescriptor, UserDataCount, UserData ); 83 | //} 84 | PLATFORM_INTERFACE ULONG __stdcall Plat_EventWriteTransfer( REGHANDLE RegHandle, PCEVENT_DESCRIPTOR EventDescriptor, LPCGUID ActivityId, LPCGUID RelatedActivityId, ULONG UserDataCount, PEVENT_DATA_DESCRIPTOR UserData ) 85 | { 86 | return (*s_pEventWriteTransfer)( RegHandle, EventDescriptor, ActivityId, RelatedActivityId, UserDataCount, UserData ); 87 | } 88 | PLATFORM_INTERFACE ULONG __stdcall Plat_EventActivityIdControl( ULONG ControlCode, LPGUID ActivityId ) 89 | { 90 | return (*s_pEventActivityIdControl)( ControlCode, ActivityId ); 91 | } 92 | 93 | #endif // #if IsTraceLoggingEnabled() 94 | -------------------------------------------------------------------------------- /src/tier1/ipv6text.h: -------------------------------------------------------------------------------- 1 | /// Standalone plain C utilities for parsing and printing IPv6 addresses 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | /// Max length of an IPv6 string, with scope, WITHOUT port number, including \0': 8 | /// 0123:4567:89ab:cdef:0123:4567:89ab:cdef%4294967295 9 | const int k_cchMaxIPV6AddrStringWithoutPort = 51; 10 | 11 | /// Max number of bytes output by IPv6AddrToString, including '\0': 12 | /// [0123:4567:89ab:cdef:0123:4567:89ab:cdef%4294967295]:12345 13 | /// There are other strings that are acceptable to ParseIPv6Addr 14 | /// that are longer than this, but this is the longest canonical 15 | /// string. 16 | const int k_cchMaxIPV6AddrStringWithPort = 59; 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /// Format an IPv6 address to the canonical form according to RFC5952. 23 | /// The address should be 16 bytes (e.g. same as in6_addr::s6_addr). 24 | /// Your buffer MUST be at least k_cchMaxIPV6AddrStringWithoutPort bytes. 25 | extern void IPv6IPToString( char *pszOutText, const unsigned char *ip ); 26 | 27 | /// Format IPv6 IP and port to string. This uses the recommended 28 | /// bracket notation, eg [1234::1]:12345. Your buffer MUST be 29 | /// at least k_cchMaxIPV6AddrStringWithPort bytes. 30 | /// 31 | /// If the scope is zero, it is not printed. 32 | extern void IPv6AddrToString( char *pszOutText, const unsigned char *ip, uint16_t port, uint32_t scope ); 33 | 34 | /// Parse IPv6 address string. Returns true if parsed OK. Returns false 35 | /// if input cannot be parsed, or if input specifies a port but pOutPort is NULL. 36 | /// If input does not specify a port, and pOutPort is non-NULL, then *pOutPort is 37 | /// set to -1. 38 | /// 39 | /// Parsing is tolerant of any unambiguous IPv6 representation, the input 40 | /// need not be the canonical RFC5952 representation. 41 | /// 42 | /// IPv6 zones are not supported. 43 | /// 44 | /// Leading and trailing whitespace is OK around the entire string, 45 | /// but not internal whitespace. The different methods for separating the 46 | /// port in RFC5952 section 6 are supported, except the ambiguous case 47 | /// of a colon to separate the port, when the IP contains a double-colon. 48 | /// Brackets around an IP are OK, even if there is no port. 49 | /// 50 | /// Address must point to a 16-byte buffer (e.g. same as in6_addr::s6_addr) 51 | /// Port is returned in host byte order. 52 | extern bool ParseIPv6Addr( const char *pszText, unsigned char *pOutIP, int *pOutPort, uint32_t *pOutScope ); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(SANITIZE) 2 | add_definitions(-DSANITIZER) 3 | endif() 4 | 5 | # Let's always link all tests statically with the lib 6 | # To keep things simple. (Since some of the tests MUST 7 | # link statically) 8 | set( GAMENETWORKINGSOCKETS_LIB "GameNetworkingSockets::static" ) 9 | 10 | add_executable( 11 | test_connection 12 | test_common.cpp 13 | test_connection.cpp) 14 | set_target_common_gns_properties( test_connection ) 15 | target_link_libraries(test_connection ${GAMENETWORKINGSOCKETS_LIB}) 16 | add_sanitizers(test_connection) 17 | 18 | add_executable( 19 | test_crypto 20 | test_crypto.cpp 21 | ) 22 | set_target_common_gns_properties( test_crypto ) 23 | target_include_directories(test_crypto PRIVATE ../src ../src/public ../src/common ../include) 24 | target_link_libraries(test_crypto GameNetworkingSockets::static) 25 | add_sanitizers(test_crypto) 26 | 27 | # Test data for the crypto test when the project is built 28 | file(COPY aesgcmtestvectors DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 29 | 30 | # P2P test 31 | if(ENABLE_ICE) 32 | add_executable( 33 | test_p2p 34 | test_common.cpp 35 | test_p2p.cpp 36 | ../examples/trivial_signaling_client.cpp) 37 | set_target_common_gns_properties( test_p2p ) 38 | target_link_libraries(test_p2p ${GAMENETWORKINGSOCKETS_LIB}) 39 | 40 | # Publish the test script 41 | set( P2P_TEST_SCRIPT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_p2p.py ) 42 | set( P2P_TEST_SCRIPT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/test_p2p.py ) 43 | add_custom_command( 44 | OUTPUT ${P2P_TEST_SCRIPT} 45 | COMMAND ${CMAKE_COMMAND} -E copy ${P2P_TEST_SCRIPT_SRC} ${P2P_TEST_SCRIPT} 46 | DEPENDS ${P2P_TEST_SCRIPT_SRC} ) 47 | add_custom_target( publish_test_script ALL DEPENDS ${P2P_TEST_SCRIPT} ) 48 | endif() 49 | -------------------------------------------------------------------------------- /tests/aesgcmtestvectors/readme.txt: -------------------------------------------------------------------------------- 1 | https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES 2 | https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/gcmtestvectors.zip 3 | -------------------------------------------------------------------------------- /tests/make_test_certs.py: -------------------------------------------------------------------------------- 1 | import re 2 | import json 3 | import subprocess 4 | 5 | def run_cert_tool( args ): 6 | args = [ "../../../bin/win64/steamnetworkingsockets_certtool.exe", "--output-json" ] + args 7 | #print ' '.join( args ) 8 | stdout = subprocess.check_output( args ) 9 | return json.loads( stdout ) 10 | 11 | def create_keypair(): 12 | return run_cert_tool( [ "gen_keypair" ] ) 13 | 14 | def compress_whitespace( s ): 15 | return re.sub( r'\s+', ' ', s ) 16 | def remove_all_whitespace( s ): 17 | return re.sub( r'\s+', '', s ) 18 | 19 | def get_pem_body( s ): 20 | m = re.match( r'-+.*BEGIN.*-\s+(.+)\s+.*END.*-+', s, re.DOTALL ) 21 | body = m.group(1) 22 | return remove_all_whitespace( body ) 23 | 24 | def run_cert_tool_with_ca_key( ca_key, args ): 25 | args = [ '--ca-priv-key', compress_whitespace( ca_key['private_key'] ) ] + args 26 | return run_cert_tool( args ) 27 | 28 | def create_keypair_and_cert( ca_key, args ): 29 | args = args + [ 'gen_keypair', 'create_cert' ] 30 | return run_cert_tool_with_ca_key( ca_key, args ) 31 | 32 | def EmitKey( info, key_name, comment ): 33 | #print info 34 | print '// KeyID . . . .: ' + info['public_key_id'] 35 | print '// Public key . : ' + info['public_key'] 36 | priv_key_var = 'privkey_' + key_name; 37 | priv_key = compress_whitespace( info['private_key'] ) 38 | print 'CECSigningPrivateKey %s;' % priv_key_var 39 | print 'DbgVerify( %s.ParsePEM( "%s", %d ) );' % ( priv_key_var, priv_key, len(priv_key) ) 40 | 41 | def EmitAddCert( cert, key_name, comment ): 42 | #print cert 43 | print '// ' + comment 44 | EmitKey( cert, key_name, comment ) 45 | print '// CA KeyID . . : ' + cert['ca_key_id'] 46 | if cert.get('app_ids'): 47 | print '// Apps . . . . : ' + str( cert['app_ids'] ) 48 | if cert.get('pop_ids'): 49 | print '// POPs . . . . : ' + str( cert['pop_ids'] ) 50 | print 'const uint64 k_key_' + key_name + ' = ' + cert['public_key_id'] + 'ull;' 51 | print 'DbgVerify( CertStore_AddCertFromBase64( "' + cert['cert'] + '", errMsg ) );' 52 | print 53 | 54 | # Hardcoded root that matches the project #define 55 | root1 = { 56 | "private_key" : "-----BEGIN OPENSSH PRIVATE KEY-----\r\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZWQy\r\nNTUxOQAAACDjD7CQNxVGkErB5MmIVr3GLfb9128EQXFrlbmslhnStQAAAH8SNFZ4EjRWeAAA\r\nAAtzc2gtZWQyNTUxOQAAACDjD7CQNxVGkErB5MmIVr3GLfb9128EQXFrlbmslhnStQAAAECP\r\nodiZttz1v9cQKikYj69kVAjlKU7X78vBRreB9eJRJuMPsJA3FUaQSsHkyYhWvcYt9v3XbwRB\r\ncWuVuayWGdK1\r\n-----END OPENSSH PRIVATE KEY-----\r\n", 57 | "public_key" : "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMPsJA3FUaQSsHkyYhWvcYt9v3XbwRBcWuVuayWGdK1 ", 58 | "public_key_id" : "9417917822780561193" 59 | } 60 | 61 | # Another root key, this one not hardcoded. Generate a self-signed cert 62 | root2 = create_keypair() 63 | root2cert = run_cert_tool_with_ca_key( root2, [ '--pub-key', root2['public_key'], "create_cert" ] ) 64 | root2cert['private_key'] = root2['private_key'] 65 | EmitAddCert( root2cert, 'dynamic_root', "Dynamic (not-hardcoded) self-signed cert" ) 66 | 67 | csgo = create_keypair_and_cert( root1, [ '--app', '730' ] ) 68 | EmitAddCert( csgo, 'csgo', "Intermediate cert for app (CSGO), signed by hardcoded key" ) 69 | 70 | csgo_eatmwh = create_keypair_and_cert( csgo, [ '--pop', 'eat,mwh' ] ) 71 | EmitAddCert( csgo_eatmwh, 'csgo_eatmwh', "Cert for particular data center. Not specifically scoped to app, but signed by CSGO cert, so should effectively be scoped." ) 72 | 73 | tf2 = create_keypair_and_cert( root2, [ '--app', '440' ] ) 74 | EmitAddCert( tf2, 'tf2', "Intermediate cert for app (TF2), signed by self-signed cert" ) 75 | 76 | dota_revoked = create_keypair_and_cert( root1, [ '--app', '570' ] ) 77 | EmitAddCert( dota_revoked, 'dota_revoked', "Another intermediate cert signed by hardcoded root" ) 78 | -------------------------------------------------------------------------------- /tests/test_common.cpp: -------------------------------------------------------------------------------- 1 | // Misc stuff used in the tests 2 | 3 | #include "test_common.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #ifndef STEAMNETWORKINGSOCKETS_OPENSOURCE 16 | #include 17 | #endif 18 | 19 | static FILE *g_fpLog = nullptr; 20 | static SteamNetworkingMicroseconds g_logTimeZero; 21 | 22 | static void DebugOutput( ESteamNetworkingSocketsDebugOutputType eType, const char *pszMsg ) 23 | { 24 | // !KLUDGE! 25 | if ( strstr( pszMsg, "Send Nagle") ) 26 | return; 27 | 28 | SteamNetworkingMicroseconds time = SteamNetworkingUtils()->GetLocalTimestamp() - g_logTimeZero; 29 | if ( g_fpLog ) 30 | fprintf( g_fpLog, "%10.6f %s\n", time*1e-6, pszMsg ); 31 | if ( eType <= k_ESteamNetworkingSocketsDebugOutputType_Msg ) 32 | { 33 | printf( "%10.6f %s\n", time*1e-6, pszMsg ); 34 | fflush(stdout); 35 | } 36 | if ( eType == k_ESteamNetworkingSocketsDebugOutputType_Bug ) 37 | { 38 | fflush(stdout); 39 | fflush(stderr); 40 | if ( g_fpLog ) 41 | fflush( g_fpLog ); 42 | 43 | // !KLUDGE! Our logging (which is done while we hold the lock) 44 | // is occasionally triggering this assert. Just ignroe that one 45 | // error for now. 46 | // Yes, this is a kludge. 47 | if ( strstr( pszMsg, "SteamNetworkingGlobalLock held for" ) ) 48 | return; 49 | 50 | assert( !"TEST FAILED" ); 51 | } 52 | } 53 | 54 | void TEST_Printf( const char *fmt, ... ) 55 | { 56 | char text[ 2048 ]; 57 | va_list ap; 58 | va_start( ap, fmt ); 59 | vsprintf( text, fmt, ap ); 60 | va_end(ap); 61 | char *nl = strchr( text, '\0' ) - 1; 62 | if ( nl >= text && *nl == '\n' ) 63 | *nl = '\0'; 64 | DebugOutput( k_ESteamNetworkingSocketsDebugOutputType_Msg, text ); 65 | } 66 | 67 | void TEST_Fatal( const char *fmt, ... ) 68 | { 69 | fflush(stdout); 70 | va_list ap; 71 | va_start(ap, fmt); 72 | vfprintf(stderr, fmt, ap); 73 | va_end(ap); 74 | fputc('\n', stderr); 75 | fflush(stderr); 76 | exit(1); 77 | } 78 | 79 | void TEST_InitLog( const char *pszFilename ) 80 | { 81 | if ( g_logTimeZero ) 82 | return; 83 | 84 | g_logTimeZero = SteamNetworkingUtils()->GetLocalTimestamp(); 85 | 86 | //SteamNetworkingUtils()->SetDebugOutputFunction( k_ESteamNetworkingSocketsDebugOutputType_Debug, DebugOutput ); 87 | SteamNetworkingUtils()->SetDebugOutputFunction( k_ESteamNetworkingSocketsDebugOutputType_Verbose, DebugOutput ); 88 | //SteamNetworkingUtils()->SetDebugOutputFunction( k_ESteamNetworkingSocketsDebugOutputType_Msg, DebugOutput ); 89 | 90 | SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_LogLevel_P2PRendezvous, k_ESteamNetworkingSocketsDebugOutputType_Verbose ); 91 | 92 | if ( !g_fpLog ) 93 | g_fpLog = fopen( pszFilename, "wt" ); 94 | } 95 | 96 | void TEST_Init( const SteamNetworkingIdentity *pIdentity ) 97 | { 98 | TEST_InitLog( "log.txt" ); 99 | 100 | #ifdef STEAMNETWORKINGSOCKETS_OPENSOURCE 101 | SteamDatagramErrMsg errMsg; 102 | if ( !GameNetworkingSockets_Init( pIdentity, errMsg ) ) 103 | { 104 | fprintf( stderr, "GameNetworkingSockets_Init failed. %s", errMsg ); 105 | exit(1); 106 | } 107 | #else 108 | //SteamAPI_Init(); 109 | 110 | SteamDatagram_SetUniverse(); 111 | SteamDatagram_SetAppID( 570 ); // Just set something, doesn't matter what 112 | 113 | SteamDatagramErrMsg errMsg; 114 | if ( !SteamDatagramClient_Init( errMsg ) ) 115 | { 116 | fprintf( stderr, "SteamDatagramClient_Init failed. %s", errMsg ); 117 | exit(1); 118 | } 119 | 120 | if ( pIdentity ) 121 | SteamNetworkingSockets()->ResetIdentity( pIdentity ); 122 | 123 | // Disable auth 124 | SteamNetworkingUtils()->SetGlobalConfigValueInt32( k_ESteamNetworkingConfig_IP_AllowWithoutAuth, 2 ); 125 | 126 | #endif 127 | } 128 | 129 | void TEST_Kill() 130 | { 131 | #ifdef STEAMNETWORKINGSOCKETS_OPENSOURCE 132 | GameNetworkingSockets_Kill(); 133 | #else 134 | SteamDatagramClient_Kill(); 135 | SteamDatagramServer_Kill(); 136 | #endif 137 | } 138 | 139 | void TEST_PumpCallbacks() 140 | { 141 | if ( SteamNetworkingSockets() ) 142 | SteamNetworkingSockets()->RunCallbacks(); 143 | #ifndef STEAMNETWORKINGSOCKETS_OPENSOURCE 144 | if ( SteamGameServerNetworkingSockets() ) 145 | SteamGameServerNetworkingSockets()->RunCallbacks(); 146 | #endif 147 | std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) ); 148 | } 149 | 150 | -------------------------------------------------------------------------------- /tests/test_common.h: -------------------------------------------------------------------------------- 1 | // Misc stuff used in the tests 2 | #pragma once 3 | 4 | // Include a bunch of common headers, especially the ones that will configure 5 | // Visual Studio memory allocation and check the _DEBUG flag. We are 6 | // about to slam that flag to force assert to be enabled below. 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | // Force asserts to be enabled, even in release build 14 | #undef NDEBUG 15 | #ifndef _DEBUG 16 | #define _DEBUG 17 | #endif 18 | #include 19 | 20 | struct SteamNetworkingIdentity; 21 | 22 | extern void TEST_InitLog( const char *pszFilename ); 23 | extern void TEST_Printf( const char *fmt, ... ); 24 | extern void TEST_Fatal( const char *fmt, ... ); 25 | extern void TEST_Init( const SteamNetworkingIdentity *pIdentity ); 26 | extern void TEST_Kill(); 27 | extern void TEST_PumpCallbacks(); 28 | -------------------------------------------------------------------------------- /tests/test_flat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", 3 | "name": "gamenetworkingsockets", 4 | "version-string": "1.4.0", 5 | "description": "A basic transport layer for games.", 6 | "homepage": "https://github.com/ValveSoftware/GameNetworkingSockets", 7 | "dependencies": [ "protobuf", "openssl" ], 8 | "default-features": [ "openssl" ], 9 | "features": { 10 | "openssl": { 11 | "description": "Use OpenSSL as the crypto provider. This is the default.", 12 | "dependencies": [ "openssl" ] 13 | }, 14 | "libsodium": { 15 | "description": "Use libsodium as the crypto provider.", 16 | "dependencies": [ "libsodium" ] 17 | }, 18 | "webrtc": { 19 | "description": "Compiles WebRTC support for P2P.", 20 | "dependencies": [ "abseil" ] 21 | }, 22 | "examples": { 23 | "description": "Build the examples." 24 | }, 25 | "tests": { 26 | "description": "Build the tests." 27 | }, 28 | "tools": { 29 | "description": "Build cert management tool." 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vcpkg_ports/gamenetworkingsockets/portfile.cmake: -------------------------------------------------------------------------------- 1 | set(SOURCE_PATH ".") 2 | 3 | # Select crypto backend based on the selected crypto "feature" 4 | # WE ARE NOT SUPPOSED TO BE DOING THIS. 5 | # I'd be super happy if somebody wants to fix this up properly. 6 | if ("libsodium" IN_LIST FEATURES) 7 | set(CRYPTO_BACKEND "libsodium") 8 | endif() 9 | if ("bcrypt" IN_LIST FEATURES) 10 | set(CRYPTO_BACKEND "BCrypt") 11 | endif() 12 | if ( ( "${CRYPTO_BACKEND}" STREQUAL "" ) OR ( "openssl" IN_LIST FEATURES ) ) 13 | set(CRYPTO_BACKEND "OpenSSL") 14 | endif() 15 | 16 | # Handle some simple options that we can just 17 | # pass straight through to cmake 18 | vcpkg_check_features( 19 | OUT_FEATURE_OPTIONS FEATURE_OPTIONS 20 | FEATURES 21 | webrtc USE_STEAMWEBRTC 22 | examples BUILD_EXAMPLES 23 | tests BUILD_TESTS 24 | tools BUILD_TOOLS 25 | ) 26 | 27 | # Check static versus dynamic in the triple. Our cmakefile can build both 28 | # of them, but in the context of vcpkg, we will only build one or the other 29 | string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED_LIB) 30 | string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIB) 31 | 32 | # Select how to link the MSVC C runtime lib. When building the static 33 | # lib, we will link the CRT statically. Otherwise, link dynamically. 34 | string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" MSVC_CRT_STATIC) 35 | 36 | # Examples require linking with the shared lib 37 | if (BUILD_EXAMPLES) 38 | set(BUILD_SHARED_LIB true) 39 | endif() 40 | 41 | # Tests and tools require linking with the static lib 42 | if (BUILD_TESTS OR BUILD_TOOLS) 43 | set(BUILD_STATIC_LIB true) 44 | endif() 45 | 46 | vcpkg_configure_cmake( 47 | SOURCE_PATH ${SOURCE_PATH} 48 | PREFER_NINJA 49 | OPTIONS 50 | -DUSE_CRYPTO=${CRYPTO_BACKEND} 51 | -DBUILD_STATIC_LIB=${BUILD_STATIC_LIB} 52 | -DBUILD_SHARED_LIB=${BUILD_SHARED_LIB} 53 | -DMSVC_CRT_STATIC=${MSVC_CRT_STATIC} 54 | ${FEATURE_OPTIONS} 55 | ) 56 | 57 | vcpkg_cmake_install() 58 | 59 | # Copy some files 60 | 61 | file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) 62 | vcpkg_copy_pdbs() 63 | 64 | # Cleanup some file droppings that our cmakefile really should 65 | # not be publishing 66 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") 67 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") 68 | --------------------------------------------------------------------------------