r13455 - in /branches/upstream/libcrypt-openssl-random-perl: ./ current/ current/Changes current/MANIFEST current/Makefile.PL current/Random.pm current/Random.xs current/test.pl
dmn at users.alioth.debian.org
dmn at users.alioth.debian.org
Thu Jan 24 19:09:47 UTC 2008
Author: dmn
Date: Thu Jan 24 19:09:47 2008
New Revision: 13455
URL: http://svn.debian.org/wsvn/?sc=1&rev=13455
Log:
[svn-inject] Installing original source of libcrypt-openssl-random-perl
Added:
branches/upstream/libcrypt-openssl-random-perl/
branches/upstream/libcrypt-openssl-random-perl/current/
branches/upstream/libcrypt-openssl-random-perl/current/Changes
branches/upstream/libcrypt-openssl-random-perl/current/MANIFEST
branches/upstream/libcrypt-openssl-random-perl/current/Makefile.PL
branches/upstream/libcrypt-openssl-random-perl/current/Random.pm
branches/upstream/libcrypt-openssl-random-perl/current/Random.xs
branches/upstream/libcrypt-openssl-random-perl/current/test.pl
Added: branches/upstream/libcrypt-openssl-random-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-random-perl/current/Changes?rev=13455&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-random-perl/current/Changes (added)
+++ branches/upstream/libcrypt-openssl-random-perl/current/Changes Thu Jan 24 19:09:47 2008
@@ -1,0 +1,12 @@
+Revision history for Perl extension Crypt::OpenSSL::Random.
+
+0.03 Thu Sep 06 23:05:36
+ - Added documentation
+
+0.02 Mon Apr 9 18:55:30 2001
+ - Got rid of perl 5.6 dependencies. Bad perl! Bad!
+
+0.01 Sun Apr 8 15:25:10 2001
+ - original version; created by h2xs 1.20 with options
+ -n Crypt::OpenSSL::Random
+
Added: branches/upstream/libcrypt-openssl-random-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-random-perl/current/MANIFEST?rev=13455&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-random-perl/current/MANIFEST (added)
+++ branches/upstream/libcrypt-openssl-random-perl/current/MANIFEST Thu Jan 24 19:09:47 2008
@@ -1,0 +1,6 @@
+Changes
+MANIFEST
+Makefile.PL
+Random.pm
+Random.xs
+test.pl
Added: branches/upstream/libcrypt-openssl-random-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-random-perl/current/Makefile.PL?rev=13455&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-random-perl/current/Makefile.PL (added)
+++ branches/upstream/libcrypt-openssl-random-perl/current/Makefile.PL Thu Jan 24 19:09:47 2008
@@ -1,0 +1,11 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+ 'NAME' => 'Crypt::OpenSSL::Random',
+ 'VERSION_FROM' => 'Random.pm', # finds $VERSION
+ 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1
+ 'LIBS' => ['-lssl -lcrypto'], # e.g., '-lm'
+ 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING'
+ 'INC' => '', # e.g., '-I/usr/include/other'
+);
Added: branches/upstream/libcrypt-openssl-random-perl/current/Random.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-random-perl/current/Random.pm?rev=13455&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-random-perl/current/Random.pm (added)
+++ branches/upstream/libcrypt-openssl-random-perl/current/Random.pm Thu Jan 24 19:09:47 2008
@@ -1,0 +1,111 @@
+package Crypt::OpenSSL::Random;
+
+use strict;
+use Carp;
+
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+
+require Exporter;
+require DynaLoader;
+use AutoLoader;
+
+ at ISA = qw(Exporter DynaLoader);
+
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+
+ at EXPORT_OK = qw( random_bytes random_pseudo_bytes random_seed
+ random_egd random_status );
+
+$VERSION = '0.03';
+
+bootstrap Crypt::OpenSSL::Random $VERSION;
+
+# Preloaded methods go here.
+
+# Autoload methods go after =cut, and are processed by the autosplit program.
+
+1;
+__END__
+
+=head1 NAME
+
+Crypt::OpenSSL::RSA - RSA encoding and decoding, using the openSSL libraries
+
+Crypt::OpenSSL::Random - Routines for accessing the OpenSSL
+pseudo-random number generator
+
+=head1 SYNOPSIS
+
+ use Crypt::OpenSSL::Random;
+
+ Crypt::OpenSSL::Random::random_seed($good_random_data);
+ Crypt::OpenSSL::Random::random_egd("/tmp/entropy");
+ Crypt::OpenSSL::Random::random_status() or
+ die "Unable to sufficiently seed the random number generator".
+
+ my $ten_good_random_bytes = Crypt::OpenSSL::Random::random_bytes(10);
+ my $ten_ok_random_bytes = Crypt::OpenSSL::Random::random_pseudo_bytes(10);
+
+=head1 DESCRIPTION
+
+Crypt::OpenSSL::Random provides the ability to seed and query the
+OpenSSL library's pseudo-random number generator
+
+=head2 EXPORT
+
+None by default.
+
+=head1 Static Methods
+
+=item random_bytes
+
+This function, returns a specified number of cryptographically strong
+pseudo-random bytes from the PRNG. If the PRNG has not been seeded
+with enough randomness to ensure an unpredictable byte sequence, then
+a false value is returned.
+
+=item random_pseudo_bytes
+
+This function, is similar to c<random_bytes>, but the resulting
+sequence of bytes are not necessarily unpredictable. They can be used
+for non-cryptographic purposes and for certain purposes in
+cryptographic protocols, but usually not for key generation etc.
+
+=item random_seed
+
+This function seeds the PRNG with a supplied string of bytes. It
+returns true if the PRNG has sufficient seeding. Note: calling this
+function with non-random bytes is of limited value at best!
+
+=item random_egd
+
+This function seeds the PRNG with data from the specified entropy
+gathering daemon. Returns the number of bytes read from the daemon on
+succes, or -1 if not enough bytes were read, or if the connection to
+the daemon failed.
+
+=item random_status
+
+This function returns true if the PRNG has sufficient seeding.
+
+=head1 BUGS
+
+Because of the internal workings of OpenSSL's random library, the
+pseudo-random number generator (PRNG) accessed by
+Crypt::OpenSSL::Random will be different than the one accessed by any
+other perl module. Hence, to use a module such as
+Crypt::OpenSSL::Random, you will need to seed the PRNG used there from
+one used here. This class is still advantageous, however, as it
+centralizes other methods, such as random_egd, in one place.
+
+=head1 AUTHOR
+
+Ian Robertson, iroberts at cpan.com
+
+=head1 SEE ALSO
+
+perl(1), rand(3), RAND_add(3), RAND_egd(3), RAND_bytes(3).
+
+=cut
Added: branches/upstream/libcrypt-openssl-random-perl/current/Random.xs
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-random-perl/current/Random.xs?rev=13455&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-random-perl/current/Random.xs (added)
+++ branches/upstream/libcrypt-openssl-random-perl/current/Random.xs Thu Jan 24 19:09:47 2008
@@ -1,0 +1,100 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#include <openssl/rand.h>
+
+#define PACKAGE_NAME "Crypt::OpenSSL::RSA"
+
+MODULE = Crypt::OpenSSL::Random PACKAGE = Crypt::OpenSSL::Random
+void
+random_bytes(num_bytes_SV)
+ SV * num_bytes_SV;
+PPCODE:
+{
+ unsigned char *rand_bytes;
+ int num_bytes = SvIV(num_bytes_SV);
+ if(New(0,rand_bytes, num_bytes, unsigned char) == NULL)
+ {
+ croak ("unable to allocate buffer for random bytes in package "
+ PACKAGE_NAME);
+ }
+
+ if(RAND_bytes(rand_bytes, num_bytes))
+ {
+ XPUSHs(sv_2mortal(newSVpv(rand_bytes, num_bytes)));
+ Safefree(rand_bytes);
+ XSRETURN(1);
+ }
+ else
+ {
+ XSRETURN_NO;
+ }
+}
+
+void
+random_pseudo_bytes(num_bytes_SV)
+ SV * num_bytes_SV;
+PPCODE:
+{
+ unsigned char *rand_bytes;
+ int num_bytes = SvIV(num_bytes_SV);
+ if(New(0,rand_bytes, num_bytes, unsigned char) == NULL)
+ {
+ croak ("unable to allocate buffer for random bytes in package "
+ PACKAGE_NAME);
+ }
+
+ if(RAND_bytes(rand_bytes, num_bytes))
+ {
+ XPUSHs(sv_2mortal(newSVpv(rand_bytes, num_bytes)));
+ Safefree(rand_bytes);
+ XSRETURN(1);
+ }
+ else
+ {
+ XSRETURN_NO;
+ }
+}
+
+ # Seed the PRNG with user-provided bytes; returns true if the
+ # seeding was sufficient.
+
+void
+random_seed(random_bytes_SV)
+ SV * random_bytes_SV;
+PPCODE:
+{
+ int random_bytes_length;
+ char *random_bytes;
+ random_bytes = SvPV(random_bytes_SV, random_bytes_length);
+ RAND_seed(random_bytes, random_bytes_length);
+ XPUSHs( sv_2mortal( newSViv( RAND_status() ) ) );
+}
+
+ # Seed the PRNG with data from the indicated EntropyGatheringDaemon;
+ # returns the number of bytes gathered, or -1 if there was a
+ # connection failure or if the PRNG is still insufficiently seeded.
+
+void
+random_egd(egd_SV)
+ SV * egd_SV;
+PPCODE:
+{
+ int random_bytes_length;
+ char *random_bytes;
+ int status;
+ char *egd = SvPV(egd_SV, random_bytes_length);
+ status = RAND_egd(egd);
+ XPUSHs( sv_2mortal( newSViv( status ) ) );
+}
+
+ # Returns true if the PRNG has enough seed data
+
+void
+random_status()
+PPCODE:
+{
+ XPUSHs( sv_2mortal( newSViv( RAND_status() ) ) );
+}
+
Added: branches/upstream/libcrypt-openssl-random-perl/current/test.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-random-perl/current/test.pl?rev=13455&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-random-perl/current/test.pl (added)
+++ branches/upstream/libcrypt-openssl-random-perl/current/test.pl Thu Jan 24 19:09:47 2008
@@ -1,0 +1,43 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl test.pl'
+
+######################### We start with some black magic to print on failure.
+
+# Change 1..1 below to 1..last_test_to_print .
+# (It may become useful if the test is moved to ./t subdirectory.)
+
+BEGIN { $| = 1; print "1..1\n"; }
+END {print "not ok 1\n" unless $loaded;}
+use Crypt::OpenSSL::Random;
+$loaded = 1;
+print "ok 1\n";
+
+######################### End of black magic.
+
+# Insert your test code below (better if it prints "ok 13"
+# (correspondingly "not ok 13") depending on the success of chunk 13
+# of the test code):
+
+my $test_number = 2;
+sub my_test
+{
+ my($cond) = @_;
+ my $number = $test_number++;
+ if ($cond)
+ {
+ print "ok $number\n";
+ }
+ else
+ {
+ my ($pack, $file, $line) = caller;
+ print "not ok $number - from $file:$line\n";
+ }
+}
+
+Crypt::OpenSSL::Random::random_seed("Here are 19 bytes...");
+
+# We should now be seeded, regardless.
+my_test(Crypt::OpenSSL::Random::random_status());
+
+my_test(length(Crypt::OpenSSL::Random::random_bytes(53)), 53);
+my_test(length(Crypt::OpenSSL::Random::random_pseudo_bytes(53)), 53);
More information about the Pkg-perl-cvs-commits
mailing list