github.com/emmansun/gmsm@v0.29.1/sm4/ecb_cipher_asm_test.go (about) 1 package sm4 2 3 import ( 4 "testing" 5 6 "github.com/emmansun/gmsm/cipher" 7 ) 8 9 func TestECBValidate(t *testing.T) { 10 key := make([]byte, 16) 11 src := make([]byte, 32) 12 c, err := NewCipher(key) 13 if err != nil { 14 t.Fatal(err) 15 } 16 17 decrypter := cipher.NewECBDecrypter(c) 18 // test len(src) == 0 19 decrypter.CryptBlocks(nil, nil) 20 21 // cipher: input not full blocks 22 shouldPanic(t, func() { 23 decrypter.CryptBlocks(src, src[1:]) 24 }) 25 // cipher: output smaller than input 26 shouldPanic(t, func() { 27 decrypter.CryptBlocks(src[1:], src) 28 }) 29 // cipher: invalid buffer overlap 30 shouldPanic(t, func() { 31 decrypter.CryptBlocks(src[1:17], src[2:18]) 32 }) 33 }