307 lines
16 KiB
Go
307 lines
16 KiB
Go
|
package eme
|
||
|
|
||
|
// Test using EME-32 test vectors
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"crypto/aes"
|
||
|
"encoding/hex"
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type testVec struct {
|
||
|
// direction
|
||
|
dir directionConst
|
||
|
// AES key
|
||
|
key []byte
|
||
|
// IV, in EME called tweak
|
||
|
tweak []byte
|
||
|
// input data
|
||
|
in []byte
|
||
|
// expected output data
|
||
|
out []byte
|
||
|
}
|
||
|
|
||
|
func verifyTestVec(v testVec, t *testing.T) {
|
||
|
bc, err := aes.NewCipher(v.key)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
// Transform and check expected data
|
||
|
out := Transform(bc, v.tweak, v.in, v.dir)
|
||
|
if bytes.Compare(v.out, out) != 0 {
|
||
|
fmt.Println(hex.EncodeToString(out))
|
||
|
t.Errorf("Different content in forward verify")
|
||
|
}
|
||
|
// Transform the other way and check that we get back the original data
|
||
|
in := Transform(bc, v.tweak, out, !v.dir)
|
||
|
if bytes.Compare(v.in, in) != 0 {
|
||
|
fmt.Println(hex.EncodeToString(out))
|
||
|
t.Errorf("Different content in reverse verify")
|
||
|
}
|
||
|
|
||
|
// Once more using the eme.New() interface.
|
||
|
e := New(bc)
|
||
|
if v.dir == DirectionDecrypt {
|
||
|
out = e.Decrypt(v.tweak, v.in)
|
||
|
in = e.Encrypt(v.tweak, out)
|
||
|
} else {
|
||
|
out = e.Encrypt(v.tweak, v.in)
|
||
|
in = e.Decrypt(v.tweak, out)
|
||
|
}
|
||
|
if bytes.Compare(v.out, out) != 0 {
|
||
|
fmt.Println(hex.EncodeToString(out))
|
||
|
t.Errorf("Different content in forward verify")
|
||
|
}
|
||
|
if bytes.Compare(v.in, in) != 0 {
|
||
|
fmt.Println(hex.EncodeToString(out))
|
||
|
t.Errorf("Different content in reverse verify")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// EME-32 encryption test vector from http://grouper.ieee.org/groups/1619/email/pdf00020.pdf
|
||
|
var buf9F2E = []byte{
|
||
|
0x9F, 0x2E, 0x6C, 0x3D, 0xAE, 0xCA, 0xE7, 0x9E, 0x88, 0x39, 0xB0, 0x58, 0x8F, 0xF3, 0x78, 0xCD,
|
||
|
0x06, 0x68, 0x97, 0x0B, 0x95, 0x69, 0x1C, 0xB0, 0x01, 0x82, 0xB9, 0xE3, 0x4C, 0xD6, 0x58, 0xED,
|
||
|
0x3C, 0x9C, 0x27, 0x68, 0x38, 0xCC, 0x5E, 0x14, 0x11, 0xFC, 0xB8, 0xCF, 0x3D, 0xA1, 0xC0, 0xF3,
|
||
|
0x08, 0x75, 0x80, 0x4C, 0x9D, 0xF5, 0x11, 0x57, 0xB0, 0x79, 0x11, 0x00, 0xD2, 0x55, 0x13, 0x34,
|
||
|
0x83, 0x4C, 0xF4, 0x02, 0x4F, 0x6B, 0x71, 0x8F, 0xBC, 0x7D, 0xAB, 0xA0, 0x7D, 0x14, 0xEB, 0x7C,
|
||
|
0xBC, 0x79, 0xC2, 0x61, 0xB1, 0xEB, 0x03, 0x6D, 0x0C, 0x9F, 0x85, 0xB9, 0x14, 0x38, 0x58, 0x40,
|
||
|
0x72, 0x72, 0x84, 0x00, 0x5F, 0x06, 0xA9, 0xC1, 0x62, 0x7C, 0x0B, 0x7F, 0xB1, 0x2A, 0x1F, 0x81,
|
||
|
0xFA, 0x83, 0xC4, 0xB0, 0x35, 0xDB, 0x00, 0x6C, 0xCE, 0x84, 0x6D, 0x07, 0x56, 0xDB, 0x9F, 0xB2,
|
||
|
0x44, 0x8E, 0xE5, 0x62, 0x8D, 0x23, 0x76, 0xEE, 0x13, 0x95, 0x42, 0x13, 0xDB, 0x3D, 0xCA, 0x72,
|
||
|
0x5F, 0x2C, 0x67, 0x95, 0x0E, 0xAF, 0x2C, 0xDA, 0xC8, 0xA2, 0x7A, 0x04, 0x33, 0xA1, 0x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xD3, 0xCC, 0x57, 0x7C, 0x28, 0xEE, 0xDA, 0xAF, 0xCE, 0xDD, 0x89, 0xA6}
|
||
|
|
||
|
func TestEnc512(t *testing.T) {
|
||
|
var v testVec
|
||
|
v.dir = DirectionEncrypt
|
||
|
v.key = make([]byte, 32) // all-zero
|
||
|
v.tweak = make([]byte, 16) // all-zero
|
||
|
v.in = make([]byte, 512) // all-zero
|
||
|
v.out = buf9F2E
|
||
|
verifyTestVec(v, t)
|
||
|
}
|
||
|
|
||
|
// Test vectors from http://grouper.ieee.org/groups/1619/email/msg00218.html
|
||
|
// Encrypt 100 times
|
||
|
func TestEnc512x100(t *testing.T) {
|
||
|
var v testVec
|
||
|
v.dir = DirectionEncrypt
|
||
|
v.key = []byte{
|
||
|
0x9F, 0x2E, 0x6C, 0x3D, 0xAE, 0xCA, 0xE7, 0x9E, 0x88, 0x39, 0xB0, 0x58, 0x8F, 0xF3, 0x78, 0xCD,
|
||
|
0x06, 0x68, 0x97, 0x0B, 0x95, 0x69, 0x1C, 0xB0, 0x01, 0x82, 0xB9, 0xE3, 0x4C, 0xD6, 0x58, 0xED}
|
||
|
v.tweak = []byte{
|
||
|
0x3C, 0x9C, 0x27, 0x68, 0x38, 0xCC, 0x5E, 0x14, 0x11, 0xFC, 0xB8, 0xCF, 0x3D, 0xA1, 0xC0, 0xF3}
|
||
|
v.in = buf9F2E
|
||
|
v.out = []byte{
|
||
|
0x36, 0x00, 0x8C, 0x95, 0xE7, 0x32, 0xA2, 0x31, 0x94, 0x93, 0x7C, 0xC4, 0xDD, 0xED, 0x30, 0xFF,
|
||
|
0xEE, 0x0F, 0xF6, 0x00, 0xF3, 0xEE, 0x87, 0x96, 0xA5, 0x8A, 0xF9, 0xBB, 0x12, 0x4A, 0xD0, 0x28,
|
||
|
0x50, 0xFB, 0x30, 0xFA, 0xC7, 0x83, 0x16, 0xA6, 0x46, 0x93, 0xAC, 0xD3, 0x86, 0x02, 0xE4, 0xC7,
|
||
|
0x04, 0xA4,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0x6C, 0x57, 0x2C, 0x16, 0x96, 0xE1, 0x5F, 0xFC,
|
||
|
0xBB, 0xE8, 0x9A, 0x9E, 0xA3, 0xE0, 0x9C, 0xFA, 0x2A, 0xB4, 0x63, 0xA3, 0x7B, 0xA6, 0xEB, 0xED,
|
||
|
0xCC, 0x02, 0x59, 0x79, 0xFB, 0xC0, 0xED, 0xA8, 0x88, 0xDB, 0x93, 0xEC, 0xAA, 0xC4, 0x48, 0x69,
|
||
|
0xA1, 0x76, 0xA9, 0x4E, 0x59, 0x56, 0x4E, 0xAF, 0xC8, 0xE9, 0x78, 0x1D, 0xDB, 0xCE, 0x6B, 0x74,
|
||
|
0xC9, 0x84, 0xEC, 0x1F, 0x27, 0xF7, 0xB9, 0xC0, 0xE4, 0xAE, 0xB7, 0x14, 0xB1, 0x47, 0xE2, 0x79,
|
||
|
0x34, 0xBF, 0x09, 0xA1, 0x5F, 0x90, 0x13, 0x29, 0x9A, 0x2D, 0x32, 0x07, 0x2A, 0x7C, 0x11, 0x2D,
|
||
|
0x06, 0x48, 0x52, 0xE0, 0xC3, 0x34, 0x5D, 0x88, 0x34, 0xF1, 0x6F, 0x1F, 0xB2, 0x80, 0xB9, 0xEA,
|
||
|
0xF8, 0x8C, 0xAD, 0xD4, 0x0C, 0xA2, 0x9C, 0x42, 0x86, 0x66, 0xCF, 0x53, 0x3F, 0xB0, 0x5C, 0x1E}
|
||
|
|
||
|
bc, err := aes.NewCipher(v.key)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
out := v.in
|
||
|
for i := 0; i < 100; i++ {
|
||
|
out = Transform(bc, v.tweak, out, v.dir)
|
||
|
}
|
||
|
if bytes.Compare(v.out, out) != 0 {
|
||
|
t.Errorf("Different content")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// EME-32 decryption test vector from http://grouper.ieee.org/groups/1619/email/pdf00020.pdf
|
||
|
var buf0809 = []byte{
|
||
|
0x08, 0x09, 0x05, 0xDE, 0xE8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v testVec
|
||
|
v.dir = DirectionDecrypt
|
||
|
v.key = make([]byte, 32) // all-zero
|
||
|
v.tweak = make([]byte, 16) // all-zero
|
||
|
v.in = make([]byte, 512) // all-zero
|
||
|
v.out = buf0809
|
||
|
verifyTestVec(v, t)
|
||
|
}
|
||
|
|
||
|
// Test vectors from http://grouper.ieee.org/groups/1619/email/msg00218.html
|
||
|
// Decrypt 100 times
|
||
|
func TestDec512x100(t *testing.T) {
|
||
|
var v testVec
|
||
|
v.dir = DirectionDecrypt
|
||
|
v.key = []byte{
|
||
|
0x08, 0x09, 0x05, 0xDE, 0xE8, 0xEB, 0xCC, 0x89, 0xF6, 0x8B, 0xD1, 0xAF, 0x63, 0x5D, 0xB3, 0xF5,
|
||
|
0xB6, 0x0C, 0x2F, 0x13, 0xF7, 0xC7, 0x68, 0xFC, 0xEB, 0x12, 0x20, 0xF6, 0xC2, 0x27, 0xFD, 0x83}
|
||
|
v.tweak = []byte{
|
||
|
0x5F, 0x29, 0x3E, 0x85, 0xF1, 0xEA, 0xA8, 0xEE, 0x23, 0x22, 0xF5, 0x42, 0x91, 0xBF, 0x05, 0x1E}
|
||
|
v.in = buf0809
|
||
|
v.out = []byte{
|
||
|
0x78, 0xD8, 0xF9, 0xC2, 0xBA, 0xAE, 0xBC, 0xB9, 0x7C, 0x39, 0x14, 0xFE, 0x4F, 0xD9, 0xB9, 0xED,
|
||
|
0x1B, 0x0F, 0xD0, 0x8C, 0x64, 0xCE, 0x0F, 0x7F, 0xA4, 0x40, 0xC2, 0xB2, 0x31, 0x7C, 0xAC, 0xC6,
|
||
|
0x10, 0xE7, 0x5A, 0xE2, 0x26, 0xA6, 0x4C, 0x8D, 0xE4, 0x27, 0x36, 0x86, 0x7D, 0xBC, 0x5F, 0xE2,
|
||
|
0xAC, 0x66, 0x3B, 0x6D, 0xB5, 0x55, 0xD7, 0x9D, 0xC4, 0x80, 0xB7, 0x07, 0xC1, 0x04, 0x11, 0xB8,
|
||
|
0x31, 0xAA, 0x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 0x77, 0xC9, 0xB2, 0x86, 0xA2, 0x06, 0x34,
|
||
|
0x39, 0x4C, 0xB7, 0xEA, 0x72, 0xDD, 0x7E, 0xE3, 0x65, 0x7D, 0x6E, 0xE1, 0xCF, 0xED, 0x8C, 0x3B,
|
||
|
0x94, 0xB8, 0xBC, 0xC5, 0x78, 0x47, 0x02, 0x57, 0x7F, 0xE4, 0x00, 0xB3, 0x8A, 0x7B, 0x08, 0x95,
|
||
|
0x74, 0x73, 0xCB, 0x57, 0xEF, 0xB8, 0x61, 0xF2, 0xEB, 0x9E, 0xEC, 0x5A, 0x12, 0x00, 0xCB, 0xD7,
|
||
|
0x5B, 0x41, 0x43, 0x3F, 0xF1, 0x75, 0x6C, 0xE7, 0x29, 0x88, 0xCA, 0x9A, 0x69, 0x0F, 0x65, 0x97,
|
||
|
0xCA, 0x0E, 0x8C, 0x98, 0xA1, 0x5C, 0x8B, 0x54, 0x71, 0xBC, 0x11, 0x67, 0x97, 0x8E, 0xC8, 0x3B,
|
||
|
0xC5, 0xB5, 0x66, 0x0B, 0x4B, 0xC9, 0x93, 0x8A, 0x41, 0xDB, 0xCF, 0x8F, 0xCE, 0x32, 0x1D, 0x1F}
|
||
|
|
||
|
bc, err := aes.NewCipher(v.key)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
out := v.in
|
||
|
for i := 0; i < 100; i++ {
|
||
|
out = Transform(bc, v.tweak, out, v.dir)
|
||
|
}
|
||
|
if bytes.Compare(v.out, out) != 0 {
|
||
|
t.Errorf("Different content")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func BenchmarkEnc512(b *testing.B) {
|
||
|
var v testVec
|
||
|
v.dir = DirectionEncrypt
|
||
|
v.key = make([]byte, 32)
|
||
|
v.tweak = make([]byte, 16)
|
||
|
v.in = make([]byte, 512)
|
||
|
b.SetBytes(int64(len(v.in)))
|
||
|
|
||
|
bc, err := aes.NewCipher(v.key)
|
||
|
if err != nil {
|
||
|
b.Fatal(err)
|
||
|
}
|
||
|
|
||
|
b.ResetTimer()
|
||
|
for n := 0; n < b.N; n++ {
|
||
|
Transform(bc, v.tweak, v.in, v.dir)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func BenchmarkDec512(b *testing.B) {
|
||
|
var v testVec
|
||
|
v.dir = DirectionDecrypt
|
||
|
v.key = make([]byte, 32)
|
||
|
v.tweak = make([]byte, 16)
|
||
|
v.in = make([]byte, 512)
|
||
|
b.SetBytes(int64(len(v.in)))
|
||
|
|
||
|
bc, err := aes.NewCipher(v.key)
|
||
|
if err != nil {
|
||
|
b.Fatal(err)
|
||
|
}
|
||
|
|
||
|
b.ResetTimer()
|
||
|
for n := 0; n < b.N; n++ {
|
||
|
Transform(bc, v.tweak, v.in, v.dir)
|
||
|
}
|
||
|
}
|