The "Input Block" for each test case is your IV, as you can see only the first matches the IV you've provided.
Adding that passes all 4 tests: https://play.golang.org/p/96H-Sf-gCxG
// aes ctr test vectors
testVectors := []testVector{
testVector{
iv: "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff",
plainText: "6bc1bee22e409f96e93d7e117393172a",
cipherText: "601ec313775789a5b7a7f504bbf3d228",
},
testVector{
iv: "f0f1f2f3f4f5f6f7f8f9fafbfcfdff00",
plainText: "ae2d8a571e03ac9c9eb76fac45af8e51",
cipherText: "f443e3ca4d62b59aca84e990cacaf5c5",
},
testVector{
iv: "f0f1f2f3f4f5f6f7f8f9fafbfcfdff01",
plainText: "30c81c46a35ce411e5fbc1191a0a52ef",
cipherText: "2b0930daa23de94ce87017ba2d84988d",
},
testVector{
iv: "f0f1f2f3f4f5f6f7f8f9fafbfcfdff02",
plainText: "f69f2445df4f9b17ad2b417be66c3710",
cipherText: "dfc9c58db67aada613c2dd08457941a6",
},
}
for _, v := range testVectors {
block, err := aes.NewCipher(encryptionKey)
if err != nil {
panic(err)
}
plainText, err := hex.DecodeString(v.plainText)
if err != nil {
panic(err)
}
iv, err := hex.DecodeString(v.iv)
if err != nil {
panic(err)
}
// create cipher text
cipherText := make([]byte, 16)
// encrypt
stream := cipher.NewCTR(block, iv)
stream.XORKeyStream(cipherText, plainText)
fmt.Println("expected: " + v.cipherText)
fmt.Println("calculated:" + hex.EncodeToString(cipherText))
fmt.Println("------")
}
Alternatively, the reason for the changing "Input Block" is that these examples are meant to be chained together in the same stream, and those represent the state of the block after each example. You can see the CTR mode incrementing the last byte of the IV. Reusing the stream in this way will also pass all tests:https://play.golang.org/p/Adqu8KPN7ED
stream := cipher.NewCTR(block, iv)
for _, v := range testVectors {
plainText, err := hex.DecodeString(v.plainText)
if err != nil {
panic(err)
}
// create cipher text
cipherText := make([]byte, 16)
// encrypt
stream.XORKeyStream(cipherText, plainText)
fmt.Println("expected: " + v.cipherText)
fmt.Println("calculated:" + hex.EncodeToString(cipherText))
fmt.Println("------")
}