]> Cypherpunks.ru repositories - gogost.git/blob - gost34112012512/pbkdf2_test.go
Download link for 5.14.1 release
[gogost.git] / gost34112012512 / pbkdf2_test.go
1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2024 Sergey Matveev <stargrave@stargrave.org>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 package gost34112012512
17
18 import (
19         "bytes"
20         "testing"
21
22         "golang.org/x/crypto/pbkdf2"
23 )
24
25 // Test vectors from http://tc26.ru/.../R_50.1.111-2016.pdf
26
27 func Test1(t *testing.T) {
28         if !bytes.Equal(pbkdf2.Key(
29                 []byte("password"),
30                 []byte("salt"),
31                 1,
32                 64,
33                 New,
34         ), []byte{
35                 0x64, 0x77, 0x0a, 0xf7, 0xf7, 0x48, 0xc3, 0xb1,
36                 0xc9, 0xac, 0x83, 0x1d, 0xbc, 0xfd, 0x85, 0xc2,
37                 0x61, 0x11, 0xb3, 0x0a, 0x8a, 0x65, 0x7d, 0xdc,
38                 0x30, 0x56, 0xb8, 0x0c, 0xa7, 0x3e, 0x04, 0x0d,
39                 0x28, 0x54, 0xfd, 0x36, 0x81, 0x1f, 0x6d, 0x82,
40                 0x5c, 0xc4, 0xab, 0x66, 0xec, 0x0a, 0x68, 0xa4,
41                 0x90, 0xa9, 0xe5, 0xcf, 0x51, 0x56, 0xb3, 0xa2,
42                 0xb7, 0xee, 0xcd, 0xdb, 0xf9, 0xa1, 0x6b, 0x47,
43         }) {
44                 t.FailNow()
45         }
46 }
47
48 func Test2(t *testing.T) {
49         if !bytes.Equal(pbkdf2.Key(
50                 []byte("password"),
51                 []byte("salt"),
52                 2,
53                 64,
54                 New,
55         ), []byte{
56                 0x5a, 0x58, 0x5b, 0xaf, 0xdf, 0xbb, 0x6e, 0x88,
57                 0x30, 0xd6, 0xd6, 0x8a, 0xa3, 0xb4, 0x3a, 0xc0,
58                 0x0d, 0x2e, 0x4a, 0xeb, 0xce, 0x01, 0xc9, 0xb3,
59                 0x1c, 0x2c, 0xae, 0xd5, 0x6f, 0x02, 0x36, 0xd4,
60                 0xd3, 0x4b, 0x2b, 0x8f, 0xbd, 0x2c, 0x4e, 0x89,
61                 0xd5, 0x4d, 0x46, 0xf5, 0x0e, 0x47, 0xd4, 0x5b,
62                 0xba, 0xc3, 0x01, 0x57, 0x17, 0x43, 0x11, 0x9e,
63                 0x8d, 0x3c, 0x42, 0xba, 0x66, 0xd3, 0x48, 0xde,
64         }) {
65                 t.FailNow()
66         }
67 }
68
69 func Test4096(t *testing.T) {
70         if !bytes.Equal(pbkdf2.Key(
71                 []byte("password"),
72                 []byte("salt"),
73                 4096,
74                 64,
75                 New,
76         ), []byte{
77                 0xe5, 0x2d, 0xeb, 0x9a, 0x2d, 0x2a, 0xaf, 0xf4,
78                 0xe2, 0xac, 0x9d, 0x47, 0xa4, 0x1f, 0x34, 0xc2,
79                 0x03, 0x76, 0x59, 0x1c, 0x67, 0x80, 0x7f, 0x04,
80                 0x77, 0xe3, 0x25, 0x49, 0xdc, 0x34, 0x1b, 0xc7,
81                 0x86, 0x7c, 0x09, 0x84, 0x1b, 0x6d, 0x58, 0xe2,
82                 0x9d, 0x03, 0x47, 0xc9, 0x96, 0x30, 0x1d, 0x55,
83                 0xdf, 0x0d, 0x34, 0xe4, 0x7c, 0xf6, 0x8f, 0x4e,
84                 0x3c, 0x2c, 0xda, 0xf1, 0xd9, 0xab, 0x86, 0xc3,
85         }) {
86                 t.FailNow()
87         }
88 }
89
90 func TestWithZero(t *testing.T) {
91         if !bytes.Equal(pbkdf2.Key(
92                 []byte("pass\x00word"),
93                 []byte("sa\x00lt"),
94                 4096,
95                 64,
96                 New,
97         ), []byte{
98                 0x50, 0xdf, 0x06, 0x28, 0x85, 0xb6, 0x98, 0x01,
99                 0xa3, 0xc1, 0x02, 0x48, 0xeb, 0x0a, 0x27, 0xab,
100                 0x6e, 0x52, 0x2f, 0xfe, 0xb2, 0x0c, 0x99, 0x1c,
101                 0x66, 0x0f, 0x00, 0x14, 0x75, 0xd7, 0x3a, 0x4e,
102                 0x16, 0x7f, 0x78, 0x2c, 0x18, 0xe9, 0x7e, 0x92,
103                 0x97, 0x6d, 0x9c, 0x1d, 0x97, 0x08, 0x31, 0xea,
104                 0x78, 0xcc, 0xb8, 0x79, 0xf6, 0x70, 0x68, 0xcd,
105                 0xac, 0x19, 0x10, 0x74, 0x08, 0x44, 0xe8, 0x30,
106         }) {
107                 t.FailNow()
108         }
109 }
110
111 func Test100(t *testing.T) {
112         if !bytes.Equal(pbkdf2.Key(
113                 []byte("passwordPASSWORDpassword"),
114                 []byte("saltSALTsaltSALTsaltSALTsaltSALTsalt"),
115                 4096,
116                 100,
117                 New,
118         ), []byte{
119                 0xb2, 0xd8, 0xf1, 0x24, 0x5f, 0xc4, 0xd2, 0x92,
120                 0x74, 0x80, 0x20, 0x57, 0xe4, 0xb5, 0x4e, 0x0a,
121                 0x07, 0x53, 0xaa, 0x22, 0xfc, 0x53, 0x76, 0x0b,
122                 0x30, 0x1c, 0xf0, 0x08, 0x67, 0x9e, 0x58, 0xfe,
123                 0x4b, 0xee, 0x9a, 0xdd, 0xca, 0xe9, 0x9b, 0xa2,
124                 0xb0, 0xb2, 0x0f, 0x43, 0x1a, 0x9c, 0x5e, 0x50,
125                 0xf3, 0x95, 0xc8, 0x93, 0x87, 0xd0, 0x94, 0x5a,
126                 0xed, 0xec, 0xa6, 0xeb, 0x40, 0x15, 0xdf, 0xc2,
127                 0xbd, 0x24, 0x21, 0xee, 0x9b, 0xb7, 0x11, 0x83,
128                 0xba, 0x88, 0x2c, 0xee, 0xbf, 0xef, 0x25, 0x9f,
129                 0x33, 0xf9, 0xe2, 0x7d, 0xc6, 0x17, 0x8c, 0xb8,
130                 0x9d, 0xc3, 0x74, 0x28, 0xcf, 0x9c, 0xc5, 0x2a,
131                 0x2b, 0xaa, 0x2d, 0x3a,
132         }) {
133                 t.FailNow()
134         }
135 }
136
137 func Test16777216(t *testing.T) {
138         t.Skip("takes too long")
139         if !bytes.Equal(pbkdf2.Key(
140                 []byte("password"),
141                 []byte("salt"),
142                 16777216,
143                 64,
144                 New,
145         ), []byte{
146                 0x49, 0xe4, 0x84, 0x3b, 0xba, 0x76, 0xe3, 0x00,
147                 0xaf, 0xe2, 0x4c, 0x4d, 0x23, 0xdc, 0x73, 0x92,
148                 0xde, 0xf1, 0x2f, 0x2c, 0x0e, 0x24, 0x41, 0x72,
149                 0x36, 0x7c, 0xd7, 0x0a, 0x89, 0x82, 0xac, 0x36,
150                 0x1a, 0xdb, 0x60, 0x1c, 0x7e, 0x2a, 0x31, 0x4e,
151                 0x8c, 0xb7, 0xb1, 0xe9, 0xdf, 0x84, 0x0e, 0x36,
152                 0xab, 0x56, 0x15, 0xbe, 0x5d, 0x74, 0x2b, 0x6c,
153                 0xf2, 0x03, 0xfb, 0x55, 0xfd, 0xc4, 0x80, 0x71,
154         }) {
155                 t.FailNow()
156         }
157 }