Skip to content

Commit

Permalink
Exercise GCM in tests
Browse files Browse the repository at this point in the history
re #6
  • Loading branch information
Richard Kettlewell authored and Richard Kettlewell committed Oct 3, 2018
1 parent 5ffcf58 commit 227df68
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion symmetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ func testHardSymmetric(t *testing.T, keytype int, bits int) {
enc.Close()
dec.Close()
})
if bits == 128 {
t.Run("GCM", func(t *testing.T) {
aead, err := cipher.NewGCM(key2)
if err != nil {
t.Errorf("cipher.NewGCM: %v", err)
return
}
testAEADMode(t, aead)
})
}
// TODO CFB
// TODO OFB
// TODO CTR
// TODO GCM
}

func testSymmetricBlock(t *testing.T, encryptKey cipher.Block, decryptKey cipher.Block) {
Expand Down Expand Up @@ -179,6 +188,28 @@ func testSymmetricMode(t *testing.T, encrypt cipher.BlockMode, decrypt cipher.Bl
}
}

func testAEADMode(t *testing.T, aead cipher.AEAD) {
nonce := make([]byte, aead.NonceSize())
plaintext := make([]byte, 127)
for i := 0; i < len(plaintext); i++ {
plaintext[i] = byte(i)
}
additionalData := make([]byte, 129)
for i := 0; i < len(additionalData); i++ {
additionalData[i] = byte(i + 16)
}
ciphertext := aead.Seal([]byte{}, nonce, plaintext, additionalData)
decrypted, err := aead.Open([]byte{}, nonce, ciphertext, additionalData)
if err != nil {
t.Errorf("aead.Open: %s", err)
return
}
if bytes.Compare(plaintext, decrypted) != 0 {
t.Errorf("aead.Open: mismatch")
return
}
}

func BenchmarkCBC(b *testing.B) {
ConfigureFromFile("config")
var err error
Expand Down

0 comments on commit 227df68

Please sign in to comment.