diff --git a/srtcore/api.cpp b/srtcore/api.cpp index 9a07be357..9046782e2 100644 --- a/srtcore/api.cpp +++ b/srtcore/api.cpp @@ -254,6 +254,8 @@ int srt::CUDTUnited::startup() throw CUDTException(MJ_SETUP, MN_NONE, WSAGetLastError()); #endif + CCryptoControl::globalInit(); + PacketFilter::globalInit(); if (m_bGCStatus) diff --git a/srtcore/api.h b/srtcore/api.h index 98bfe0417..ca812bf9e 100644 --- a/srtcore/api.h +++ b/srtcore/api.h @@ -216,6 +216,7 @@ class CUDTUnited friend class CUDT; friend class CUDTGroup; friend class CRendezvousQueue; + friend class CCryptoControl; public: CUDTUnited(); diff --git a/srtcore/crypto.cpp b/srtcore/crypto.cpp index 1cb823faf..1b00aa7d3 100644 --- a/srtcore/crypto.cpp +++ b/srtcore/crypto.cpp @@ -26,6 +26,7 @@ written by #include "crypto.h" #include "logging.h" #include "core.h" +#include "api.h" using namespace srt_logging; @@ -69,6 +70,15 @@ std::string KmStateStr(SRT_KM_STATE state) using srt_logging::KmStateStr; +void srt::CCryptoControl::globalInit() +{ +#ifdef SRT_ENABLE_ENCRYPTION + // We need to force the Cryspr to be initialized during startup to avoid the + // possibility of multiple threads initialzing the same static data later on. + HaiCryptCryspr_Get_Instance(); +#endif +} + #if ENABLE_LOGGING std::string srt::CCryptoControl::FormatKmMessage(std::string hdr, int cmd, size_t srtlen) { diff --git a/srtcore/crypto.h b/srtcore/crypto.h index 25320452e..e6e588fc1 100644 --- a/srtcore/crypto.h +++ b/srtcore/crypto.h @@ -86,6 +86,8 @@ class CCryptoControl public: + static void globalInit(); + bool sendingAllowed() { // This function is called to state as to whether the