Skip to content

Commit 8e3f563

Browse files
committed
add failing AES 192 validation test
The test vectors are generated based on RFC 6188 section 7.4 . It demonstrates that the kdf for AES 192 is currently broken. It mistakenly uses the kdf in AES 256 mode as described in #763.
1 parent 50d8062 commit 8e3f563

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

test/srtp_driver.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm(void);
8484

8585
srtp_err_status_t srtp_validate_aes_256(void);
8686

87+
#ifdef GCM
88+
srtp_err_status_t srtp_validate_aes_192(void);
89+
#endif
90+
8791
srtp_err_status_t srtp_create_big_policy(srtp_policy_t **list);
8892

8993
srtp_err_status_t srtp_dealloc_big_policy(srtp_policy_t *list);
@@ -772,6 +776,21 @@ int main(int argc, char *argv[])
772776
}
773777
#endif
774778

779+
#ifdef GCM
780+
/*
781+
* run validation test against the reference packets for
782+
* AES-192
783+
*/
784+
printf("testing srtp_protect and srtp_unprotect against "
785+
"reference packet (AES-192)\n");
786+
if (srtp_validate_aes_192() == srtp_err_status_ok) {
787+
printf("passed\n\n");
788+
} else {
789+
printf("failed\n");
790+
exit(1);
791+
}
792+
#endif
793+
775794
/*
776795
* run validation test against the reference packets for
777796
* AES-256
@@ -3985,6 +4004,105 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm(void)
39854004

39864005
return srtp_err_status_ok;
39874006
}
4007+
4008+
/*
4009+
* srtp_validate_aes_192() verifies the correctness of libsrtp by comparing
4010+
* some computed packets against some pre-computed reference values.
4011+
* These packets were made with the AES-CM-192/HMAC-SHA-1-80 policy.
4012+
*
4013+
* The master key and master salt come from RFC 6188 section 7.4 .
4014+
* The test vectors where generated using the cipher key and cipher salt
4015+
* in section 7.4 with cipher_driver with the nonce and plaintext in the
4016+
* srtp_plaintext_ref.
4017+
*/
4018+
4019+
srtp_err_status_t srtp_validate_aes_192(void)
4020+
{
4021+
// clang-format off
4022+
uint8_t aes_192_test_key[38] = {
4023+
0x73, 0xed, 0xc6, 0x6c, 0x4f, 0xa1, 0x57, 0x76,
4024+
0xfb, 0x57, 0xf9, 0x50, 0x5c, 0x17, 0x13, 0x65,
4025+
0x50, 0xff, 0xda, 0x71, 0xf3, 0xe8, 0xe5, 0xf1,
4026+
4027+
0xc8, 0x52, 0x2f, 0x3a, 0xcd, 0x4c, 0xe8, 0x6d,
4028+
0x5a, 0xdd, 0x78, 0xed, 0xbb, 0x11
4029+
};
4030+
uint8_t srtp_plaintext_ref[28] = {
4031+
0x80, 0x0f, 0x00, 0x00, 0xde, 0xca, 0xfb, 0xad,
4032+
0x00, 0x00, 0x00, 0x00, 0xab, 0xab, 0xab, 0xab,
4033+
0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
4034+
0xab, 0xab, 0xab, 0xab
4035+
};
4036+
uint8_t srtp_plaintext[38] = {
4037+
0x80, 0x0f, 0x00, 0x00, 0xde, 0xca, 0xfb, 0xad,
4038+
0x00, 0x00, 0x00, 0x00, 0xab, 0xab, 0xab, 0xab,
4039+
0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
4040+
0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
4041+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4042+
};
4043+
uint8_t srtp_ciphertext[38] = {
4044+
0x80, 0x0f, 0x00, 0x00, 0xde, 0xca, 0xfb, 0xad,
4045+
0x00, 0x00, 0x00, 0x00, 0xd9, 0x88, 0x65, 0x55,
4046+
0x2f, 0x27, 0x62, 0xc3, 0xef, 0x37, 0xf8, 0x37,
4047+
0xac, 0xfd, 0xb7, 0x12, 0x2d, 0x6b, 0xc4, 0xdc,
4048+
0x84, 0xc7, 0x6f, 0x74, 0xae, 0xa5
4049+
};
4050+
// clang-format on
4051+
4052+
srtp_t srtp_snd, srtp_recv;
4053+
size_t len;
4054+
srtp_policy_t policy;
4055+
4056+
/*
4057+
* create a session with a single stream using the default srtp
4058+
* policy and with the SSRC value 0xcafebabe
4059+
*/
4060+
memset(&policy, 0, sizeof(policy));
4061+
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy.rtp);
4062+
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&policy.rtcp);
4063+
policy.ssrc.type = ssrc_specific;
4064+
policy.ssrc.value = 0x00000000;
4065+
policy.key = aes_192_test_key;
4066+
policy.window_size = 128;
4067+
policy.allow_repeat_tx = false;
4068+
policy.next = NULL;
4069+
4070+
CHECK_OK(srtp_create(&srtp_snd, &policy));
4071+
4072+
/*
4073+
* protect plaintext, then compare with ciphertext
4074+
*/
4075+
len = 28;
4076+
CHECK_OK(call_srtp_protect(srtp_snd, srtp_plaintext, &len, 0));
4077+
CHECK(len == 38);
4078+
4079+
debug_print(mod_driver, "ciphertext:\n %s",
4080+
octet_string_hex_string(srtp_plaintext, len));
4081+
debug_print(mod_driver, "ciphertext reference:\n %s",
4082+
octet_string_hex_string(srtp_ciphertext, len));
4083+
4084+
CHECK_BUFFER_EQUAL(srtp_plaintext, srtp_ciphertext, len);
4085+
4086+
/*
4087+
* create a receiver session context comparable to the one created
4088+
* above - we need to do this so that the replay checking doesn't
4089+
* complain
4090+
*/
4091+
CHECK_OK(srtp_create(&srtp_recv, &policy));
4092+
4093+
/*
4094+
* unprotect ciphertext, then compare with plaintext
4095+
*/
4096+
CHECK_OK(call_srtp_unprotect(srtp_recv, srtp_ciphertext, &len));
4097+
CHECK(len == 28);
4098+
4099+
CHECK_BUFFER_EQUAL(srtp_ciphertext, srtp_plaintext_ref, len);
4100+
4101+
CHECK_OK(srtp_dealloc(srtp_snd));
4102+
CHECK_OK(srtp_dealloc(srtp_recv));
4103+
4104+
return srtp_err_status_ok;
4105+
}
39884106
#endif
39894107

39904108
/*

0 commit comments

Comments
 (0)