44 for (i = 0, outpos = 0; outpos < outlen; i++) {
48 for (j = 0; j < 16 && outpos < outlen; j++, outpos++)
49 outbuf[outpos] ^= keystream[j];
57 memcpy(input, salt, 14);
59 input[14 - 7] ^= label;
60 memset(out, 0, outlen);
72 if (!strcmp(suite,
"AES_CM_128_HMAC_SHA1_80") ||
73 !strcmp(suite,
"SRTP_AES128_CM_HMAC_SHA1_80")) {
75 }
else if (!strcmp(suite,
"AES_CM_128_HMAC_SHA1_32")) {
77 }
else if (!strcmp(suite,
"SRTP_AES128_CM_HMAC_SHA1_32")) {
119 for (i = 0; i < 8; i++)
120 iv[6 + i] ^= indexbuf[i];
121 for (i = 0; i < 14; i++)
127 uint8_t iv[16] = { 0 }, hmac[20];
158 if (seq_largest < 32768) {
159 if (seq - seq_largest > 32768)
162 if (seq_largest - 32768 > seq)
166 seq_largest =
FFMAX(seq_largest, seq);
167 }
else if (v == roc + 1) {
171 index = seq + (((uint64_t)v) << 16);
178 if (memcmp(hmac, buf + len - hmac_size, hmac_size)) {
190 uint32_t srtcp_index =
AV_RB32(buf + len - 4);
195 index = srtcp_index & 0x7fffffff;
199 if (!(srtcp_index & 0x80000000))
207 csrc = buf[0] & 0x0f;
222 ext = (
AV_RB16(buf + 2) + 1) * 4;
240 uint8_t iv[16] = { 0 }, hmac[20];
243 int rtcp, hmac_size, padding;
255 if (len + padding > outlen)
258 memcpy(out, in, len);
276 if (seq < s->seq_largest)
279 index = seq + (((uint64_t)s->
roc) << 16);
281 csrc = buf[0] & 0x0f;
295 ext = (
AV_RB16(buf + 2) + 1) * 4;
308 AV_WB32(buf + len, 0x80000000 | index);
321 memcpy(buf + len, hmac, hmac_size);
323 return buf + len -
out;
329 static const char *aes128_80_key =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
331 static const uint8_t rtp_aes128_80[] = {
333 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
335 0x62, 0x69, 0x76, 0xca, 0xc5,
337 0xa1, 0xac, 0x1b, 0xb4, 0xa0, 0x1c, 0xd5, 0x49, 0x28, 0x99,
340 static const uint8_t rtcp_aes128_80[] = {
342 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
344 0x8a, 0xac, 0xdc, 0xa5, 0x4c, 0xf6, 0x78, 0xa6, 0x62, 0x8f, 0x24, 0xda,
345 0x6c, 0x09, 0x3f, 0xa9, 0x28, 0x7a, 0xb5, 0x7f, 0x1f, 0x0f, 0xc9, 0x35,
347 0x80, 0x00, 0x00, 0x03,
349 0xe9, 0x3b, 0xc0, 0x5c, 0x0c, 0x06, 0x9f, 0xab, 0xc0, 0xde,
352 static const char *aes128_32_key =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
354 static const uint8_t rtp_aes128_32[] = {
356 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
358 0x62, 0x69, 0x76, 0xca, 0xc5,
360 0xa1, 0xac, 0x1b, 0xb4,
363 static const uint8_t rtcp_aes128_32[] = {
365 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
367 0x35, 0xe9, 0xb5, 0xff, 0x0d, 0xd1, 0xde, 0x70, 0x74, 0x10, 0xaa, 0x1b,
368 0xb2, 0x8d, 0xf0, 0x20, 0x02, 0x99, 0x6b, 0x1b, 0x0b, 0xd0, 0x47, 0x34,
370 0x80, 0x00, 0x00, 0x04,
372 0x5b, 0xd2, 0xa9, 0x9d,
375 static const char *aes128_80_32_key =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
377 static const uint8_t rtp_aes128_80_32[] = {
379 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
381 0x62, 0x69, 0x76, 0xca, 0xc5,
383 0xa1, 0xac, 0x1b, 0xb4,
386 static const uint8_t rtcp_aes128_80_32[] = {
388 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
390 0xd6, 0xae, 0xc1, 0x58, 0x63, 0x70, 0xc9, 0x88, 0x66, 0x26, 0x1c, 0x53,
391 0xff, 0x5d, 0x5d, 0x2b, 0x0f, 0x8c, 0x72, 0x3e, 0xc9, 0x1d, 0x43, 0xf9,
393 0x80, 0x00, 0x00, 0x05,
395 0x09, 0x16, 0xb4, 0x27, 0x9a, 0xe9, 0x92, 0x26, 0x4e, 0x10,
398 static void print_data(
const uint8_t *buf,
int len)
401 for (i = 0; i <
len; i++)
402 printf(
"%02x", buf[i]);
409 memcpy(out, in, len);
411 print_data(out, len);
417 static void test_encrypt(
const uint8_t *
data,
int in_len,
const char *suite,
427 if (len == in_len && !memcmp(buf, data, len))
428 printf(
"Decrypted content matches input\n");
430 printf(
"Decrypted content doesn't match input\n");
432 printf(
"Decryption failed\n");
440 static const char *aes128_80_suite =
"AES_CM_128_HMAC_SHA1_80";
441 static const char *aes128_32_suite =
"AES_CM_128_HMAC_SHA1_32";
442 static const char *aes128_80_32_suite =
"SRTP_AES128_CM_HMAC_SHA1_32";
443 static const char *test_key =
"abcdefghijklmnopqrstuvwxyz1234567890ABCD";
448 len = test_decrypt(&srtp, rtp_aes128_80,
sizeof(rtp_aes128_80), buf);
449 test_encrypt(buf, len, aes128_80_suite, test_key);
450 test_encrypt(buf, len, aes128_32_suite, test_key);
451 test_encrypt(buf, len, aes128_80_32_suite, test_key);
452 test_decrypt(&srtp, rtcp_aes128_80,
sizeof(rtcp_aes128_80), buf);
453 test_encrypt(buf, len, aes128_80_suite, test_key);
454 test_encrypt(buf, len, aes128_32_suite, test_key);
455 test_encrypt(buf, len, aes128_80_32_suite, test_key);
458 memset(&srtp, 0,
sizeof(srtp));
460 test_decrypt(&srtp, rtp_aes128_32,
sizeof(rtp_aes128_32), buf);
461 test_decrypt(&srtp, rtcp_aes128_32,
sizeof(rtcp_aes128_32), buf);
464 memset(&srtp, 0,
sizeof(srtp));
466 test_decrypt(&srtp, rtp_aes128_80_32,
sizeof(rtp_aes128_80_32), buf);
467 test_decrypt(&srtp, rtcp_aes128_80_32,
sizeof(rtcp_aes128_80_32), buf);