Skip to content

Commit

Permalink
Merge branch 'master' into dev-fix-connectionlock-inversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Jul 21, 2023
2 parents 610cf23 + 1737e96 commit 8a154d0
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 10 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ if(WIN32)
if(ENABLE_INET_PTON)
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
check_function_exists(inet_pton HAVE_INET_PTON)
add_definitions(-D_WIN32_WINNT=0x0600)
try_compile(AT_LEAST_VISTA
${CMAKE_BINARY_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/test_vista.c")
if(NOT AT_LEAST_VISTA)
# force targeting Vista
add_definitions(-D_WIN32_WINNT=0x0600)
endif()
else()
add_definitions(-D_WIN32_WINNT=0x0501)
endif()
Expand Down
2 changes: 1 addition & 1 deletion docs/API/API-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Since SRT v1.5.0.
| [SRT_REJ_FILTER](#SRT_REJ_FILTER) | 1.3.4 | The [`SRTO_PACKETFILTER`](API-socket-options.md#SRTO_PACKETFILTER) option has been set differently on both connection parties |
| [SRT_REJ_GROUP](#SRT_REJ_GROUP) | 1.4.2 | The group type or some group settings are incompatible for both connection parties |
| [SRT_REJ_TIMEOUT](#SRT_REJ_TIMEOUT) | 1.4.2 | The connection wasn't rejected, but it timed out |
| [SRT_REJ_CRYPTO](#SRT_REJ_CRYPTO) | 1.6.0-dev | The connection was rejected due to an unsupported or mismatching encryption mode |
| [SRT_REJ_CRYPTO](#SRT_REJ_CRYPTO) | 1.5.2 | The connection was rejected due to an unsupported or mismatching encryption mode |
| <img width=290px height=1px/> | | |

<h4 id="error-codes">Error Codes</h4>
Expand Down
4 changes: 2 additions & 2 deletions docs/API/API-socket-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ The following table lists SRT API socket options in alphabetical order. Option d
| [`SRTO_BINDTODEVICE`](#SRTO_BINDTODEVICE) | 1.4.2 | pre-bind | `string` | | | | RW | GSD+ |
| [`SRTO_CONGESTION`](#SRTO_CONGESTION) | 1.3.0 | pre | `string` | | "live" | \* | W | S |
| [`SRTO_CONNTIMEO`](#SRTO_CONNTIMEO) | 1.1.2 | pre | `int32_t` | ms | 3000 | 0.. | W | GSD+ |
| [`SRTO_CRYPTOMODE`](#SRTO_CRYPTOMODE) | 1.6.0-dev | pre | `int32_t` | | 0 (Auto) | [0, 2] | W | GSD |
| [`SRTO_CRYPTOMODE`](#SRTO_CRYPTOMODE) | 1.5.2 | pre | `int32_t` | | 0 (Auto) | [0, 2] | W | GSD |
| [`SRTO_DRIFTTRACER`](#SRTO_DRIFTTRACER) | 1.4.2 | post | `bool` | | true | | RW | GSD |
| [`SRTO_ENFORCEDENCRYPTION`](#SRTO_ENFORCEDENCRYPTION) | 1.3.2 | pre | `bool` | | true | | W | GSD |
| [`SRTO_EVENT`](#SRTO_EVENT) | | | `int32_t` | flags | | | R | S |
Expand Down Expand Up @@ -327,7 +327,7 @@ will be 10 times the value set with `SRTO_CONNTIMEO`.

| OptName | Since | Restrict | Type | Units | Default | Range | Dir | Entity |
| ------------------ | --------- | -------- | --------- | ------ | -------- | ------ | --- | ------ |
| `SRTO_CRYPTOMODE` | 1.6.0-dev | pre | `int32_t` | | 0 (Auto) | [0, 2] | RW | GSD |
| `SRTO_CRYPTOMODE` | 1.5.2 | pre | `int32_t` | | 0 (Auto) | [0, 2] | RW | GSD |

The encryption mode to be used if the [`SRTO_PASSPHRASE`](#SRTO_PASSPHRASE) is set.

Expand Down
3 changes: 2 additions & 1 deletion docs/build/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ use encryption for the connection.

When ON, the AEAD API is enabled. The `ENABLE_ENCRYPTION` must be enabled as well.
The AEAD functionality is only available if OpenSSL EVP is selected as the crypto provider:
build option `-DUSE_ENCLIB=openssl-evp`.
build option should be set to `USE_ENCLIB=openssl-evp`.

The AEAD API is to be official in SRT v1.6.0.


Expand Down
3 changes: 2 additions & 1 deletion haicrypt/hcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ int HaiCrypt_Clone(HaiCrypt_Handle hhcSrc, HaiCrypt_CryptoDir tx, HaiCrypt_Handl

if (tx) {
HaiCrypt_Cfg crypto_config;
HaiCrypt_ExtractConfig(hhcSrc, &crypto_config);
if (-1 == HaiCrypt_ExtractConfig(hhcSrc, &crypto_config))
return -1;

/*
* Just invert the direction written in flags and use the
Expand Down
10 changes: 10 additions & 0 deletions scripts/test_vista.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright © 2023 Steve Lhomme */
/* SPDX-License-Identifier: ISC */
#include <windows.h>
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 /* _WIN32_WINNT_VISTA */
#error NOPE
#endif
int main(void)
{
return 0;
}
15 changes: 13 additions & 2 deletions srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,19 @@ int srt::CChannel::sendto(const sockaddr_any& addr, CPacket& packet, const socka
#else
DWORD size = (DWORD)(CPacket::HDR_SIZE + packet.getLength());
int addrsize = addr.size();
int res = ::WSASendTo(m_iSocket, (LPWSABUF)packet.m_PacketVector, 2, &size, 0, addr.get(), addrsize, NULL, NULL);
res = (0 == res) ? size : -1;
WSAOVERLAPPED overlapped;
SecureZeroMemory((PVOID)&overlapped, sizeof(WSAOVERLAPPED));
int res = ::WSASendTo(m_iSocket, (LPWSABUF)packet.m_PacketVector, 2, &size, 0, addr.get(), addrsize, &overlapped, NULL);

if (res == SOCKET_ERROR && NET_ERROR == WSA_IO_PENDING)
{
DWORD dwFlags = 0;
const bool bCompleted = WSAGetOverlappedResult(m_iSocket, &overlapped, &size, true, &dwFlags);
WSACloseEvent(overlapped.hEvent);
res = bCompleted ? 0 : -1;
}

res = (0 == res) ? size : -1;
#endif

packet.toHL();
Expand Down
2 changes: 1 addition & 1 deletion srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ enum SRT_KM_STATE
SRT_KM_S_NOSECRET = 3, // Stream encrypted and no secret to decrypt Keying Material
SRT_KM_S_BADSECRET = 4 // Stream encrypted and wrong secret is used, cannot decrypt Keying Material
#ifdef ENABLE_AEAD_API_PREVIEW
,SRT_KM_S_BADCRYPTOMODE = 5 // Stream encrypted but wrong cryptographic mode is used, cannot decrypt. Since v1.6.0.
,SRT_KM_S_BADCRYPTOMODE = 5 // Stream encrypted but wrong cryptographic mode is used, cannot decrypt. Since v1.5.2.
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion srtcore/sync_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void rdtsc(uint64_t& x)
asm("mov %0=ar.itc" : "=r"(x)::"memory");
#elif SRT_SYNC_CLOCK == SRT_SYNC_CLOCK_AMD64_RDTSC
uint32_t lval, hval;
asm("rdtsc" : "=a"(lval), "=d"(hval));
asm volatile("rdtsc" : "=a"(lval), "=d"(hval));
x = hval;
x = (x << 32) | lval;
#elif SRT_SYNC_CLOCK == SRT_SYNC_CLOCK_WINQPC
Expand Down

0 comments on commit 8a154d0

Please sign in to comment.