4 my $engine_name = $ENV{ENGINE_NAME} || 'gost';
5 my $provider_name = $ENV{PROVIDER_NAME} || 'gostprov';
7 # Supported test types:
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
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
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' )
35 ( !$ARGV[0] || $ENV{PROVIDER_NAME}
36 ? ( 'standalone-provider-conf', 'standalone-provider-args' )
39 plan(19 * scalar @test_types);
43 open $F,">","testdata.dat";
44 print $F "12345670" x 128;
47 open $F,">","testbig.dat";
48 print $F ("12345670" x 8 . "\n") x 4096;
51 my $key='0123456789abcdef' x 2;
52 note("\@ARGV = (", join(', ', @ARGV), ")");
53 my %configurations = (
55 'module-type' => $ARGV[0],
57 'standalone-engine-args' => {
58 'module-type' => 'engine',
59 'openssl-args' => "-engine $engine_name",
61 'standalone-provider-args' => {
62 'module-type' => 'provider',
63 'openssl-args' => "-provider $provider_name -provider default",
65 'standalone-engine-conf' => {
66 'module-type' => 'engine',
67 'openssl-conf' => <<EOCFG,
68 openssl_conf = openssl_def
72 ${engine_name}=${engine_name}_conf
74 default_algorithms = ALL
77 'standalone-provider-conf' => {
78 'module-type' => 'provider',
79 'openssl-conf' => <<EOCFG,
80 openssl_conf = openssl_def
84 ${provider_name}=${provider_name}_conf
85 [${provider_name}_conf]
94 my $cmd = "openssl dgst $opts{-args}"
95 . " -mac $opts{-mac} -macopt key:$opts{-key}"
96 . (defined $opts{-size} ? " -sigopt size:$opts{-size}" : "")
101 check_expected => sub {
104 return "$opts{-mac}($opts{-infile})= $opts{-result}\n";
110 my $cmd = "openssl mac $opts{-args} -macopt key:$opts{-key}"
111 . (defined $opts{-size} ? " -macopt size:$opts{-size}" : "")
112 . " -in $opts{-infile} $opts{-mac}";
116 check_expected => sub {
119 return uc($opts{-result})."\n";
124 foreach my $test_type (@test_types) {
125 my $configuration = $configurations{$test_type};
126 my $module_type = $configuration->{'module-type'};
127 my $module_args = $configuration->{'openssl-args'} // '';
128 my $module_conf = $configuration->{'openssl-conf'};
129 # This is a trick to make a locally modifiable environment variable and
130 # retain it's current value as a default.
131 local $ENV{OPENSSL_CONF} = $ENV{OPENSSL_CONF};
134 skip "No module type detected for test type '$test_type'", 19
137 note("Running tests for test type $test_type");
140 $module_args = ' ' . $module_args;
142 if (defined $module_conf) {
143 my $confname = "$test_type.cnf";
144 open my $F, '>', $confname;
145 print $F $module_conf;
147 $ENV{OPENSSL_CONF} = abs_path($confname);
150 # Reopen STDERR to eliminate extra output
151 #open STDERR, ">>","tests.err";
153 my $mac_cmd = $executors{$module_type}->{mac_cmd};
154 my $mac_expected = $executors{$module_type}->{check_expected};
158 $cmd = $mac_cmd->(-mac => 'gost-mac', -key => $key,
159 -args => $module_args, -infile => 'testdata.dat');
160 $expected = $mac_expected->(-mac => 'GOST-MAC-gost-mac',
161 -infile => 'testdata.dat',
162 -result => '2ee8d13d');
163 unless (is(`$cmd`, $expected, "GOST MAC - default size")) {
164 diag("Command was: $cmd");
168 for ($i=1;$i<=8; $i++) {
169 $cmd = $mac_cmd->(-mac => 'gost-mac', -key => $key, -size => $i,
170 -args => $module_args, -infile => 'testdata.dat');
171 $expected = $mac_expected->(-mac => 'GOST-MAC-gost-mac',
172 -infile => 'testdata.dat',
173 -result => substr("2ee8d13dff7f037d",0,$i*2));
174 unless (is(`$cmd`, $expected, "GOST MAC - size $i bytes")) {
175 diag("Command was: $cmd");
181 $cmd = $mac_cmd->(-mac => 'gost-mac', -key => $key,
182 -args => $module_args, -infile => 'testbig.dat');
183 $expected = $mac_expected->(-mac => 'GOST-MAC-gost-mac',
184 -infile => 'testbig.dat',
185 -result => '5efab81f');
186 unless (is(`$cmd`, $expected, "GOST MAC - big data")) {
187 diag("Command was: $cmd");
190 $cmd = $mac_cmd->(-mac => 'gost-mac-12', -key => $key,
191 -args => $module_args, -infile => 'testdata.dat');
192 $expected = $mac_expected->(-mac => 'GOST-MAC-12-gost-mac-12',
193 -infile => 'testdata.dat',
194 -result => 'be4453ec');
195 unless (is(`$cmd`, $expected, "GOST MAC parameters 2012 - default size")) {
196 diag("Command was: $cmd");
198 for ($i=1;$i<=8; $i++) {
199 $cmd = $mac_cmd->(-mac => 'gost-mac-12', -key => $key, -size => $i,
200 -args => $module_args, -infile => 'testdata.dat');
201 $expected = $mac_expected->(-mac => 'GOST-MAC-12-gost-mac-12',
202 -infile => 'testdata.dat',
203 -result => substr("be4453ec1ec327be",0,$i*2));
204 unless (is(`$cmd`, $expected, "GOST MAC parameters 2012 - size $i bytes")) {
205 diag("Command was: $cmd");
211 unlink('testdata.dat');
212 unlink('testbig.dat');