From ae01e8d29540cc9b8492ef63938507f1a225e43f Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Fri, 18 Jan 2013 13:44:34 +0200 Subject: srtp: Add tests for the crypto suite with 32/80 bit HMAC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/srtp.c | 32 ++++++++++++++++++++++++++++++++ tests/ref/fate/srtp | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/libavformat/srtp.c b/libavformat/srtp.c index 0fa0d19671..5c49794486 100644 --- a/libavformat/srtp.c +++ b/libavformat/srtp.c @@ -372,6 +372,29 @@ static const uint8_t rtcp_aes128_32[] = { 0x5b, 0xd2, 0xa9, 0x9d, }; +static const char *aes128_80_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; + +static const uint8_t rtp_aes128_80_32[] = { + // RTP header + 0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0x62, 0x69, 0x76, 0xca, 0xc5, + // HMAC + 0xa1, 0xac, 0x1b, 0xb4, +}; + +static const uint8_t rtcp_aes128_80_32[] = { + // RTCP header + 0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, + // encrypted payload + 0xd6, 0xae, 0xc1, 0x58, 0x63, 0x70, 0xc9, 0x88, 0x66, 0x26, 0x1c, 0x53, + 0xff, 0x5d, 0x5d, 0x2b, 0x0f, 0x8c, 0x72, 0x3e, 0xc9, 0x1d, 0x43, 0xf9, + // RTCP index + 0x80, 0x00, 0x00, 0x05, + // HMAC + 0x09, 0x16, 0xb4, 0x27, 0x9a, 0xe9, 0x92, 0x26, 0x4e, 0x10, +}; + static void print_data(const uint8_t *buf, int len) { int i; @@ -416,6 +439,7 @@ int main(void) { static const char *aes128_80_suite = "AES_CM_128_HMAC_SHA1_80"; static const char *aes128_32_suite = "AES_CM_128_HMAC_SHA1_32"; + static const char *aes128_80_32_suite = "SRTP_AES128_CM_HMAC_SHA1_32"; static const char *test_key = "abcdefghijklmnopqrstuvwxyz1234567890ABCD"; uint8_t buf[1500]; struct SRTPContext srtp = { 0 }; @@ -424,9 +448,11 @@ int main(void) len = test_decrypt(&srtp, rtp_aes128_80, sizeof(rtp_aes128_80), buf); test_encrypt(buf, len, aes128_80_suite, test_key); test_encrypt(buf, len, aes128_32_suite, test_key); + test_encrypt(buf, len, aes128_80_32_suite, test_key); test_decrypt(&srtp, rtcp_aes128_80, sizeof(rtcp_aes128_80), buf); test_encrypt(buf, len, aes128_80_suite, test_key); test_encrypt(buf, len, aes128_32_suite, test_key); + test_encrypt(buf, len, aes128_80_32_suite, test_key); ff_srtp_free(&srtp); memset(&srtp, 0, sizeof(srtp)); // Clear the context @@ -434,6 +460,12 @@ int main(void) test_decrypt(&srtp, rtp_aes128_32, sizeof(rtp_aes128_32), buf); test_decrypt(&srtp, rtcp_aes128_32, sizeof(rtcp_aes128_32), buf); ff_srtp_free(&srtp); + + memset(&srtp, 0, sizeof(srtp)); // Clear the context + ff_srtp_set_crypto(&srtp, aes128_80_32_suite, aes128_80_32_key); + test_decrypt(&srtp, rtp_aes128_80_32, sizeof(rtp_aes128_80_32), buf); + test_decrypt(&srtp, rtcp_aes128_80_32, sizeof(rtcp_aes128_80_32), buf); + ff_srtp_free(&srtp); return 0; } #endif /* TEST */ diff --git a/tests/ref/fate/srtp b/tests/ref/fate/srtp index 091d3f3a0d..687a59f78b 100644 --- a/tests/ref/fate/srtp +++ b/tests/ref/fate/srtp @@ -1,8 +1,12 @@ 80e0123412345678123456780102030405 Decrypted content matches input Decrypted content matches input +Decrypted content matches input 81c90007123456788765432100000000000012340000069ec73069ba000001fd Decrypted content matches input Decrypted content matches input +Decrypted content matches input +80e0123412345678123456780102030405 +81c90007123456788765432100000000000012340000069ec73069ba000001fd 80e0123412345678123456780102030405 81c90007123456788765432100000000000012340000069ec73069ba000001fd -- cgit v1.2.3 From c9311f3e46649786556b6c8ba742129cdfa16f2e Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sun, 20 Jan 2013 19:06:51 +0200 Subject: srtp: Move a variable to a local scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This simplifies the code slightly. Signed-off-by: Martin Storsjö --- libavformat/srtp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/srtp.c b/libavformat/srtp.c index 5c49794486..1fe34a7c5a 100644 --- a/libavformat/srtp.c +++ b/libavformat/srtp.c @@ -126,7 +126,7 @@ int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr) { uint8_t iv[16] = { 0 }, hmac[20]; int len = *lenptr; - int ext, av_uninit(seq_largest); + int av_uninit(seq_largest); uint32_t ssrc, av_uninit(roc); uint64_t index; int rtcp, hmac_size; @@ -199,7 +199,7 @@ int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr) if (!(srtcp_index & 0x80000000)) return 0; } else { - int csrc; + int ext, csrc; s->seq_initialized = 1; s->seq_largest = seq_largest; s->roc = roc; -- cgit v1.2.3 From 8a4f26206d7914eaf2903954ce97cb7686933382 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 20 Jan 2013 21:57:35 -0800 Subject: dsputil: remove butterflies_float_interleave. The function is unused. --- libavcodec/dsputil.c | 13 ------------- libavcodec/dsputil.h | 17 ----------------- libavcodec/x86/dsputil.asm | 44 -------------------------------------------- libavcodec/x86/dsputil_mmx.c | 7 ------- 4 files changed, 81 deletions(-) diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index d1bc2c9c04..d0544a4c7a 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -2377,18 +2377,6 @@ static void butterflies_float_c(float *restrict v1, float *restrict v2, } } -static void butterflies_float_interleave_c(float *dst, const float *src0, - const float *src1, int len) -{ - int i; - for (i = 0; i < len; i++) { - float f1 = src0[i]; - float f2 = src1[i]; - dst[2*i ] = f1 + f2; - dst[2*i + 1] = f1 - f2; - } -} - float ff_scalarproduct_float_c(const float *v1, const float *v2, int len) { float p = 0.0; @@ -2823,7 +2811,6 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) c->vector_clip_int32 = vector_clip_int32_c; c->scalarproduct_float = ff_scalarproduct_float_c; c->butterflies_float = butterflies_float_c; - c->butterflies_float_interleave = butterflies_float_interleave_c; c->shrink[0]= av_image_copy_plane; c->shrink[1]= ff_shrink22; diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index 8924e46ffe..6121c9d7f0 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -364,23 +364,6 @@ typedef struct DSPContext { */ void (*butterflies_float)(float *restrict v1, float *restrict v2, int len); - /** - * Calculate the sum and difference of two vectors of floats and interleave - * results into a separate output vector of floats, with each sum - * positioned before the corresponding difference. - * - * @param dst output vector - * constraints: 16-byte aligned - * @param src0 first input vector - * constraints: 32-byte aligned - * @param src1 second input vector - * constraints: 32-byte aligned - * @param len number of elements in the input - * constraints: multiple of 8 - */ - void (*butterflies_float_interleave)(float *dst, const float *src0, - const float *src1, int len); - /* (I)DCT */ void (*fdct)(DCTELEM *block/* align 16*/); void (*fdct248)(DCTELEM *block/* align 16*/); diff --git a/libavcodec/x86/dsputil.asm b/libavcodec/x86/dsputil.asm index b9990bb1ba..257e579c8e 100644 --- a/libavcodec/x86/dsputil.asm +++ b/libavcodec/x86/dsputil.asm @@ -632,50 +632,6 @@ VECTOR_FMUL_ADD INIT_YMM avx VECTOR_FMUL_ADD -;----------------------------------------------------------------------------- -; void ff_butterflies_float_interleave(float *dst, const float *src0, -; const float *src1, int len); -;----------------------------------------------------------------------------- - -%macro BUTTERFLIES_FLOAT_INTERLEAVE 0 -cglobal butterflies_float_interleave, 4,4,3, dst, src0, src1, len -%if ARCH_X86_64 - movsxd lenq, lend -%endif - test lenq, lenq - jz .end - shl lenq, 2 - lea src0q, [src0q + lenq] - lea src1q, [src1q + lenq] - lea dstq, [ dstq + 2*lenq] - neg lenq -.loop: - mova m0, [src0q + lenq] - mova m1, [src1q + lenq] - subps m2, m0, m1 - addps m0, m0, m1 - unpcklps m1, m0, m2 - unpckhps m0, m0, m2 -%if cpuflag(avx) - vextractf128 [dstq + 2*lenq ], m1, 0 - vextractf128 [dstq + 2*lenq + 16], m0, 0 - vextractf128 [dstq + 2*lenq + 32], m1, 1 - vextractf128 [dstq + 2*lenq + 48], m0, 1 -%else - mova [dstq + 2*lenq ], m1 - mova [dstq + 2*lenq + mmsize], m0 -%endif - add lenq, mmsize - jl .loop -.end: - REP_RET -%endmacro - -INIT_XMM sse -BUTTERFLIES_FLOAT_INTERLEAVE -INIT_YMM avx -BUTTERFLIES_FLOAT_INTERLEAVE - ; %1 = aligned/unaligned %macro BSWAP_LOOPS 1 mov r3, r2 diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c index 7a122ab653..828af9b047 100644 --- a/libavcodec/x86/dsputil_mmx.c +++ b/libavcodec/x86/dsputil_mmx.c @@ -1867,11 +1867,6 @@ void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src, void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src, int32_t min, int32_t max, unsigned int len); -extern void ff_butterflies_float_interleave_sse(float *dst, const float *src0, - const float *src1, int len); -extern void ff_butterflies_float_interleave_avx(float *dst, const float *src0, - const float *src1, int len); - #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \ do { \ c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \ @@ -2149,7 +2144,6 @@ static void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx, int mm_flags) c->vector_fmul_add = ff_vector_fmul_add_sse; c->scalarproduct_float = ff_scalarproduct_float_sse; - c->butterflies_float_interleave = ff_butterflies_float_interleave_sse; #endif /* HAVE_YASM */ } @@ -2300,7 +2294,6 @@ static void dsputil_init_avx(DSPContext *c, AVCodecContext *avctx, int mm_flags) c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx; } } - c->butterflies_float_interleave = ff_butterflies_float_interleave_avx; c->vector_fmul_reverse = ff_vector_fmul_reverse_avx; c->vector_fmul_add = ff_vector_fmul_add_avx; #endif /* HAVE_AVX_EXTERNAL */ -- cgit v1.2.3