### Re^4: Decent crypto library?

by vsespb (Chaplain)
 on Oct 28, 2013 at 17:55 UTC ( #1060023=note: print w/replies, xml ) Need Help??

in reply to Re^3: Decent crypto library?

Thank you. 5.5 times slower. Not so bad.
```use strict;
use warnings;

use Digest::MD5 qw/md5_hex/;
use Time::HiRes qw/tv_interval gettimeofday/;
use Crypt::Mode::CBC;

my \$key = "\241(_E\203\223\337\322\317\214\24'\352\231\352\177W\\\6^\3
+21a\3\6:-qQ\r\225&\264";
my \$IV = "<C\202\305\377\305\205\24\211\321\257\372z\363\333\357";

my \$IV_hex = unpack('H*', \$IV);
my \$key_hex = unpack('H*', \$key);

my \$m = Crypt::Mode::CBC->new('AES');
my \$s = "x" x 100_000_000;

my \$ciphertext = \$m->encrypt(\$s, \$key, \$IV);

my (\$t0, \$t1);
\$t0 = [gettimeofday];
my \$ss = \$m->decrypt(\$ciphertext, \$key, \$IV);
\$t1 = [gettimeofday];

die unless \$ss eq \$s;

print "decrypt Crypt::Mode::CBC\t";
print tv_interval \$t0, \$t1;
print "\n";

open my \$f, ">", "/tmp/enctest";
binmode \$f;
print \$f \$ciphertext;
close \$f;

my \$sdata_md5 = md5_hex(\$s);

\$t0 = [gettimeofday];
system 'openssl', 'enc', '-aes-256-cbc', '-d', '-in', '/tmp/enctest',
+'-out', '/tmp/enctest.out', '-K',  \$key_hex, '-iv', \$IV_hex;
\$t1 = [gettimeofday];

print "decrypt OPENSSL\t";
print tv_interval \$t0, \$t1;
print "\n";
die unless `md5sum /tmp/enctest.out` =~ /\$sdata_md5/;
__END__
decrypt Crypt::Mode::CBC    0.91427
decrypt OPENSSL    0.149651

Create A New User
Node Status?
node history
Node Type: note [id://1060023]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2017-08-23 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (350 votes). Check out past polls.

Notices?