123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #include "../srtp/srtp.c"
- #include "cutest.h"
- void srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output(void);
- void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param(void);
- void srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number(void);
- TEST_LIST = { { "srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output()",
- srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output },
- { "srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param()",
- srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param },
- { "srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number()",
- srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number },
- { NULL } };
- void srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output()
- {
-
- srtp_session_keys_t session_keys;
- v128_t init_vector;
- srtcp_hdr_t header;
- uint32_t sequence_num;
-
- srtp_err_status_t status;
- const v128_t zero_vector;
- memset((v128_t *)&zero_vector, 0, sizeof(v128_t));
-
- memset(&session_keys, 0, sizeof(srtp_session_keys_t));
- memset(&init_vector, 0, sizeof(v128_t));
- memset(&header, 0, sizeof(srtcp_hdr_t));
- sequence_num = 0x0UL;
-
- status = srtp_calc_aead_iv_srtcp(&session_keys, &init_vector, sequence_num,
- &header);
-
- TEST_CHECK(status == srtp_err_status_ok);
- TEST_CHECK(memcmp(&zero_vector, &init_vector, sizeof(v128_t)) == 0);
- }
- void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param()
- {
-
- srtp_session_keys_t session_keys;
- v128_t init_vector;
- srtcp_hdr_t header;
- uint32_t sequence_num;
-
- srtp_err_status_t status;
-
- memset(&session_keys, 0, sizeof(srtp_session_keys_t));
- memset(&init_vector, 0, sizeof(v128_t));
- memset(&header, 0, sizeof(srtcp_hdr_t));
- sequence_num = 0x7FFFFFFFUL + 0x1UL;
-
- status = srtp_calc_aead_iv_srtcp(&session_keys, &init_vector, sequence_num,
- &header);
-
- TEST_CHECK(status == srtp_err_status_bad_param);
- }
- void srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number()
- {
- #define SAMPLE_COUNT (3)
-
-
- srtp_session_keys_t session_keys;
- srtcp_hdr_t header;
- v128_t output_iv[SAMPLE_COUNT];
- uint32_t sequence_num[SAMPLE_COUNT];
- v128_t final_iv[SAMPLE_COUNT];
- size_t i = 0;
- memset(&output_iv, 0, SAMPLE_COUNT * sizeof(v128_t));
- sequence_num[0] = 0xFF;
- sequence_num[1] = 0xFF00;
- sequence_num[2] = 0xFF0000;
-
- memset(&final_iv, 0, SAMPLE_COUNT * sizeof(v128_t));
- final_iv[0].v8[11] = 0xFF;
- final_iv[1].v8[10] = 0xFF;
- final_iv[2].v8[9] = 0xFF;
-
- memset(&session_keys, 0, sizeof(srtp_session_keys_t));
- memset(&header, 0, sizeof(srtcp_hdr_t));
-
- for (i = 0; i < SAMPLE_COUNT; i++) {
- TEST_CHECK(srtp_calc_aead_iv_srtcp(&session_keys, &output_iv[i],
- sequence_num[i],
- &header) == srtp_err_status_ok);
- }
-
- for (i = 0; i < SAMPLE_COUNT; i++) {
- TEST_CHECK(memcmp(&final_iv[i], &output_iv[i], sizeof(v128_t)) == 0);
- }
- #undef SAMPLE_COUNT
- }
|