diff --git a/crypto/cipher/aes_gcm_mbedtls.c b/crypto/cipher/aes_gcm_mbedtls.c index 428f816cf..730b3f66c 100644 --- a/crypto/cipher/aes_gcm_mbedtls.c +++ b/crypto/cipher/aes_gcm_mbedtls.c @@ -213,8 +213,8 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_context_init(void *cv, break; } - errCode = mbedtls_gcm_setkey(c->ctx, MBEDTLS_CIPHER_ID_AES, - (const unsigned char *)key, key_len_in_bits); + errCode = + mbedtls_gcm_setkey(c->ctx, MBEDTLS_CIPHER_ID_AES, key, key_len_in_bits); if (errCode != 0) { debug_print(srtp_mod_aes_gcm, "mbedtls error code: %d", errCode); return srtp_err_status_init_fail; @@ -281,7 +281,7 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_set_aad(void *cv, * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_gcm_mbedtls_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { FUNC_ENTRY(); @@ -337,7 +337,7 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_get_tag(void *cv, * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_gcm_mbedtls_decrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { FUNC_ENTRY(); diff --git a/crypto/cipher/aes_gcm_nss.c b/crypto/cipher/aes_gcm_nss.c index 2a0598c3f..5c447d70a 100644 --- a/crypto/cipher/aes_gcm_nss.c +++ b/crypto/cipher/aes_gcm_nss.c @@ -281,7 +281,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_set_aad(void *cv, static srtp_err_status_t srtp_aes_gcm_nss_do_crypto(void *cv, int encrypt, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv; @@ -328,7 +328,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_do_crypto(void *cv, * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_gcm_nss_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv; @@ -338,8 +338,8 @@ static srtp_err_status_t srtp_aes_gcm_nss_encrypt(void *cv, // even though there's no data, we need to give NSS a buffer // where it can write the tag. We can't just use c->tag because // memcpy has undefined behavior on overlapping ranges. - unsigned char tagbuf[16]; - unsigned char *non_null_buf = buf; + uint8_t tagbuf[16]; + uint8_t *non_null_buf = buf; if (!non_null_buf && (*enc_len == 0)) { non_null_buf = tagbuf; } else if (!non_null_buf) { @@ -387,7 +387,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_get_tag(void *cv, * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_gcm_nss_decrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_err_status_t status = srtp_aes_gcm_nss_do_crypto(cv, 0, buf, enc_len); diff --git a/crypto/cipher/aes_gcm_ossl.c b/crypto/cipher/aes_gcm_ossl.c index c2df02d4f..27445c178 100644 --- a/crypto/cipher/aes_gcm_ossl.c +++ b/crypto/cipher/aes_gcm_ossl.c @@ -293,7 +293,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv, * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_gcm_openssl_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv; @@ -354,7 +354,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_get_tag(void *cv, * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_gcm_openssl_decrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv; diff --git a/crypto/cipher/aes_icm.c b/crypto/cipher/aes_icm.c index 2d2cae40a..5c3810b3d 100644 --- a/crypto/cipher/aes_icm.c +++ b/crypto/cipher/aes_icm.c @@ -295,7 +295,7 @@ static void srtp_aes_icm_advance(srtp_aes_icm_ctx_t *c) */ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; diff --git a/crypto/cipher/aes_icm_mbedtls.c b/crypto/cipher/aes_icm_mbedtls.c index a1ff4fbe0..f1546a322 100644 --- a/crypto/cipher/aes_icm_mbedtls.c +++ b/crypto/cipher/aes_icm_mbedtls.c @@ -290,7 +290,7 @@ static srtp_err_status_t srtp_aes_icm_mbedtls_set_iv( * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_icm_mbedtls_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; diff --git a/crypto/cipher/aes_icm_nss.c b/crypto/cipher/aes_icm_nss.c index 5e1d090cd..d0e640e11 100644 --- a/crypto/cipher/aes_icm_nss.c +++ b/crypto/cipher/aes_icm_nss.c @@ -323,7 +323,7 @@ static srtp_err_status_t srtp_aes_icm_nss_set_iv(void *cv, * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_icm_nss_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; diff --git a/crypto/cipher/aes_icm_ossl.c b/crypto/cipher/aes_icm_ossl.c index 01d465dd2..6caa4b00b 100644 --- a/crypto/cipher/aes_icm_ossl.c +++ b/crypto/cipher/aes_icm_ossl.c @@ -298,7 +298,7 @@ static srtp_err_status_t srtp_aes_icm_openssl_set_iv( * enc_len length of encrypt buffer */ static srtp_err_status_t srtp_aes_icm_openssl_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *enc_len) { srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv; diff --git a/crypto/cipher/cipher.c b/crypto/cipher/cipher.c index 59b5d1826..fe4b16c4f 100644 --- a/crypto/cipher/cipher.c +++ b/crypto/cipher/cipher.c @@ -169,17 +169,16 @@ size_t srtp_cipher_get_key_length(const srtp_cipher_t *c) * A trivial platform independent random source. * For use in test only. */ -void srtp_cipher_rand_for_tests(void *dest, size_t len) +void srtp_cipher_rand_for_tests(uint8_t *dest, size_t len) { /* Generic C-library (rand()) version */ /* This is a random source of last resort */ - uint8_t *dst = (uint8_t *)dest; while (len) { int val = rand(); /* rand() returns 0-32767 (ugh) */ /* Is this a good enough way to get random bytes? It is if it passes FIPS-140... */ - *dst++ = val & 0xff; + *dest++ = val & 0xff; len--; } } @@ -191,7 +190,7 @@ void srtp_cipher_rand_for_tests(void *dest, size_t len) uint32_t srtp_cipher_rand_u32_for_tests(void) { uint32_t r; - srtp_cipher_rand_for_tests(&r, sizeof(r)); + srtp_cipher_rand_for_tests((uint8_t *)&r, sizeof(r)); return r; } @@ -266,8 +265,7 @@ srtp_err_status_t srtp_cipher_type_test( buffer, test_case->plaintext_length_octets)); /* set the initialization vector */ - status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx, - srtp_direction_encrypt); + status = srtp_cipher_set_iv(c, test_case->idx, srtp_direction_encrypt); if (status) { srtp_cipher_dealloc(c); return status; @@ -370,8 +368,7 @@ srtp_err_status_t srtp_cipher_type_test( buffer, test_case->plaintext_length_octets)); /* set the initialization vector */ - status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx, - srtp_direction_decrypt); + status = srtp_cipher_set_iv(c, test_case->idx, srtp_direction_decrypt); if (status) { srtp_cipher_dealloc(c); return status; @@ -492,8 +489,7 @@ srtp_err_status_t srtp_cipher_type_test( } /* set initialization vector */ - status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx, - srtp_direction_encrypt); + status = srtp_cipher_set_iv(c, test_case->idx, srtp_direction_encrypt); if (status) { srtp_cipher_dealloc(c); return status; @@ -630,13 +626,13 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, int i; v128_t nonce; clock_t timer; - unsigned char *enc_buf; + uint8_t *enc_buf; size_t len = octets_in_buffer; size_t tag_len = SRTP_MAX_TAG_LEN; unsigned char aad[4] = { 0, 0, 0, 0 }; size_t aad_len = 4; - enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer + tag_len); + enc_buf = (uint8_t *)srtp_crypto_alloc(octets_in_buffer + tag_len); if (enc_buf == NULL) { return 0; /* indicate bad parameters by returning null */ } @@ -667,7 +663,7 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c, // Get tag if supported by the cipher if (c->type->get_tag) { - if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + len), &tag_len) != + if (srtp_cipher_get_tag(c, enc_buf + len, &tag_len) != srtp_err_status_ok) { srtp_crypto_free(enc_buf); return 0; diff --git a/crypto/cipher/null_cipher.c b/crypto/cipher/null_cipher.c index d89e37a47..a507f4758 100644 --- a/crypto/cipher/null_cipher.c +++ b/crypto/cipher/null_cipher.c @@ -116,7 +116,7 @@ static srtp_err_status_t srtp_null_cipher_set_iv(void *cv, } static srtp_err_status_t srtp_null_cipher_encrypt(void *cv, - unsigned char *buf, + uint8_t *buf, size_t *bytes_to_encr) { /* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */ diff --git a/crypto/include/cipher_priv.h b/crypto/include/cipher_priv.h index 5bbc71a83..de15896f6 100644 --- a/crypto/include/cipher_priv.h +++ b/crypto/include/cipher_priv.h @@ -47,7 +47,7 @@ extern "C" { * A trivial platform independent random source. * For use in test only. */ -void srtp_cipher_rand_for_tests(void *dest, size_t len); +void srtp_cipher_rand_for_tests(uint8_t *dest, size_t len); /* * A trivial platform independent 32 bit random number. diff --git a/crypto/test/aes_calc.c b/crypto/test/aes_calc.c index f35c672e8..1bde92f70 100644 --- a/crypto/test/aes_calc.c +++ b/crypto/test/aes_calc.c @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) AES_MAX_KEY_LEN * 2, (unsigned)strlen(argv[1])); exit(1); } - len = hex_string_to_octet_string((char *)key, argv[1], AES_MAX_KEY_LEN * 2); + len = hex_string_to_octet_string(key, argv[1], AES_MAX_KEY_LEN * 2); /* check that hex string is the right length */ if (len != 32 && len != 48 && len != 64) { fprintf(stderr, @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) 16 * 2, (unsigned)strlen(argv[2])); exit(1); } - len = hex_string_to_octet_string((char *)(&data), argv[2], 16 * 2); + len = hex_string_to_octet_string((uint8_t *)&data, argv[2], 16 * 2); /* check that hex string is the right length */ if (len < 16 * 2) { fprintf(stderr, diff --git a/crypto/test/cipher_driver.c b/crypto/test/cipher_driver.c index 0ae6fe34a..d3efb3c53 100644 --- a/crypto/test/cipher_driver.c +++ b/crypto/test/cipher_driver.c @@ -367,7 +367,7 @@ srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c) } /* initialize cipher */ - status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt); + status = srtp_cipher_set_iv(c, idx, srtp_direction_encrypt); if (status) return status; @@ -377,7 +377,7 @@ srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c) return status; /* re-initialize cipher */ - status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt); + status = srtp_cipher_set_iv(c, idx, srtp_direction_encrypt); if (status) return status; @@ -525,7 +525,7 @@ uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[], int i; v128_t nonce; clock_t timer; - unsigned char *enc_buf; + uint8_t *enc_buf; int cipher_index = srtp_cipher_rand_u32_for_tests() % num_cipher; /* Over-alloc, for NIST CBC padding */ diff --git a/crypto/test/datatypes_driver.c b/crypto/test/datatypes_driver.c index 1a1487b85..7be8dcd19 100644 --- a/crypto/test/datatypes_driver.c +++ b/crypto/test/datatypes_driver.c @@ -152,7 +152,7 @@ void test_hex_string_funcs(void) { char hex1[] = "abadcafe"; char hex2[] = "0123456789abcdefqqqqq"; - char raw[10]; + uint8_t raw[10]; size_t len; len = hex_string_to_octet_string(raw, hex1, strlen(hex1)); diff --git a/crypto/test/sha1_driver.c b/crypto/test/sha1_driver.c index 735a1635e..31d506fb6 100644 --- a/crypto/test/sha1_driver.c +++ b/crypto/test/sha1_driver.c @@ -82,15 +82,15 @@ srtp_err_status_t hash_test_case_add(hash_test_case_t **list_ptr, if (test_case == NULL) return srtp_err_status_alloc_fail; - tmp_len = hex_string_to_octet_string((char *)test_case->data, hex_data, - data_len * 2); + tmp_len = + hex_string_to_octet_string(test_case->data, hex_data, data_len * 2); if (tmp_len != data_len * 2) { free(test_case); return srtp_err_status_parse_err; } - tmp_len = hex_string_to_octet_string((char *)test_case->hash, hex_hash, - hash_len * 2); + tmp_len = + hex_string_to_octet_string(test_case->hash, hex_hash, hash_len * 2); if (tmp_len != hash_len * 2) { free(test_case); return srtp_err_status_parse_err; diff --git a/include/srtp.h b/include/srtp.h index 90bfe7313..555460d4a 100644 --- a/include/srtp.h +++ b/include/srtp.h @@ -296,8 +296,8 @@ typedef struct { * Index Size to correctly read it from a packet. */ typedef struct srtp_master_key_t { - unsigned char *key; - unsigned char *mki_id; + uint8_t *key; + uint8_t *mki_id; size_t mki_size; } srtp_master_key_t; @@ -334,7 +334,7 @@ typedef struct srtp_policy_t { /**< is used for this policy element. */ srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */ srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */ - unsigned char *key; /**< Pointer to the SRTP master key for */ + uint8_t *key; /**< Pointer to the SRTP master key for */ /**< this stream. */ srtp_master_key_t **keys; /** Array of Master Key structures */ size_t num_master_keys; /** Number of master keys */ @@ -422,7 +422,7 @@ srtp_err_status_t srtp_shutdown(void); * - srtp_err_status_replay_fail rtp sequence number was non-increasing * - @e other failure in cryptographic mechanisms */ -srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, size_t *len_ptr); +srtp_err_status_t srtp_protect(srtp_t ctx, uint8_t *rtp_hdr, size_t *len_ptr); /** * @brief srtp_protect_mki() is the Secure RTP sender-side packet processing @@ -473,7 +473,7 @@ srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, size_t *len_ptr); * - @e other failure in cryptographic mechanisms */ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, - void *rtp_hdr, + uint8_t *rtp_hdr, size_t *pkt_octet_len, bool use_mki, unsigned int mki_index); @@ -518,7 +518,9 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, * - [other] if there has been an error in the cryptographic mechanisms. * */ -srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, size_t *len_ptr); +srtp_err_status_t srtp_unprotect(srtp_t ctx, + uint8_t *srtp_hdr, + size_t *len_ptr); /** * @brief srtp_unprotect_mki() is the Secure RTP receiver-side packet @@ -567,7 +569,7 @@ srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, size_t *len_ptr); * */ srtp_err_status_t srtp_unprotect_mki(srtp_t ctx, - void *srtp_hdr, + uint8_t *srtp_hdr, size_t *len_ptr, bool use_mki); @@ -1266,9 +1268,9 @@ size_t srtp_profile_get_master_salt_length(srtp_profile_t profile); * available at the location pointed to by key. * */ -void srtp_append_salt_to_key(unsigned char *key, +void srtp_append_salt_to_key(uint8_t *key, size_t bytes_in_key, - unsigned char *salt, + uint8_t *salt, size_t bytes_in_salt); /** @@ -1332,7 +1334,7 @@ void srtp_append_salt_to_key(unsigned char *key, * the cryptographic mechanisms. */ srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, - void *rtcp_hdr, + uint8_t *rtcp_hdr, size_t *pkt_octet_len); /** @@ -1381,7 +1383,7 @@ srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, * the cryptographic mechanisms. */ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, - void *rtcp_hdr, + uint8_t *rtcp_hdr, size_t *pkt_octet_len, bool use_mki, unsigned int mki_index); @@ -1425,7 +1427,7 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, * */ srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, - void *srtcp_hdr, + uint8_t *srtcp_hdr, size_t *pkt_octet_len); /** @@ -1474,7 +1476,7 @@ srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, * */ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, - void *srtcp_hdr, + uint8_t *srtcp_hdr, size_t *pkt_octet_len, bool use_mki); diff --git a/include/srtp_priv.h b/include/srtp_priv.h index 40391dda0..3cc69de58 100644 --- a/include/srtp_priv.h +++ b/include/srtp_priv.h @@ -93,7 +93,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, */ srtp_err_status_t srtp_stream_init_all_master_keys( srtp_stream_ctx_t *srtp, - unsigned char *key, + uint8_t *key, srtp_master_key_t **keys, const size_t max_master_keys); diff --git a/srtp/srtp.c b/srtp/srtp.c index 16dabd0d5..84dbd24b9 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -105,7 +105,7 @@ static size_t srtp_get_rtp_xtn_hdr_len(const srtp_hdr_xtnd_t *xtn_hdr) return (ntohs(xtn_hdr->length) + 1u) * 4u; } -static srtp_err_status_t srtp_validate_rtp_header(const void *rtp_hdr, +static srtp_err_status_t srtp_validate_rtp_header(const uint8_t *rtp_hdr, size_t pkt_octet_len) { const srtp_hdr_t *hdr = (const srtp_hdr_t *)rtp_hdr; @@ -125,7 +125,7 @@ static srtp_err_status_t srtp_validate_rtp_header(const void *rtp_hdr, return srtp_err_status_bad_param; rtp_header_len += srtp_get_rtp_xtn_hdr_len( - (const srtp_hdr_xtnd_t *)((const uint8_t *)hdr + rtp_header_len)); + (const srtp_hdr_xtnd_t *)(rtp_hdr + rtp_header_len)); if (pkt_octet_len < rtp_header_len) return srtp_err_status_bad_param; } @@ -910,7 +910,7 @@ size_t srtp_inject_mki(uint8_t *mki_tag_location, } srtp_err_status_t srtp_stream_init_all_master_keys(srtp_stream_ctx_t *srtp, - unsigned char *key, + uint8_t *key, srtp_master_key_t **keys, const size_t max_master_keys) { @@ -951,7 +951,7 @@ srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, size_t rtp_base_key_len, rtp_salt_len; size_t rtcp_base_key_len, rtcp_salt_len; srtp_session_keys_t *session_keys = NULL; - unsigned char *key = master_key->key; + uint8_t *key = master_key->key; /* If RTP or RTCP have a key length > AES-128, assume matching kdf. */ /* TODO: kdf algorithm, master key length, and master salt length should @@ -1769,7 +1769,7 @@ static srtp_err_status_t srtp_get_est_pkt_index(const srtp_hdr_t *hdr, */ static srtp_err_status_t srtp_protect_aead(srtp_ctx_t *ctx, srtp_stream_ctx_t *stream, - void *rtp_hdr, + uint8_t *rtp_hdr, size_t *pkt_octet_len, srtp_session_keys_t *session_keys, bool use_mki) @@ -1815,16 +1815,16 @@ static srtp_err_status_t srtp_protect_aead(srtp_ctx_t *ctx, * extension, if present; otherwise, it starts after the last csrc, * if any are present */ - enc_start = (uint8_t *)hdr + srtp_get_rtp_hdr_len(hdr); + enc_start = rtp_hdr + srtp_get_rtp_hdr_len(hdr); if (hdr->x == 1) { xtn_hdr = srtp_get_rtp_xtn_hdr(hdr); enc_start += srtp_get_rtp_xtn_hdr_len(xtn_hdr); } /* note: the passed size is without the auth tag */ - if (!(enc_start <= (uint8_t *)hdr + *pkt_octet_len)) + if (!(enc_start <= rtp_hdr + *pkt_octet_len)) return srtp_err_status_parse_err; - enc_octet_len = *pkt_octet_len - (size_t)(enc_start - (uint8_t *)hdr); + enc_octet_len = *pkt_octet_len - (size_t)(enc_start - rtp_hdr); /* * estimate the packet index using the start of the replay window @@ -1895,9 +1895,8 @@ static srtp_err_status_t srtp_protect_aead(srtp_ctx_t *ctx, /* * Set the AAD over the RTP header */ - aad_len = (uint32_t)(enc_start - (uint8_t *)hdr); - status = - srtp_cipher_set_aad(session_keys->rtp_cipher, (uint8_t *)hdr, aad_len); + aad_len = (size_t)(enc_start - rtp_hdr); + status = srtp_cipher_set_aad(session_keys->rtp_cipher, rtp_hdr, aad_len); if (status) { return (srtp_err_status_cipher_fail); } @@ -1918,7 +1917,7 @@ static srtp_err_status_t srtp_protect_aead(srtp_ctx_t *ctx, return (srtp_err_status_cipher_fail); } - mki_location = (uint8_t *)hdr + *pkt_octet_len + tag_len; + mki_location = rtp_hdr + *pkt_octet_len + tag_len; mki_size = srtp_inject_mki(mki_location, session_keys, use_mki); /* increase the packet length by the length of the auth tag */ @@ -1941,7 +1940,7 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, srtp_stream_ctx_t *stream, int delta, srtp_xtd_seq_num_t est, - void *srtp_hdr, + uint8_t *srtp_hdr, size_t *pkt_octet_len, srtp_session_keys_t *session_keys, size_t mki_size, @@ -1996,18 +1995,17 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, * extension, if present; otherwise, it starts after the last csrc, * if any are present */ - enc_start = (uint8_t *)hdr + srtp_get_rtp_hdr_len(hdr); + enc_start = srtp_hdr + srtp_get_rtp_hdr_len(hdr); if (hdr->x == 1) { xtn_hdr = srtp_get_rtp_xtn_hdr(hdr); enc_start += srtp_get_rtp_xtn_hdr_len(xtn_hdr); } - if (!(enc_start <= (uint8_t *)hdr + (*pkt_octet_len - tag_len - mki_size))) + if (!(enc_start <= srtp_hdr + (*pkt_octet_len - tag_len - mki_size))) return srtp_err_status_parse_err; /* * We pass the tag down to the cipher when doing GCM mode */ - enc_octet_len = - *pkt_octet_len - mki_size - (size_t)(enc_start - (uint8_t *)hdr); + enc_octet_len = *pkt_octet_len - mki_size - (size_t)(enc_start - srtp_hdr); /* * Sanity check the encrypted payload length against @@ -2039,16 +2037,15 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, /* * Set the AAD for AES-GCM, which is the RTP header */ - aad_len = (size_t)(enc_start - (uint8_t *)hdr); - status = - srtp_cipher_set_aad(session_keys->rtp_cipher, (uint8_t *)hdr, aad_len); + aad_len = (size_t)(enc_start - srtp_hdr); + status = srtp_cipher_set_aad(session_keys->rtp_cipher, srtp_hdr, aad_len); if (status) { return (srtp_err_status_cipher_fail); } /* Decrypt the ciphertext. This also checks the auth tag based * on the AAD we just specified above */ - status = srtp_cipher_decrypt(session_keys->rtp_cipher, (uint8_t *)enc_start, + status = srtp_cipher_decrypt(session_keys->rtp_cipher, enc_start, &enc_octet_len); if (status) { return status; @@ -2138,14 +2135,14 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx, } srtp_err_status_t srtp_protect(srtp_ctx_t *ctx, - void *rtp_hdr, + uint8_t *rtp_hdr, size_t *pkt_octet_len) { return srtp_protect_mki(ctx, rtp_hdr, pkt_octet_len, false, 0); } srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, - void *rtp_hdr, + uint8_t *rtp_hdr, size_t *pkt_octet_len, bool use_mki, unsigned int mki_index) @@ -2274,21 +2271,21 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, * if we're not providing confidentiality, set enc_start to NULL */ if (stream->rtp_services & sec_serv_conf) { - enc_start = (uint8_t *)hdr + srtp_get_rtp_hdr_len(hdr); + enc_start = rtp_hdr + srtp_get_rtp_hdr_len(hdr); if (hdr->x == 1) { xtn_hdr = srtp_get_rtp_xtn_hdr(hdr); enc_start += srtp_get_rtp_xtn_hdr_len(xtn_hdr); } /* note: the passed size is without the auth tag */ - if (!(enc_start <= (uint8_t *)hdr + *pkt_octet_len)) + if (!(enc_start <= rtp_hdr + *pkt_octet_len)) return srtp_err_status_parse_err; - enc_octet_len = *pkt_octet_len - (size_t)(enc_start - (uint8_t *)hdr); + enc_octet_len = *pkt_octet_len - (size_t)(enc_start - rtp_hdr); } else { enc_start = NULL; } - mki_location = (uint8_t *)hdr + *pkt_octet_len; + mki_location = rtp_hdr + *pkt_octet_len; mki_size = srtp_inject_mki(mki_location, session_keys, use_mki); /* @@ -2297,8 +2294,8 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, * to indicate that no authentication is needed */ if (stream->rtp_services & sec_serv_auth) { - auth_start = (uint8_t *)hdr; - auth_tag = (uint8_t *)hdr + *pkt_octet_len + mki_size; + auth_start = rtp_hdr; + auth_tag = rtp_hdr + *pkt_octet_len + mki_size; } else { auth_start = NULL; auth_tag = NULL; @@ -2460,14 +2457,14 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, } srtp_err_status_t srtp_unprotect(srtp_ctx_t *ctx, - void *srtp_hdr, + uint8_t *srtp_hdr, size_t *pkt_octet_len) { return srtp_unprotect_mki(ctx, srtp_hdr, pkt_octet_len, false); } srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, - void *srtp_hdr, + uint8_t *srtp_hdr, size_t *pkt_octet_len, bool use_mki) { @@ -2562,8 +2559,8 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, /* Determine if MKI is being used and what session keys should be used */ if (use_mki) { - session_keys = srtp_get_session_keys(stream, (const uint8_t *)hdr, - *pkt_octet_len, &mki_size); + session_keys = + srtp_get_session_keys(stream, srtp_hdr, *pkt_octet_len, &mki_size); if (session_keys == NULL) return srtp_err_status_bad_mki; @@ -2643,17 +2640,16 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, * if we're not providing confidentiality, set enc_start to NULL */ if (stream->rtp_services & sec_serv_conf) { - enc_start = (uint8_t *)hdr + srtp_get_rtp_hdr_len(hdr); + enc_start = srtp_hdr + srtp_get_rtp_hdr_len(hdr); if (hdr->x == 1) { xtn_hdr = srtp_get_rtp_xtn_hdr(hdr); enc_start += srtp_get_rtp_xtn_hdr_len(xtn_hdr); } - if (!(enc_start <= - (uint8_t *)hdr + (*pkt_octet_len - tag_len - mki_size))) + if (!(enc_start <= srtp_hdr + (*pkt_octet_len - tag_len - mki_size))) return srtp_err_status_parse_err; enc_octet_len = *pkt_octet_len - tag_len - mki_size - - (size_t)(enc_start - (uint8_t *)hdr); + (size_t)(enc_start - srtp_hdr); } else { enc_start = NULL; } @@ -2664,8 +2660,8 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx, * to indicate that no authentication is needed */ if (stream->rtp_services & sec_serv_auth) { - auth_start = (uint8_t *)hdr; - auth_tag = (uint8_t *)hdr + *pkt_octet_len - tag_len; + auth_start = srtp_hdr; + auth_tag = srtp_hdr + *pkt_octet_len - tag_len; } else { auth_start = NULL; auth_tag = NULL; @@ -3613,7 +3609,7 @@ static srtp_err_status_t srtp_calc_aead_iv_srtcp( */ static srtp_err_status_t srtp_protect_rtcp_aead( srtp_stream_ctx_t *stream, - void *rtcp_hdr, + uint8_t *rtcp_hdr, size_t *pkt_octet_len, srtp_session_keys_t *session_keys, bool use_mki) @@ -3638,7 +3634,7 @@ static srtp_err_status_t srtp_protect_rtcp_aead( * set encryption start and encryption length - if we're not * providing confidentiality, set enc_start to NULL */ - enc_start = (uint8_t *)hdr + octets_in_rtcp_header; + enc_start = rtcp_hdr + octets_in_rtcp_header; enc_octet_len = *pkt_octet_len - octets_in_rtcp_header; /* NOTE: hdr->length is not usable - it refers to only the first @@ -3655,7 +3651,7 @@ static srtp_err_status_t srtp_protect_rtcp_aead( trailer = 0x00000000; /* set encrypt bit */ } - mki_size = srtp_inject_mki((uint8_t *)hdr + *pkt_octet_len + tag_len + + mki_size = srtp_inject_mki(rtcp_hdr + *pkt_octet_len + tag_len + sizeof(srtcp_trailer_t), session_keys, use_mki); @@ -3665,7 +3661,7 @@ static srtp_err_status_t srtp_protect_rtcp_aead( * (note that srtpc *always* provides authentication, unlike srtp) */ /* Note: This would need to change for optional mikey data */ - auth_tag = (uint8_t *)hdr + *pkt_octet_len; + auth_tag = rtcp_hdr + *pkt_octet_len; /* * check sequence number for overruns, and copy it into the packet @@ -3702,7 +3698,7 @@ static srtp_err_status_t srtp_protect_rtcp_aead( * If payload encryption is enabled, then the AAD consist of * the RTCP header and the seq# at the end of the packet */ - status = srtp_cipher_set_aad(session_keys->rtcp_cipher, (uint8_t *)hdr, + status = srtp_cipher_set_aad(session_keys->rtcp_cipher, rtcp_hdr, octets_in_rtcp_header); if (status) { return (srtp_err_status_cipher_fail); @@ -3713,7 +3709,7 @@ static srtp_err_status_t srtp_protect_rtcp_aead( * the entire packet as described in RFC 7714 (Section 9.3. Data * Types in Unencrypted SRTCP Compound Packets) */ - status = srtp_cipher_set_aad(session_keys->rtcp_cipher, (uint8_t *)hdr, + status = srtp_cipher_set_aad(session_keys->rtcp_cipher, rtcp_hdr, *pkt_octet_len); if (status) { return (srtp_err_status_cipher_fail); @@ -3784,7 +3780,7 @@ static srtp_err_status_t srtp_protect_rtcp_aead( static srtp_err_status_t srtp_unprotect_rtcp_aead( srtp_t ctx, srtp_stream_ctx_t *stream, - void *srtcp_hdr, + uint8_t *srtcp_hdr, size_t *pkt_octet_len, srtp_session_keys_t *session_keys, bool use_mki) @@ -3818,8 +3814,7 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( */ /* This should point trailer to the word past the end of the normal data. */ /* This would need to be modified for optional mikey data */ - trailer_p = - (uint8_t *)hdr + *pkt_octet_len - sizeof(srtcp_trailer_t) - mki_size; + trailer_p = srtcp_hdr + *pkt_octet_len - sizeof(srtcp_trailer_t) - mki_size; memcpy(&trailer, trailer_p, sizeof(trailer)); /* @@ -3827,11 +3822,11 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( */ enc_octet_len = *pkt_octet_len - (octets_in_rtcp_header + sizeof(srtcp_trailer_t) + mki_size); - auth_tag = (uint8_t *)hdr + *pkt_octet_len - tag_len - mki_size - + auth_tag = srtcp_hdr + *pkt_octet_len - tag_len - mki_size - sizeof(srtcp_trailer_t); - if (*((unsigned char *)trailer_p) & SRTCP_E_BYTE_BIT) { - enc_start = (uint8_t *)hdr + octets_in_rtcp_header; + if (*trailer_p & SRTCP_E_BYTE_BIT) { + enc_start = srtcp_hdr + octets_in_rtcp_header; } else { enc_octet_len = 0; enc_start = NULL; /* this indicates that there's no encryption */ @@ -3869,9 +3864,8 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( * If payload encryption is enabled, then the AAD consist of * the RTCP header and the seq# at the end of the packet */ - status = - srtp_cipher_set_aad(session_keys->rtcp_cipher, (const uint8_t *)hdr, - octets_in_rtcp_header); + status = srtp_cipher_set_aad(session_keys->rtcp_cipher, srtcp_hdr, + octets_in_rtcp_header); if (status) { return (srtp_err_status_cipher_fail); } @@ -3882,7 +3876,7 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( * Types in Unencrypted SRTCP Compound Packets) */ status = srtp_cipher_set_aad( - session_keys->rtcp_cipher, (uint8_t *)hdr, + session_keys->rtcp_cipher, srtcp_hdr, (*pkt_octet_len - tag_len - sizeof(srtcp_trailer_t) - mki_size)); if (status) { return (srtp_err_status_cipher_fail); @@ -3978,14 +3972,14 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead( } srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, - void *rtcp_hdr, + uint8_t *rtcp_hdr, size_t *pkt_octet_len) { return srtp_protect_rtcp_mki(ctx, rtcp_hdr, pkt_octet_len, false, 0); } srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, - void *rtcp_hdr, + uint8_t *rtcp_hdr, size_t *pkt_octet_len, bool use_mki, unsigned int mki_index) @@ -4079,7 +4073,7 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, * set encryption start and encryption length - if we're not * providing confidentiality, set enc_start to NULL */ - enc_start = (uint8_t *)hdr + octets_in_rtcp_header; + enc_start = rtcp_hdr + octets_in_rtcp_header; enc_octet_len = *pkt_octet_len - octets_in_rtcp_header; /* all of the packet, except the header, gets encrypted */ @@ -4098,18 +4092,17 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, trailer = 0x00000000; /* set encrypt bit */ } - mki_size = srtp_inject_mki((uint8_t *)hdr + *pkt_octet_len + - sizeof(srtcp_trailer_t), - session_keys, use_mki); + mki_size = + srtp_inject_mki(rtcp_hdr + *pkt_octet_len + sizeof(srtcp_trailer_t), + session_keys, use_mki); /* * set the auth_start and auth_tag pointers to the proper locations * (note that srtpc *always* provides authentication, unlike srtp) */ /* Note: This would need to change for optional mikey data */ - auth_start = (uint8_t *)hdr; - auth_tag = - (uint8_t *)hdr + *pkt_octet_len + sizeof(srtcp_trailer_t) + mki_size; + auth_start = rtcp_hdr; + auth_tag = rtcp_hdr + *pkt_octet_len + sizeof(srtcp_trailer_t) + mki_size; /* * check sequence number for overruns, and copy it into the packet @@ -4207,14 +4200,14 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, } srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, - void *srtcp_hdr, + uint8_t *srtcp_hdr, size_t *pkt_octet_len) { return srtp_unprotect_rtcp_mki(ctx, srtcp_hdr, pkt_octet_len, false); } srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, - void *srtcp_hdr, + uint8_t *srtcp_hdr, size_t *pkt_octet_len, bool use_mki) { @@ -4270,8 +4263,8 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, * Determine if MKI is being used and what session keys should be used */ if (use_mki) { - session_keys = srtp_get_session_keys(stream, (uint8_t *)hdr, - *pkt_octet_len, &mki_size); + session_keys = + srtp_get_session_keys(stream, srtcp_hdr, *pkt_octet_len, &mki_size); if (session_keys == NULL) return srtp_err_status_bad_mki; @@ -4314,7 +4307,7 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, */ /* This should point trailer to the word past the end of the normal data. */ /* This would need to be modified for optional mikey data */ - trailer_p = (uint8_t *)hdr + *pkt_octet_len - + trailer_p = srtcp_hdr + *pkt_octet_len - (tag_len + mki_size + sizeof(srtcp_trailer_t)); memcpy(&trailer, trailer_p, sizeof(trailer)); @@ -4323,7 +4316,7 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, return srtp_err_status_cant_check; } if (sec_serv_confidentiality) { - enc_start = (uint8_t *)hdr + octets_in_rtcp_header; + enc_start = srtcp_hdr + octets_in_rtcp_header; } else { enc_octet_len = 0; enc_start = NULL; /* this indicates that there's no encryption */ @@ -4333,7 +4326,7 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, * set the auth_start and auth_tag pointers to the proper locations * (note that srtcp *always* uses authentication, unlike srtp) */ - auth_start = (uint8_t *)hdr; + auth_start = srtcp_hdr; /* * The location of the auth tag in the packet needs to know MKI @@ -4341,7 +4334,7 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, * must not include the MKI */ auth_len = *pkt_octet_len - tag_len - mki_size; - auth_tag = (uint8_t *)hdr + auth_len + mki_size; + auth_tag = srtcp_hdr + auth_len + mki_size; /* * check the sequence number for replays diff --git a/test/rtp.c b/test/rtp.c index bc87d0c29..487cf95fe 100644 --- a/test/rtp.c +++ b/test/rtp.c @@ -74,7 +74,8 @@ ssize_t rtp_sendto(rtp_sender_t sender, const void *msg, size_t len) sender->message.header.ts = htonl(sender->message.header.ts); /* apply srtp */ - stat = srtp_protect(sender->srtp_ctx, &sender->message.header, &pkt_len); + stat = srtp_protect(sender->srtp_ctx, (uint8_t *)&sender->message.header, + &pkt_len); if (stat) { #if PRINT_DEBUG fprintf(stderr, "error: srtp protection failed with code %d\n", stat); @@ -129,8 +130,8 @@ ssize_t rtp_recvfrom(rtp_receiver_t receiver, void *msg, size_t *len) #endif /* apply srtp */ - stat = srtp_unprotect(receiver->srtp_ctx, &receiver->message.header, - &octets_recvd); + stat = srtp_unprotect(receiver->srtp_ctx, + (uint8_t *)&receiver->message.header, &octets_recvd); if (stat) { fprintf(stderr, "error: srtp unprotection failed with code %d%s\n", stat, diff --git a/test/rtp.h b/test/rtp.h index 3c2e8eadc..bc670e41b 100644 --- a/test/rtp.h +++ b/test/rtp.h @@ -114,24 +114,6 @@ int rtp_sender_init(rtp_sender_t sender, struct sockaddr_in addr, uint32_t ssrc); -/* - * srtp_sender_init(...) initializes an rtp_sender_t - */ - -int srtp_sender_init( - rtp_sender_t rtp_ctx, /* structure to be init'ed */ - struct sockaddr_in name, /* socket name */ - srtp_sec_serv_t security_services, /* sec. servs. to be used */ - unsigned char *input_key /* master key/salt in hex */ -); - -int srtp_receiver_init( - rtp_receiver_t rtp_ctx, /* structure to be init'ed */ - struct sockaddr_in name, /* socket name */ - srtp_sec_serv_t security_services, /* sec. servs. to be used */ - unsigned char *input_key /* master key/salt in hex */ -); - int rtp_sender_init_srtp(rtp_sender_t sender, const srtp_policy_t *policy); int rtp_sender_deinit_srtp(rtp_sender_t sender); diff --git a/test/rtp_decoder.c b/test/rtp_decoder.c index 189e1db81..869512dcf 100644 --- a/test/rtp_decoder.c +++ b/test/rtp_decoder.c @@ -170,7 +170,7 @@ int main(int argc, char *argv[]) int gcm_on = 0; char *input_key = NULL; int b64_input = 0; - char key[MAX_KEY_LEN]; + uint8_t key[MAX_KEY_LEN]; struct bpf_program fp; char filter_exp[MAX_FILTER] = ""; char pcap_file[MAX_FILE] = "-"; @@ -520,7 +520,7 @@ int main(int argc, char *argv[]) return -1; } - policy.key = (uint8_t *)key; + policy.key = key; policy.next = NULL; policy.window_size = 128; policy.allow_repeat_tx = false; @@ -779,14 +779,16 @@ void rtp_decoder_handle_pkt(u_char *arg, return; } - status = srtp_unprotect(dcdr->srtp_ctx, &message, &octets_recvd); + status = + srtp_unprotect(dcdr->srtp_ctx, (uint8_t *)&message, &octets_recvd); if (status) { dcdr->error_cnt++; return; } dcdr->rtp_cnt++; } else { - status = srtp_unprotect_rtcp(dcdr->srtp_ctx, &message, &octets_recvd); + status = srtp_unprotect_rtcp(dcdr->srtp_ctx, (uint8_t *)&message, + &octets_recvd); if (status) { dcdr->error_cnt++; return; diff --git a/test/rtpw.c b/test/rtpw.c index eb8d1895c..414f0dd57 100644 --- a/test/rtpw.c +++ b/test/rtpw.c @@ -155,7 +155,7 @@ int main(int argc, char *argv[]) char *input_key = NULL; int b64_input = 0; char *address = NULL; - char key[MAX_KEY_LEN]; + uint8_t key[MAX_KEY_LEN]; unsigned short port = 0; rtp_sender_t snd; srtp_policy_t policy; @@ -453,7 +453,7 @@ int main(int argc, char *argv[]) } policy.ssrc.type = ssrc_specific; policy.ssrc.value = ssrc; - policy.key = (uint8_t *)key; + policy.key = key; policy.next = NULL; policy.window_size = 128; policy.allow_repeat_tx = false; diff --git a/test/srtp_driver.c b/test/srtp_driver.c index f13c8abe0..95ce801fd 100644 --- a/test/srtp_driver.c +++ b/test/srtp_driver.c @@ -121,8 +121,8 @@ srtp_err_status_t srtp_session_print_policy(srtp_t srtp); srtp_err_status_t srtp_print_policy(const srtp_policy_t *policy); -char *srtp_packet_to_string(srtp_hdr_t *hdr, size_t packet_len); -char *srtp_rtcp_packet_to_string(srtcp_hdr_t *hdr, size_t pkt_octet_len); +char *srtp_packet_to_string(uint8_t *packet, size_t packet_len); +char *srtp_rtcp_packet_to_string(uint8_t *packet, size_t pkt_octet_len); double mips_estimate(int num_trials, int *ignore); @@ -707,9 +707,9 @@ int main(int argc, char *argv[]) * deallocated with the free() call once it is no longer needed. */ -srtp_hdr_t *srtp_create_test_packet(size_t pkt_octet_len, - uint32_t ssrc, - size_t *pkt_len) +uint8_t *srtp_create_test_packet(size_t pkt_octet_len, + uint32_t ssrc, + size_t *pkt_len) { size_t i; uint8_t *buffer; @@ -748,12 +748,12 @@ srtp_hdr_t *srtp_create_test_packet(size_t pkt_octet_len, *pkt_len = bytes_in_hdr + pkt_octet_len; - return hdr; + return (uint8_t *)hdr; } -srtcp_hdr_t *srtp_create_rtcp_test_packet(size_t pkt_octet_len, - uint32_t ssrc, - size_t *pkt_len) +uint8_t *srtp_create_rtcp_test_packet(size_t pkt_octet_len, + uint32_t ssrc, + size_t *pkt_len) { size_t i; uint8_t *buffer; @@ -789,29 +789,30 @@ srtcp_hdr_t *srtp_create_rtcp_test_packet(size_t pkt_octet_len, *pkt_len = bytes_in_hdr + pkt_octet_len; - return hdr; + return (uint8_t *)hdr; } -static srtp_hdr_t *srtp_create_test_packet_extended(size_t pkt_octet_len, - uint32_t ssrc, - uint16_t seq, - uint32_t ts, - size_t *pkt_len) +static uint8_t *srtp_create_test_packet_extended(size_t pkt_octet_len, + uint32_t ssrc, + uint16_t seq, + uint32_t ts, + size_t *pkt_len) { srtp_hdr_t *hdr; - hdr = srtp_create_test_packet(pkt_octet_len, ssrc, pkt_len); - if (hdr == NULL) - return hdr; + hdr = (srtp_hdr_t *)srtp_create_test_packet(pkt_octet_len, ssrc, pkt_len); + if (hdr == NULL) { + return NULL; + } hdr->seq = htons(seq); hdr->ts = htonl(ts); - return hdr; + return (uint8_t *)hdr; } -srtp_hdr_t *srtp_create_test_packet_ext_hdr(size_t pkt_octet_len, - uint32_t ssrc, - size_t *pkt_len) +uint8_t *srtp_create_test_packet_ext_hdr(size_t pkt_octet_len, + uint32_t ssrc, + size_t *pkt_len) { size_t i; uint8_t *buffer; @@ -868,7 +869,7 @@ srtp_hdr_t *srtp_create_test_packet_ext_hdr(size_t pkt_octet_len, *pkt_len = bytes_in_hdr + sizeof(extension_header) + pkt_octet_len; - return hdr; + return (uint8_t *)hdr; } void srtp_do_timing(const srtp_policy_t *policy) @@ -919,7 +920,7 @@ void srtp_do_rejection_timing(const srtp_policy_t *policy) double srtp_bits_per_second(size_t msg_len_octets, const srtp_policy_t *policy) { srtp_t srtp; - srtp_hdr_t *mesg; + uint8_t *mesg; int i; clock_t timer; int num_trials = 100000; @@ -966,8 +967,9 @@ double srtp_bits_per_second(size_t msg_len_octets, const srtp_policy_t *policy) { /* hack sequence to avoid problems with macros for htons/ntohs on * some systems */ - short new_seq = ntohs(mesg->seq) + 1; - mesg->seq = htons(new_seq); + srtp_hdr_t *hdr = (srtp_hdr_t *)mesg; + short new_seq = ntohs(hdr->seq) + 1; + hdr->seq = htons(new_seq); } } timer = clock() - timer; @@ -987,7 +989,7 @@ double srtp_rejections_per_second(int msg_len_octets, const srtp_policy_t *policy) { srtp_ctx_t *srtp; - srtp_hdr_t *mesg; + uint8_t *mesg; int i; size_t len; clock_t timer; @@ -1008,12 +1010,12 @@ double srtp_rejections_per_second(int msg_len_octets, if (mesg == NULL) { return 0.0; /* indicate failure by returning zero */ } - srtp_protect(srtp, (srtp_hdr_t *)mesg, &len); + srtp_protect(srtp, mesg, &len); timer = clock(); for (i = 0; i < num_trials; i++) { len = msg_len_octets; - srtp_unprotect(srtp, (srtp_hdr_t *)mesg, &len); + srtp_unprotect(srtp, mesg, &len); } timer = clock() - timer; @@ -1037,7 +1039,7 @@ void err_check(srtp_err_status_t s) } srtp_err_status_t srtp_test_call_protect(srtp_t srtp_sender, - srtp_hdr_t *hdr, + uint8_t *hdr, size_t *len, int mki_index) { @@ -1049,7 +1051,7 @@ srtp_err_status_t srtp_test_call_protect(srtp_t srtp_sender, } srtp_err_status_t srtp_test_call_protect_rtcp(srtp_t srtp_sender, - srtcp_hdr_t *hdr, + uint8_t *hdr, size_t *len, int mki_index) { @@ -1061,7 +1063,7 @@ srtp_err_status_t srtp_test_call_protect_rtcp(srtp_t srtp_sender, } srtp_err_status_t srtp_test_call_unprotect(srtp_t srtp_sender, - srtp_hdr_t *hdr, + uint8_t *hdr, size_t *len, bool use_mki) { @@ -1073,7 +1075,7 @@ srtp_err_status_t srtp_test_call_unprotect(srtp_t srtp_sender, } srtp_err_status_t srtp_test_call_unprotect_rtcp(srtp_t srtp_sender, - srtcp_hdr_t *hdr, + uint8_t *hdr, size_t *len, bool use_mki) { @@ -1092,7 +1094,7 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, srtp_t srtp_sender; srtp_t srtp_rcvr; srtp_err_status_t status = srtp_err_status_ok; - srtp_hdr_t *hdr, *hdr2; + uint8_t *hdr, *hdr2; uint8_t hdr_enc[64]; uint8_t *pkt_end; size_t msg_len_octets, msg_len_enc, msg_len; @@ -1155,7 +1157,7 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, #if PRINT_REFERENCE_PACKET debug_print(mod_driver, "reference packet before protection:\n%s", - octet_string_hex_string((uint8_t *)hdr, len)); + octet_string_hex_string(hdr, len)); #endif err_check(srtp_test_call_protect(srtp_sender, hdr, &len, mki_index)); @@ -1163,7 +1165,7 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, srtp_packet_to_string(hdr, len)); #if PRINT_REFERENCE_PACKET debug_print(mod_driver, "after protection:\n%s", - octet_string_hex_string((uint8_t *)hdr, len)); + octet_string_hex_string(hdr, len)); #endif /* save protected message and length */ @@ -1179,13 +1181,13 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, */ err_check(srtp_get_protect_trailer_length(srtp_sender, use_mki, mki_index, &tag_length)); - pkt_end = (uint8_t *)hdr + msg_len + tag_length; + pkt_end = hdr + msg_len + tag_length; for (i = 0; i < 4; i++) { if (pkt_end[i] != 0xff) { fprintf(stdout, "overwrite in srtp_protect() function " "(expected %x, found %x in trailing octet %zu)\n", - 0xff, ((uint8_t *)hdr)[i], i); + 0xff, hdr[i], i); free(hdr); free(hdr2); return srtp_err_status_algo_fail; @@ -1205,7 +1207,7 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, printf("testing that ciphertext is distinct from plaintext..."); status = srtp_err_status_algo_fail; for (i = 12; i < msg_len_octets + 12; i++) { - if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) { + if (hdr[i] != hdr2[i]) { status = srtp_err_status_ok; } } @@ -1252,7 +1254,7 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, /* verify that the unprotected packet matches the origial one */ for (i = 0; i < len; i++) { - if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) { + if (hdr[i] != hdr2[i]) { fprintf(stdout, "mismatch at octet %zu\n", i); status = srtp_err_status_algo_fail; } @@ -1268,7 +1270,7 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, * if the policy includes authentication, then test for false positives */ if (policy->rtp.sec_serv & sec_serv_auth) { - char *data = ((char *)hdr) + (extension_header ? 24 : 12); + uint8_t *data = hdr + (extension_header ? 24 : 12); printf("testing for false positives in replay check..."); @@ -1288,7 +1290,7 @@ srtp_err_status_t srtp_test(const srtp_policy_t *policy, printf("testing for false positives in auth check..."); /* increment sequence number in header */ - hdr->seq++; + ((srtp_hdr_t *)hdr)->seq++; /* apply protection */ err_check(srtp_test_call_protect(srtp_sender, hdr, &len, mki_index)); @@ -1325,7 +1327,7 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) srtp_t srtcp_sender; srtp_t srtcp_rcvr; srtp_err_status_t status = srtp_err_status_ok; - srtcp_hdr_t *hdr, *hdr2; + uint8_t *hdr, *hdr2; uint8_t hdr_enc[64]; uint8_t *pkt_end; size_t msg_len_octets, msg_len_enc, msg_len; @@ -1372,7 +1374,7 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) #if PRINT_REFERENCE_PACKET debug_print(mod_driver, "reference packet before protection:\n%s", - octet_string_hex_string((uint8_t *)hdr, len)); + octet_string_hex_string(hdr, len)); #endif err_check(srtp_test_call_protect_rtcp(srtcp_sender, hdr, &len, mki_index)); @@ -1380,7 +1382,7 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) srtp_rtcp_packet_to_string(hdr, len)); #if PRINT_REFERENCE_PACKET debug_print(mod_driver, "after protection:\n%s", - octet_string_hex_string((uint8_t *)hdr, len)); + octet_string_hex_string(hdr, len)); #endif /* save protected message and length */ @@ -1396,13 +1398,13 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) */ srtp_get_protect_rtcp_trailer_length(srtcp_sender, use_mki, mki_index, &tag_length); - pkt_end = (uint8_t *)hdr + msg_len + tag_length; + pkt_end = hdr + msg_len + tag_length; for (i = 0; i < 4; i++) { if (pkt_end[i] != 0xff) { fprintf(stdout, "overwrite in srtp_protect_rtcp() function " "(expected %x, found %x in trailing octet %zu)\n", - 0xff, ((uint8_t *)hdr)[i], i); + 0xff, hdr[i], i); free(hdr); free(hdr2); return srtp_err_status_algo_fail; @@ -1422,7 +1424,7 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) printf("testing that ciphertext is distinct from plaintext..."); status = srtp_err_status_algo_fail; for (i = 12; i < msg_len_octets + 12; i++) { - if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) { + if (hdr[i] != hdr2[i]) { status = srtp_err_status_ok; } } @@ -1462,7 +1464,7 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) /* verify that the unprotected packet matches the original one */ for (i = 0; i < len; i++) { - if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) { + if (hdr[i] != hdr2[i]) { fprintf(stdout, "mismatch at octet %zu\n", i); status = srtp_err_status_algo_fail; } @@ -1478,7 +1480,7 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index) * if the policy includes authentication, then test for false positives */ if (policy->rtp.sec_serv & sec_serv_auth) { - char *data = ((char *)hdr) + 12; + uint8_t *data = hdr + 12; printf("testing for false positives in replay check..."); @@ -1649,10 +1651,11 @@ srtp_err_status_t srtp_print_policy(const srtp_policy_t *policy) char packet_string[MTU]; -char *srtp_packet_to_string(srtp_hdr_t *hdr, size_t pkt_octet_len) +char *srtp_packet_to_string(uint8_t *packet, size_t pkt_octet_len) { + srtp_hdr_t *hdr = (srtp_hdr_t *)packet; size_t octets_in_rtp_header = 12; - uint8_t *data = ((uint8_t *)hdr) + octets_in_rtp_header; + uint8_t *data = packet + octets_in_rtp_header; size_t hex_len = pkt_octet_len - octets_in_rtp_header; /* sanity checking */ @@ -1681,10 +1684,11 @@ char *srtp_packet_to_string(srtp_hdr_t *hdr, size_t pkt_octet_len) return packet_string; } -char *srtp_rtcp_packet_to_string(srtcp_hdr_t *hdr, size_t pkt_octet_len) +char *srtp_rtcp_packet_to_string(uint8_t *packet, size_t pkt_octet_len) { + srtcp_hdr_t *hdr = (srtcp_hdr_t *)packet; size_t octets_in_rtcp_header = 8; - uint8_t *data = ((uint8_t *)hdr) + octets_in_rtcp_header; + uint8_t *data = packet + octets_in_rtcp_header; size_t hex_len = pkt_octet_len - octets_in_rtcp_header; /* sanity checking */ @@ -2637,7 +2641,7 @@ srtp_err_status_t srtp_test_empty_payload(void) srtp_err_status_t status; size_t len; srtp_policy_t policy; - srtp_hdr_t *mesg; + uint8_t *mesg; /* * create a session with a single stream using the default srtp @@ -2712,7 +2716,7 @@ srtp_err_status_t srtp_test_empty_payload_gcm(void) srtp_err_status_t status; size_t len; srtp_policy_t policy; - srtp_hdr_t *mesg; + uint8_t *mesg; /* * create a session with a single stream using the default srtp @@ -2899,7 +2903,7 @@ srtp_err_status_t srtp_test_update(void) uint32_t ssrc = 0x12121212; size_t msg_len_octets = 32; size_t protected_msg_len_octets; - srtp_hdr_t *msg; + uint8_t *msg; srtp_t srtp_snd, srtp_recv; srtp_policy_t policy; @@ -2928,7 +2932,7 @@ srtp_err_status_t srtp_test_update(void) &protected_msg_len_octets); if (msg == NULL) return srtp_err_status_alloc_fail; - msg->seq = htons(65535); + ((srtp_hdr_t *)msg)->seq = htons(65535); status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets); if (status) @@ -2944,7 +2948,7 @@ srtp_err_status_t srtp_test_update(void) &protected_msg_len_octets); if (msg == NULL) return srtp_err_status_alloc_fail; - msg->seq = htons(1); + ((srtp_hdr_t *)msg)->seq = htons(1); status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets); if (status) @@ -2967,7 +2971,7 @@ srtp_err_status_t srtp_test_update(void) &protected_msg_len_octets); if (msg == NULL) return srtp_err_status_alloc_fail; - msg->seq = htons(2); + ((srtp_hdr_t *)msg)->seq = htons(2); status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets); if (status) @@ -2991,7 +2995,7 @@ srtp_err_status_t srtp_test_update(void) &protected_msg_len_octets); if (msg == NULL) return srtp_err_status_alloc_fail; - msg->seq = htons(3); + ((srtp_hdr_t *)msg)->seq = htons(3); status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets); if (status) @@ -3259,7 +3263,7 @@ srtp_err_status_t srtp_test_out_of_order_after_rollover(void) srtp_t receiver_session; const uint32_t num_pkts = 5; - srtp_hdr_t *pkts[5]; + uint8_t *pkts[5]; size_t pkt_len_octets[5]; uint32_t i; @@ -3471,7 +3475,7 @@ srtp_err_status_t srtp_test_get_roc(void) srtp_err_status_t status; srtp_policy_t policy; srtp_t session; - srtp_hdr_t *pkt; + uint8_t *pkt; uint32_t i; uint32_t roc; uint32_t ts; @@ -3541,11 +3545,11 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, srtp_policy_t receiver_policy; srtp_t receiver_session; - srtp_hdr_t *pkt_1; - unsigned char *recv_pkt_1; + uint8_t *pkt_1; + uint8_t *recv_pkt_1; - srtp_hdr_t *pkt_2; - unsigned char *recv_pkt_2; + uint8_t *pkt_2; + uint8_t *recv_pkt_2; uint32_t i; uint32_t ts; @@ -3582,7 +3586,7 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets, ts = 0; stride = 0x4000; while (i < packets) { - srtp_hdr_t *tmp_pkt; + uint8_t *tmp_pkt; size_t tmp_len; tmp_pkt = srtp_create_test_packet_extended( @@ -3706,8 +3710,8 @@ static srtp_err_status_t test_set_sender_roc(uint16_t seq, uint32_t roc_to_set) srtp_policy_t receiver_policy; srtp_t receiver_session; - srtp_hdr_t *pkt; - unsigned char *recv_pkt; + uint8_t *pkt; + uint8_t *recv_pkt; uint32_t ts; diff --git a/test/util.c b/test/util.c index 5aae90309..1ef405896 100644 --- a/test/util.c +++ b/test/util.c @@ -51,7 +51,7 @@ /* include space for null terminator */ static char bit_string[MAX_PRINT_STRING_LEN + 1]; -static inline int hex_char_to_nibble(uint8_t c) +static inline int hex_char_to_nibble(char c) { switch (c) { case ('0'): @@ -103,7 +103,7 @@ static inline int hex_char_to_nibble(uint8_t c) } } -uint8_t nibble_to_hex_char(uint8_t nibble) +char nibble_to_hex_char(uint8_t nibble) { char buf[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; @@ -115,7 +115,7 @@ uint8_t nibble_to_hex_char(uint8_t nibble) * hex_string_to_octet_string converts a hexadecimal string * of length 2 * len to a raw octet string of length len */ -size_t hex_string_to_octet_string(char *raw, char *hex, size_t len) +size_t hex_string_to_octet_string(uint8_t *raw, const char *hex, size_t len) { uint8_t x; int tmp; @@ -141,9 +141,8 @@ size_t hex_string_to_octet_string(char *raw, char *hex, size_t len) return hex_len; } -char *octet_string_hex_string(const void *s, size_t length) +const char *octet_string_hex_string(const uint8_t *str, size_t length) { - const uint8_t *str = (const uint8_t *)s; size_t i; /* double length, since one octet takes two hex characters */ @@ -165,16 +164,16 @@ char *octet_string_hex_string(const void *s, size_t length) static const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789+/"; -static size_t base64_block_to_octet_triple(char *out, char *in) +static size_t base64_block_to_octet_triple(uint8_t *out, const char *in) { - unsigned char sextets[4] = { 0 }; + uint8_t sextets[4] = { 0 }; size_t j = 0; size_t i; for (i = 0; i < 4; i++) { char *p = strchr(b64chars, in[i]); if (p != NULL) { - sextets[i] = (unsigned char)(p - b64chars); + sextets[i] = (uint8_t)(p - b64chars); } else { j++; } @@ -190,7 +189,10 @@ static size_t base64_block_to_octet_triple(char *out, char *in) return j; } -size_t base64_string_to_octet_string(char *out, int *pad, char *in, size_t len) +size_t base64_string_to_octet_string(uint8_t *out, + int *pad, + const char *in, + size_t len) { size_t k = 0; size_t i = 0; diff --git a/test/util.h b/test/util.h index 72b8ed72b..c0fd6c2a6 100644 --- a/test/util.h +++ b/test/util.h @@ -45,14 +45,15 @@ #define SRTP_TEST_UTIL_H #include +#include #define MAX_PRINT_STRING_LEN 1024 -size_t hex_string_to_octet_string(char *raw, char *hex, size_t len); -char *octet_string_hex_string(const void *s, size_t length); -size_t base64_string_to_octet_string(char *raw, +size_t hex_string_to_octet_string(uint8_t *raw, const char *hex, size_t len); +const char *octet_string_hex_string(const uint8_t *str, size_t length); +size_t base64_string_to_octet_string(uint8_t *raw, int *pad, - char *base64, + const char *base64, size_t len); #endif