Debian Codegraph @

srtp_cipher_aes_cm_hmac_sha1_rfc_test.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package srtpscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/
5
6 import (
7 "testingscip-go gomod github.com/golang/go/src go1.21 testing/"
8
9 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/"
10 )
11
12 type testRfcAesCipherscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher# struct {
13 profilescip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#profile. ProtectionProfilescip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/ProtectionProfile# // Protection profile
14 keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys. derivedSessionKeysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys# // Derived session keys
15 keystreamscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keystream. []byte
16 }
17
18 // createRfcAesTestCiphers returns a list of test ciphers for the RFC test vectors.
19 func createRfcAesTestCiphersscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/createRfcAesTestCiphers().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) []testRfcAesCipherscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher# {
20 t.Helperscip-go gomod github.com/golang/go/src go1.21 testing/common#Helper().()
21 tests := []testRfcAesCipherscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#{}
22
23 // AES-128-CM, RFC 3711, Appendix B.2
24 aes128Cm := testRfcAesCipherscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#{
25 profilescip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#profile.: ProtectionProfileAes128CmHmacSha1_80scip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/ProtectionProfileAes128CmHmacSha1_80.,
26 keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys.: derivedSessionKeysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#{
27 srtpSessionKeyscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionKey.: fromHexscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/fromHex().(t, `2B7E151628AED2A6ABF7158809CF4F3C`),
28 srtpSessionSaltscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionSalt.: fromHexscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/fromHex().(t, `F0F1F2F3F4F5F6F7F8F9FAFBFCFD0000`),
29 },
30 keystreamscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keystream.: fromHexscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/fromHex().(t, `E03EAD0935C95E80E166B16DD92B4EB4
31 D23513162B02D0F72A43A2FE4A5F97AB
32 41E95B3BB0A2E8DD477901E4FCA894C0`),
33 }
34 aes128Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtcpSessionKeyscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtcpSessionKey. = aes128Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtpSessionKeyscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionKey.
35 aes128Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtcpSessionSaltscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtcpSessionSalt. = aes128Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtpSessionSaltscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionSalt.
36 tests = append(tests, aes128Cm)
37
38 // AES-256-CM, RFC 6188, Section 7.1
39 aes256Cm := testRfcAesCipherscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#{
40 profilescip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#profile.: ProtectionProfileAes256CmHmacSha1_80scip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/ProtectionProfileAes256CmHmacSha1_80.,
41 keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys.: derivedSessionKeysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#{
42 srtpSessionKeyscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionKey.: fromHexscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/fromHex().(t, `57f82fe3613fd170a85ec93c40b1f092
43 2ec4cb0dc025b58272147cc438944a98`),
44 srtpSessionSaltscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionSalt.: fromHexscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/fromHex().(t, `f0f1f2f3f4f5f6f7f8f9fafbfcfd0000`),
45 },
46 keystreamscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keystream.: fromHexscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/fromHex().(t, `92bdd28a93c3f52511c677d08b5515a4
47 9da71b2378a854f67050756ded165bac
48 63c4868b7096d88421b563b8c94c9a31`),
49 }
50 aes256Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtcpSessionKeyscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtcpSessionKey. = aes256Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtpSessionKeyscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionKey.
51 aes256Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtcpSessionSaltscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtcpSessionSalt. = aes256Cm.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys..srtpSessionSaltscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/derivedSessionKeys#srtpSessionSalt.
52 tests = append(tests, aes256Cm)
53
54 return tests
55 }
56
57 func TestAesCiphersWithRfcTestVectorsscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/TestAesCiphersWithRfcTestVectors().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) {
58 for _, testCase := range createRfcAesTestCiphersscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/createRfcAesTestCiphers().(t) {
59 t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(testCase.profilescip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#profile..Stringscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/ProtectionProfile#String().(), func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) {
60 // Use zero SSRC and sequence number as specified in RFC
61 rtpHeader := []byte{
62 0x80, 0x0f, 0x00, 0x00, 0xde, 0xca, 0xfb, 0xad,
63 0x00, 0x00, 0x00, 0x00,
64 }
65
66 t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().("Keystream generation", func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) {
67 cipher, err := newSrtpCipherAesCmHmacSha1WithDerivedKeysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/newSrtpCipherAesCmHmacSha1WithDerivedKeys().(testCase.profilescip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#profile., testCase.keysscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keys., true, true)
68 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
69 ctx, err := createContextWithCipherscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/createContextWithCipher().(testCase.profilescip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#profile., cipher)
70 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
71
72 // Generated AES keystream will be XOR'ed with zeroes in RTP packet payload,
73 // so SRTP payload will be equal to keystream
74 decryptedRTPPacket := make([]byte, len(rtpHeader)+len(testCase.keystreamscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keystream.))
75 copy(decryptedRTPPacket, rtpHeader)
76
77 actualEncrypted, err := ctx.EncryptRTPscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/Context#EncryptRTP().(nil, decryptedRTPPacket, nil)
78 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
79
80 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, rtpHeader, actualEncrypted[:len(rtpHeader)])
81 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, testCase.keystreamscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keystream., actualEncrypted[len(rtpHeader):len(rtpHeader)+len(testCase.keystreamscip-go gomod github.com/pion/srtp/v3 . `github.com/pion/srtp/v3`/testRfcAesCipher#keystream.)])
82 })
83 })
84 }
85 }