diff --git a/xts/xts.go b/xts/xts.go index d64f536f9d..65972a181d 100644 --- a/xts/xts.go +++ b/xts/xts.go @@ -87,7 +87,7 @@ func (c *Cipher) Encrypt(ciphertext, plaintext []byte, sectorNum uint64) { c.k2.Encrypt(tweak[:], tweak[:]) - for len(plaintext) > 0 { + for len(plaintext) >= blockSize && len(ciphertext) >= blockSize { for j := range tweak { ciphertext[j] = plaintext[j] ^ tweak[j] } @@ -126,7 +126,7 @@ func (c *Cipher) Decrypt(plaintext, ciphertext []byte, sectorNum uint64) { c.k2.Encrypt(tweak[:], tweak[:]) - for len(ciphertext) > 0 { + for len(ciphertext) >= blockSize && len(plaintext) >= blockSize { for j := range tweak { plaintext[j] = ciphertext[j] ^ tweak[j] } diff --git a/xts/xts_test.go b/xts/xts_test.go index 75db1c509b..cb6d26e866 100644 --- a/xts/xts_test.go +++ b/xts/xts_test.go @@ -106,13 +106,14 @@ func TestShorterCiphertext(t *testing.T) { func BenchmarkXTS(b *testing.B) { b.ReportAllocs() + b.SetBytes(320) c, err := NewCipher(aes.NewCipher, make([]byte, 32)) if err != nil { b.Fatalf("NewCipher failed: %s", err) } - plaintext := make([]byte, 32) - encrypted := make([]byte, 48) - decrypted := make([]byte, 48) + plaintext := make([]byte, 320) + encrypted := make([]byte, 336) + decrypted := make([]byte, 336) for i := 0; i < b.N; i++ { c.Encrypt(encrypted, plaintext, 0)