Skip to content

Commit

Permalink
Fix test for in-place encryption using GCM
Browse files Browse the repository at this point in the history
We used to skip the test that encryption is done in place for GCM.
It turns out we were simply passing too small a buffer.  Use
a larger buffer, and reenable the test.
  • Loading branch information
jech authored and adriancable committed May 19, 2022
1 parent b6a7656 commit 16044eb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions srtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,19 @@ func testRTPLifecyleInPlace(t *testing.T, profile ProtectionProfile) {
}

// Copy packet, asserts that everything was done in place
encryptInput := make([]byte, len(decryptedRaw), len(decryptedRaw)+10)
slack := 10
if profile == profileGCM {
slack = 16
}
encryptInput := make([]byte, len(decryptedRaw), len(decryptedRaw)+slack)
copy(encryptInput, decryptedRaw)

actualEncrypted, err := encryptContext.EncryptRTP(encryptInput, encryptInput, encryptHeader)
switch {
case err != nil:
t.Fatal(err)
case &encryptInput[0] != &actualEncrypted[0]:
if profile == profileCTR {
t.Errorf("EncryptRTP failed to encrypt in place")
} else {
t.Logf("Ignoring failure on GCM run")
}
t.Errorf("EncryptRTP failed to encrypt in place")
case encryptHeader.SequenceNumber != testCase.sequenceNumber:
t.Errorf("EncryptRTP failed to populate input rtp.Header")
}
Expand Down Expand Up @@ -378,19 +378,19 @@ func testRTPReplayProtection(t *testing.T, profile ProtectionProfile) {
}

// Copy packet, asserts that everything was done in place
encryptInput := make([]byte, len(decryptedRaw), len(decryptedRaw)+10)
slack := 10
if profile == profileGCM {
slack = 16
}
encryptInput := make([]byte, len(decryptedRaw), len(decryptedRaw)+slack)
copy(encryptInput, decryptedRaw)

actualEncrypted, err := encryptContext.EncryptRTP(encryptInput, encryptInput, encryptHeader)
switch {
case err != nil:
t.Fatal(err)
case &encryptInput[0] != &actualEncrypted[0]:
if profile == profileCTR {
t.Errorf("EncryptRTP failed to encrypt in place")
} else {
t.Logf("Ignoring failure on GCM run")
}
t.Errorf("EncryptRTP failed to encrypt in place")
case encryptHeader.SequenceNumber != testCase.sequenceNumber:
t.Fatal("EncryptRTP failed to populate input rtp.Header")
}
Expand Down

0 comments on commit 16044eb

Please sign in to comment.