diff --git a/include/srtp.hh b/include/srtp.hh index 0bf16fe..259fecf 100644 --- a/include/srtp.hh +++ b/include/srtp.hh @@ -112,7 +112,7 @@ namespace uvg_rtp { * Return RTP_OK if SRTP setup was successful * Return RTP_INVALID_VALUE if "zrtp" is nullptr * Return RTP_MEMORY allocation failed */ - rtp_error_t init_zrtp(int type, bool use_null_cipher, uvg_rtp::rtp *rtp, uvg_rtp::zrtp *zrtp); + rtp_error_t init_zrtp(int type, int flags, uvg_rtp::rtp *rtp, uvg_rtp::zrtp *zrtp); /* Setup Secure RTP/RTCP connection using user-managed keys * @@ -122,7 +122,7 @@ namespace uvg_rtp { * Return RTP_OK if SRTP setup was successful * Return RTP_INVALID_VALUE if "key" or "salt" is nullptr * Return RTP_MEMORY allocation failed */ - rtp_error_t init_user(int type, bool use_null_cipher, uint8_t *key, uint8_t *salt); + rtp_error_t init_user(int type, int flags, uint8_t *key, uint8_t *salt); /* Encrypt the payload of "frame" using the private session key * @@ -168,7 +168,7 @@ namespace uvg_rtp { rtp_error_t __encrypt(uint32_t ssrc, uint16_t seq, uint8_t *buffer, size_t len); /* Internal init method that initialize the SRTP context using values in key_ctx_.master */ - rtp_error_t __init(int type, bool use_null_cipher); + rtp_error_t __init(int type, int flags); #endif srtp_key_ctx_t key_ctx_; diff --git a/src/media_stream.cc b/src/media_stream.cc index ac620be..73eb37c 100644 --- a/src/media_stream.cc +++ b/src/media_stream.cc @@ -12,7 +12,6 @@ #define RECV_ONLY(flags) ((flags & RECV_ONLY_FLAGS) == RECV_ONLY_FLAGS) #define SEND_ONLY(flags) ((flags & SEND_ONLY_FLAGS) == SEND_ONLY_FLAGS) -#define NULL_CHIPER(flags) ((flags & RCE_SRTP_USE_NULL_CIPHER) == RCE_SRTP_USE_NULL_CIPHER) uvg_rtp::media_stream::media_stream(std::string addr, int src_port, int dst_port, rtp_format_t fmt, int flags): srtp_(nullptr), @@ -174,7 +173,7 @@ rtp_error_t uvg_rtp::media_stream::init(uvg_rtp::zrtp *zrtp) if ((srtp_ = new uvg_rtp::srtp()) == nullptr) return RTP_MEMORY_ERROR; - if ((ret = srtp_->init_zrtp(SRTP, NULL_CHIPER(ctx_config_.flags), rtp_, zrtp)) != RTP_OK) { + if ((ret = srtp_->init_zrtp(SRTP, ctx_config_.flags, rtp_, zrtp)) != RTP_OK) { LOG_WARN("Failed to initialize SRTP for media stream!"); return ret; } @@ -214,7 +213,7 @@ rtp_error_t uvg_rtp::media_stream::add_srtp_ctx(uint8_t *key, uint8_t *salt) if ((srtp_ = new uvg_rtp::srtp()) == nullptr) return RTP_MEMORY_ERROR; - if ((ret = srtp_->init_user(SRTP, NULL_CHIPER(ctx_config_.flags), key, salt)) != RTP_OK) { + if ((ret = srtp_->init_user(SRTP, ctx_config_.flags, key, salt)) != RTP_OK) { LOG_WARN("Failed to initialize SRTP for media stream!"); return ret; } diff --git a/src/srtp.cc b/src/srtp.cc index c6ecaac..cbf0ed5 100644 --- a/src/srtp.cc +++ b/src/srtp.cc @@ -54,7 +54,7 @@ rtp_error_t uvg_rtp::srtp::create_iv(uint8_t *out, uint32_t ssrc, uint64_t index return RTP_OK; } -rtp_error_t uvg_rtp::srtp::__init(int type, bool use_null_cipher) +rtp_error_t uvg_rtp::srtp::__init(int type, int flags) { srtp_ctx_.roc = 0; srtp_ctx_.type = type; @@ -75,7 +75,7 @@ rtp_error_t uvg_rtp::srtp::__init(int type, bool use_null_cipher) srtp_ctx_.s_l = 0; srtp_ctx_.replay = nullptr; - use_null_cipher_ = use_null_cipher; + use_null_cipher_ = !!(flags & RCE_SRTP_NULL_CIPHER); /* Local aka encryption keys */ (void)derive_key( @@ -126,7 +126,7 @@ rtp_error_t uvg_rtp::srtp::__init(int type, bool use_null_cipher) return RTP_OK; } -rtp_error_t uvg_rtp::srtp::init_zrtp(int type, bool use_null_cipher, uvg_rtp::rtp *rtp, uvg_rtp::zrtp *zrtp) +rtp_error_t uvg_rtp::srtp::init_zrtp(int type, int flags, uvg_rtp::rtp *rtp, uvg_rtp::zrtp *zrtp) { (void)rtp; @@ -151,10 +151,10 @@ rtp_error_t uvg_rtp::srtp::init_zrtp(int type, bool use_null_cipher, uvg_rtp::rt return ret; } - return __init(type, use_null_cipher); + return __init(type, flags); } -rtp_error_t uvg_rtp::srtp::init_user(int type, bool use_null_cipher, uint8_t *key, uint8_t *salt) +rtp_error_t uvg_rtp::srtp::init_user(int type, int flags, uint8_t *key, uint8_t *salt) { if (!key || !salt) return RTP_INVALID_VALUE; @@ -164,7 +164,7 @@ rtp_error_t uvg_rtp::srtp::init_user(int type, bool use_null_cipher, uint8_t *ke memcpy(key_ctx_.master.local_salt, salt, SALT_LENGTH); memcpy(key_ctx_.master.remote_salt, salt, SALT_LENGTH); - return __init(type, use_null_cipher); + return __init(type, flags); } rtp_error_t uvg_rtp::srtp::__encrypt(uint32_t ssrc, uint16_t seq, uint8_t *buffer, size_t len)