From b6595822cbf5fb5dee912eadc3c82ea2d7f15904 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Thu, 13 Aug 2020 06:47:26 +0300 Subject: [PATCH] Fix warnings --- include/crypto.hh | 1 + include/mzrtp/confack.hh | 2 +- include/mzrtp/dh_kxchng.hh | 2 +- src/crypto.cc | 11 +++++++++++ src/mzrtp/commit.cc | 2 +- src/mzrtp/confack.cc | 2 +- src/mzrtp/confirm.cc | 2 +- src/mzrtp/dh_kxchng.cc | 2 +- src/mzrtp/error.cc | 2 +- src/mzrtp/hello.cc | 2 +- src/mzrtp/hello_ack.cc | 2 +- src/rtcp.cc | 2 ++ src/srtp.cc | 6 +++--- src/zrtp.cc | 4 ++++ 14 files changed, 30 insertions(+), 12 deletions(-) diff --git a/include/crypto.hh b/include/crypto.hh index d52d284..773d8d2 100644 --- a/include/crypto.hh +++ b/include/crypto.hh @@ -139,6 +139,7 @@ namespace uvg_rtp { namespace crc32 { void get_crc32(uint8_t *input, size_t len, uint32_t *output); bool verify_crc32(uint8_t *input, size_t len, uint32_t old_crc); + uint32_t calculate_crc32(uint8_t *input, size_t len); }; }; }; diff --git a/include/mzrtp/confack.hh b/include/mzrtp/confack.hh index 6d7835c..4d83674 100644 --- a/include/mzrtp/confack.hh +++ b/include/mzrtp/confack.hh @@ -11,7 +11,7 @@ namespace uvg_rtp { namespace zrtp_msg { - struct zrtp_confack { + PACKED_STRUCT(zrtp_confack) { zrtp_msg msg_start; uint32_t crc; }; diff --git a/include/mzrtp/dh_kxchng.hh b/include/mzrtp/dh_kxchng.hh index 5fa92b1..cf58f31 100644 --- a/include/mzrtp/dh_kxchng.hh +++ b/include/mzrtp/dh_kxchng.hh @@ -13,7 +13,7 @@ namespace uvg_rtp { namespace zrtp_msg { - struct zrtp_dh { + PACKED_STRUCT(zrtp_dh) { zrtp_msg msg_start; uint32_t hash[8]; uint8_t rs1_id[8]; diff --git a/src/crypto.cc b/src/crypto.cc index 0bbb15d..be0dde2 100644 --- a/src/crypto.cc +++ b/src/crypto.cc @@ -249,6 +249,17 @@ void uvg_rtp::crypto::crc32::get_crc32(uint8_t *input, size_t len, uint32_t *out crc32.TruncatedFinal((uint8_t *)output, sizeof(uint32_t)); } +uint32_t uvg_rtp::crypto::crc32::calculate_crc32(uint8_t *input, size_t len) +{ + CryptoPP::CRC32 crc32; + uint32_t out; + + crc32.Update(input, len); + crc32.TruncatedFinal((uint8_t *)&out, sizeof(uint32_t)); + + return out; +} + bool uvg_rtp::crypto::crc32::verify_crc32(uint8_t *input, size_t len, uint32_t old_crc) { CryptoPP::CRC32 crc32; diff --git a/src/mzrtp/commit.cc b/src/mzrtp/commit.cc index 1cb2fee..f072a76 100644 --- a/src/mzrtp/commit.cc +++ b/src/mzrtp/commit.cc @@ -62,7 +62,7 @@ uvg_rtp::zrtp_msg::commit::commit(zrtp_session_t& session) memcpy(&msg->mac, mac_full, sizeof(uint64_t)); /* Calculate CRC32 for the whole ZRTP packet */ - uvg_rtp::crypto::crc32::get_crc32((uint8_t *)frame_, len_ - 4, &msg->crc); + msg->crc = uvg_rtp::crypto::crc32::calculate_crc32((uint8_t *)frame_, len_ - sizeof(uint32_t)); /* Finally make a copy of the message and save it for later use */ session.l_msg.commit.first = len_; diff --git a/src/mzrtp/confack.cc b/src/mzrtp/confack.cc index 0e240bb..fdf928f 100644 --- a/src/mzrtp/confack.cc +++ b/src/mzrtp/confack.cc @@ -38,7 +38,7 @@ uvg_rtp::zrtp_msg::confack::confack(zrtp_session_t& session) memcpy(&msg->msg_start.msgblock, ZRTP_CONFACK, 8); /* Calculate CRC32 for the whole ZRTP packet */ - uvg_rtp::crypto::crc32::get_crc32((uint8_t *)frame_, len_ - 4, &msg->crc); + msg->crc = uvg_rtp::crypto::crc32::calculate_crc32((uint8_t *)frame_, len_ - sizeof(uint32_t)); } uvg_rtp::zrtp_msg::confack::~confack() diff --git a/src/mzrtp/confirm.cc b/src/mzrtp/confirm.cc index e1bb3bc..1b3f60c 100644 --- a/src/mzrtp/confirm.cc +++ b/src/mzrtp/confirm.cc @@ -73,7 +73,7 @@ uvg_rtp::zrtp_msg::confirm::confirm(zrtp_session_t& session, int part) memcpy(&msg->confirm_mac, mac_full, sizeof(uint64_t)); /* Calculate CRC32 for the whole ZRTP packet */ - uvg_rtp::crypto::crc32::get_crc32((uint8_t *)frame_, len_ - 4, &msg->crc); + msg->crc = uvg_rtp::crypto::crc32::calculate_crc32((uint8_t *)frame_, len_ - sizeof(uint32_t)); delete hmac_sha256; delete aes_cfb; diff --git a/src/mzrtp/dh_kxchng.cc b/src/mzrtp/dh_kxchng.cc index b0f7448..af30b05 100644 --- a/src/mzrtp/dh_kxchng.cc +++ b/src/mzrtp/dh_kxchng.cc @@ -87,7 +87,7 @@ uvg_rtp::zrtp_msg::dh_key_exchange::dh_key_exchange(zrtp_session_t& session, int memcpy(msg->mac, mac_full, 8); /* Calculate CRC32 for the whole ZRTP packet */ - uvg_rtp::crypto::crc32::get_crc32((uint8_t *)frame_, len_ - 4, &msg->crc); + msg->crc = uvg_rtp::crypto::crc32::calculate_crc32((uint8_t *)frame_, len_ - sizeof(uint32_t)); /* Finally make a copy of the message and save it for later use */ if (session.l_msg.dh.second) diff --git a/src/mzrtp/error.cc b/src/mzrtp/error.cc index 406ff36..f407a5a 100644 --- a/src/mzrtp/error.cc +++ b/src/mzrtp/error.cc @@ -27,7 +27,7 @@ uvg_rtp::zrtp_msg::error::error(int error_code) msg->error = error_code; - uvg_rtp::crypto::crc32::get_crc32((uint8_t *)frame_, len_ - 4, &msg->crc); + msg->crc = uvg_rtp::crypto::crc32::calculate_crc32((uint8_t *)frame_, len_ - sizeof(uint32_t)); } uvg_rtp::zrtp_msg::error::~error() diff --git a/src/mzrtp/hello.cc b/src/mzrtp/hello.cc index 102346e..0374dad 100644 --- a/src/mzrtp/hello.cc +++ b/src/mzrtp/hello.cc @@ -66,7 +66,7 @@ uvg_rtp::zrtp_msg::hello::hello(zrtp_session_t& session) memcpy(&msg->mac, mac_full, sizeof(uint64_t)); /* Calculate CRC32 of the whole packet (excluding crc) */ - uvg_rtp::crypto::crc32::get_crc32((uint8_t *)frame_, len_ - 4, &msg->crc); + msg->crc = uvg_rtp::crypto::crc32::calculate_crc32((uint8_t *)frame_, len_ - sizeof(uint32_t)); /* Finally make a copy of the message and save it for later use */ session.l_msg.hello.first = len_; diff --git a/src/mzrtp/hello_ack.cc b/src/mzrtp/hello_ack.cc index 4a3812e..384d6d2 100644 --- a/src/mzrtp/hello_ack.cc +++ b/src/mzrtp/hello_ack.cc @@ -25,7 +25,7 @@ uvg_rtp::zrtp_msg::hello_ack::hello_ack() memcpy(&msg->msg_start.msgblock, ZRTP_HELLO_ACK, 8); - uvg_rtp::crypto::crc32::get_crc32((uint8_t *)frame_, len_ - 4, &msg->crc); + msg->crc = uvg_rtp::crypto::crc32::calculate_crc32((uint8_t *)frame_, len_ - sizeof(uint32_t)); } uvg_rtp::zrtp_msg::hello_ack::~hello_ack() diff --git a/src/rtcp.cc b/src/rtcp.cc index b5d6da3..72884f6 100644 --- a/src/rtcp.cc +++ b/src/rtcp.cc @@ -440,6 +440,8 @@ rtp_error_t uvg_rtp::rtcp::recv_packet_handler(void *arg, int flags, frame::rtp_ rtp_error_t uvg_rtp::rtcp::send_packet_handler_buf(void *arg, ssize_t len, void *buf) { + (void)buf; + return ((uvg_rtp::rtcp *)arg)->update_sender_stats(len - uvg_rtp::frame::HEADER_SIZE_RTP); } diff --git a/src/srtp.cc b/src/srtp.cc index d99f1b9..ed257af 100644 --- a/src/srtp.cc +++ b/src/srtp.cc @@ -209,6 +209,8 @@ rtp_error_t uvg_rtp::srtp::init_user(int type, int flags, uint8_t *key, uint8_t rtp_error_t uvg_rtp::srtp::recv_packet_handler(void *arg, int flags, frame::rtp_frame **out) { + (void)flags; + uvg_rtp::srtp *srtp = (uvg_rtp::srtp *)arg; uvg_rtp::srtp_ctx_t ctx = srtp->get_ctx(); uvg_rtp::frame::rtp_frame *frame = *out; @@ -226,7 +228,7 @@ rtp_error_t uvg_rtp::srtp::recv_packet_handler(void *arg, int flags, frame::rtp_ if (seq == 0xffff) ctx.roc++; - if (srtp->create_iv(iv, frame->header.ssrc, index, ctx.key_ctx.remote.salt_key) != RTP_OK) { + if (srtp->create_iv(iv, ssrc, index, ctx.key_ctx.remote.salt_key) != RTP_OK) { LOG_ERROR("Failed to create IV, unable to encrypt the RTP packet!"); return RTP_INVALID_VALUE; } @@ -247,8 +249,6 @@ rtp_error_t uvg_rtp::srtp::recv_packet_handler(void *arg, int flags, frame::rtp_ hmac_sha1.update((uint8_t *)&ctx.roc, sizeof(ctx.roc)); hmac_sha1.final((uint8_t *)&digest); - uint8_t *tmp_buffer = (uint8_t *)frame; - if (memcmp(&digest, &frame[frame->payload_len - AUTH_TAG_LENGTH], AUTH_TAG_LENGTH)) { LOG_ERROR("Authentication tag mismatch!"); return RTP_AUTH_TAG_MISMATCH; diff --git a/src/zrtp.cc b/src/zrtp.cc index 3ed28f7..0190bcc 100644 --- a/src/zrtp.cc +++ b/src/zrtp.cc @@ -817,6 +817,8 @@ rtp_error_t uvg_rtp::zrtp::get_srtp_keys( rtp_error_t uvg_rtp::zrtp::packet_handler(ssize_t size, void *packet, int flags, frame::rtp_frame **out) { + (void)size, (void)flags, (void)out; + auto msg = (uvg_rtp::zrtp_msg::zrtp_msg *)packet; /* not a ZRTP packet */ @@ -856,5 +858,7 @@ rtp_error_t uvg_rtp::zrtp::packet_handler(ssize_t size, void *packet, int flags, /* TODO: goclear & co-opeartion with srtp */ } + + return RTP_OK; } #endif