r13445 - in /branches/upstream/libcrypt-openssl-bignum-perl: ./ current/ current/Bignum.pm current/Bignum.xs current/Bignum/ current/Bignum/CTX.pm current/Changes current/MANIFEST current/Makefile.PL current/README current/test.pl current/typemap

dmn at users.alioth.debian.org dmn at users.alioth.debian.org
Thu Jan 24 18:59:15 UTC 2008


Author: dmn
Date: Thu Jan 24 18:59:15 2008
New Revision: 13445

URL: http://svn.debian.org/wsvn/?sc=1&rev=13445
Log:
[svn-inject] Installing original source of libcrypt-openssl-bignum-perl

Added:
    branches/upstream/libcrypt-openssl-bignum-perl/
    branches/upstream/libcrypt-openssl-bignum-perl/current/
    branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum/
    branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.pm
    branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.xs
    branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum/CTX.pm
    branches/upstream/libcrypt-openssl-bignum-perl/current/Changes
    branches/upstream/libcrypt-openssl-bignum-perl/current/MANIFEST
    branches/upstream/libcrypt-openssl-bignum-perl/current/Makefile.PL
    branches/upstream/libcrypt-openssl-bignum-perl/current/README
    branches/upstream/libcrypt-openssl-bignum-perl/current/test.pl
    branches/upstream/libcrypt-openssl-bignum-perl/current/typemap

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.pm?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.pm (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.pm Thu Jan 24 18:59:15 2008
@@ -1,0 +1,228 @@
+package Crypt::OpenSSL::Bignum;
+
+use 5.005;
+use strict;
+use Carp;
+
+use vars qw( $VERSION @ISA );
+
+require DynaLoader;
+
+ at ISA = qw(DynaLoader);
+
+$VERSION = '0.03';
+
+bootstrap Crypt::OpenSSL::Bignum $VERSION;
+
+sub DESTROY
+{
+    shift->_free_BN();
+}
+
+sub bless_pointer
+{
+    my( $proto, $p_pointer ) = @_;
+    return bless( \$p_pointer, $proto );
+}
+
+sub equals
+{
+    my( $self, $a ) = @_;
+    return ! $self->cmp( $a );
+}
+
+
+1;
+__END__
+
+=head1 NAME
+
+Crypt::OpenSSL::Bignum - OpenSSL's multiprecision integer arithmetic
+
+=head1 SYNOPSIS
+
+  use Crypt::OpenSSL::Bignum;
+
+  my $bn = Crypt::OpenSSL::Bignum->new_from_decimal( "1000" );
+  # or
+  my $bn = Crypt::OpenSSL::Bignum->new_from_word( 1000 );
+  # or
+  my $bn = Crypt::OpenSSL::Bignum->new_from_hex("0x3e8");
+  # or
+  my $bn = Crypt::OpenSSL::Bignum->new_from_bin(pack( "C*", 3, 232 ))
+
+  use Crypt::OpenSSL::Bignum::CTX;
+
+  sub print_factorial
+  {
+    my( $n ) = @_;
+    my $fac = Crypt::OpenSSL::Bignum->one();
+    my $ctx = Crypt::OpenSSL::Bignum::CTX->new();
+    foreach my $i (1 .. $n)
+    {
+      $fac->mul( Crypt::OpenSSL::Bignum->new_from_word( $i ), $ctx, $fac );
+    }
+    print "$n factorial is ", $fac->to_decimal(), "\n";
+  }
+
+=head1 DESCRIPTION
+
+Crypt::OpenSSL::Bignum provides access to OpenSSL multiprecision
+integer arithmetic libraries.  Presently, many though not all of the
+arithmetic operations that OpenSSL provides are exposed to perl.  In
+addition, this module can be used to provide access to bignum values
+produced by other OpenSSL modules, such as key parameters from
+Crypt::OpenSSL::RSA.
+
+I<NOTE>: Many of the methods in this package can croak, so use eval, or
+Error.pm's try/catch mechanism to capture errors.
+
+=head1 Class Methods
+
+=over
+
+=item new_from_word
+
+Create a new Crypt::OpenSSL::Bignum object whose value will be the
+word given.  Note that numbers represneted by objects created using
+this method are necessarily between 0 and 2^32 - 1.
+
+=item new_from_decimal
+
+Create a new Crypt::OpenSSL::Bignum object whose value is specified by
+the given decimal representation.
+
+=item new_from_hex
+
+Create a new Crypt::OpenSSL::Bignum object whose value is specified by
+the given hexidecimal representation.
+
+=item new_from_bin
+
+Create a new Crypt::OpenSSL::Bignum object whose value is specified by
+the given packed binary string.  Note that objects created using this
+method are necessarily nonnegative.
+
+=item zero
+
+Returns a new Crypt::OpenSSL::Bignum object representing 0
+
+=item one
+
+Returns a new Crypt::OpenSSL::Bignum object representing 1
+
+=item bless_pointer
+
+Given a pointer to a OpenSSL BIGNUM object in memory, construct and
+return Crypt::OpenSSL::Bignum object around this.  Note that the
+underlying BIGNUM object will be destroyed (via BN_clear_free(3ssl))
+when the returned Crypt::OpenSSL::Bignum object is no longer
+referenced, so the pointer passed to this method should only be
+referenced via the returned perl object after calling bless_pointer.
+
+This method is intended only for use by XSUB writers writing code that
+interfaces with OpenSSL library methods, and who wish to be able to
+return a BIGNUM structure to perl as a Crypt::OpenSSL::Bignum object.
+
+=back
+
+=head1 Instance Methods
+
+=over
+
+=item to_decimal
+
+Return a decimal string representation of this object.
+
+=item to_hex
+
+Return a hexidecimal string representation of this object.
+
+=item to_bin
+
+Return a packed binary string representation of this object.  Note
+that sign is ignored, so that to bin called on a
+Crypt::OpenSSL::Bignum object representing a negative number returns
+the same value as it would called on an object representing that
+number's absolute value.
+
+=item get_word
+
+Return a scalar integer representation of this object, if it can be
+represented as an unsigned long.
+
+=item is_zero
+
+Returns true of this object represents 0.
+
+=item is_one
+
+Returns true of this object represents 1.
+
+=item is_odd
+
+Returns true of this object represents an odd number.
+
+=item copy
+
+Returns a copy of this object.
+
+=item add
+
+This method returns the sum of this object and the first argument.  If
+only one argument is passed, a new Crypt::OpenSSL::Bignum object is
+created for the return value; otherwise, the value of second argument
+is set to the result and returned.
+
+=item sub
+
+This method returns the difference of this object and the first
+argument.  If only one argument is passed, a new
+Crypt::OpenSSL::Bignum object is created for the return value;
+otherwise, the value of second argument is set to the result and
+returned.
+
+=item mul
+
+This method returns the product of this object and the first argument,
+using the second argument, a Crypt::OpenSSL::Bignum::CTX object, as a
+scratchpad.  If only two arguments are passed, a new
+Crypt::OpenSSL::Bignum object is created for the return value;
+otherwise, the value of third argument is set to the result and
+returned.
+
+=item mul
+
+This method returns a list consisting of quotient and the remainder
+obtained by dividing this object by the first argument, using the
+second argument, a Crypt::OpenSSL::Bignum::CTX object, as a
+scratchpad.  If only two arguments are passed, new
+Crypt::OpenSSL::Bignum objects is created for both return values.  If
+a third argument is passed, otherwise, the value of third argument is
+set to the quotient.  If a fourth argument is passed, the value of the
+fourth argument is set to the remainder.
+
+=item pointer_copy
+
+This method is intended only for use by XSUB writers wanting to have
+access to the underlying BIGNUM structure referenced by a
+Crypt::OpenSSL::Bignum perl object so that they can pass them to other
+routines in the OpenSSL library.  It returns a perl scalar whose IV
+can be cast to a BIGNUM* value.  This can then be passed to an XSUB
+which can work with the BIGNUM directly.  Note that the BIGNUM object
+pointed to will be a copy of the BIGNUM object wrapped by the
+instance; it is thus the responsiblity of the client to free space
+allocated by this BIGNUM object if and when it is done with it. See
+also bless_pointer.
+
+=back
+
+=head1 AUTHOR
+
+Ian Robertson, iroberts at cpan.org
+
+=head1 SEE ALSO
+
+L<perl>, L<bn(3ssl)>
+
+=cut

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.xs
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.xs?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.xs (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum.xs Thu Jan 24 18:59:15 2008
@@ -1,0 +1,384 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#include <openssl/ssl.h>
+#include <openssl/bn.h>
+
+#define checkOpenSslCall( result ) if( ! ( result ) ) \
+  croak( "OpenSSL error: %s", ERR_reason_error_string( ERR_get_error() ) );
+
+SV* new_obj( SV * p_proto, void* obj )
+{
+    return sv_2mortal( sv_bless( newRV_noinc( newSViv( (IV)obj ) ),
+                                 ( SvROK( p_proto )
+                                   ? SvSTASH( SvRV( p_proto ) )
+                                   : gv_stashsv( p_proto, 1 ) ) ) );
+}
+
+#define proto_obj( obj ) new_obj( ST(0), obj )
+
+BIGNUM* sv2bn( SV* sv )
+{
+    if( ! SvROK( sv ) )
+    {
+      croak( "argument is not a Crypt::OpenSSL::Bignum object" );
+    }
+    return (BIGNUM*) SvIV( SvRV( sv ) );
+}
+
+MODULE = Crypt::OpenSSL::Bignum      PACKAGE = Crypt::OpenSSL::Bignum   PREFIX=BN_
+
+BOOT:
+    ERR_load_crypto_strings();
+
+void
+_free_BN(self)
+    BIGNUM* self;
+  CODE:
+    BN_clear_free( self );
+
+BIGNUM*
+new_from_word(p_proto, p_word)
+    SV* p_proto;
+    unsigned long p_word;
+  PREINIT:
+    BIGNUM* bn;
+  CODE:
+    checkOpenSslCall( bn = BN_new() );
+    checkOpenSslCall( BN_set_word( bn, p_word ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+new_from_decimal(p_proto, p_dec_string)
+    SV* p_proto;
+    char* p_dec_string;
+  PREINIT:
+    BIGNUM* bn;
+  CODE:
+    bn = NULL;
+    checkOpenSslCall( BN_dec2bn( &bn, p_dec_string ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+new_from_hex(p_proto, p_hex_string)
+    SV* p_proto;
+    char* p_hex_string;
+  PREINIT:
+    BIGNUM* bn;
+  CODE:
+    bn = NULL;
+    checkOpenSslCall( BN_hex2bn( &bn, p_hex_string ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+new_from_bin(p_proto, p_bin_string_SV)
+    SV* p_proto;
+    SV* p_bin_string_SV;
+  PREINIT:
+    BIGNUM* bn;
+    char* bin;
+    STRLEN bin_length;
+  CODE:
+    bin = SvPV( p_bin_string_SV, bin_length );
+    checkOpenSslCall( bn = BN_bin2bn( bin, bin_length, NULL ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+zero(p_proto)
+    SV* p_proto;
+  PREINIT:
+    BIGNUM *bn;
+  CODE:
+    checkOpenSslCall( bn = BN_new() );
+    checkOpenSslCall( BN_zero( bn ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+one(p_proto)
+    SV* p_proto;
+  PREINIT:
+    BIGNUM *bn;
+  CODE:
+    checkOpenSslCall( bn = BN_new() );
+    checkOpenSslCall( BN_one( bn ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+
+
+char*
+to_decimal(self)
+    BIGNUM* self;
+  CODE:
+    checkOpenSslCall( RETVAL = BN_bn2dec( self ) );
+  OUTPUT:
+    RETVAL
+  CLEANUP:
+    OPENSSL_free( RETVAL );
+
+
+char*
+to_hex(self)
+    BIGNUM* self;
+  CODE:
+    checkOpenSslCall( RETVAL = BN_bn2hex( self ) );
+  OUTPUT:
+    RETVAL
+  CLEANUP:
+    OPENSSL_free( RETVAL );
+
+SV*
+to_bin(self)
+    BIGNUM* self;
+  PREINIT:
+    char* bin;
+    int length;
+  CODE:
+    length = BN_num_bytes( self );
+    New( 0, bin, length, char );
+    BN_bn2bin( self, bin );
+    RETVAL = newSVpv( bin, length );
+    Safefree( bin );
+  OUTPUT:
+    RETVAL
+
+unsigned long
+BN_get_word(self)
+    BIGNUM* self;
+
+PROTOTYPES: DISABLE
+
+SV*
+add(a, b, ...)
+    BIGNUM* a;
+    BIGNUM* b;
+  PREINIT:
+    BIGNUM *bn;
+  PPCODE:
+    if( items > 3 )
+      croak( "usage: $bn->add( $bn2[, $target] )" );
+    bn = ( items < 3 ) ? BN_new() : sv2bn( ST(2) );
+    checkOpenSslCall( BN_add( bn, a, b ) );
+    ST(0) = ( (items < 3 ) ? proto_obj( bn ) : ST(2) );
+    XSRETURN(1);
+
+SV*
+sub(a, b, ...)
+    BIGNUM* a;
+    BIGNUM* b;
+  PREINIT:
+    BIGNUM *bn;
+  PPCODE:
+    if( items > 3 )
+      croak( "usage: $bn->sub( $bn2[, $target] )" );
+    bn = ( items < 3 ) ? BN_new() : sv2bn( ST(2) );
+    checkOpenSslCall( BN_sub( bn, a, b ) );
+    ST(0) = ( (items < 3 ) ? proto_obj( bn ) : ST(2) );
+    XSRETURN(1);
+
+SV*
+mul(a, b, ctx, ...)
+    BIGNUM* a;
+    BIGNUM* b;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+  PPCODE:
+    if( items > 4 )
+      croak( "usage: $bn->mul( $bn2, $ctx, [, $target] )" );
+    bn = ( items < 4 ) ? BN_new() : sv2bn( ST(3) );
+    checkOpenSslCall( BN_mul( bn, a, b, ctx ) );
+    ST(0) = ( (items < 4 ) ? proto_obj( bn ) : ST(3) );
+    XSRETURN(1);
+
+SV*
+div(a, b, ctx, ...)
+    BIGNUM* a;
+    BIGNUM* b;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* quotient;
+    BIGNUM* remainder;
+  PPCODE:
+    if( items > 5 )
+      croak( "usage: $bn->add( $bn2, $ctx, [, $quotient [, $remainder ] ] )" );
+    quotient = ( items < 4 ) ? BN_new() : sv2bn( ST(3) );
+    remainder = ( items < 5 ) ? BN_new() : sv2bn( ST(4) );
+    checkOpenSslCall( BN_div( quotient, remainder, a, b, ctx ) );
+    ST(0) = ( (items < 4 ) ? proto_obj( quotient ) : ST(3) );
+    ST(1) = ( (items < 5 ) ? proto_obj( remainder ) : ST(4) );
+    XSRETURN(2);
+
+BIGNUM*
+sqr(a, ctx)
+    BIGNUM* a;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+    SV* p_proto;
+  CODE:
+    p_proto = ST(0);
+    bn = BN_new();
+    checkOpenSslCall( BN_sqr( bn, a, ctx ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+SV*
+mod(a, b, ctx, ...)
+    BIGNUM* a;
+    BIGNUM* b;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+  PPCODE:
+    if( items > 4 )
+      croak( "usage: $bn->add( $bn2, $ctx, [, $target] )" );
+    bn = ( items < 4 ) ? BN_new() : sv2bn( ST(3) );
+    checkOpenSslCall( BN_mod( bn, a, b, ctx ) );
+    ST(0) = ( (items < 4 ) ? proto_obj( bn ) : ST(3) );
+    XSRETURN(1);
+
+BIGNUM*
+mod_mul(a, b, m, ctx)
+    BIGNUM* a;
+    BIGNUM* b;
+    BIGNUM* m;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+    SV* p_proto;
+  CODE:
+    p_proto = ST(0);
+    bn = BN_new();
+    checkOpenSslCall( BN_mod_mul( bn, a, b, m, ctx ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+exp(a, p, ctx)
+    BIGNUM* a;
+    BIGNUM* p;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+    SV* p_proto;
+  CODE:
+    p_proto = ST(0);
+    bn = BN_new();
+    checkOpenSslCall( BN_exp( bn, a, p, ctx ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+mod_exp(a, p, m, ctx)
+    BIGNUM* a;
+    BIGNUM* p;
+    BIGNUM* m;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+    SV* p_proto;
+  CODE:
+    p_proto = ST(0);
+    bn = BN_new();
+    checkOpenSslCall( BN_mod_exp( bn, a, p, m, ctx ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+mod_inverse(a, n, ctx)
+    BIGNUM* a;
+    BIGNUM* n;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+    SV* p_proto;
+  CODE:
+    p_proto = ST(0);
+    bn = BN_new();
+    checkOpenSslCall( BN_mod_inverse( bn, a, n, ctx ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+BIGNUM*
+gcd(a, b, ctx)
+    BIGNUM* a;
+    BIGNUM* b;
+    BN_CTX* ctx;
+  PREINIT:
+    BIGNUM* bn;
+    SV* p_proto;
+  CODE:
+    p_proto = ST(0);
+    bn = BN_new();
+    checkOpenSslCall( BN_gcd( bn, a, b, ctx ) );
+    RETVAL = bn;
+  OUTPUT:
+    RETVAL
+
+int
+BN_cmp(a, b)
+    BIGNUM* a;
+    BIGNUM* b;
+
+int
+BN_is_zero(a)
+    BIGNUM* a;
+
+int
+BN_is_one(a)
+    BIGNUM* a;
+
+int
+BN_is_odd(a)
+    BIGNUM* a;
+
+BIGNUM*
+copy(a)
+    BIGNUM* a;
+  PREINIT:
+    SV* p_proto;
+  CODE:
+    p_proto = ST(0);
+    checkOpenSslCall( RETVAL = BN_dup(a) );
+  OUTPUT:
+    RETVAL
+
+IV
+pointer_copy(a)
+    BIGNUM* a;
+  PREINIT:
+  CODE:
+    checkOpenSslCall( RETVAL = (IV) BN_dup(a) );
+  OUTPUT:
+    RETVAL
+
+MODULE = Crypt::OpenSSL::Bignum  PACKAGE = Crypt::OpenSSL::Bignum::CTX PREFIX=BN_CTX_
+
+BN_CTX*
+BN_CTX_new(p_proto)
+    SV* p_proto;
+  C_ARGS:
+
+void
+_free_BN_CTX(self)
+    BN_CTX* self;
+  CODE:
+    BN_CTX_free( self );

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum/CTX.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum/CTX.pm?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum/CTX.pm (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/Bignum/CTX.pm Thu Jan 24 18:59:15 2008
@@ -1,0 +1,46 @@
+package Crypt::OpenSSL::Bignum::CTX;
+
+use 5.005;
+use strict;
+use Carp;
+
+use Crypt::OpenSSL::Bignum;
+use vars qw( @ISA );
+
+require DynaLoader;
+
+ at ISA = qw(DynaLoader);
+
+bootstrap Crypt::OpenSSL::Bignum $Crypt::OpenSSL::Bignum::VERSION;
+
+sub DESTROY
+{
+    shift->_free_BN_CTX();
+}
+
+1;
+__END__
+# Below is stub documentation for your module. You better edit it!
+
+=head1 NAME
+
+Crypt::OpenSSL::Bignum::CTX - Perl interface to the OpenSSL BN_CTX structure.
+
+=head1 SYNOPSIS
+
+  use Crypt::OpenSSL::Bignum::CTX;
+  my $bn_ctx = Crypt::OpenSSL::Bignum::CTX->new();
+
+=head1 DESCRIPTION
+
+See the man page for Crypt::OpenSSL::Bignum.
+
+=head1 AUTHOR
+
+Ian Robertson, iroberts at cpan.org
+
+=head1 SEE ALSO
+
+L<perl>, L<Crypt::OpenSSL::Bignum>, L<BN_CTX_new(3ssl)>
+
+=cut

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/Changes?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/Changes (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/Changes Thu Jan 24 18:59:15 2008
@@ -1,0 +1,12 @@
+Revision history for Perl extension Crypt::OpenSSL::Bignum.
+
+0.03  Sun Apr 27 2003 18:33:48
+        - Revert back to old declaration style so that we no longer
+          break under perl 5.005 (spotted by Rob Brown <bbb at cpan.org>).
+
+0.02  Fri Feb 21 21:55:14
+        - link against libcrypto instead of libssl
+        - more documentation
+
+0.01  Mon Feb 17 22:00 2003
+        - original version

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/MANIFEST?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/MANIFEST (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/MANIFEST Thu Jan 24 18:59:15 2008
@@ -1,0 +1,9 @@
+Bignum.pm
+Bignum.xs
+Bignum/CTX.pm
+Changes
+Makefile.PL
+MANIFEST
+README
+test.pl
+typemap

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/Makefile.PL?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/Makefile.PL (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/Makefile.PL Thu Jan 24 18:59:15 2008
@@ -1,0 +1,13 @@
+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::Bignum',
+    'VERSION_FROM'      => 'Bignum.pm',
+    'PREREQ_PM'         => {},
+    'ABSTRACT_FROM'     => 'Bignum.pm', # retrieve abstract from module
+    'AUTHOR'            => 'Ian Robertson <iroberts at cpan.org>',
+    'LIBS'              => ['-lcrypto'],   # e.g., '-lm'
+    'DEFINE'            => '-DPERL5',   # perl-5.8/gcc-3.2 needs this
+    'INC'               => '',
+);

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/README?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/README (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/README Thu Jan 24 18:59:15 2008
@@ -1,0 +1,23 @@
+Crypt::OpenSSL::Bignum is an XS perl module designed to provide basic
+access to the OpenSSL multiprecision integer arithmetic libraries.
+Presently, many though not all of the arithmetic operations that
+OpenSSL provides are exposed to perl.  In addition, this module can be
+used to provide access to bignum values produced by other OpenSSL
+modules, such as key parameters from Crypt::OpenSSL::RSA.  This module
+requires that the OpenSSL libraries and header files be installed.
+
+Crypt::OpenSSL::Bignum is currently under active development, and the
+many of the arithmetic APIs may change.  However, the author is
+committed to greater stability of the following methods:
+
+  new_from_bin, new_from_hex, new_from_decimal
+  to_bin, to_hex, to_decimal
+  pointer_copy, bless_pointer
+
+The module is being developed on sourceforge; if you find something
+you like or hate, please come to http://perl-openssl.sf.net/ for
+discussion and the latest in the cvs repository.
+
+Copyright (c) 2003 Ian Robertson.  Crypt::OpenSSL::RSA is free
+software; you may redistribute it and/or modify it under the same
+terms as Perl itself.

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/test.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/test.pl?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/test.pl (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/test.pl Thu Jan 24 18:59:15 2008
@@ -1,0 +1,126 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl test.pl'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test;
+BEGIN { plan tests => 52 };
+use Crypt::OpenSSL::Bignum;
+use Crypt::OpenSSL::Bignum::CTX;
+
+#########################
+
+# Insert your test code below, the Test module is use()ed here so read
+# its man page ( perldoc Test ) for help writing this test script.
+
+use strict;
+
+sub _new_bn
+{
+    return Crypt::OpenSSL::Bignum->new_from_word( shift );
+}
+
+my $bn;
+my $decimal_string = "2342234235235235235";
+$bn = Crypt::OpenSSL::Bignum->new_from_decimal( $decimal_string );
+ok( $bn );
+ok( $bn->to_decimal() eq $decimal_string );
+
+my $hex_string = "7f";
+$bn = Crypt::OpenSSL::Bignum->new_from_hex( $hex_string );
+ok( $bn );
+ok( $bn->to_hex() eq uc( $hex_string ) );
+ok( $bn->to_decimal() eq '127' );
+
+my $bin_string = pack( "C*", 2, 0 );
+$bn = Crypt::OpenSSL::Bignum->new_from_bin( $bin_string );
+ok( $bn );
+ok( $bn->to_bin() eq $bin_string );
+ok( $bn->to_decimal() eq '512' );
+
+my $bn23 = _new_bn( 23 );
+my $bn25 = _new_bn( 25 );
+
+ok( $bn23->cmp($ bn25 ) == -1 );
+ok( $bn25->cmp( $bn23 ) == 1 );
+ok( $bn23->cmp( $bn23 ) == 0 );
+ok( $bn23->equals( $bn23 ) );
+
+my $bn_copy = $bn->copy();
+ok( $bn_copy ne $bn );
+ok( $bn->equals( $bn_copy ) );
+
+my $ptr = $bn->pointer_copy();
+ok( ! ref $ptr );
+ok( $bn + 0 != $ptr );
+my $from_ptr = Crypt::OpenSSL::Bignum->bless_pointer( $ptr );
+ok( $bn->equals( $from_ptr ) );
+
+
+my $zero = Crypt::OpenSSL::Bignum->zero();
+my $one = Crypt::OpenSSL::Bignum->one();
+
+ok( $one->is_one() );
+ok( !$zero->is_one() );
+
+ok( $zero->is_zero() );
+ok( !$one->is_zero() );
+
+ok( !$zero->is_odd() );
+ok( $one->is_odd() );
+
+my $word = 0xffffeeee;
+ok( _new_bn($word)->get_word() == $word );
+
+# test creation from object rather than class string.
+my $bn2 = $bn->new_from_bin( $bin_string );
+ok( $bn2 );
+ok( $bn2->to_bin() eq $bn->to_bin() );
+
+ok( '48' eq $bn23->add( $bn25 )->to_decimal() );
+$bn = _new_bn( 18 );
+$bn->add( $one, $bn );
+ok( 19 == $bn->get_word() );
+
+ok( '-2' eq $bn23->sub( $bn25 )->to_decimal() );
+$bn = _new_bn( 18 );
+$bn->sub( $one, $bn );
+ok( 17 == $bn->get_word() );
+
+my $ctx = Crypt::OpenSSL::Bignum::CTX->new();
+
+ok( $ctx );
+ok( 575 == $bn23->mul( $bn25, $ctx )->get_word() );
+ok( 575 == $bn23->mul( $bn25, $ctx, $bn )->get_word() );
+ok( 575 == $bn->get_word() );
+
+ok( 2 == $bn25->mod( $bn23, $ctx )->get_word() );
+ok( 2 == $bn25->mod( $bn23, $ctx, $bn )->get_word() );
+ok( 2 == $bn->get_word() );
+
+my $bn6 = _new_bn( 6 );
+my $bn3 = _new_bn( 3 );
+
+my( $quotient, $remainder ) = $bn25->div( $bn23, $ctx );
+ok( $quotient->is_one );
+ok( 2 == $remainder->get_word() );
+my( $quotient2, $remainder2 ) =
+    $bn25->div( $bn6, $ctx, $quotient, $remainder );
+ok( $quotient2 == $quotient );
+ok( $remainder2 == $remainder );
+ok( 4 == $quotient->get_word() );
+ok( $remainder->is_one );
+my( $quotient3, $remainder3 ) =
+    $bn25->div( $bn6, $ctx, $quotient );
+ok( $quotient3 == $quotient );
+ok( 4 == $quotient->get_word() );
+ok( $remainder3->is_one() );
+
+ok( 6 == _new_bn( 18 )->gcd( _new_bn( 42 ), $ctx )->get_word() );
+ok( 5 == $bn23->mod_mul( $bn25, $bn6, $ctx )->get_word() );
+ok( 729 == $bn3->exp( $bn6, $ctx )->get_word() );
+ok( 4 == $bn3->mod_exp( $bn6, $bn25, $ctx )->get_word() );
+ok( 36 == $bn6->sqr( $ctx )->get_word() );
+ok( 12 == $bn23->mod_inverse( $bn25, $ctx )->get_word() );

Added: branches/upstream/libcrypt-openssl-bignum-perl/current/typemap
URL: http://svn.debian.org/wsvn/branches/upstream/libcrypt-openssl-bignum-perl/current/typemap?rev=13445&op=file
==============================================================================
--- branches/upstream/libcrypt-openssl-bignum-perl/current/typemap (added)
+++ branches/upstream/libcrypt-openssl-bignum-perl/current/typemap Thu Jan 24 18:59:15 2008
@@ -1,0 +1,12 @@
+TYPEMAP
+BIGNUM*         O_OBJECT
+BN_CTX*         O_OBJECT
+
+INPUT
+O_OBJECT
+    if( ! SvROK( $arg ) ) { croak( \"argument is not a ${type} object\" ); }
+    $var = (${type}) SvIV( SvRV( $arg ) );
+
+OUTPUT
+O_OBJECT
+   sv_setsv( $arg, new_obj( p_proto, $var ) );




More information about the Pkg-perl-cvs-commits mailing list