9 func TestECB(T *testing.T) {
12 rnd := rand.New(rand.NewSource(31415))
14 salt := make([]byte, rnd.Intn(64))
16 salt[i] = byte(rnd.Intn(255))
18 plain := make([]byte, 1200+rnd.Intn(200))
19 for i := range plain {
20 plain[i] = byte(rnd.Intn(255))
23 ecbState := newECBState("agaa", salt)
25 T.Log("Length of plaintext:", len(plain))
26 cipher := ecbState.Encrypt(plain)
27 T.Log("Length of ciphertext:", len(cipher))
28 plain2 := ecbState.Decrypt(cipher)
29 T.Log("Length of roundtrip plaintext:", len(plain2))
31 if !reflect.DeepEqual(plain, plain2) {
32 T.Error("Encoding roundtrip result doesn't match plaintext")
36 func TestPKCS7(T *testing.T) {
41 [2]string{"testing", "testing\x01"},
42 [2]string{"byte", "byte\x04\x04\x04\x04"},
43 [2]string{"stuff", "stuff\x03\x03\x03"},
46 for i, v := range vec {
47 p := string(pkcs7Pad([]byte(v[0]), blockSize))
49 T.Errorf("Vector #%d: expected %q, got %q", i, v[1], p)
51 u := string(pkcs7Unpad([]byte(p), blockSize))
53 T.Errorf("Vector #%d: expected %q, got %q", i, v[0], u)