]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - test/00-engine.t
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / test / 00-engine.t
1 #!/usr/bin/perl
2 use Test2::V0;
3 skip_all('This test is only suitable for the engine')
4     unless $ARGV[0] eq 'engine';
5 plan(7);
6 use Cwd 'abs_path';
7
8 # prepare data for 
9
10 open (my $F,">","testdata.dat");
11 print $F "12345670" x 128;
12 close $F;
13
14 my $key='0123456789abcdef' x 2;
15
16 #
17 # You can redefine engine to use using ENGINE_NAME environment variable
18
19 my $engine=$ENV{'ENGINE_NAME'}||"gost";
20
21 # Reopen STDERR to eliminate extra output
22 open STDERR, ">>","tests.err";
23
24 if (exists $ENV{'OPENSSL_CONF'}) {
25         delete $ENV{'OPENSSL_CONF'}
26 }
27 #
28 # This test needs output of openssl engine -c command.
29 # Default one  is hardcoded below, but you can place file
30 # ${ENGINE_NAME}.info into this directory if you use this test suite
31 # to test other engine implementing GOST cryptography.
32 #
33 my $engine_info;
34
35 if ( -f $engine . ".info") {
36         diag("Reading $engine.info");
37         open F, "<", $engine . ".info";
38         read F,$engine_info,1024;
39 } else {
40
41 $engine_info= <<EOINF;
42 (gost) Reference implementation of GOST engine
43  [gost89, gost89-cnt, gost89-cnt-12, gost89-cbc, kuznyechik-ecb, kuznyechik-cbc, kuznyechik-cfb, kuznyechik-ofb, kuznyechik-ctr, magma-ecb, kuznyechik-mgm, magma-cbc, magma-ctr, magma-ctr-acpkm, magma-ctr-acpkm-omac, magma-mgm, kuznyechik-ctr-acpkm, kuznyechik-ctr-acpkm-omac, magma-kexp15, kuznyechik-kexp15, md_gost94, gost-mac, md_gost12_256, md_gost12_512, gost-mac-12, magma-mac, kuznyechik-mac, kuznyechik-ctr-acpkm-omac, gost2001, id-GostR3410-2001DH, gost-mac, gost2012_256, gost2012_512, gost-mac-12, magma-mac, kuznyechik-mac, magma-ctr-acpkm-omac, kuznyechik-ctr-acpkm-omac]
44 EOINF
45 }
46
47 $ENV{'OPENSSL_CONF'}=abs_path("no_such_file.cfg");
48 is(`openssl engine -c $engine`,
49 $engine_info,
50 "load engine without any config");
51
52 is(`openssl dgst -engine $engine -md_gost94 testdata.dat`,
53 "md_gost94(testdata.dat)= f7fc6d16a6a5c12ac4f7d320e0fd0d8354908699125e09727a4ef929122b1cae\n",
54 "compute digest without config");
55
56
57 open $F,">","test.cnf";
58 print $F <<EOCFG;
59 openssl_conf = openssl_def
60 [openssl_def]
61 engines = engines
62 [engines]
63 ${engine}=gost_conf
64 [gost_conf]
65 default_algorithms = ALL
66
67 EOCFG
68 close $F;
69 $ENV{'OPENSSL_CONF'}=abs_path('test.cnf');
70
71 is(`openssl engine -c $engine`,
72 $engine_info,
73 "load engine with config");
74
75 is(`openssl dgst -md_gost94 testdata.dat`,
76 "md_gost94(testdata.dat)= f7fc6d16a6a5c12ac4f7d320e0fd0d8354908699125e09727a4ef929122b1cae\n",
77 "compute digest with config without explicit engine param");
78
79 is(`openssl dgst -engine $engine -md_gost94 testdata.dat`,
80 "md_gost94(testdata.dat)= f7fc6d16a6a5c12ac4f7d320e0fd0d8354908699125e09727a4ef929122b1cae\n",
81 "compute digest with both config and explicit engine param");
82
83 like(`openssl ciphers`, qr|GOST2001-GOST89-GOST89|, 'display GOST2001-GOST89-GOST89 cipher');
84
85 like(`openssl ciphers`, qr|GOST2012-GOST8912-GOST8912|, 'display GOST2012-GOST8912-GOST8912 cipher');
86
87 unlink('testdata.dat');
88 unlink('test.cnf');