summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2017-09-18 23:43:49 +0200
committerChristian Pointner <equinox@anytun.org>2017-09-18 23:43:49 +0200
commit56e49504ef87777dd6b628901cc5780af51a2b09 (patch)
treeafb3ecea541654245f7ef5b98af998f53d239f2e
parentadded some test functions (diff)
added key derivation test case
-rw-r--r--satp/crypto-kd-aesctr_test.go42
1 files changed, 39 insertions, 3 deletions
diff --git a/satp/crypto-kd-aesctr_test.go b/satp/crypto-kd-aesctr_test.go
index 704ff75..63ac57a 100644
--- a/satp/crypto-kd-aesctr_test.go
+++ b/satp/crypto-kd-aesctr_test.go
@@ -104,9 +104,45 @@ func TestAESCTRKeyDerivationGenerateCtr(t *testing.T) {
}
}
-//func TestAESCTRKeyDerivationGenerateRepeat(t *testing.T) {
-// TODO: implement this with actual test vectors
-//}
+func TestAESCTRKeyDerivationGenerate(t *testing.T) {
+ testvectors := []struct {
+ dir KeyDirection
+ usage KeyUsage
+ sequenceNumber uint32
+ out []byte
+ }{
+ {DirLeft, UsageEncryptKey, 0,
+ []byte{0x46, 0x04, 0x12, 0x67, 0x0C, 0x7A, 0x20, 0x07, 0x67, 0xC5, 0x9A, 0xB4, 0xBE, 0x2E, 0xBE, 0x50,
+ 0xE9, 0xBC, 0x04, 0x7C, 0x17, 0x54, 0x73, 0x02, 0x4A, 0x54, 0x28, 0x44, 0x6F, 0xFA, 0xD2, 0xB6}},
+ {DirRight, UsageEncryptKey, 0x0012CA37,
+ []byte{0x93, 0xEE, 0xC4, 0xD4, 0x94, 0xDA, 0x29, 0x72, 0x0C, 0xF5, 0xB6, 0x1D, 0x45, 0x3F, 0xA1, 0x19,
+ 0xB0, 0x31, 0xB1, 0x7D, 0xA3, 0x78, 0x2C, 0x7A, 0x72, 0x19, 0x39, 0x4E, 0xEE, 0x40, 0x52, 0xDA}},
+ {DirRight, UsageEncryptSalt, 0x0012CA37,
+ []byte{0x7C, 0x20, 0x7D, 0x35, 0xAD, 0x9C, 0xED, 0xC6, 0xE6, 0x16, 0xE4, 0xA9, 0x36, 0x3C, 0x49, 0xAA,
+ 0xF4, 0xA9, 0x59, 0x0D, 0x6A, 0xC1, 0x63, 0xAB, 0x17, 0x3D, 0xA8, 0x9F, 0x3F, 0xD7, 0x10, 0xC3}},
+ {DirRight, UsageAuthKey, 0xE,
+ []byte{0xE3, 0x26, 0x29, 0x37, 0xED, 0xF1, 0x36, 0x80, 0xB4, 0x8E, 0x6C, 0xF7, 0x7C, 0xEE, 0x8C, 0x49,
+ 0xEA, 0x70, 0x6D, 0x24, 0x25, 0x35, 0xAF, 0x79, 0x7F, 0x02, 0x7C, 0x59, 0x2C, 0x7E, 0x41, 0x55}},
+ {DirLeft, UsageAuthKey, 0xC,
+ []byte{0x2C, 0xF9, 0x7A, 0x96, 0x17, 0x28, 0x52, 0xFD, 0xF6, 0x57, 0xC4, 0x86, 0x7D, 0xA8, 0x04, 0xE3,
+ 0xB4, 0x23, 0xA6, 0xAE, 0x66, 0xF8, 0xB9, 0xCC, 0x79, 0x72, 0xA6, 0xB9, 0x54, 0x72, 0x7F, 0xF4}},
+ }
+
+ key := []byte{0x77, 0x67, 0xA3, 0x90, 0x3E, 0xB9, 0x22, 0x06, 0x87, 0xBF, 0xF8, 0xA1, 0x4E, 0x94, 0x0F, 0xA7}
+ salt := []byte{0x3D, 0x58, 0x3F, 0xC6, 0x70, 0xA9, 0x6B, 0xCF, 0x92, 0xDA, 0x27, 0x0D, 0x07, 0x67}
+ kd, err := NewAESCTRKeyDerivation(key, salt)
+ if err != nil {
+ t.Fatal("unexpected error:", err)
+ }
+
+ for _, vector := range testvectors {
+ out := [32]byte{}
+ kd.Generate(vector.dir, vector.usage, vector.sequenceNumber, out[:])
+ if bytes.Compare(out[:], vector.out) != 0 {
+ t.Fatalf("resulting key material is invalid, is: '%v', should be '%v'", out[:], vector.out)
+ }
+ }
+}
func TestAESCTRKeyDerivationGenerateRepeat(t *testing.T) {
var buffer [256]byte