Skip to content

Commit

Permalink
test: add tests for DecryptBlocks and EncryptBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jun 6, 2021
1 parent ee9db41 commit 05915c8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ func TestDecrypterCryptBlocks(t *testing.T) {
}
}

func TestDecryptBlocks(t *testing.T) {
for a, v := range TestVectors {
out := make([]byte, len(v.Ciphertext))

c, err := aes.NewCipher(v.Key)
if err != nil {
t.Fatal(err)
}

DecryptBlocks(c, v.IV, out, v.Ciphertext)

if !bytes.Equal(out, v.Plaintext) {
t.Fatalf("test vector %d has wrong ciphertext\n", a+1)
}
}
}

func TestDecryptCryptBlocksPanicSrc(t *testing.T) {
c, err := aes.NewCipher(make([]byte, 16))
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ func TestEncrypterCryptBlocks(t *testing.T) {
}
}

func TestEncryptBlocks(t *testing.T) {
for a, v := range TestVectors {
out := make([]byte, len(v.Ciphertext))

c, err := aes.NewCipher(v.Key)
if err != nil {
t.Fatal(err)
}

EncryptBlocks(c, v.IV, out, v.Plaintext)

if !bytes.Equal(out, v.Ciphertext) {
t.Fatalf("test vector %d has wrong ciphertext\n", a+1)
}
}
}

func TestEncryptCryptBlocksPanicSrc(t *testing.T) {
c, err := aes.NewCipher(make([]byte, 16))
if err != nil {
Expand Down

0 comments on commit 05915c8

Please sign in to comment.