Skip to content

Commit

Permalink
Removed excessive argument from regenCryptoKm
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 12, 2022
1 parent f212a38 commit 54fec45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
18 changes: 8 additions & 10 deletions srtcore/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ int srt::CCryptoControl::processSrtMsg_KMRSP(const uint32_t* srtdata, size_t len

void srt::CCryptoControl::sendKeysToPeer(CUDT* sock SRT_ATR_UNUSED, int iSRTT SRT_ATR_UNUSED, Whether2RegenKm regen SRT_ATR_UNUSED)
{
if ( !m_hSndCrypto || m_SndKmState == SRT_KM_S_UNSECURED)
if (!m_hSndCrypto || m_SndKmState == SRT_KM_S_UNSECURED)
{
HLOGC(cnlog.Debug, log << "sendKeysToPeer: NOT sending/regenerating keys: "
<< (m_hSndCrypto ? "CONNECTION UNSECURED" : "NO TX CRYPTO CTX created"));
Expand Down Expand Up @@ -466,16 +466,15 @@ void srt::CCryptoControl::sendKeysToPeer(CUDT* sock SRT_ATR_UNUSED, int iSRTT SR
if (regen)
{
regenCryptoKm(
sock,
true, // send UMSG_EXT + SRT_CMD_KMREQ to the peer, if regenerated the key
sock, // send UMSG_EXT + SRT_CMD_KMREQ to the peer using this socket
false // Do not apply the regenerated key to the to the receiver context
); // regenerate and send
}
#endif
}

#ifdef SRT_ENABLE_ENCRYPTION
void srt::CCryptoControl::regenCryptoKm(CUDT* sock, bool sendit, bool bidirectional)
void srt::CCryptoControl::regenCryptoKm(CUDT* sock, bool bidirectional)
{
if (!m_hSndCrypto)
return;
Expand Down Expand Up @@ -514,7 +513,7 @@ void srt::CCryptoControl::regenCryptoKm(CUDT* sock, bool sendit, bool bidirectio
m_SndKmMsg[ki].MsgLen = out_len_p[i];
m_SndKmMsg[ki].iPeerRetry = SRT_MAX_KMRETRY;

if (bidirectional && !sendit)
if (bidirectional && !sock)
{
// "Send" this key also to myself, just to be applied to the receiver crypto,
// exactly the same way how this key is interpreted on the peer side into its receiver crypto
Expand All @@ -527,7 +526,7 @@ void srt::CCryptoControl::regenCryptoKm(CUDT* sock, bool sendit, bool bidirectio
}
}

if (sendit)
if (sock)
{
HLOGC(cnlog.Debug, log << "regenCryptoKm: SENDING ki=" << ki << " len=" << m_SndKmMsg[ki].MsgLen
<< " retry(updated)=" << m_SndKmMsg[ki].iPeerRetry);
Expand Down Expand Up @@ -628,10 +627,9 @@ bool srt::CCryptoControl::init(HandshakeSide side, const CSrtConfig& cfg, bool b
}

regenCryptoKm(
NULL,
false, // Do not send the key (will be attached it to the HSv5 handshake)
bidirectional // replicate the key to the receiver context, if bidirectional
);
NULL, // Do not send the key (the KM msg will be attached to the HSv5 handshake)
bidirectional // replicate the key to the receiver context, if bidirectional
);
#else
// This error would be a consequence of setting the passphrase, while encryption
// is turned off at compile time. Setting the password itself should be not allowed
Expand Down
18 changes: 9 additions & 9 deletions srtcore/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern Logger cnlog;
namespace srt
{
class CUDT;
class CSrtConfig;
struct CSrtConfig;


// For KMREQ/KMRSP. Only one field is used.
Expand Down Expand Up @@ -85,7 +85,6 @@ class CCryptoControl
bool m_bErrorReported;

public:

static void globalInit();

bool sendingAllowed()
Expand All @@ -111,9 +110,11 @@ class CCryptoControl
}

private:

#ifdef SRT_ENABLE_ENCRYPTION
void regenCryptoKm(CUDT* sock, bool sendit, bool bidirectional);
/// Regenerate cryptographic key material.
/// @param[in] sock If not null, the socket will be used to send the KM message to the peer (e.g. KM refresh).
/// @param[in] bidirectional If true, the key material will be regenerated for both directions (receiver and sender).
void regenCryptoKm(CUDT* sock, bool bidirectional);
#endif

public:
Expand Down Expand Up @@ -206,16 +207,15 @@ class CCryptoControl
bool init(HandshakeSide, const CSrtConfig&, bool);
void close();

// This function is used in:
// - HSv4 (initial key material exchange - in HSv5 it's attached to handshake)
// - case of key regeneration, which should be then exchanged again
/// @return True if the handshake is in progress.
/// This function is used in:
/// - HSv4 (initial key material exchange - in HSv5 it's attached to handshake)
/// - case of key regeneration, which should be then exchanged again.
void sendKeysToPeer(CUDT* sock, int iSRTT, Whether2RegenKm regen);


void setCryptoSecret(const HaiCrypt_Secret& secret)
{
m_KmSecret = secret;
//memcpy(&m_KmSecret, &secret, sizeof(m_KmSecret));
}

void setCryptoKeylen(size_t keylen)
Expand Down
2 changes: 1 addition & 1 deletion srtcore/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static unsigned int* getRandSeed()
int srt::sync::genRandomInt(int minVal, int maxVal)
{
// This Meyers singleton initialization is thread-safe since C++11, but is not thread-safe in C++03.
// A mutex to protect simulteneout access to the random device.
// A mutex to protect simultaneous access to the random device.
// Thread-local storage could be used here instead to store the seed / random device.
// However the generator is not used often (Initial Socket ID, Initial sequence number, FileCC),
// so sharing a single seed among threads should not impact the performance.
Expand Down

0 comments on commit 54fec45

Please sign in to comment.