new digests SHA512_224 + SHA512_256
Karel Miko
9 years ago
10 | 10 | use File::Glob qw(bsd_glob); |
11 | 11 | |
12 | 12 | sub equal_files { |
13 | return 0 unless -f $_[0] && -f $_[1]; | |
13 | 14 | my $d1 = sha1_hex(read_file(shift, binmode => ':raw')); |
14 | 15 | my $d2 = sha1_hex(read_file(shift, binmode => ':raw')); |
15 | 16 | return $d1 eq $d2; |
34 | 35 | SHA256 => { ltc=>'sha256', info=>'Hash function SHA-256 [size: 256 bits]', urls=>['http://en.wikipedia.org/wiki/SHA-2'] }, |
35 | 36 | SHA384 => { ltc=>'sha384', info=>'Hash function SHA-384 [size: 384 bits]', urls=>['http://en.wikipedia.org/wiki/SHA-2'] }, |
36 | 37 | SHA512 => { ltc=>'sha512', info=>'Hash function SHA-512 [size: 512 bits]', urls=>['http://en.wikipedia.org/wiki/SHA-2'] }, |
38 | SHA512_224 => { ltc=>'sha512_224',info=>'Hash function SHA-512/224 [size: 224 bits]', urls=>['http://en.wikipedia.org/wiki/SHA-2'] }, | |
39 | SHA512_256 => { ltc=>'sha512_256',info=>'Hash function SHA-512/256 [size: 256 bits]', urls=>['http://en.wikipedia.org/wiki/SHA-2'] }, | |
37 | 40 | Tiger192 => { ltc=>'tiger', info=>'Hash function Tiger-192 [size: 192 bits]', urls=>['http://en.wikipedia.org/wiki/Tiger_(cryptography)'] }, |
38 | 41 | Whirlpool => { ltc=>'whirlpool', info=>'Hash function Whirlpool [size: 512 bits]', urls=>['http://en.wikipedia.org/wiki/Whirlpool_(cryptography)'] }, |
39 | 42 | ); |
80 | 83 | |
81 | 84 | my $t_out = catfile($outdir_t, "digest_".lc($n).".t"); |
82 | 85 | my $t_tt = Template->new(ABSOLUTE=>1) || die $Template::ERROR, "\n"; |
83 | $t_tt->process("$FindBin::Bin/Digest.t.tt", $data, "$t_out.$$") || die $t_tt->error(), "\n"; | |
86 | $t_tt->process("$FindBin::Bin/Digest.t.tt", $data, "$t_out.$$", {binmode=>1}) || die $t_tt->error(), "\n"; | |
84 | 87 | copy("$t_out.$$", $t_out) and warn("Writting '$t_out'\n") unless equal_files("$t_out.$$", $t_out); |
85 | 88 | unlink "$t_out.$$"; |
86 | 89 | } |
88 | 91 | if ($outdir_l) { |
89 | 92 | my $pm_out = catfile($outdir_l, "Crypt", "Digest", "$n.pm"); |
90 | 93 | my $pm_tt = Template->new(ABSOLUTE=>1) || die $Template::ERROR, "\n"; |
91 | $pm_tt->process("$FindBin::Bin/Digest.pm.tt", $data, $pm_out) || die $pm_tt->error(), "\n"; | |
94 | $pm_tt->process("$FindBin::Bin/Digest.pm.tt", $data, $pm_out, {binmode=>1}) || die $pm_tt->error(), "\n"; | |
92 | 95 | } |
93 | 96 | |
94 | 97 | } |
32 | 32 | RIPEMD256 => 'rmd256', |
33 | 33 | RIPEMD320 => 'rmd320', |
34 | 34 | TIGER192 => 'tiger', |
35 | SHA512_224=> 'sha512-224', | |
36 | SHA512_256=> 'sha512-256', | |
35 | 37 | ); |
36 | 38 | $name =~ s/^Crypt::Digest:://i; |
37 | 39 | return $trans{uc($name)} if defined $trans{uc($name)}; |
171 | 173 | |
172 | 174 | 'CHAES', 'MD2', 'MD4', 'MD5', 'RIPEMD128', 'RIPEMD160', |
173 | 175 | 'RIPEMD256', 'RIPEMD320', 'SHA1', 'SHA224', 'SHA256', |
174 | 'SHA384', 'SHA512', 'Tiger192', 'Whirlpool' | |
176 | 'SHA384', 'SHA512', 'SHA512_224', 'SHA512_256', 'Tiger192', 'Whirlpool' | |
175 | 177 | |
176 | 178 | (simply any <FUNCNAME> for which there is Crypt::Digest::<FUNCNAME> module) |
177 | 179 | |
249 | 251 | |
250 | 252 | $d = Crypt::Digest->new($name); |
251 | 253 | # $name could be: 'CHAES', 'MD2', 'MD4', 'MD5', 'RIPEMD128', 'RIPEMD160', |
252 | # 'RIPEMD256', 'RIPEMD320', 'SHA1', 'SHA224', 'SHA256', | |
253 | # 'SHA384', 'SHA512', 'Tiger192', 'Whirlpool' | |
254 | # 'RIPEMD256', 'RIPEMD320', 'SHA1', 'SHA224', 'SHA256', 'SHA384', | |
255 | # 'SHA512', 'SHA512_224', 'SHA512_256', 'Tiger192', 'Whirlpool' | |
254 | 256 | # |
255 | 257 | # simply any <FUNCNAME> for which there is Crypt::Digest::<FUNCNAME> module |
256 | 258 |
2 | 2 | use strict; |
3 | 3 | use warnings ; |
4 | 4 | |
5 | our $VERSION = '0.021'; | |
5 | our $VERSION = '0.021_2'; | |
6 | 6 | |
7 | 7 | require XSLoader; |
8 | 8 | XSLoader::load('CryptX', $VERSION); |
41 | 41 | |
42 | 42 | L<Crypt::Digest::CHAES>, L<Crypt::Digest::MD2>, L<Crypt::Digest::MD4>, L<Crypt::Digest::MD5>, L<Crypt::Digest::RIPEMD128>, L<Crypt::Digest::RIPEMD160>, |
43 | 43 | L<Crypt::Digest::RIPEMD256>, L<Crypt::Digest::RIPEMD320>, L<Crypt::Digest::SHA1>, L<Crypt::Digest::SHA224>, L<Crypt::Digest::SHA256>, L<Crypt::Digest::SHA384>, |
44 | L<Crypt::Digest::SHA512>, L<Crypt::Digest::Tiger192>, L<Crypt::Digest::Whirlpool> | |
44 | L<Crypt::Digest::SHA512>, L<Crypt::Digest::SHA512_224>, L<Crypt::Digest::SHA512_256>, L<Crypt::Digest::Tiger192>, L<Crypt::Digest::Whirlpool> | |
45 | 45 | |
46 | 46 | =item * Message Authentication Codes |
47 | 47 |
276 | 276 | if(register_hash(&sha256_desc)==-1) { croak("FATAL: cannot register_hash sha256"); } |
277 | 277 | if(register_hash(&sha384_desc)==-1) { croak("FATAL: cannot register_hash sha384"); } |
278 | 278 | if(register_hash(&sha512_desc)==-1) { croak("FATAL: cannot register_hash sha512"); } |
279 | if(register_hash(&sha512_224_desc)==-1) { croak("FATAL: cannot register_hash sha512_224"); } | |
280 | if(register_hash(&sha512_256_desc)==-1) { croak("FATAL: cannot register_hash sha512_256"); } | |
279 | 281 | if(register_hash(&tiger_desc)==-1) { croak("FATAL: cannot register_hash tiger"); } |
280 | 282 | if(register_hash(&whirlpool_desc)==-1) { croak("FATAL: cannot register_hash whirlpool"); } |
281 | 283 | /* --- */ |