summaryrefslogtreecommitdiff
path: root/internal/stupidgcm/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/stupidgcm/common_test.go')
-rw-r--r--internal/stupidgcm/common_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/stupidgcm/common_test.go b/internal/stupidgcm/common_test.go
index 28f3308..27ca7cc 100644
--- a/internal/stupidgcm/common_test.go
+++ b/internal/stupidgcm/common_test.go
@@ -3,10 +3,20 @@ package stupidgcm
import (
"bytes"
"crypto/cipher"
+ "crypto/rand"
"encoding/hex"
+ "log"
"testing"
)
+func testCiphers(t *testing.T, c1 cipher.AEAD, c2 cipher.AEAD) {
+ t.Run("testEncryptDecrypt", func(t *testing.T) { testEncryptDecrypt(t, c1, c2) })
+ t.Run("testInplaceSeal", func(t *testing.T) { testInplaceSeal(t, c1, c2) })
+ t.Run("testInplaceOpen", func(t *testing.T) { testInplaceOpen(t, c1, c2) })
+ t.Run("testCorruption_c1", func(t *testing.T) { testCorruption(t, c1) })
+ t.Run("testCorruption_c2", func(t *testing.T) { testCorruption(t, c2) })
+}
+
// testEncryptDecrypt encrypts and decrypts using both stupidgcm and Go's built-in
// GCM implementation and verifies that the results are identical.
func testEncryptDecrypt(t *testing.T, c1 cipher.AEAD, c2 cipher.AEAD) {
@@ -150,3 +160,13 @@ func testCorruption(t *testing.T, c cipher.AEAD) {
t.Fatalf("Should have gotten error")
}
}
+
+// Get "n" random bytes from /dev/urandom or panic
+func randBytes(n int) []byte {
+ b := make([]byte, n)
+ _, err := rand.Read(b)
+ if err != nil {
+ log.Panic("Failed to read random bytes: " + err.Error())
+ }
+ return b
+}