Skip to content

Commit

Permalink
initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
gray committed Nov 9, 2010
0 parents commit 79c45ac
Show file tree
Hide file tree
Showing 30 changed files with 7,708 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
Digest-JH-*
JH.bs
JH.c
JH.o
MANIFEST.bak
Makefile
Makefile.old
blib/
pm_to_blib
4 changes: 4 additions & 0 deletions Changes
@@ -0,0 +1,4 @@
Revision history for Digest-JH

0.01 Tue Nov 9 19:03:59 UTC 2010
- Initial distribution.
109 changes: 109 additions & 0 deletions JH.xs
@@ -0,0 +1,109 @@
#define PERL_NO_GET_CONTEXT

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"

#include "src/sha3nist.c"
#include "src/jh.c"

typedef hashState *Digest__JH;

MODULE = Digest::JH PACKAGE = Digest::JH

PROTOTYPES: ENABLE

Digest::JH
new (class, hashsize)
SV *class
int hashsize
CODE:
Newx(RETVAL, 1, hashState);
if (Init(RETVAL, hashsize) != SUCCESS)
XSRETURN_UNDEF;
OUTPUT:
RETVAL

Digest::JH
clone (self)
Digest::JH self
CODE:
Newx(RETVAL, 1, hashState);
Copy(self, RETVAL, 1, hashState);
OUTPUT:
RETVAL

int
hashsize(self)
Digest::JH self
ALIAS:
algorithm = 1
CODE:
RETVAL = self->hashbitlen;
OUTPUT:
RETVAL

void
add (self, ...)
Digest::JH self
PREINIT:
int i;
unsigned char *data;
STRLEN len;
PPCODE:
for (i = 1; i < items; i++) {
data = (unsigned char *)(SvPV(ST(i), len));
if (Update(self, data, len << 3) != SUCCESS)
XSRETURN_UNDEF;
}
XSRETURN(1);

SV *
digest (self)
Digest::JH self
PREINIT:
unsigned char *result;
CODE:
Newx(result, self->hashbitlen >> 3, unsigned char);
if (Final(self, result) != SUCCESS)
XSRETURN_UNDEF;
RETVAL = newSVpv(result, self->hashbitlen >> 3);
Safefree(result);
OUTPUT:
RETVAL

void
DESTROY (self)
Digest::JH self
CODE:
Safefree(self);

SV *
jh_224 (...)
ALIAS:
jh_224 = 224
jh_256 = 256
jh_384 = 384
jh_512 = 512
PREINIT:
hashState ctx;
int i;
unsigned char *data;
unsigned char *result;
STRLEN len;
CODE:
if (Init(&ctx, ix) != SUCCESS)
XSRETURN_UNDEF;
for (i = 0; i < items; i++) {
data = (unsigned char *)(SvPV(ST(i), len));
if (Update(&ctx, data, len << 3) != SUCCESS)
XSRETURN_UNDEF;
}
Newx(result, ix >> 3, unsigned char);
if (Final(&ctx, result) != SUCCESS)
XSRETURN_UNDEF;
RETVAL = newSVpv(result, ix >> 3);
Safefree(result);
OUTPUT:
RETVAL
29 changes: 29 additions & 0 deletions MANIFEST
@@ -0,0 +1,29 @@
Changes
ex/benchmark.pl
JH.xs
lib/Digest/JH.pm
Makefile.PL
MANIFEST This list of files
ppport.h
README
src/jh.c
src/sha3nist.c
src/sha3nist.h
src/sph_jh.h
src/sph_types.h
t/00_load.t
t/01_new.t
t/224.t
t/256.t
t/384.t
t/512.t
typemap
xt/kwalitee.t
xt/leaktrace.t
xt/perlcritic.t
xt/perlcriticrc
xt/pod.t
xt/pod_coverage.t
xt/portability_filenames.t
xt/valgrind.t
xt/vars.t
50 changes: 50 additions & 0 deletions Makefile.PL
@@ -0,0 +1,50 @@
use strict;
use warnings;
use ExtUtils::MakeMaker;

my %conf = (
NAME => 'Digest::JH',
AUTHOR => 'gray <gray@cpan.org>',
LICENSE => 'perl',
VERSION_FROM => 'lib/Digest/JH.pm',
ABSTRACT_FROM => 'lib/Digest/JH.pm',
PREREQ_PM => {
Digest => 0,
'MIME::Base64' => 0,
parent => 0,
},
BUILD_REQUIRES => { 'Test::More' => 0.82, },
META_MERGE => {
resources => {
repository => 'http://github.com/gray/digest-jh',
},
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Digest-JH-*' },
);

my $eumm_version = do {
no warnings 'numeric';
eval $ExtUtils::MakeMaker::VERSION;
};
delete $conf{META_MERGE} if $eumm_version < 6.46;
$conf{PREREQ_PM} = {
%{ $conf{PREREQ_PM} || {} }, %{ delete $conf{BUILD_REQUIRES} },
} if ($conf{BUILD_REQUIRES} and $eumm_version < 6.5503);

WriteMakefile(%conf);


sub MY::postamble {
return <<" MAKE_FRAG";
authortest:
\t\$(MAKE) -e \$(TEST_TYPE) TEST_FILES="xt/*.t"
MAKE_FRAG
}

sub MY::dist_test {
my $self = shift;
return $self->MM::dist_test . <<" MAKE_FRAG";
\tcd \$(DISTVNAME) && \$(MAKE) authortest \$(PASTHRU)
MAKE_FRAG
}
31 changes: 31 additions & 0 deletions README
@@ -0,0 +1,31 @@
Digest-JH
=========

This module provides an interface to the JH message digest algorithm.

INSTALLATION

To install this module type the following:

perl Makefile.PL
make
make test
make install

DEPENDENCIES

This module requires these other modules and libraries:

Digest
MIME::Base64
Test::More
parent

A C compiler is required to build this module.

COPYRIGHT AND LICENCE

Copyright (C) 2010 by gray <gray@cpan.org>

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
115 changes: 115 additions & 0 deletions ex/benchmark.pl
@@ -0,0 +1,115 @@
#!/usr/bin/env perl
use strict;
use warnings;

use Benchmark qw(timethese);
use Getopt::Long qw(GetOptions :config no_ignore_case);
use List::Util qw(max);

use Digest::BLAKE ();
use Digest::BMW ();
use Digest::CubeHash ();
use Digest::ECHO ();
use Digest::Fugue ();
use Digest::JH ();
use Digest::Keccak ();
use Digest::Luffa ();
use Digest::MD5 ();
use Digest::MD6 ();
use Digest::SHA ();
use Digest::SIMD ();
use Digest::Shabal ();
use Digest::Skein ();
use Digest::Whirlpool ();

my %opts = (
iterations => -1,
size => 1, # KB
);
GetOptions(\%opts, 'iterations|i=i', 'size|s=f',);

my $data = '01234567' x (128 * $opts{size});

my %digests = (
blake_224 => sub { Digest::BLAKE::blake_224($data) },
blake_256 => sub { Digest::BLAKE::blake_256($data) },
blake_384 => sub { Digest::BLAKE::blake_384($data) },
blake_512 => sub { Digest::BLAKE::blake_512($data) },
bmw_224 => sub { Digest::BMW::bmw_224($data) },
bmw_256 => sub { Digest::BMW::bmw_256($data) },
bmw_384 => sub { Digest::BMW::bmw_384($data) },
bmw_512 => sub { Digest::BMW::bmw_512($data) },
cubehash_224 => sub { Digest::CubeHash::cubehash_224($data) },
cubehash_256 => sub { Digest::CubeHash::cubehash_256($data) },
cubehash_384 => sub { Digest::CubeHash::cubehash_384($data) },
cubehash_512 => sub { Digest::CubeHash::cubehash_512($data) },
echo_224 => sub { Digest::ECHO::echo_224($data) },
echo_256 => sub { Digest::ECHO::echo_256($data) },
echo_384 => sub { Digest::ECHO::echo_384($data) },
echo_512 => sub { Digest::ECHO::echo_512($data) },
keccak_224 => sub { Digest::Keccak::keccak_224($data) },
fugue_224 => sub { Digest::Fugue::fugue_224($data) },
fugue_256 => sub { Digest::Fugue::fugue_256($data) },
fugue_384 => sub { Digest::Fugue::fugue_384($data) },
fugue_512 => sub { Digest::Fugue::fugue_512($data) },
jh_224 => sub { Digest::JH::jh_224($data) },
jh_256 => sub { Digest::JH::jh_256($data) },
jh_384 => sub { Digest::JH::jh_384($data) },
jh_512 => sub { Digest::JH::jh_512($data) },
keccak_256 => sub { Digest::Keccak::keccak_256($data) },
keccak_384 => sub { Digest::Keccak::keccak_384($data) },
keccak_512 => sub { Digest::Keccak::keccak_512($data) },
luffa_224 => sub { Digest::Luffa::luffa_224($data) },
luffa_256 => sub { Digest::Luffa::luffa_256($data) },
luffa_384 => sub { Digest::Luffa::luffa_384($data) },
luffa_512 => sub { Digest::Luffa::luffa_512($data) },
md5 => sub { Digest::MD5::md5($data) },
md6_224 => sub { Digest::MD6::md6_224($data) },
md6_256 => sub { Digest::MD6::md6_256($data) },
md6_384 => sub { Digest::MD6::md6_384($data) },
md6_512 => sub { Digest::MD6::md6_512($data) },
sha1 => sub { Digest::SHA::sha1($data) },
sha_224 => sub { Digest::SHA::sha224($data) },
sha_384 => sub { Digest::SHA::sha256($data) },
sha_256 => sub { Digest::SHA::sha384($data) },
sha_512 => sub { Digest::SHA::sha512($data) },
simd_224 => sub { Digest::SIMD::simd_224($data) },
simd_256 => sub { Digest::SIMD::simd_256($data) },
simd_384 => sub { Digest::SIMD::simd_384($data) },
simd_512 => sub { Digest::SIMD::simd_512($data) },
shabal_224 => sub { Digest::Shabal::shabal_224($data) },
shabal_256 => sub { Digest::Shabal::shabal_256($data) },
shabal_384 => sub { Digest::Shabal::shabal_384($data) },
shabal_512 => sub { Digest::Shabal::shabal_512($data) },
skein_256 => sub { Digest::Skein::skein_256($data) },
skein_512 => sub { Digest::Skein::skein_512($data) },
skein_1024 => sub { Digest::Skein::skein_1024($data) },
whirlpool => sub { Digest::Whirlpool->new->add($data)->digest },
);

my $times = timethese -1, \%digests, 'none';

my @info;
my ($max_name_len, $max_rate_len, $max_bw_len) = (0, 0, 0);

while (my ($name, $info) = each %$times) {
my ($duration, $cycles) = @{$info}[ 1, 5 ];
my $rate = sprintf '%.0f', $cycles / $duration;
my $bw = sprintf '%.0f', $rate * $opts{size} / 1024;

push @info, [$name, $rate, $bw];

$max_name_len = max $max_name_len, length($name);
$max_rate_len = max $max_rate_len, length($rate);
$max_bw_len = max $max_bw_len, length($bw);
}

for my $rec (sort { $a->[1] <=> $b->[1] } @info) {
my ($name, $rate, $bw) = @$rec;

my $name_padding = $max_name_len - length($name);

printf "%s%s %${max_rate_len}s/s %${max_bw_len}s MB/s\n",
$name, ' 'x$name_padding, $rate, $bw;
}

0 comments on commit 79c45ac

Please sign in to comment.