Debian Codegraph @

kdf/nist_sp800_56a_test.go

raw
1 package kdf
2
3 import (
4 . "gopkg.in/check.v1"
5 "crypto/sha256"
6 "github.com/dvsekhvalnov/jose2go/arrays"
7 "github.com/dvsekhvalnov/jose2go/base64url"
8 )
9
10 var z=[]byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}
11 var z2=[]byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47}
12
13 var algId=prependDatalen([]byte("alg"))
14 var partyUInfo=datalenFormat("pui")
15 var partyVInfo=datalenFormat("pvi")
16
17 func (s *TestSuite) Test256Secret_256Key(c *C) {
18 //when
19 test:=DeriveConcatKDF(256,z,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(256),nil,sha256.New())
20
21 //then
22 c.Assert(test, DeepEquals, []byte{190, 69, 15, 62, 38, 64, 30, 141, 208, 163, 55, 202, 18, 71, 176, 174, 114, 221, 249, 255, 207, 131, 190, 77, 12, 115, 220, 144, 102, 149, 78, 28})
23 }
24
25 func (s *TestSuite) Test256Secret_384Key(c *C) {
26 //when
27 test:=DeriveConcatKDF(384,z,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(384),nil,sha256.New())
28
29 //then
30 c.Assert(test, DeepEquals, []byte{187, 16, 110, 253, 151, 199, 57, 235, 219, 8, 73, 191, 208, 108, 63, 241, 235, 137, 178, 149, 3, 199, 216, 99, 105, 217, 45, 114, 109, 213, 83, 198, 52, 101, 99, 146, 193, 31, 172, 157, 19, 140, 25, 202, 153, 92, 252, 192})
31 }
32
33 func (s *TestSuite) Test256Secret_521Key(c *C) {
34 //when
35 test:=DeriveConcatKDF(521,z,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(521),nil,sha256.New())
36
37 //then
38 c.Assert(test, DeepEquals, []byte{245, 40, 159, 13, 25, 70, 170, 74, 210, 240, 242, 224, 37, 215, 23, 201, 126, 90, 108, 103, 205, 180, 48, 193, 131, 40, 86, 183, 97, 144, 1, 150, 154, 186, 196, 127, 6, 19, 17, 230, 75, 144, 229, 195, 61, 240, 20, 173, 167, 159, 50, 103, 133, 177, 241, 145, 134, 84, 50, 246, 157, 252, 51, 24, 35})
39 }
40
41 func (s *TestSuite) Test384Secret_256Key(c *C) {
42 //when
43 test:=DeriveConcatKDF(256,z2,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(256),nil,sha256.New())
44
45 //then
46 c.Assert(test, DeepEquals, []byte{27, 55, 33, 99, 20, 191, 202, 69, 84, 176, 250, 108, 99, 7, 91, 49, 200, 47, 219, 142, 190, 216, 197, 154, 235, 17, 76, 12, 165, 75, 201, 108})
47 }
48
49 //test utils
50 func datalenFormat(str string) []byte {
51 bytes,_:=base64url.Decode(str)
52 return prependDatalen(bytes)
53 }
54
55 func prependDatalen(bytes []byte) []byte {
56 return arrays.Concat(arrays.UInt32ToBytes(uint32(len(bytes))),bytes)
57 }