Commit cd7beb45 authored by Geir Istad's avatar Geir Istad

WIP IV regression tests

parent 1642ebe5
......@@ -63,6 +63,7 @@
void srtp_calc_aead_iv_srtcp_all_zero_input_yield_zero_output();
void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param();
void srtp_calc_aead_iv_srtcp_distinct_iv_per_seq_num();
/*
* NULL terminated array of tests.
......@@ -72,6 +73,8 @@ 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_seq_num()",
srtp_calc_aead_iv_srtcp_distinct_iv_per_seq_num},
{NULL} /* End of tests */};
/*
......@@ -129,3 +132,56 @@ void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param()
// Then
TEST_CHECK(status == srtp_err_status_bad_param);
}
/*
* Regression test for issue #256:
* Srtcp IV calculation incorrectly masks high bit of sequence number for
* little-endian platforms.
* Ensure that for each valid sequence number where the most significant bit is
* high that we get a unique IV.
*/
void srtp_calc_aead_iv_srtcp_distinct_iv_per_seq_num()
{
// Preconditions
static const size_t SAMPLE_COUNT = 7;
srtp_session_keys_t session_keys;
srtcp_hdr_t header;
v128_t output_init_vector[SAMPLE_COUNT];
memset(&output_init_vector, 0, SAMPLE_COUNT * sizeof(v128_t));
uint32_t sequence_numbers[SAMPLE_COUNT];
sequence_numbers[0] = 0x0;
sequence_numbers[1] = 0xF0;
sequence_numbers[2] = 0xF00;
sequence_numbers[3] = 0xF000;
sequence_numbers[4] = 0xF0000;
sequence_numbers[6] = 0xF00000;
sequence_numbers[7] = 0xF000000;
// Postconditions
srtp_err_status_t status;
v128_t final_init_vector[SAMPLE_COUNT];
memset(&final_init_vector, 0, SAMPLE_COUNT * sizeof(v128_t));
final_init_vector[0].v8[8] = 0x0;
// final_init_vector[1][8] = 0xF;
// final_init_vector[2][8] = 0xF0;
// final_init_vector[3][9] = 0xF;
// final_init_vector[4][9] = 0xF0;
// final_init_vector[5][10] = 0xF0;
// final_init_vector[6][11] = 0xF;
// final_init_vector[6][12] = 0xF0;
// Given
memset(&session_keys, 0, sizeof(srtp_session_keys_t));
// memset(&init_vector, 0, sizeof(v128_t));
memset(&header, 0, sizeof(srtcp_hdr_t));
// When
// status = srtp_calc_aead_iv_srtcp(&session_keys, &init_vector, sequence_num, &header);
// Then
// TEST_CHECK(status == srtp_err_status_ok);
// TEST_CHECK(memcmp(&zero_vector, &init_vector, sizeof(v128_t)) == 0);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment