From e41421bfc5a91e6c0ef85144704c293130553242 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 21 Nov 2016 09:36:14 +0300 Subject: [PATCH] 34.11-94 PBKDF2 test vectors and digest reversing --- .gitmodules | 3 + src/cypherpunks.ru/gogost/gost3410/private.go | 1 - src/cypherpunks.ru/gogost/gost341194/hash.go | 3 +- .../gogost/gost341194/hash_test.go | 136 +++++++++--------- .../gogost/gost341194/pbkdf2_test.go | 92 ++++++++++++ src/golang.org/x/crypto | 1 + 6 files changed, 166 insertions(+), 70 deletions(-) create mode 100644 .gitmodules create mode 100644 src/cypherpunks.ru/gogost/gost341194/pbkdf2_test.go create mode 160000 src/golang.org/x/crypto diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6607578 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/golang.org/x/crypto"] + path = src/golang.org/x/crypto + url = https://go.googlesource.com/crypto diff --git a/src/cypherpunks.ru/gogost/gost3410/private.go b/src/cypherpunks.ru/gogost/gost3410/private.go index b64dc47..709e61b 100644 --- a/src/cypherpunks.ru/gogost/gost3410/private.go +++ b/src/cypherpunks.ru/gogost/gost3410/private.go @@ -132,6 +132,5 @@ func (pk *PrivateKey) KEK(pub *PublicKey, ukm []byte) ([]byte, error) { reverse(t) h.Write(t) t = h.Sum(t[:0]) - reverse(t) return t, nil } diff --git a/src/cypherpunks.ru/gogost/gost341194/hash.go b/src/cypherpunks.ru/gogost/gost341194/hash.go index ebbbca5..3ad4f7a 100644 --- a/src/cypherpunks.ru/gogost/gost341194/hash.go +++ b/src/cypherpunks.ru/gogost/gost341194/hash.go @@ -79,7 +79,7 @@ func (h *Hash) Reset() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } h.chk = big.NewInt(0) - h.buf = nil + h.buf = h.buf[:0] } func (h *Hash) BlockSize() int { @@ -266,5 +266,6 @@ func (h *Hash) Sum(in []byte) []byte { chkBytes := chk.Bytes() copy(block[BlockSize-len(chkBytes):], chkBytes) hsh = h.step(hsh, *block) + blockReverse(hsh[:], hsh[:]) return append(in, hsh[:]...) } diff --git a/src/cypherpunks.ru/gogost/gost341194/hash_test.go b/src/cypherpunks.ru/gogost/gost341194/hash_test.go index cfc9dd7..2e6960e 100644 --- a/src/cypherpunks.ru/gogost/gost341194/hash_test.go +++ b/src/cypherpunks.ru/gogost/gost341194/hash_test.go @@ -35,10 +35,10 @@ func TestVectors(t *testing.T) { h := New(SboxDefault) if bytes.Compare(h.Sum(nil), []byte{ - 0x8d, 0x0f, 0x49, 0x49, 0x2c, 0x91, 0xf4, 0x5a, - 0x68, 0xff, 0x5c, 0x05, 0xd2, 0xc2, 0xb4, 0xab, - 0x78, 0x02, 0x7b, 0x9a, 0xab, 0x5c, 0xe3, 0xfe, - 0xff, 0x52, 0x67, 0xc4, 0x9c, 0xb9, 0x85, 0xce, + 0xce, 0x85, 0xb9, 0x9c, 0xc4, 0x67, 0x52, 0xff, + 0xfe, 0xe3, 0x5c, 0xab, 0x9a, 0x7b, 0x02, 0x78, + 0xab, 0xb4, 0xc2, 0xd2, 0x05, 0x5c, 0xff, 0x68, + 0x5a, 0xf4, 0x91, 0x2c, 0x49, 0x49, 0x0f, 0x8d, }) != 0 { t.Fail() } @@ -46,10 +46,10 @@ func TestVectors(t *testing.T) { h.Reset() h.Write([]byte("a")) if bytes.Compare(h.Sum(nil), []byte{ - 0xdd, 0x14, 0xf3, 0x62, 0xce, 0xfd, 0x49, 0xf8, - 0x73, 0xa5, 0xc6, 0x44, 0x43, 0x1b, 0x87, 0x21, - 0x9c, 0x34, 0x49, 0x66, 0x1f, 0x80, 0x8a, 0xc8, - 0xe9, 0x66, 0x7c, 0x36, 0x9e, 0x53, 0x2c, 0xd4, + 0xd4, 0x2c, 0x53, 0x9e, 0x36, 0x7c, 0x66, 0xe9, + 0xc8, 0x8a, 0x80, 0x1f, 0x66, 0x49, 0x34, 0x9c, + 0x21, 0x87, 0x1b, 0x43, 0x44, 0xc6, 0xa5, 0x73, + 0xf8, 0x49, 0xfd, 0xce, 0x62, 0xf3, 0x14, 0xdd, }) != 0 { t.Fail() } @@ -57,10 +57,10 @@ func TestVectors(t *testing.T) { h.Reset() h.Write([]byte("abc")) if bytes.Compare(h.Sum(nil), []byte{ - 0x1d, 0xd5, 0xa4, 0x06, 0x7c, 0x49, 0x70, 0x3b, - 0x75, 0xbc, 0x75, 0xc9, 0x29, 0x0f, 0x5e, 0xcb, - 0xb5, 0xeb, 0x85, 0x22, 0x9e, 0x72, 0x77, 0xa2, - 0xb2, 0xb1, 0x4f, 0xc4, 0x48, 0x43, 0x13, 0xf3, + 0xf3, 0x13, 0x43, 0x48, 0xc4, 0x4f, 0xb1, 0xb2, + 0xa2, 0x77, 0x72, 0x9e, 0x22, 0x85, 0xeb, 0xb5, + 0xcb, 0x5e, 0x0f, 0x29, 0xc9, 0x75, 0xbc, 0x75, + 0x3b, 0x70, 0x49, 0x7c, 0x06, 0xa4, 0xd5, 0x1d, }) != 0 { t.Fail() } @@ -68,10 +68,10 @@ func TestVectors(t *testing.T) { h.Reset() h.Write([]byte("message digest")) if bytes.Compare(h.Sum(nil), []byte{ - 0x4d, 0x9a, 0x88, 0xa4, 0x16, 0xde, 0x2f, 0xdb, - 0x72, 0xde, 0x48, 0x3f, 0x27, 0x65, 0x2b, 0x58, - 0x69, 0x24, 0x3d, 0xec, 0x59, 0xbe, 0x0c, 0xb6, - 0x99, 0x2c, 0x8f, 0xb1, 0xec, 0x34, 0x44, 0xad, + 0xad, 0x44, 0x34, 0xec, 0xb1, 0x8f, 0x2c, 0x99, + 0xb6, 0x0c, 0xbe, 0x59, 0xec, 0x3d, 0x24, 0x69, + 0x58, 0x2b, 0x65, 0x27, 0x3f, 0x48, 0xde, 0x72, + 0xdb, 0x2f, 0xde, 0x16, 0xa4, 0x88, 0x9a, 0x4d, }) != 0 { t.Fail() } @@ -81,10 +81,10 @@ func TestVectors(t *testing.T) { h.Write([]byte("U")) } if bytes.Compare(h.Sum(nil), []byte{ - 0xa4, 0x33, 0x57, 0xfe, 0xe8, 0xa9, 0x26, 0xd9, - 0x52, 0x2a, 0x06, 0x87, 0x0a, 0x66, 0x25, 0x1c, - 0x55, 0x3e, 0x27, 0x74, 0xa0, 0x85, 0x1d, 0x0c, - 0xef, 0x0c, 0x18, 0x25, 0xed, 0xa3, 0xa3, 0x53, + 0x53, 0xa3, 0xa3, 0xed, 0x25, 0x18, 0x0c, 0xef, + 0x0c, 0x1d, 0x85, 0xa0, 0x74, 0x27, 0x3e, 0x55, + 0x1c, 0x25, 0x66, 0x0a, 0x87, 0x06, 0x2a, 0x52, + 0xd9, 0x26, 0xa9, 0xe8, 0xfe, 0x57, 0x33, 0xa4, }) != 0 { t.Fail() } @@ -92,10 +92,10 @@ func TestVectors(t *testing.T) { h.Reset() h.Write([]byte("The quick brown fox jumps over the lazy dog")) if bytes.Compare(h.Sum(nil), []byte{ - 0x94, 0x42, 0x1f, 0x6d, 0x37, 0x0f, 0xa1, 0xd1, - 0x6b, 0xa7, 0xac, 0x5e, 0x31, 0x29, 0x65, 0x29, - 0xc9, 0x68, 0x04, 0x7d, 0xca, 0x9b, 0xf4, 0x25, - 0x8a, 0xc5, 0x9a, 0x0c, 0x41, 0xfa, 0xb7, 0x77, + 0x77, 0xb7, 0xfa, 0x41, 0x0c, 0x9a, 0xc5, 0x8a, + 0x25, 0xf4, 0x9b, 0xca, 0x7d, 0x04, 0x68, 0xc9, + 0x29, 0x65, 0x29, 0x31, 0x5e, 0xac, 0xa7, 0x6b, + 0xd1, 0xa1, 0x0f, 0x37, 0x6d, 0x1f, 0x42, 0x94, }) != 0 { t.Fail() } @@ -103,10 +103,10 @@ func TestVectors(t *testing.T) { h.Reset() h.Write([]byte("The quick brown fox jumps over the lazy cog")) if bytes.Compare(h.Sum(nil), []byte{ - 0x45, 0xc4, 0xee, 0x4e, 0xe1, 0xd2, 0x50, 0x91, - 0x31, 0x21, 0x35, 0x54, 0x0d, 0x67, 0x02, 0xe6, - 0x67, 0x7f, 0x7a, 0x73, 0xb5, 0xda, 0x31, 0xe1, - 0x0b, 0x8b, 0xb7, 0xaa, 0xda, 0xc4, 0xeb, 0xa3, + 0xa3, 0xeb, 0xc4, 0xda, 0xaa, 0xb7, 0x8b, 0x0b, + 0xe1, 0x31, 0xda, 0xb5, 0x73, 0x7a, 0x7f, 0x67, + 0xe6, 0x02, 0x67, 0x0d, 0x54, 0x35, 0x21, 0x31, + 0x91, 0x50, 0xd2, 0xe1, 0x4e, 0xee, 0xc4, 0x45, }) != 0 { t.Fail() } @@ -114,10 +114,10 @@ func TestVectors(t *testing.T) { h.Reset() h.Write([]byte("This is message, length=32 bytes")) if bytes.Compare(h.Sum(nil), []byte{ - 0xfa, 0xff, 0x37, 0xa6, 0x15, 0xa8, 0x16, 0x69, - 0x1c, 0xff, 0x3e, 0xf8, 0xb6, 0x8c, 0xa2, 0x47, - 0xe0, 0x95, 0x25, 0xf3, 0x9f, 0x81, 0x19, 0x83, - 0x2e, 0xb8, 0x19, 0x75, 0xd3, 0x66, 0xc4, 0xb1, + 0xb1, 0xc4, 0x66, 0xd3, 0x75, 0x19, 0xb8, 0x2e, + 0x83, 0x19, 0x81, 0x9f, 0xf3, 0x25, 0x95, 0xe0, + 0x47, 0xa2, 0x8c, 0xb6, 0xf8, 0x3e, 0xff, 0x1c, + 0x69, 0x16, 0xa8, 0x15, 0xa6, 0x37, 0xff, 0xfa, }) != 0 { t.Fail() } @@ -125,10 +125,10 @@ func TestVectors(t *testing.T) { h.Reset() h.Write([]byte("Suppose the original message has length = 50 bytes")) if bytes.Compare(h.Sum(nil), []byte{ - 0x08, 0x52, 0xf5, 0x62, 0x3b, 0x89, 0xdd, 0x57, - 0xae, 0xb4, 0x78, 0x1f, 0xe5, 0x4d, 0xf1, 0x4e, - 0xea, 0xfb, 0xc1, 0x35, 0x06, 0x13, 0x76, 0x3a, - 0x0d, 0x77, 0x0a, 0xa6, 0x57, 0xba, 0x1a, 0x47, + 0x47, 0x1a, 0xba, 0x57, 0xa6, 0x0a, 0x77, 0x0d, + 0x3a, 0x76, 0x13, 0x06, 0x35, 0xc1, 0xfb, 0xea, + 0x4e, 0xf1, 0x4d, 0xe5, 0x1f, 0x78, 0xb4, 0xae, + 0x57, 0xdd, 0x89, 0x3b, 0x62, 0xf5, 0x52, 0x08, }) != 0 { t.Fail() } @@ -138,10 +138,10 @@ func TestVectorsCryptoPro(t *testing.T) { h := New(&gost28147.GostR3411_94_CryptoProParamSet) if bytes.Compare(h.Sum(nil), []byte{ - 0xc0, 0x56, 0xd6, 0x4c, 0x23, 0x83, 0xc4, 0x4a, - 0x58, 0x13, 0x9c, 0x9b, 0x56, 0x01, 0x11, 0xac, - 0x13, 0x3e, 0x43, 0xfb, 0x84, 0x0f, 0x83, 0x87, - 0x14, 0x84, 0x0c, 0xa3, 0x3c, 0x5f, 0x1e, 0x98, + 0x98, 0x1e, 0x5f, 0x3c, 0xa3, 0x0c, 0x84, 0x14, + 0x87, 0x83, 0x0f, 0x84, 0xfb, 0x43, 0x3e, 0x13, + 0xac, 0x11, 0x01, 0x56, 0x9b, 0x9c, 0x13, 0x58, + 0x4a, 0xc4, 0x83, 0x23, 0x4c, 0xd6, 0x56, 0xc0, }) != 0 { t.Fail() } @@ -149,10 +149,10 @@ func TestVectorsCryptoPro(t *testing.T) { h.Reset() h.Write([]byte("a")) if bytes.Compare(h.Sum(nil), []byte{ - 0x11, 0x30, 0x40, 0x2f, 0xcf, 0xaa, 0xf1, 0xef, - 0x3c, 0x13, 0xe3, 0x17, 0x3f, 0x10, 0x5a, 0x71, - 0x55, 0x80, 0xf7, 0xc9, 0x79, 0x00, 0xaf, 0x37, - 0xbf, 0x83, 0x21, 0x28, 0xdd, 0x52, 0x4c, 0xe7, + 0xe7, 0x4c, 0x52, 0xdd, 0x28, 0x21, 0x83, 0xbf, + 0x37, 0xaf, 0x00, 0x79, 0xc9, 0xf7, 0x80, 0x55, + 0x71, 0x5a, 0x10, 0x3f, 0x17, 0xe3, 0x13, 0x3c, + 0xef, 0xf1, 0xaa, 0xcf, 0x2f, 0x40, 0x30, 0x11, }) != 0 { t.Fail() } @@ -160,10 +160,10 @@ func TestVectorsCryptoPro(t *testing.T) { h.Reset() h.Write([]byte("abc")) if bytes.Compare(h.Sum(nil), []byte{ - 0x2c, 0xd4, 0x2f, 0xf9, 0x86, 0x29, 0x3b, 0x16, - 0x7e, 0x99, 0x43, 0x81, 0xed, 0x59, 0x74, 0x74, - 0x14, 0xdd, 0x24, 0x95, 0x36, 0x77, 0x76, 0x2d, - 0x39, 0xd7, 0x18, 0xbf, 0x6d, 0x05, 0x85, 0xb2, + 0xb2, 0x85, 0x05, 0x6d, 0xbf, 0x18, 0xd7, 0x39, + 0x2d, 0x76, 0x77, 0x36, 0x95, 0x24, 0xdd, 0x14, + 0x74, 0x74, 0x59, 0xed, 0x81, 0x43, 0x99, 0x7e, + 0x16, 0x3b, 0x29, 0x86, 0xf9, 0x2f, 0xd4, 0x2c, }) != 0 { t.Fail() } @@ -171,10 +171,10 @@ func TestVectorsCryptoPro(t *testing.T) { h.Reset() h.Write([]byte("message digest")) if bytes.Compare(h.Sum(nil), []byte{ - 0xa0, 0x1b, 0x72, 0x29, 0x9b, 0xc3, 0x9a, 0x54, - 0x0f, 0xd6, 0x72, 0xa9, 0x9a, 0x72, 0xb4, 0xbd, - 0xfe, 0x74, 0x41, 0x73, 0x86, 0x98, 0x6e, 0xfa, - 0xeb, 0x01, 0xa4, 0x2a, 0xdd, 0x41, 0x60, 0xbc, + 0xbc, 0x60, 0x41, 0xdd, 0x2a, 0xa4, 0x01, 0xeb, + 0xfa, 0x6e, 0x98, 0x86, 0x73, 0x41, 0x74, 0xfe, + 0xbd, 0xb4, 0x72, 0x9a, 0xa9, 0x72, 0xd6, 0x0f, + 0x54, 0x9a, 0xc3, 0x9b, 0x29, 0x72, 0x1b, 0xa0, }) != 0 { t.Fail() } @@ -182,10 +182,10 @@ func TestVectorsCryptoPro(t *testing.T) { h.Reset() h.Write([]byte("The quick brown fox jumps over the lazy dog")) if bytes.Compare(h.Sum(nil), []byte{ - 0x76, 0x0a, 0x83, 0x65, 0xd5, 0x70, 0x47, 0x6e, - 0x78, 0x72, 0x54, 0x76, 0x1b, 0xe7, 0x65, 0x67, - 0x74, 0x02, 0x1b, 0x1f, 0x3d, 0xe5, 0x6f, 0x58, - 0x8c, 0x50, 0x1a, 0x36, 0x4a, 0x29, 0x04, 0x90, + 0x90, 0x04, 0x29, 0x4a, 0x36, 0x1a, 0x50, 0x8c, + 0x58, 0x6f, 0xe5, 0x3d, 0x1f, 0x1b, 0x02, 0x74, + 0x67, 0x65, 0xe7, 0x1b, 0x76, 0x54, 0x72, 0x78, + 0x6e, 0x47, 0x70, 0xd5, 0x65, 0x83, 0x0a, 0x76, }) != 0 { t.Fail() } @@ -193,10 +193,10 @@ func TestVectorsCryptoPro(t *testing.T) { h.Reset() h.Write([]byte("This is message, length=32 bytes")) if bytes.Compare(h.Sum(nil), []byte{ - 0xeb, 0x48, 0xde, 0x3e, 0x89, 0xe7, 0x1b, 0xcb, - 0x69, 0x5f, 0xc7, 0x52, 0xd6, 0x17, 0xfa, 0xe7, - 0x57, 0xf3, 0x4f, 0xa7, 0x7f, 0xa5, 0x8e, 0xe1, - 0x14, 0xc5, 0xbd, 0xb7, 0xf7, 0xc2, 0xef, 0x2c, + 0x2c, 0xef, 0xc2, 0xf7, 0xb7, 0xbd, 0xc5, 0x14, + 0xe1, 0x8e, 0xa5, 0x7f, 0xa7, 0x4f, 0xf3, 0x57, + 0xe7, 0xfa, 0x17, 0xd6, 0x52, 0xc7, 0x5f, 0x69, + 0xcb, 0x1b, 0xe7, 0x89, 0x3e, 0xde, 0x48, 0xeb, }) != 0 { t.Fail() } @@ -204,10 +204,10 @@ func TestVectorsCryptoPro(t *testing.T) { h.Reset() h.Write([]byte("Suppose the original message has length = 50 bytes")) if bytes.Compare(h.Sum(nil), []byte{ - 0x11, 0x50, 0xa6, 0x30, 0x31, 0xdc, 0x61, 0x1a, - 0x5f, 0x5e, 0x40, 0xd9, 0x31, 0x53, 0xf7, 0x4e, - 0xbd, 0xe8, 0x21, 0x6f, 0x67, 0x92, 0xc2, 0x5a, - 0x91, 0xcf, 0xca, 0xbc, 0x5c, 0x0c, 0x73, 0xc3, + 0xc3, 0x73, 0x0c, 0x5c, 0xbc, 0xca, 0xcf, 0x91, + 0x5a, 0xc2, 0x92, 0x67, 0x6f, 0x21, 0xe8, 0xbd, + 0x4e, 0xf7, 0x53, 0x31, 0xd9, 0x40, 0x5e, 0x5f, + 0x1a, 0x61, 0xdc, 0x31, 0x30, 0xa6, 0x50, 0x11, }) != 0 { t.Fail() } @@ -217,10 +217,10 @@ func TestVectorsCryptoPro(t *testing.T) { h.Write([]byte{'U'}) } if bytes.Compare(h.Sum(nil), []byte{ - 0xe8, 0xc4, 0x49, 0xf6, 0x08, 0x10, 0x4c, 0x51, - 0x27, 0x10, 0xcd, 0x37, 0xfd, 0xed, 0x92, 0x0d, - 0xf1, 0xe8, 0x6b, 0x21, 0x16, 0x23, 0xfa, 0x27, - 0xf4, 0xbb, 0x91, 0x46, 0x61, 0xc7, 0x4a, 0x1c, + 0x1c, 0x4a, 0xc7, 0x61, 0x46, 0x91, 0xbb, 0xf4, + 0x27, 0xfa, 0x23, 0x16, 0x21, 0x6b, 0xe8, 0xf1, + 0x0d, 0x92, 0xed, 0xfd, 0x37, 0xcd, 0x10, 0x27, + 0x51, 0x4c, 0x10, 0x08, 0xf6, 0x49, 0xc4, 0xe8, }) != 0 { t.Fail() } diff --git a/src/cypherpunks.ru/gogost/gost341194/pbkdf2_test.go b/src/cypherpunks.ru/gogost/gost341194/pbkdf2_test.go new file mode 100644 index 0000000..aafa045 --- /dev/null +++ b/src/cypherpunks.ru/gogost/gost341194/pbkdf2_test.go @@ -0,0 +1,92 @@ +// GoGOST -- Pure Go GOST cryptographic functions library +// Copyright (C) 2015-2016 Sergey Matveev +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package gost341194 + +import ( + "bytes" + "hash" + "testing" + + "cypherpunks.ru/gogost/gost28147" + "golang.org/x/crypto/pbkdf2" +) + +func PBKDF2Hash() hash.Hash { + return New(&gost28147.GostR3411_94_CryptoProParamSet) +} + +// Test vectors for PBKDF2 taken from +// http://tc26.ru/methods/containers_v1/Addition_to_PKCS5_v1_0.pdf test vectors +func TestPBKDF2Vectors(t *testing.T) { + if bytes.Compare(pbkdf2.Key( + []byte("password"), + []byte("salt"), + 1, + 32, + PBKDF2Hash, + ), []byte{0x73, 0x14, 0xe7, 0xc0, 0x4f, 0xb2, 0xe6, 0x62, 0xc5, 0x43, 0x67, 0x42, 0x53, 0xf6, 0x8b, 0xd0, 0xb7, 0x34, 0x45, 0xd0, 0x7f, 0x24, 0x1b, 0xed, 0x87, 0x28, 0x82, 0xda, 0x21, 0x66, 0x2d, 0x58}) != 0 { + t.Fail() + } + if bytes.Compare(pbkdf2.Key( + []byte("password"), + []byte("salt"), + 2, + 32, + PBKDF2Hash, + ), []byte{0x99, 0x0d, 0xfa, 0x2b, 0xd9, 0x65, 0x63, 0x9b, 0xa4, 0x8b, 0x07, 0xb7, 0x92, 0x77, 0x5d, 0xf7, 0x9f, 0x2d, 0xb3, 0x4f, 0xef, 0x25, 0xf2, 0x74, 0x37, 0x88, 0x72, 0xfe, 0xd7, 0xed, 0x1b, 0xb3}) != 0 { + t.Fail() + } + if bytes.Compare(pbkdf2.Key( + []byte("password"), + []byte("salt"), + 4096, + 32, + PBKDF2Hash, + ), []byte{0x1f, 0x18, 0x29, 0xa9, 0x4b, 0xdf, 0xf5, 0xbe, 0x10, 0xd0, 0xae, 0xb3, 0x6a, 0xf4, 0x98, 0xe7, 0xa9, 0x74, 0x67, 0xf3, 0xb3, 0x11, 0x16, 0xa5, 0xa7, 0xc1, 0xaf, 0xff, 0x9d, 0xea, 0xda, 0xfe}) != 0 { + t.Fail() + } + /* + // It takes too long + if bytes.Compare(pbkdf2.Key( + []byte("password"), + []byte("salt"), + 16777216, + 32, + PBKDF2Hash, + ), []byte{0xa5, 0x7a, 0xe5, 0xa6, 0x08, 0x83, 0x96, 0xd1, 0x20, 0x85, 0x0c, 0x5c, 0x09, 0xde, 0x0a, 0x52, 0x51, 0x00, 0x93, 0x8a, 0x59, 0xb1, 0xb5, 0xc3, 0xf7, 0x81, 0x09, 0x10, 0xd0, 0x5f, 0xcd, 0x97}) != 0 { + t.Fail() + } + */ + if bytes.Compare(pbkdf2.Key( + []byte("passwordPASSWORDpassword"), + []byte("saltSALTsaltSALTsaltSALTsaltSALTsalt"), + 4096, + 40, + PBKDF2Hash, + ), []byte{0x78, 0x83, 0x58, 0xc6, 0x9c, 0xb2, 0xdb, 0xe2, 0x51, 0xa7, 0xbb, 0x17, 0xd5, 0xf4, 0x24, 0x1f, 0x26, 0x5a, 0x79, 0x2a, 0x35, 0xbe, 0xcd, 0xe8, 0xd5, 0x6f, 0x32, 0x6b, 0x49, 0xc8, 0x50, 0x47, 0xb7, 0x63, 0x8a, 0xcb, 0x47, 0x64, 0xb1, 0xfd}) != 0 { + t.Fail() + } + if bytes.Compare(pbkdf2.Key( + []byte("pass\x00word"), + []byte("sa\x00lt"), + 4096, + 20, + PBKDF2Hash, + ), []byte{0x43, 0xe0, 0x6c, 0x55, 0x90, 0xb0, 0x8c, 0x02, 0x25, 0x24, 0x23, 0x73, 0x12, 0x7e, 0xdf, 0x9c, 0x8e, 0x9c, 0x32, 0x91}) != 0 { + t.Fail() + } +} diff --git a/src/golang.org/x/crypto b/src/golang.org/x/crypto new file mode 160000 index 0000000..9477e0b --- /dev/null +++ b/src/golang.org/x/crypto @@ -0,0 +1 @@ +Subproject commit 9477e0b78b9ac3d0b03822fd95422e2fe07627cd -- 2.44.0