Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement build configuration header for SRT_ENABLE_AEAD_API_PREVIEW. #2696

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,13 @@ if(DEFINED ENV{TEAMCITY_VERSION})
endif()

configure_file("srtcore/version.h.in" "version.h" @ONLY)

list(INSERT HEADERS_srt 0 "${CMAKE_CURRENT_BINARY_DIR}/version.h")
include_directories("${CMAKE_CURRENT_BINARY_DIR}")

set(SRT_ENABLE_AEAD_API_PREVIEW ${ENABLE_AEAD_API_PREVIEW})
configure_file("srtcore/srt_config.h.in" "srt_config.h" @ONLY)
list(APPEND HEADERS_srt "${CMAKE_CURRENT_BINARY_DIR}/srt_config.h")

add_library(srt_virtual OBJECT ${SOURCES_srt} ${SOURCES_srt_extra} ${HEADERS_srt} ${SOURCES_haicrypt} ${SOURCES_common})
Comment on lines +955 to 959
Copy link
Collaborator

@ethouris ethouris May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(SRT_ENABLE_AEAD_API_PREVIEW ${ENABLE_AEAD_API_PREVIEW})
configure_file("srtcore/srt_config.h.in" "srt_config.h" @ONLY)
list(APPEND HEADERS_srt "${CMAKE_CURRENT_BINARY_DIR}/srt_config.h")
add_library(srt_virtual OBJECT ${SOURCES_srt} ${SOURCES_srt_extra} ${HEADERS_srt} ${SOURCES_haicrypt} ${SOURCES_common})
add_library(srt_virtual OBJECT ${SOURCES_srt} ${SOURCES_srt_extra} ${HEADERS_srt} ${SOURCES_haicrypt} ${SOURCES_common})
set_if(SRT_ENABLE_AEAD_API_PREVIEW ENABLE_AEAD_API_PREVIEW)
target_compile_definitions(srt_virtual PRIVATE ENABLE_AEAD_API_PREVIEW=${SRT_ENABLE_AEAD_API_PREVIEW})


if (ENABLE_SHARED)
Expand Down
2 changes: 1 addition & 1 deletion apps/socketoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const SocketOption srt_options [] {
{ "bindtodevice", 0, SRTO_BINDTODEVICE, SocketOption::PRE, SocketOption::STRING, nullptr},
#endif
{ "retransmitalgo", 0, SRTO_RETRANSMITALGO, SocketOption::PRE, SocketOption::INT, nullptr }
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
#if SRT_ENABLE_AEAD_API_PREVIEW

,{ "cryptomode", 0, SRTO_CRYPTOMODE, SocketOption::PRE, SocketOption::INT, nullptr }
#endif
};
Expand Down
8 changes: 4 additions & 4 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ struct SrtOptionAction
#endif
flags[SRTO_PACKETFILTER] = SRTO_R_PRE;
flags[SRTO_RETRANSMITALGO] = SRTO_R_PRE;
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
flags[SRTO_CRYPTOMODE] = SRTO_R_PRE;
#endif

Expand Down Expand Up @@ -813,7 +813,7 @@ void srt::CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
*(int32_t *)optval = m_config.iRetransmitAlgo;
optlen = sizeof(int32_t);
break;
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
case SRTO_CRYPTOMODE:
if (m_pCryptoControl)
*(int32_t*)optval = m_pCryptoControl->getCryptoMode();
Expand Down Expand Up @@ -2624,7 +2624,7 @@ bool srt::CUDT::interpretSrtHandshake(const CHandShake& hs,
}
if (*pw_len == 1)
{
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
if (m_pCryptoControl->m_RcvKmState == SRT_KM_S_BADCRYPTOMODE)
{
// Cryptographic modes mismatch. Not acceptable at all.
Expand Down Expand Up @@ -2663,7 +2663,7 @@ bool srt::CUDT::interpretSrtHandshake(const CHandShake& hs,
{
if (m_pCryptoControl->m_SndKmState == SRT_KM_S_BADSECRET)
m_RejectReason = SRT_REJ_BADSECRET;
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
else if (m_pCryptoControl->m_SndKmState == SRT_KM_S_BADCRYPTOMODE)
m_RejectReason = SRT_REJ_CRYPTO;
#endif
Expand Down
6 changes: 3 additions & 3 deletions srtcore/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string KmStateStr(SRT_KM_STATE state)
TAKE(SECURING);
TAKE(NOSECRET);
TAKE(BADSECRET);
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
TAKE(BADCRYPTOMODE);
#endif
#undef TAKE
Expand Down Expand Up @@ -254,7 +254,7 @@ int srt::CCryptoControl::processSrtMsg_KMREQ(
LOGC(cnlog.Warn, log << "KMREQ/rcv: (snd) Rx process failure - BADSECRET");
break;
case HAICRYPT_ERROR_CIPHER:
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
m_RcvKmState = m_SndKmState = SRT_KM_S_BADCRYPTOMODE;
#else
m_RcvKmState = m_SndKmState = SRT_KM_S_BADSECRET; // Use "bad secret" as a fallback.
Expand Down Expand Up @@ -410,7 +410,7 @@ int srt::CCryptoControl::processSrtMsg_KMRSP(const uint32_t* srtdata, size_t len
m_SndKmState = SRT_KM_S_UNSECURED;
retstatus = 0;
break;
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
case SRT_KM_S_BADCRYPTOMODE:
// The peer expects to use a different cryptographic mode (e.g. AES-GCM, not AES-CTR).
m_RcvKmState = SRT_KM_S_BADCRYPTOMODE;
Expand Down
4 changes: 2 additions & 2 deletions srtcore/socketconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ struct CSrtConfigSetter<SRTO_RETRANSMITALGO>
}
};

#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
template<>
struct CSrtConfigSetter<SRTO_CRYPTOMODE>
{
Expand Down Expand Up @@ -994,7 +994,7 @@ int dispatchSet(SRT_SOCKOPT optName, CSrtConfig& co, const void* optval, int opt
DISPATCH(SRTO_IPV6ONLY);
DISPATCH(SRTO_PACKETFILTER);
DISPATCH(SRTO_RETRANSMITALGO);
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
DISPATCH(SRTO_CRYPTOMODE);
#endif

Expand Down
4 changes: 3 additions & 1 deletion srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ written by

#include "version.h"

#include "srt_config.h"

#include "platform_sys.h"

#include <string.h>
Expand Down Expand Up @@ -239,7 +241,7 @@ typedef enum SRT_SOCKOPT {
SRTO_GROUPTYPE, // Group type to which an accepted socket is about to be added, available in the handshake (ENABLE_BONDING)
SRTO_PACKETFILTER = 60, // Add and configure a packet filter
SRTO_RETRANSMITALGO = 61, // An option to select packet retransmission algorithm
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
SRTO_CRYPTOMODE = 62, // Encryption cipher mode (AES-CTR, AES-GCM, ...).
#endif

Expand Down
4 changes: 2 additions & 2 deletions srtcore/srt_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ const char* const srt_rejection_reason_msg [] = {
"Packet Filter settings error",
"Group settings collision",
"Connection timeout"
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
,"Crypto mode"
#endif
};
Expand All @@ -463,7 +463,7 @@ extern const char* const srt_rejectreason_msg[] = {
srt_rejection_reason_msg[14],
srt_rejection_reason_msg[15],
srt_rejection_reason_msg[16]
#ifdef ENABLE_AEAD_API_PREVIEW
#if defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
, srt_rejection_reason_msg[17]
#endif
};
Expand Down
16 changes: 16 additions & 0 deletions srtcore/srt_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SRT - Secure, Reliable, Transport
* Copyright (c) 2023 Haivision Systems Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/

#ifndef INC_SRT_CONIFG_H
#define INC_SRT_CONIFG_H

#cmakedefine01 SRT_ENABLE_AEAD_API_PREVIEW

#endif // INC_SRT_CONIFG_H
4 changes: 2 additions & 2 deletions test/test_crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "gtest/gtest.h"

#if defined(SRT_ENABLE_ENCRYPTION) && defined(ENABLE_AEAD_API_PREVIEW)
#if defined(SRT_ENABLE_ENCRYPTION) && defined(SRT_ENABLE_AEAD_API_PREVIEW) && (SRT_ENABLE_AEAD_API_PREVIEW == 1)
#include "crypto.h"
#include "hcrypt.h" // Imports the CRYSPR_HAS_AESGCM definition.
#include "socketconfig.h"
Expand Down Expand Up @@ -108,4 +108,4 @@ namespace srt

} // namespace srt

#endif //SRT_ENABLE_ENCRYPTION && ENABLE_AEAD_API_PREVIEW
#endif //SRT_ENABLE_ENCRYPTION && SRT_ENABLE_AEAD_API_PREVIEW