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