]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Added tests for encryption-decryption.
authorVictor Wagner <wagner@atlas-kard.ru>
Fri, 18 Sep 2015 14:33:05 +0000 (17:33 +0300)
committerVictor Wagner <wagner@atlas-kard.ru>
Fri, 18 Sep 2015 14:33:05 +0000 (17:33 +0300)
gost_crypt.c
gost_eng.c
test/03-encrypt.t [new file with mode: 0644]

index 0c6592aba7ebd3e493fb8080a062821467438799..23a99e4bb5ce6b4a3de4b8cfa1280f4b79c243a7 100644 (file)
@@ -65,7 +65,12 @@ EVP_CIPHER cipher_gost = {
 
 EVP_CIPHER cipher_gost_cbc =
     {
-    NID_gost89_cbc,
+#ifdef NID_gost89_cbc  
+    NID_gost89_cbc
+#else  
+       NID_undef
+#endif
+       ,
     8,/*block_size*/
     32,/*key_size*/
     8,/*iv_len */
@@ -99,7 +104,12 @@ EVP_CIPHER cipher_gost_cpacnt = {
 };
 
 EVP_CIPHER cipher_gost_cpcnt_12 = {
-    NID_undef /* NID_gost89_cnt_12 */,
+#ifdef NID_gost89_cnt_12
+       NID_gost89_cnt_12
+#else
+    NID_undef
+#endif 
+       ,
     1,                          /* block_size */
     32,                         /* key_size */
     8,                          /* iv_len */
@@ -148,7 +158,12 @@ EVP_MD imit_gost_cpa = {
 };
 
 EVP_MD imit_gost_cp_12 = {
-    NID_undef, /* NID_gost_mac_12,*/
+#ifdef NID_gost_mac_12
+       NID_gost_mac_12
+#else  
+    NID_undef
+#endif
+       ,
     NID_undef,
     4,
     0,
index 3debd1830fa8415999324faafd55f4582e41309a..b7b6b5edd6486c165edd862fd01d54c4819664e7 100644 (file)
@@ -265,7 +265,7 @@ static int gost_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
     int ok = 1;
     if (!cipher) {
         *nids = gost_cipher_nids;
-        return 4;               /* three ciphers are supported */
+        return 4;               /* four ciphers are supported */
     }
 
     if (nid == NID_id_Gost28147_89) {
diff --git a/test/03-encrypt.t b/test/03-encrypt.t
new file mode 100644 (file)
index 0000000..5ed6b55
--- /dev/null
@@ -0,0 +1,131 @@
+#!/usr/bin/perl
+use Test::More tests => 48;
+use Cwd 'abs_path';
+
+# prepare data for 
+
+
+# Set OPENSSL_ENGINES environment variable to just build engine
+$ENV{'OPENSSL_ENGINES'} = abs_path("../.libs");
+
+$key='0123456789abcdef' x 2;
+
+#
+# You can redefine engine to use using ENGINE_NAME environment variable
+# 
+$engine=$ENV{'ENGINE_NAME'}||"gost";
+
+# Reopen STDERR to eliminate extra output
+open STDERR, ">>","tests.err";
+
+our $count=0;
+
+#
+# parameters -paramset = oid of the parameters
+# -cleartext - data to encrypt
+# -ciphertext - expected ciphertext (hex-encoded)
+# -key - key (hex-encoded)
+# -iv  - IV (hex-encoded)
+# 
+
+sub crypt_test {
+       my %p = @_;
+       our $count++;
+       open my $f, ">", "test$count.clear";
+       print $f $p{-cleartext};
+       close $f;
+       $ENV{'CRYPT_PARAMS'} = $p{-paramset} if exists $p{-paramset};
+       my $ctext = `openssl enc -engine ${engine} -e -$p{-alg} -K $p{-key} -iv $p{-iv} -in test$count.clear`;
+       is($?,0,"$p{-name} - encrypt successful");
+       is(unpack("H*",$ctext),$p{-ciphertext},"$p{-name} - ciphertext expected");
+       open my $f, ">", "test$count.enc";
+       print $f $ctext;
+       close $f;
+       my $otext = `openssl enc -engine ${engine} -d -$p{-alg} -K $p{-key} -iv $p{-iv} -in test$count.enc`;
+       is($?,0,"$p{-name} - decrypt successful");
+       is($otext,$p{-cleartext},"$p{-name} - decrypted correctly");
+       unlink "test$count.enc";
+       unlink "test$count.clear";
+       delete $ENV{'CRYPT_PARAMS'};
+}
+
+$key = '0123456789ABCDEF' x 4;
+$iv =  '0000000000000000';
+$clear1 = "The quick brown fox jumps over the lazy dog\n";
+
+crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => '07f4102c6185c4a09e676e269bfa4bc9c5df6575916b879bd13a893a2285ee6690107cdeef7a315d2eb54bfa', 
+                  -alg => 'gost89',
+                  -name=> 'CFB short text, paramset A');
+
+crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => '11465c1c9708033e784fbb5536f2719c38353cb488b01f195c20d4c027022e8300d98bb66c138afbe878c88b', 
+                  -alg => 'gost89',
+                  -name=> 'CFB short text, paramset B');
+
+crypt_test(-paramset=> "1.2.643.2.2.31.3", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => '2f213b390c9b6ceb18de479686d23f4f03c76644a0aab8894b50b71a3bbb3c027ec4c2d569ba0e6a873bd46e', 
+                  -alg => 'gost89',
+                  -name=> 'CFB short text, paramset C');
+
+crypt_test(-paramset=> "1.2.643.2.2.31.4", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => 'e835f59a7fdfd84764efe1e987660327f5d0de187afea72f9cd040983a5e5bbeb4fe1aa5ff85d623ebc4d435', 
+                  -alg => 'gost89',
+                  -name=> 'CFB short text, paramset D');
+
+
+crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => 'bcb821452e459f10f92019171e7c3b27b87f24b174306667f67704812c07b70b5e7420f74a9d54feb4897df8', 
+                  -alg => 'gost89-cnt',
+                  -name=> 'CNT short text');
+
+crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => 'bcb821452e459f10f92019171e7c3b27b87f24b174306667f67704812c07b70b5e7420f74a9d54feb4897df8', 
+                  -alg => 'gost89-cnt',
+                  -name=> 'CNT short text, paramset param doesnt affect cnt');
+
+                  
+crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => 'cf3f5f713b3d10abd0c6f7bafb6aaffe13dfc12ef5c844f84873aeaaf6eb443a9747c9311b86f97ba3cdb5c4',
+                  -alg => 'gost89-cnt-12',
+                  -name=> 'CNT-12 short text');
+
+crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => 'cf3f5f713b3d10abd0c6f7bafb6aaffe13dfc12ef5c844f84873aeaaf6eb443a9747c9311b86f97ba3cdb5c4',
+                  -alg => 'gost89-cnt-12',
+                  -name=> 'CNT-12 short text, paramset param doesnt affect cnt');
+
+
+crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => '3a3293e75089376572da44966cd1759c29d2f1e5e1c3fa9674909a63026da3dc51a4266bff37fb74a3a07155c9ca8fcf', 
+                  -alg => 'gost89-cbc',
+                  -name=> 'CBC short text, paramset A');
+
+
+crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => '11465c1c9708033e784fbb5536f2719c38353cb488b01f195c20d4c027022e8300d98bb66c138afbe878c88b', 
+                  -alg => 'gost89',
+                  -name=> 'CBC short text, paramset B');
+
+crypt_test(-paramset=> "1.2.643.2.2.31.3", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => '987c0fb3d84530467a1973791e0a25e33c5d14591976f8c1573bdb9d056eb7b353f66fef3ffe2e3524583b3997123c8a', 
+                  -alg => 'gost89-cbc',
+                  -name=> 'CBC short text, paramset C');
+
+crypt_test(-paramset=> "1.2.643.2.2.31.4", -key => $key, -iv => $iv,
+                  -cleartext => $clear1,
+                  -ciphertext => 'e076b09822d4786a2863125d16594d765d8acd0f360e52df42e9d52c8e6c0e6595b5f6bbecb04a22c8ae5f4f87c1523b', 
+                  -alg => 'gost89-cbc',
+                  -name=> 'CBC short text, paramset D');
+