]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - test/01-digest.t
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / test / 01-digest.t
1 #!/usr/bin/perl 
2 use Test2::V0;
3
4 my $engine_name = $ENV{ENGINE_NAME} || 'gost';
5 my $provider_name = $ENV{PROVIDER_NAME} || 'gostprov';
6
7 # Supported test types:
8 #
9 # conf                          Only if there's a command line argument.
10 #                               For this test type, we rely entirely on the
11 #                               caller to define the environment variable
12 #                               OPENSSL_CONF appropriately.
13 # standalone-engine-conf        Tests the engine through a generated config
14 #                               file.
15 #                               This is done when there are no command line
16 #                               arguments or when the environment variable
17 #                               ENGINE_NAME is defined.
18 # standalone-engine-args        Tests the engine through openssl command args.
19 #                               This is done when there are no command line
20 #                               arguments or when the environment variable
21 #                               ENGINE_NAME is defined.
22 # standalone-provider-conf      Tests the provider through a generated config
23 #                               file.
24 #                               This is done when there are no command line
25 #                               arguments or when the environment variable
26 #                               PROVIDER_NAME is defined.
27 # standalone-provider-args      Tests the provider through openssl command args.
28 #                               This is done when there are no command line
29 #                               arguments or when the environment variable
30 #                               PROVIDER_NAME is defined.
31 my @test_types = ( $ARGV[0] ? 'conf' : (),
32                    ( !$ARGV[0] || $ENV{ENGINE_NAME}
33                      ? ( 'standalone-engine-conf', 'standalone-engine-args' )
34                      : () ),
35                    ( !$ARGV[0] || $ENV{PROVIDER_NAME}
36                      ? ( 'standalone-provider-conf', 'standalone-provider-args' )
37                      : () ) );
38
39 plan(16 * scalar @test_types);
40
41 # prepare data for
42
43 my %configurations = (
44     'standalone-engine-args' => {
45         'openssl-args'  => "-engine $engine_name",
46     },
47     'standalone-provider-args' => {
48         'openssl-args'  => "-provider $provider_name -provider default",
49     },
50     'standalone-engine-conf' => {
51         'openssl-conf'  => <<EOCFG,
52 openssl_conf = openssl_def
53 [openssl_def]
54 engines = engines
55 [engines]
56 ${engine_name}=${engine_name}_conf
57 [${engine_name}_conf]
58 default_algorithms = ALL
59 EOCFG
60     },
61     'standalone-provider-conf' => {
62         'openssl-conf'  => <<EOCFG,
63 openssl_conf = openssl_def
64 [openssl_def]
65 providers = providers
66 [providers]
67 ${provider_name}=${provider_name}_conf
68 [${provider_name}_conf]
69 EOCFG
70     },
71 );
72
73 foreach my $test_type (@test_types) {
74     my $configuration = $configurations{$test_type};
75     my $module_args = $configuration->{'openssl-args'} // '';
76     my $module_conf = $configuration->{'openssl-conf'};
77     # This is a trick to make a locally modifiable environment variable and
78     # retain it's current value as a default.
79     local $ENV{OPENSSL_CONF} = $ENV{OPENSSL_CONF};
80
81     note("Running tests for test type $test_type");
82
83     if ($module_args) {
84         $module_args = ' ' . $module_args;
85     }
86     if (defined $module_conf) {
87         my $confname = "$test_type.cnf";
88         open my $F, '>', $confname;
89         print $F $module_conf;
90         close $F;
91         $ENV{OPENSSL_CONF} = abs_path($confname);
92     }
93
94     # Reopen STDERR to eliminate extra output
95     #open STDERR, ">>","tests.err";
96
97     my $F;
98     my $cmd;
99     my $name_re;
100
101     open $F,">","testm1.dat";
102     print $F "012345678901234567890123456789012345678901234567890123456789012";
103     close $F;
104     $cmd = "openssl dgst${module_args} -md_gost12_256 testm1.dat";
105     $name_re = qr/id-tc26-gost3411-12-256|md_gost12_256/;
106     unless (like(`$cmd`,
107                  qr/^${name_re}\Q(testm1.dat)= 9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500\E\n$/ms,
108                  "GOST R 34.11-2012 256bit example 1 from standard")) {
109         diag("Command was: $cmd");
110     }
111
112     $cmd = "openssl dgst${module_args} -md_gost12_512 testm1.dat";
113     $name_re = qr/id-tc26-gost3411-12-512|md_gost12_512/;
114     unless (like(`$cmd`,
115                  qr/^${name_re}\Q(testm1.dat)= 1b54d01a4af5b9d5cc3d86d68d285462b19abc2475222f35c085122be4ba1ffa00ad30f8767b3a82384c6574f024c311e2a481332b08ef7f41797891c1646f48\E\n$/ms,
116                  "GOST R 34.11-2012 512bit example 1 from standard")) {
117         diag("Command was: $cmd");
118     }
119
120     unlink("testm1.dat");
121
122
123     open $F,">","testm2.dat";
124     print $F pack("H*","d1e520e2e5f2f0e82c20d1f2f0e8e1eee6e820e2edf3f6e82c20e2e5fef2fa20f120eceef0ff20f1f2f0e5ebe0ece820ede020f5f0e0e1f0fbff20efebfaeafb20c8e3eef0e5e2fb");
125     close $F;
126     $cmd = "openssl dgst${module_args} -md_gost12_256 testm2.dat";
127     $name_re = qr/id-tc26-gost3411-12-256|md_gost12_256/;
128     unless (like(`$cmd`,
129                  qr/^${name_re}\Q(testm2.dat)= 9dd2fe4e90409e5da87f53976d7405b0c0cac628fc669a741d50063c557e8f50\E\n$/ms,
130                  "GOST R 34.11-2012 256bit example 2 from standard")) {
131         diag("Command was: $cmd");
132     }
133
134     $cmd = "openssl dgst${module_args} -md_gost12_512 testm2.dat";
135     $name_re = qr/id-tc26-gost3411-12-512|md_gost12_512/;
136     unless (like(`$cmd`,
137                  qr/^${name_re}\Q(testm2.dat)= 1e88e62226bfca6f9994f1f2d51569e0daf8475a3b0fe61a5300eee46d961376035fe83549ada2b8620fcd7c496ce5b33f0cb9dddc2b6460143b03dabac9fb28\E\n$/ms,
138                  "GOST R 34.11-2012 512bit example 2 from standard")) {
139         diag("Command was: $cmd");
140     }
141
142     unlink("testm2.dat");
143
144
145     open $F,">","testdata.dat";
146     binmode $F;
147     print $F "12345670" x 128;
148     close $F;
149     $cmd = "openssl dgst${module_args} -md_gost94 testdata.dat";
150     $name_re = qr/id-GostR3411-94|md_gost94/;
151     unless (like(`$cmd`,
152                  qr/^${name_re}\Q(testdata.dat)= f7fc6d16a6a5c12ac4f7d320e0fd0d8354908699125e09727a4ef929122b1cae\E\n$/ms,
153                  "GOST R 34.11-94 1K ascii")) {
154         diag("Command was: $cmd");
155     }
156
157     $cmd = "openssl dgst${module_args} -md_gost12_256 testdata.dat";
158     $name_re = qr/id-tc26-gost3411-12-256|md_gost12_256/;
159     unless (like(`$cmd`,
160                  qr/^${name_re}\Q(testdata.dat)= 1906512b86a1283c68cec8419e57113efc562a1d0e95d8f4809542900c416fe4\E\n$/ms,
161                  "GOST R 34.11-2012 256bit 1K ascii")) {
162         diag("Command was: $cmd");
163     }
164
165     $cmd = "openssl dgst${module_args} -md_gost12_512 testdata.dat";
166     $name_re = qr/id-tc26-gost3411-12-512|md_gost12_512/;
167     unless (like(`$cmd`,
168                  qr/^${name_re}\Q(testdata.dat)= 283587e434864d0d4bea97c0fb10e2dd421572fc859304bdf6a94673d652c59049212bad7802b4fcf5eecc1f8fab569d60f2c20dbd789a7fe4efbd79d8137ee7\E\n$/ms,
169                  "GOST R 34.11-2012 512bit 1K ascii")) {
170         diag("Command was: $cmd");
171     }
172
173     unlink("testdata.dat");
174
175
176     open $F,">","testdata2.dat";
177     binmode $F;
178     print $F "\x00\x01\x02\x15\x84\x67\x45\x31" x 128;
179     close $F;
180
181     $cmd = "openssl dgst${module_args} -md_gost94 testdata2.dat";
182     $name_re = qr/id-GostR3411-94|md_gost94/;
183     unless (like(`$cmd`,
184                  qr/^${name_re}\Q(testdata2.dat)= 69f529aa82d9344ab0fa550cdf4a70ecfd92a38b5520b1906329763e09105196\E\n$/ms,
185                  "GOST R 34.11-94 1K binary")) {
186         diag("Command was: $cmd");
187     }
188
189     $cmd = "openssl dgst${module_args} -md_gost12_256 testdata2.dat";
190     $name_re = qr/id-tc26-gost3411-12-256|md_gost12_256/;
191     unless (like(`$cmd`,
192                  qr/^${name_re}\Q(testdata2.dat)= 2eb1306be3e490f18ff0e2571a077b3831c815c46c7d4fdf9e0e26de4032b3f3\E\n$/ms,
193                  "GOST R 34.11-2012 256bit 1K binary")) {
194         diag("Command was: $cmd");
195     }
196
197     $cmd = "openssl dgst${module_args} -md_gost12_512 testdata2.dat";
198     $name_re = qr/id-tc26-gost3411-12-512|md_gost12_512/;
199     unless (like(`$cmd`,
200                  qr/^${name_re}\Q(testdata2.dat)= 55656e5bcf795b499031a7833cd7dc18fe10d4a47e15be545c6ab3f304a4fe411c4c39de5b1fc6844880111441e0b92bf1ec2fb7840453fe39a2b70ced461968\E\n$/ms,
201                  "GOST R 34.11-2012 512bit 1K binary")) {
202         diag("Command was: $cmd");
203     }
204
205     unlink("testdata2.dat");
206
207     open $F, ">","testdata3.dat";
208     binmode $F;
209     print $F substr("12345670" x 128,0,539);
210     close $F;
211
212     $cmd = "openssl dgst${module_args} -md_gost94 testdata3.dat";
213     $name_re = qr/id-GostR3411-94|md_gost94/;
214     unless (like(`$cmd`,
215                  qr/^${name_re}\Q(testdata3.dat)= bd5f1e4b539c7b00f0866afdbc8ed452503a18436061747a343f43efe888aac9\E\n$/ms,
216                  "GOST R 34.11-94 539 bytes")) {
217         diag("Command was: $cmd");
218     }
219
220     $cmd = "openssl dgst${module_args} -md_gost12_256 testdata3.dat";
221     $name_re = qr/id-tc26-gost3411-12-256|md_gost12_256/;
222     unless (like(`$cmd`,
223                  qr/^${name_re}\Q(testdata3.dat)= c98a17f9fadff78d08521e4179a7b2e6275f3b1da88339a3cb961a3514e5332e\E\n$/ms,
224                  "GOST R 34.11-2012 256bit 539 bytes")) {
225         diag("Command was: $cmd");
226     }
227
228     $cmd = "openssl dgst${module_args} -md_gost12_512 testdata3.dat";
229     $name_re = qr/id-tc26-gost3411-12-512|md_gost12_512/;
230     unless (like(`$cmd`,
231                  qr/^${name_re}\Q(testdata3.dat)= d5ad93fbc9ed7abc1cf28d00827a052b40bea74b04c4fd753102c1bcf9f9dad5142887f8a4cceaa0d64a0a8291592413d6adb956b99138a0023e127ff37bdf08\E\n$/ms,
232                  "GOST R 34.11-2012 512bit 539 bytes")) {
233         diag("Command was: $cmd");
234     }
235
236     unlink "testdata3.dat";
237     open $F , ">","bigdata.dat";
238     binmode $F;
239     print $F  ("121345678" x 7 . "1234567\n") x 4096,"12345\n";
240     close $F;
241
242     $cmd = "openssl dgst${module_args} -md_gost94 bigdata.dat";
243     $name_re = qr/id-GostR3411-94|md_gost94/;
244     unless (like(`$cmd`,
245                  qr/^${name_re}\Q(bigdata.dat)= e5d3ac4ea3f67896c51ff919cedb9405ad771e39f0f2eab103624f9a758e506f\E\n$/ms,
246                  "GOST R 34.11-94 128K")) {
247         diag("Command was: $cmd");
248     }
249
250     $cmd = "openssl dgst${module_args} -md_gost12_256 bigdata.dat";
251     $name_re = qr/id-tc26-gost3411-12-256|md_gost12_256/;
252     unless (like(`$cmd`,
253                  qr/^${name_re}\Q(bigdata.dat)= 50e935d725d9359e5991b6b7eba8b3539fca03584d26adf4c827c982ffd49367\E\n$/ms,
254                  "GOST R 34.11-2012 256bit 128K")) {
255         diag("Command was: $cmd");
256     }
257
258     $cmd = "openssl dgst${module_args} -md_gost12_512 bigdata.dat";
259     $name_re = qr/id-tc26-gost3411-12-512|md_gost12_512/;
260     unless (like(`$cmd`,
261                  qr/^${name_re}\Q(bigdata.dat)= 1d93645ebfbb477660f98b7d1598e37fbf3bfc8234ead26e2246e1b979e590ac46138158a692f9a0c9ac2550758b4d0d4c9fb8af5e595a16d3760c6516443f82\E\n$/ms,
262                  "GOST R 34.11-2012 512bit 128K")) {
263         diag("Command was: $cmd");
264     }
265
266     unlink "bigdata.dat";
267 }