MCPcopy Create free account
hub / github.com/Haivision/srt / createCryptoCtx

Method createCryptoCtx

srtcore/crypto.cpp:758–803  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

756#endif // ENABLE_HEAVY_LOGGING
757
758bool srt::CCryptoControl::createCryptoCtx(HaiCrypt_Handle& w_hCrypto, size_t keylen, HaiCrypt_CryptoDir cdir, bool bAESGCM)
759{
760 if (w_hCrypto)
761 {
762 // XXX You can check here if the existing handle represents
763 // a correctly defined crypto. But this doesn't seem to be
764 // necessary - the whole CCryptoControl facility seems to be valid only
765 // within the frames of one connection.
766 return true;
767 }
768
769 if ((m_KmSecret.len <= 0) || (keylen <= 0))
770 {
771 LOGC(cnlog.Error, log << CONID() << "cryptoCtx: IPE missing secret (" << m_KmSecret.len << ") or key length (" << keylen << ")");
772 return false;
773 }
774
775 HaiCrypt_Cfg crypto_cfg;
776 memset(&crypto_cfg, 0, sizeof(crypto_cfg));
777#if 0//test key refresh (fast rate)
778 m_KmRefreshRatePkt = 2000;
779 m_KmPreAnnouncePkt = 500;
780#endif
781 crypto_cfg.flags = HAICRYPT_CFG_F_CRYPTO | (cdir == HAICRYPT_CRYPTO_DIR_TX ? HAICRYPT_CFG_F_TX : 0) | (bAESGCM ? HAICRYPT_CFG_F_GCM : 0);
782 crypto_cfg.xport = HAICRYPT_XPT_SRT;
783 crypto_cfg.cryspr = HaiCryptCryspr_Get_Instance();
784 crypto_cfg.key_len = (size_t)keylen;
785 crypto_cfg.data_max_len = HAICRYPT_DEF_DATA_MAX_LENGTH; //MTU
786 crypto_cfg.km_tx_period_ms = 0;//No HaiCrypt KM inject period, handled in SRT;
787 crypto_cfg.km_refresh_rate_pkt = m_KmRefreshRatePkt == 0 ? HAICRYPT_DEF_KM_REFRESH_RATE : m_KmRefreshRatePkt;
788 crypto_cfg.km_pre_announce_pkt = m_KmPreAnnouncePkt == 0 ? SRT_CRYPT_KM_PRE_ANNOUNCE : m_KmPreAnnouncePkt;
789 crypto_cfg.secret = m_KmSecret;
790
791 HLOGC(cnlog.Debug, log << "CRYPTO CFG: flags=" << CryptoFlags(crypto_cfg.flags) << " xport=" << crypto_cfg.xport << " cryspr=" << crypto_cfg.cryspr
792 << " keylen=" << crypto_cfg.key_len << " passphrase_length=" << crypto_cfg.secret.len);
793
794 if (HaiCrypt_Create(&crypto_cfg, (&w_hCrypto)) != HAICRYPT_OK)
795 {
796 LOGC(cnlog.Error, log << CONID() << "cryptoCtx: could not create " << (cdir == HAICRYPT_CRYPTO_DIR_TX ? "tx" : "rx") << " crypto ctx");
797 return false;
798 }
799
800 HLOGC(cnlog.Debug, log << CONID() << "cryptoCtx: CREATED crypto for dir=" << (cdir == HAICRYPT_CRYPTO_DIR_TX ? "tx" : "rx") << " keylen=" << keylen);
801
802 return true;
803}
804#else
805bool srt::CCryptoControl::createCryptoCtx(HaiCrypt_Handle&, size_t, HaiCrypt_CryptoDir, bool)
806{

Callers

nothing calls this directly

Calls 3

CryptoFlagsFunction · 0.85
HaiCrypt_CreateFunction · 0.85

Tested by

no test coverage detected