Skip to content

Commit

Permalink
Removed unnecessary changes.
Browse files Browse the repository at this point in the history
Fixes tab usasge.
  • Loading branch information
maxsharabayko committed Apr 18, 2024
1 parent b7d6d01 commit 52ed4cc
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 33 deletions.
1 change: 0 additions & 1 deletion haicrypt/haicrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ typedef struct {
#define HAICRYPT_CFG_F_CRYPTO 0x02 /* Perform crypto Tx:Encrypt Rx:Decrypt */
#define HAICRYPT_CFG_F_FEC 0x04 /* Do Forward Error Correction */
#define HAICRYPT_CFG_F_GCM 0x08 /* Use AES-GCM */
#define HAICRYPT_CFG_F_GCM_153 0x10 /* Use AES-GCM compatibility mode with SRT v1.5.3 or earlier */
unsigned flags;

HaiCrypt_Secret secret; /* Security Association */
Expand Down
20 changes: 10 additions & 10 deletions haicrypt/hcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ int HaiCrypt_Create(const HaiCrypt_Cfg *cfg, HaiCrypt_Handle *phhc)

int HaiCrypt_UpdateGcm153(HaiCrypt_Handle hhc, unsigned use_gcm_153)
{
ASSERT(hhc != NULL);
hcrypt_Session* crypto = hhc;
if (!crypto)
return(-1);

crypto->ctx_pair[0].use_gcm_153 = use_gcm_153;
crypto->ctx_pair[1].use_gcm_153 = use_gcm_153;
return(0);
ASSERT(hhc != NULL);
hcrypt_Session* crypto = hhc;
if (!crypto)
return (-1);

crypto->ctx_pair[0].use_gcm_153 = use_gcm_153;
crypto->ctx_pair[1].use_gcm_153 = use_gcm_153;
return (0);
}

int HaiCrypt_ExtractConfig(HaiCrypt_Handle hhcSrc, HaiCrypt_Cfg* pcfg)
Expand Down Expand Up @@ -278,7 +278,7 @@ int HaiCrypt_Clone(HaiCrypt_Handle hhcSrc, HaiCrypt_CryptoDir tx, HaiCrypt_Handl
cryptoClone->ctx = &cryptoClone->ctx_pair[0];
cryptoClone->ctx->flags |= (HCRYPT_CTX_F_ANNOUNCE | HCRYPT_CTX_F_TTSEND);
cryptoClone->ctx->status = HCRYPT_CTX_S_ACTIVE;
cryptoClone->ctx->use_gcm_153 = cryptoSrc->ctx->use_gcm_153;
cryptoClone->ctx->use_gcm_153 = cryptoSrc->ctx->use_gcm_153;

} else { /* Receiver */

Expand Down Expand Up @@ -334,7 +334,7 @@ int HaiCrypt_Clone(HaiCrypt_Handle hhcSrc, HaiCrypt_CryptoDir tx, HaiCrypt_Handl
memset(cryptoClone->ctx_pair[0].salt, 0, sizeof(cryptoClone->ctx_pair[0].salt));
cryptoClone->ctx_pair[0].salt_len = 0;
cryptoClone->ctx = &cryptoClone->ctx_pair[0];
cryptoClone->ctx->use_gcm_153 = cryptoSrc->ctx->use_gcm_153;
cryptoClone->ctx->use_gcm_153 = cryptoSrc->ctx->use_gcm_153;
}

*phhc = (void *)cryptoClone;
Expand Down
1 change: 0 additions & 1 deletion haicrypt/hcrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ typedef struct hcrypt_Session_str {

struct {
size_t data_max_len;
bool aes_gcm_153; /* AES-GCM compatibility mode (SRT v1.5.3 and earlier) */
}cfg;

struct {
Expand Down
1 change: 0 additions & 1 deletion haicrypt/hcrypt_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ typedef struct tag_hcrypt_Ctx {
#define HCRYPT_CTX_F_ENCRYPT 0x0100 /* 0:decrypt 1:encrypt */
#define HCRYPT_CTX_F_ANNOUNCE 0x0200 /* Announce KM */
#define HCRYPT_CTX_F_TTSEND 0x0400 /* time to send */
#define HCRYPT_CTX_F_GCM_153 0x0800 /* AES-GCM compatibility mode (SRT v1.5.3 and earlier) */
unsigned flags;
#define hcryptCtx_GetKeyFlags(ctx) ((ctx)->flags & HCRYPT_CTX_F_xSEK)
#define hcryptCtx_GetKeyIndex(ctx) (((ctx)->flags & HCRYPT_CTX_F_xSEK)>>1)
Expand Down
2 changes: 1 addition & 1 deletion haicrypt/hcrypt_ctx_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ int hcryptCtx_Rx_Init(hcrypt_Session *crypto, hcrypt_Ctx *ctx, const HaiCrypt_Cf
{
if (cfg) {
ctx->mode = (cfg->flags & HAICRYPT_CFG_F_GCM) ? HCRYPT_CTX_MODE_AESGCM : HCRYPT_CTX_MODE_AESCTR;
ctx->use_gcm_153 = (cfg->flags & HAICRYPT_CFG_F_GCM_153) ? true : false;
}
ctx->status = HCRYPT_CTX_S_INIT;
ctx->msg_info = crypto->msg_info;
ctx->use_gcm_153 = false; // Default initialization.

if (cfg && hcryptCtx_SetSecret(crypto, ctx, &cfg->secret)) {
return(-1);
Expand Down
2 changes: 1 addition & 1 deletion haicrypt/hcrypt_ctx_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int hcryptCtx_Tx_Init(hcrypt_Session *crypto, hcrypt_Ctx *ctx, const HaiCrypt_Cf

ctx->mode = (cfg->flags & HAICRYPT_CFG_F_GCM) ? HCRYPT_CTX_MODE_AESGCM : HCRYPT_CTX_MODE_AESCTR;
ctx->status = HCRYPT_CTX_S_INIT;
ctx->use_gcm_153 = (cfg->flags & HAICRYPT_CFG_F_GCM_153) ? true : false;
ctx->use_gcm_153 = false; // Defaul initialization.
ctx->msg_info = crypto->msg_info;

if (hcryptCtx_SetSecret(crypto, ctx, &cfg->secret)) {
Expand Down
2 changes: 1 addition & 1 deletion srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5994,7 +5994,7 @@ bool srt::CUDT::createCrypter(HandshakeSide side, bool bidirectional)
// they have outdated values.
m_pCryptoControl->setCryptoSecret(m_config.CryptoSecret);

const bool useGcm153 = m_uPeerSrtVersion <= SrtVersion(1, 5, 3);
const bool useGcm153 = m_uPeerSrtVersion <= SrtVersion(1, 5, 3);

if (bidirectional || m_config.bDataSender)
{
Expand Down
21 changes: 9 additions & 12 deletions srtcore/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int srt::CCryptoControl::processSrtMsg_KMREQ(
(m_iCryptoMode == CSrtConfig::CIPHER_MODE_AUTO && kmdata[HCRYPT_MSG_KM_OFS_CIPHER] == HCRYPT_CIPHER_AES_GCM) ||
(m_iCryptoMode == CSrtConfig::CIPHER_MODE_AES_GCM);

m_bUseGcm153 = srtv <= SrtVersion(1, 5, 3);
m_bUseGcm153 = srtv <= SrtVersion(1, 5, 3);

// What we have to do:
// If encryption is on (we know that by having m_KmSecret nonempty), create
Expand Down Expand Up @@ -459,11 +459,11 @@ int srt::CCryptoControl::processSrtMsg_KMRSP(const uint32_t* srtdata, size_t len
HLOGC(cnlog.Debug, log << "processSrtMsg_KMRSP: key[0]: len=" << m_SndKmMsg[0].MsgLen << " retry=" << m_SndKmMsg[0].iPeerRetry
<< "; key[1]: len=" << m_SndKmMsg[1].MsgLen << " retry=" << m_SndKmMsg[1].iPeerRetry);

m_bUseGcm153 = srtv <= SrtVersion(1, 5, 3);
if (m_hRcvCrypto != NULL)
HaiCrypt_UpdateGcm153(m_hRcvCrypto, m_bUseGcm153);
if (m_hSndCrypto != NULL)
HaiCrypt_UpdateGcm153(m_hSndCrypto, m_bUseGcm153);
m_bUseGcm153 = srtv <= SrtVersion(1, 5, 3);
if (m_hRcvCrypto != NULL)
HaiCrypt_UpdateGcm153(m_hRcvCrypto, m_bUseGcm153);
if (m_hSndCrypto != NULL)
HaiCrypt_UpdateGcm153(m_hSndCrypto, m_bUseGcm153);
}

LOGP(cnlog.Note, FormatKmMessage("processSrtMsg_KMRSP", SRT_CMD_KMRSP, len));
Expand Down Expand Up @@ -598,7 +598,7 @@ srt::CCryptoControl::CCryptoControl(SRTSOCKET id)
, m_KmRefreshRatePkt(0)
, m_KmPreAnnouncePkt(0)
, m_iCryptoMode(CSrtConfig::CIPHER_MODE_AUTO)
, m_bUseGcm153(false)
, m_bUseGcm153(false)
, m_bErrorReported(false)
{
m_KmSecret.len = 0;
Expand Down Expand Up @@ -626,7 +626,7 @@ bool srt::CCryptoControl::init(HandshakeSide side, const CSrtConfig& cfg, bool b
// Set UNSECURED state as default
m_RcvKmState = SRT_KM_S_UNSECURED;
m_iCryptoMode = cfg.iCryptoMode;
m_bUseGcm153 = bUseGcm153;
m_bUseGcm153 = bUseGcm153;

#ifdef SRT_ENABLE_ENCRYPTION
if (!cfg.bTSBPD && m_iCryptoMode == CSrtConfig::CIPHER_MODE_AUTO)
Expand Down Expand Up @@ -769,9 +769,7 @@ bool srt::CCryptoControl::createCryptoCtx(HaiCrypt_Handle& w_hCrypto, size_t key
m_KmRefreshRatePkt = 2000;
m_KmPreAnnouncePkt = 500;
#endif
crypto_cfg.flags = HAICRYPT_CFG_F_CRYPTO | (cdir == HAICRYPT_CRYPTO_DIR_TX ? HAICRYPT_CFG_F_TX : 0) | (bAESGCM ? HAICRYPT_CFG_F_GCM : 0)
| (m_bUseGcm153 ? HAICRYPT_CFG_F_GCM_153 : 0);

crypto_cfg.flags = HAICRYPT_CFG_F_CRYPTO | (cdir == HAICRYPT_CRYPTO_DIR_TX ? HAICRYPT_CFG_F_TX : 0) | (bAESGCM ? HAICRYPT_CFG_F_GCM : 0);
crypto_cfg.xport = HAICRYPT_XPT_SRT;
crypto_cfg.cryspr = HaiCryptCryspr_Get_Instance();
crypto_cfg.key_len = (size_t)keylen;
Expand All @@ -794,7 +792,6 @@ bool srt::CCryptoControl::createCryptoCtx(HaiCrypt_Handle& w_hCrypto, size_t key

return true;
}

#else
bool srt::CCryptoControl::createCryptoCtx(HaiCrypt_Handle&, size_t, HaiCrypt_CryptoDir, bool)
{
Expand Down
10 changes: 5 additions & 5 deletions srtcore/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CCryptoControl
int m_KmRefreshRatePkt;
int m_KmPreAnnouncePkt;
int m_iCryptoMode;
bool m_bUseGcm153; // Older AES-GCM version existed up to SRT v1.5.3.
bool m_bUseGcm153; // Older AES-GCM version existed up to SRT v1.5.3.

HaiCrypt_Secret m_KmSecret; //Key material shared secret
// Sender
Expand Down Expand Up @@ -128,14 +128,14 @@ class CCryptoControl
// Needed for CUDT
void updateKmState(int cmd, size_t srtlen);

/// Process the KM request message.
/// @param srtv peer's SRT version.
/// Process the KM request message.
/// @param srtv peer's SRT version.
int processSrtMsg_KMREQ(const uint32_t* srtdata, size_t len, int hsv, unsigned srtv,
uint32_t srtdata_out[], size_t&);

/// Process the KM response message.
/// @param srtv peer's SRT version.
/// @returns
/// @param srtv peer's SRT version.
/// @returns
/// 1 - the given payload is the same as the currently used key
/// 0 - there's no key in agent or the payload is error message with agent NOSECRET.
/// -1 - the payload is error message with other state or it doesn't match the key
Expand Down

0 comments on commit 52ed4cc

Please sign in to comment.