diff options
author | Geir Istad <thisisG@users.noreply.github.com> | 2017-03-08 19:01:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-08 19:01:07 +0100 |
commit | d1ef7694a0b7dafbb48380239b9f66389ef89f9f (patch) | |
tree | 5cc501a42dda7df5878cd31f3ee0258121692171 /srtp | |
parent | 422b47765162dc93cdad684605b83a8d0c4cb2e8 (diff) | |
parent | 2a3176f8f7e51c5a0e09c2ba92f552b42efe6c96 (diff) | |
download | libsrtp2-d1ef7694a0b7dafbb48380239b9f66389ef89f9f.tar.gz |
Merge pull request #262 from paulej/aead_iv_return_code
Return an error in srtp_calc_aead_iv_srtcp() if seq_num is invalid
Diffstat (limited to 'srtp')
-rw-r--r-- | srtp/srtp.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/srtp/srtp.c b/srtp/srtp.c index 744ee21..af96b5d 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -3258,9 +3258,13 @@ srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p) { * seq_num - The SEQ value to use for the IV calculation. * *hdr - The RTP header, used to get the SSRC value * + * Returns: srtp_err_status_ok if no error or srtp_err_status_bad_param + * if seq_num is invalid + * */ -static void srtp_calc_aead_iv_srtcp(srtp_session_keys_t *session_keys, v128_t *iv, - uint32_t seq_num, srtcp_hdr_t *hdr) +static srtp_err_status_t +srtp_calc_aead_iv_srtcp(srtp_session_keys_t *session_keys, v128_t *iv, + uint32_t seq_num, srtcp_hdr_t *hdr) { v128_t in; v128_t salt; @@ -3271,6 +3275,9 @@ static void srtp_calc_aead_iv_srtcp(srtp_session_keys_t *session_keys, v128_t *i in.v16[0] = 0; memcpy(&in.v16[1], &hdr->ssrc, 4); /* still in network order! */ in.v16[3] = 0; + if (seq_num & 0x80000000UL) { /* the most significant bit should be zero */ + return srtp_err_status_bad_param; + } in.v32[2] = 0x7FFFFFFF & htonl(seq_num); /* bit 32 is suppose to be zero */ debug_print(mod_srtp, "Pre-salted RTCP IV = %s\n", v128_hex_string(&in)); @@ -3285,6 +3292,8 @@ static void srtp_calc_aead_iv_srtcp(srtp_session_keys_t *session_keys, v128_t *i * Finally, apply the SALT to the input */ v128_xor(iv, &in, &salt); + + return srtp_err_status_ok; } /* @@ -3357,9 +3366,12 @@ srtp_protect_rtcp_aead (srtp_t ctx, srtp_stream_ctx_t *stream, debug_print(mod_srtp, "srtcp index: %x", seq_num); /* - * Calculating the IV and pass it down to the cipher + * Calculate and set the IV */ - srtp_calc_aead_iv_srtcp(session_keys, &iv, seq_num, hdr); + status = srtp_calc_aead_iv_srtcp(session_keys, &iv, seq_num, hdr); + if (status) { + return srtp_err_status_cipher_fail; + } status = srtp_cipher_set_iv(session_keys->rtcp_cipher, (uint8_t*)&iv, srtp_direction_encrypt); if (status) { @@ -3519,7 +3531,10 @@ srtp_unprotect_rtcp_aead (srtp_t ctx, srtp_stream_ctx_t *stream, /* * Calculate and set the IV */ - srtp_calc_aead_iv_srtcp(session_keys, &iv, seq_num, hdr); + status = srtp_calc_aead_iv_srtcp(session_keys, &iv, seq_num, hdr); + if (status) { + return srtp_err_status_cipher_fail; + } status = srtp_cipher_set_iv(session_keys->rtcp_cipher, (uint8_t*)&iv, srtp_direction_decrypt); if (status) { |