提交 8073036d 编写于 作者: R Ralf S. Engelschall

Overhauled the Perl interface (perl/*):

- ported BN stuff to OpenSSL's different BN library

- made the perl/ source tree CVS-aware

- renamed the package from SSLeay to OpenSSL (the files still contain
  their history because I've copied them in the repository)

- removed obsolete files (the test scripts will be replaced
  by better Test::Harness variants in the future)
上级 0517335e
......@@ -5,6 +5,15 @@
Changes between 0.9.1c and 0.9.2
*) Overhauled the Perl interface (perl/*):
- ported BN stuff to OpenSSL's different BN library
- made the perl/ source tree CVS-aware
- renamed the package from SSLeay to OpenSSL (the files still contain
their history because I've copied them in the repository)
- removed obsolete files (the test scripts will be replaced
by better Test::Harness variants in the future)
[Ralf S. Engelschall]
*) First cut for a very conservative source tree cleanup:
1. merge various obsolete readme texts into doc/ssleay.txt
where we collect the old documents and readme texts.
......
Makefile
blib
pm_to_blib
OpenSSL.c
openssl_bio.c
openssl_bn.c
openssl_cipher.c
openssl_digest.c
openssl_err.c
openssl_ssl.c
openssl_x509.c
OpenSSL.bs
MANIFEST
Makefile.PL
SSLeay.pm
bio.xs
bn.xs
cipher.xs
digest.xs
err.xs
ssl.xs
x509.xs
test.pl
test2.pl
test3.pl
test9.pl
testbn.pl
testmd.pl
typemap
OpenSSL.pm
OpenSSL.xs
openssl.h
openssl_bio.xs
openssl_bn.xs
openssl_cipher.xs
openssl_digest.xs
openssl_err.xs
openssl_ssl.xs
openssl_x509.xs
openssl_cb.c
##
## Makefile.PL -- Perl MakeMaker specification
##
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'OPTIMIZE' => '-g',
'DISTNAME' => 'SSLeay-perl5-0.8.5',
'NAME' => 'SSLeay',
'VERSION_FROM' => 'SSLeay.pm',
'LIBS' => ['-L.. -lssl -lcrypto'],
'DEFINE' => '',
'INC' => '-I../include',
'C' => ['callback.c'],
'H' => ['p5SSLeay.h'],
'OBJECT' => " SSLeay.o bio.o bn.o cipher.o digest.o err.o
ssl.o x509.o",
'XS' => { 'SSLeay.xs' => 'SSLeay.c',
'bio.xs' => 'bio.c',
'bn.xs' => 'bn.c',
'cipher.xs' => 'cipher.c',
'digest.xs' => 'digest.c',
'err.xs' => 'err.c',
'ssl.xs' => 'ssl.c',
'x509.xs' => 'x509.c',
}
);
'OPTIMIZE' => '',
'DISTNAME' => 'OpenSSL-0.9.2',
'NAME' => 'OpenSSL',
'VERSION_FROM' => 'OpenSSL.pm',
'LIBS' => ['-L.. -lssl -lcrypto'],
'DEFINE' => '',
'INC' => '-I../include',
'H' => ['openssl.h'],
'C' => ['openssl_cb.c'],
'OBJECT' =>
'OpenSSL.o ' .
'openssl_bio.o ' .
'openssl_bn.o ' .
'openssl_cipher.o ' .
'openssl_digest.o ' .
'openssl_err.o ' .
'openssl_ssl.o ' .
'openssl_x509.o ',
'XS' => {
'OpenSSL.xs' => 'OpenSSL.c',
'openssl_bio.xs' => 'openssl_bio.c',
'openssl_bn.xs' => 'openssl_bn.c',
'openssl_cipher.xs' => 'openssl_cipher.c',
'openssl_digest.xs' => 'openssl_digest.c',
'openssl_err.xs' => 'openssl_err.c',
'openssl_ssl.xs' => 'openssl_ssl.c',
'openssl_x509.xs' => 'openssl_x509.c',
},
);
package SSLeay;
##
## OpenSSL.pm
##
package OpenSSL;
use Exporter;
use DynaLoader;
......@@ -6,28 +10,26 @@ use DynaLoader;
@ISA = qw(Exporter DynaLoader);
@EXPORT = qw();
$VERSION='0.82';
$VERSION='0.82';
bootstrap SSLeay;
@SSLeay::BN::ISA= qw(SSLeay::ERR);
@SSLeay::MD::ISA= qw(SSLeay::ERR);
@SSLeay::Cipher::ISA= qw(SSLeay::ERR);
@SSLeay::SSL::CTX::ISA= qw(SSLeay::ERR);
@SSLeay::BIO::ISA= qw(SSLeay::ERR);
@SSLeay::SSL::ISA= qw(SSLeay::ERR);
$VERSION='0.92';
bootstrap penSSL;
@BN::ISA= qw(SSLeay::BN);
@MD::ISA= qw(SSLeay::MD);
@Cipher::ISA= qw(SSLeay::Cipher);
@SSL::ISA= qw(SSLeay::SSL);
@SSL::CTX::ISA= qw(SSLeay::SSL::CTX);
@BIO::ISA= qw(SSLeay::BIO);
@OpenSSL::BN::ISA= qw(OpenSSL::ERR);
@OpenSSL::MD::ISA= qw(OpenSSL::ERR);
@OpenSSL::Cipher::ISA= qw(OpenSSL::ERR);
@OpenSSL::SSL::CTX::ISA= qw(OpenSSL::ERR);
@OpenSSL::BIO::ISA= qw(OpenSSL::ERR);
@OpenSSL::SSL::ISA= qw(OpenSSL::ERR);
@BN::ISA= qw(OpenSSL::BN);
@MD::ISA= qw(OpenSSL::MD);
@Cipher::ISA= qw(OpenSSL::Cipher);
@SSL::ISA= qw(OpenSSL::SSL);
@SSL::CTX::ISA= qw(OpenSSL::SSL::CTX);
@BIO::ISA= qw(OpenSSL::BIO);
@SSLeay::MD::names=qw(md2 md5 sha sha1 ripemd160 mdc2);
@OpenSSL::MD::names=qw(md2 md5 sha sha1 ripemd160 mdc2);
@SSLeay::Cipher::names=qw(
@OpenSSL::Cipher::names=qw(
des-ecb des-cfb des-ofb des-cbc
des-ede des-ede-cfb des-ede-ofb des-ede-cbc
des-ede3 des-ede3-cfb des-ede3-ofb des-ede3-cbc
......@@ -39,9 +41,9 @@ bootstrap SSLeay;
rc5-ecb rc5-cfb rc5-ofb rc5-cbc
);
sub SSLeay::SSL::CTX::new_ssl { SSLeay::SSL::new($_[0]); }
sub OpenSSL::SSL::CTX::new_ssl { OpenSSL::SSL::new($_[0]); }
sub SSLeay::ERR::error
sub OpenSSL::ERR::error
{
my($o)=@_;
my($s,$ret);
......@@ -53,26 +55,26 @@ sub SSLeay::ERR::error
return($ret);
}
@SSLeay::Cipher::aliases=qw(des desx des3 idea rc2 bf cast);
@OpenSSL::Cipher::aliases=qw(des desx des3 idea rc2 bf cast);
package SSLeay::BN;
package OpenSSL::BN;
sub bnfix { (ref($_[0]) ne "SSLeay::BN")?SSLeay::BN::dec2bn($_[0]):$_[0]; }
sub bnfix { (ref($_[0]) ne "OpenSSL::BN")?OpenSSL::BN::dec2bn($_[0]):$_[0]; }
use overload
"=" => sub { dup($_[0]); },
"+" => sub { add($_[0],$_[1]); },
"-" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2];
SSLeay::BN::sub($_[0],$_[1]); },
OpenSSL::BN::sub($_[0],$_[1]); },
"*" => sub { mul($_[0],$_[1]); },
"/" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; (div($_[0],$_[1]))[0]; },
"%" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; mod($_[0],$_[1]); },
"**" => sub { ($_[1],$_[0])=($_[0],$_[1]) if $_[2]; exp($_[0],$_[1]); },
"<<" => sub { lshift($_[0],$_[1]); },
">>" => sub { rshift($_[0],$_[1]); },
"<=>" => sub { SSLeay::BN::cmp($_[0],$_[1]); },
"<=>" => sub { OpenSSL::BN::cmp($_[0],$_[1]); },
'""' => sub { bn2dec($_[0]); },
'0+' => sub { dec2bn($_[0]); },
"bool" => sub { ref($_[0]) eq "SSLeay::BN"; };
"bool" => sub { ref($_[0]) eq "OpenSSL::BN"; };
sub SSLeay::BIO::do_accept { SSLeay::BIO::do_handshake(@_); }
sub OpenSSL::BIO::do_accept { OpenSSL::BIO::do_handshake(@_); }
1;
#include "p5SSLeay.h"
/*
** OpenSSL.xs
*/
#include "openssl.h"
SV *new_ref(type,obj,mort)
char *type;
......@@ -47,7 +51,7 @@ fprintf(stderr,"ex_cleanup %08X %s\n",obj,argp);
SvREFCNT_dec((SV *)data);
}
MODULE = SSLeay PACKAGE = SSLeay
MODULE = OpenSSL PACKAGE = OpenSSL
BOOT:
boot_bio();
......@@ -55,11 +59,11 @@ BOOT:
boot_digest();
boot_err();
boot_ssl();
boot_SSLeay__BN();
boot_SSLeay__BIO();
boot_SSLeay__Cipher();
boot_SSLeay__MD();
boot_SSLeay__ERR();
boot_SSLeay__SSL();
boot_SSLeay__X509();
boot_OpenSSL__BN();
boot_OpenSSL__BIO();
boot_OpenSSL__Cipher();
boot_OpenSSL__MD();
boot_OpenSSL__ERR();
boot_OpenSSL__SSL();
boot_OpenSSL__X509();
#include "p5SSLeay.h"
SV *new_ref(type,obj,mort)
char *type;
char *obj;
{
SV *ret;
if (mort)
ret=sv_newmortal();
else
ret=newSViv(0);
printf(">new_ref %d\n",type);
sv_setref_pv(ret,type,(void *)obj);
return(ret);
}
int ex_new(obj,data,ad,idx,argl,argp)
char *obj;
SV *data;
CRYPTO_EX_DATA *ad;
int idx;
long argl;
char *argp;
{
SV *sv;
fprintf(stderr,"ex_new %08X %s\n",obj,argp);
sv=sv_newmortal();
sv_setref_pv(sv,argp,(void *)obj);
printf("%d>new_ref '%s'\n",sv,argp);
CRYPTO_set_ex_data(ad,idx,(char *)sv);
return(1);
}
void ex_cleanup(obj,data,ad,idx,argl,argp)
char *obj;
SV *data;
CRYPTO_EX_DATA *ad;
int idx;
long argl;
char *argp;
{
pr_name("ex_cleanup");
fprintf(stderr,"ex_cleanup %08X %s\n",obj,argp);
if (data != NULL)
SvREFCNT_dec((SV *)data);
}
MODULE = SSLeay PACKAGE = SSLeay
BOOT:
boot_bio();
boot_cipher();
boot_digest();
boot_err();
boot_ssl();
boot_SSLeay__BN();
boot_SSLeay__BIO();
boot_SSLeay__Cipher();
boot_SSLeay__MD();
boot_SSLeay__ERR();
boot_SSLeay__SSL();
boot_SSLeay__X509();
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$cmd=<<"EOF";
EOF
$conn="localhost:4433";
$conn=$ARGV[0] if $#ARGV >= 0;
print "X\n";
$bio=BIO->new("connect");
print "XX\n";
$bio->set_callback(sub {print STDERR $_[0]->number_read."\n"; $_[$#_] });
print "XXX\n";
$bio->hostname($conn) || die $ssl->error();
print "XXXX\n";
#$ssl=BIO->new("ssl");
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$cmd=<<"EOF";
GET / HTTP/1.0
EOF
$conn="localhost:4433";
$conn=$ARGV[0] if $#ARGV >= 0;
$bio=SSLeay::BIO::new("connect");
#$bio->set_callback(sub {print STDERR SSLeay::BIO::number_read($_[0])."\n"; $_[$#_] });
#$bio->set_callback(sub {print STDERR "$#_:".$_[0].":$_[1]:$_[2]:$_[3]:$_[4]:\n"; $_[$#_] });
$bio->hostname($conn) || die $ssl->error();
(($ret=$bio->do_handshake()) > 0) || die $bio->error();
(($ret=$bio->syswrite($cmd)) > 0) || die $bio->error();
while (1)
{
$ret=$bio->sysread($buf,10240);
last if ($ret <= 0);
print $buf;
}
BIO::new(type)
"connect"
"accept"
"ssl"
"buffer"
"connect"
BIO::hostname(name) host:port to connect to
"accept"
BIO::set_accept_port(port) port to connect too.
"connect", "accept", "ssl"
BIO::do_andshake do protocol
"ssl"
BIO::set_ssl(ssl)
BIO::get_ssl()
BIO::push(bio)
BIO::pop; return BIO
BIO::number_read()
BIO::number_written()
BIO::references()
BIO::sysread(buf,len[,offset])
BIO::syswrite(in[,len][,offset])
BIO::getline()
BIO::puts(in)
BIO::flush()
BIO::type()
BIO::next_bio();
BIO::set_callback(callback[, args])
BIO::new_buffer_ssl_connect(SSL_CTX)
BIO::new_ssl_connect(SSL_CTX)
#include "p5SSLeay.h"
static int p5_bio_ex_bio_ptr=0;
static int p5_bio_ex_bio_callback=0;
static int p5_bio_ex_bio_callback_data=0;
static long p5_bio_callback(bio,state,parg,cmd,larg,ret)
BIO *bio;
int state;
char *parg;
int cmd;
long larg;
int ret;
{
int i;
SV *me,*cb;
me=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
cb=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_callback);
if (cb != NULL)
{
dSP;
ENTER ;
SAVETMPS;
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSViv(me)));
XPUSHs(sv_2mortal(newSViv(state)));
XPUSHs(sv_2mortal(newSViv(cmd)));
if ((state == BIO_CB_READ) || (state == BIO_CB_WRITE))
{
XPUSHs(sv_2mortal(newSVpv(parg,larg)));
}
else
XPUSHs(&sv_undef);
/* ptr one */
XPUSHs(sv_2mortal(newSViv(larg)));
XPUSHs(sv_2mortal(newSViv(ret)));
PUTBACK;
i=perl_call_sv(cb,G_SCALAR);
SPAGAIN;
if (i == 1)
ret=POPi;
else
ret=1;
PUTBACK;
FREETMPS;
LEAVE;
}
else
{
croak("Internal error in SSL p5_ssl_info_callback");
}
return(ret);
}
int boot_bio()
{
p5_bio_ex_bio_ptr=
BIO_get_ex_new_index(0,"SSLeay::BIO",ex_new,NULL,
ex_cleanup);
p5_bio_ex_bio_callback=
BIO_get_ex_new_index(0,"bio_callback",NULL,NULL,
ex_cleanup);
p5_bio_ex_bio_callback_data=
BIO_get_ex_new_index(0,"bio_callback_data",NULL,NULL,
ex_cleanup);
return(1);
}
MODULE = SSLeay::BIO PACKAGE = SSLeay::BIO PREFIX = p5_BIO_
VERSIONCHECK: DISABLE
void
p5_BIO_new_buffer_ssl_connect(...)
PREINIT:
SSL_CTX *ctx;
BIO *bio;
SV *arg;
PPCODE:
if (items == 1)
arg=ST(0);
else if (items == 2)
arg=ST(1);
else
arg=NULL;
if ((arg == NULL) || !(sv_derived_from(arg,"SSLeay::SSL::CTX")))
croak("Usage: SSLeay::BIO::new_buffer_ssl_connect(SSL_CTX)");
else
{
IV tmp=SvIV((SV *)SvRV(arg));
ctx=(SSL_CTX *)tmp;
}
EXTEND(sp,1);
bio=BIO_new_buffer_ssl_connect(ctx);
arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
PUSHs(arg);
void
p5_BIO_new_ssl_connect(...)
PREINIT:
SSL_CTX *ctx;
BIO *bio;
SV *arg;
PPCODE:
if (items == 1)
arg=ST(0);
else if (items == 2)
arg=ST(1);
else
arg=NULL;
if ((arg == NULL) || !(sv_derived_from(arg,"SSLeay::SSL::CTX")))
croak("Usage: SSLeay::BIO::new_ssl_connect(SSL_CTX)");
else
{
IV tmp=SvIV((SV *)SvRV(arg));
ctx=(SSL_CTX *)tmp;
}
EXTEND(sp,1);
bio=BIO_new_ssl_connect(ctx);
arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
PUSHs(arg);
void
p5_BIO_new(...)
PREINIT:
BIO *bio;
char *type;
SV *arg;
PPCODE:
pr_name("p5_BIO_new");
if ((items == 1) && SvPOK(ST(0)))
type=SvPV(ST(0),na);
else if ((items == 2) && SvPOK(ST(1)))
type=SvPV(ST(1),na);
else
croak("Usage: SSLeay::BIO::new(type)");
EXTEND(sp,1);
if (strcmp(type,"connect") == 0)
bio=BIO_new(BIO_s_connect());
else if (strcmp(type,"accept") == 0)
bio=BIO_new(BIO_s_accept());
else if (strcmp(type,"ssl") == 0)
bio=BIO_new(BIO_f_ssl());
else if (strcmp(type,"buffer") == 0)
bio=BIO_new(BIO_f_buffer());
else
croak("unknown BIO type");
arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
PUSHs(arg);
int
p5_BIO_hostname(bio,name)
BIO *bio;
char *name;
CODE:
RETVAL=BIO_set_conn_hostname(bio,name);
OUTPUT:
RETVAL
int
p5_BIO_set_accept_port(bio,str)
BIO *bio;
char *str;
CODE:
RETVAL=BIO_set_accept_port(bio,str);
OUTPUT:
RETVAL
int
p5_BIO_do_handshake(bio)
BIO *bio;
CODE:
RETVAL=BIO_do_handshake(bio);
OUTPUT:
RETVAL
BIO *
p5_BIO_push(b,bio)
BIO *b;
BIO *bio;
CODE:
/* This reference will be reduced when the reference is
* let go, and then when the BIO_free_all() is called
* inside the SSLeay library by the BIO with this
* pushed into */
bio->references++;
RETVAL=BIO_push(b,bio);
OUTPUT:
RETVAL
void
p5_BIO_pop(b)
BIO *b
PREINIT:
BIO *bio;
char *type;
SV *arg;
PPCODE:
bio=BIO_pop(b);
if (bio != NULL)
{
/* This BIO will either be one created in the
* perl library, in which case it will have a perl
* SV, otherwise it will have been created internally,
* inside SSLeay. For the 'pushed in', it needs
* the reference count decememted. */
arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
if (arg == NULL)
{
arg=new_ref("SSLeay::BIO",(char *)bio,0);
BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
PUSHs(arg);
}
else
{
/* it was pushed in */
SvREFCNT_inc(arg);
PUSHs(arg);
#if 0 /* This does not need to be done. */
if (bio->references < 1)
abort();
/* decrement the reference count */
BIO_free(bio);
#endif
}
}
int
p5_BIO_sysread(bio,in,num, ...)
BIO *bio;
SV *in;
int num;
PREINIT:
int i,n,olen;
int offset;
char *p;
CODE:
offset=0;
if (!SvPOK(in))
sv_setpvn(in,"",0);
SvPV(in,olen);
if (items > 3)
{
offset=SvIV(ST(3));
if (offset < 0)
{
if (-offset > olen)
croak("Offset outside string");
offset+=olen;
}
}
if ((num+offset) > olen)
{
SvGROW(in,num+offset+1);
p=SvPV(in,i);
memset(&(p[olen]),0,(num+offset)-olen+1);
}
p=SvPV(in,n);
i=BIO_read(bio,p+offset,num);
RETVAL=i;
if (i <= 0) i=0;
SvCUR_set(in,offset+i);
OUTPUT:
RETVAL
int
p5_BIO_syswrite(bio,in, ...)
BIO *bio;
SV *in;
PREINIT:
char *ptr;
int len,in_len;
int offset=0;
int n;
CODE:
ptr=SvPV(in,in_len);
if (items > 2)
{
len=SvOK(ST(2))?SvIV(ST(2)):in_len;
if (items > 3)
{
offset=SvIV(ST(3));
if (offset < 0)
{
if (-offset > in_len)
croak("Offset outside string");
offset+=in_len;
}
else if ((offset >= in_len) && (in_len > 0))
croak("Offset outside string");
}
if (len >= (in_len-offset))
len=in_len-offset;
}
else
len=in_len;
RETVAL=BIO_write(bio,ptr+offset,len);
OUTPUT:
RETVAL
void
p5_BIO_getline(bio)
BIO *bio;
PREINIT:
int i;
char *p;
PPCODE:
pr_name("p5_BIO_gets");
EXTEND(sp,1);
PUSHs(sv_newmortal());
sv_setpvn(ST(0),"",0);
SvGROW(ST(0),1024);
p=SvPV(ST(0),na);
i=BIO_gets(bio,p,1024);
if (i < 0) i=0;
SvCUR_set(ST(0),i);
int
p5_BIO_flush(bio)
BIO *bio;
CODE:
RETVAL=BIO_flush(bio);
OUTPUT:
RETVAL
char *
p5_BIO_type(bio)
BIO *bio;
CODE:
RETVAL=bio->method->name;
OUTPUT:
RETVAL
void
p5_BIO_next_bio(b)
BIO *b
PREINIT:
BIO *bio;
char *type;
SV *arg;
PPCODE:
bio=b->next_bio;
if (bio != NULL)
{
arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
if (arg == NULL)
{
arg=new_ref("SSLeay::BIO",(char *)bio,0);
BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
bio->references++;
PUSHs(arg);
}
else
{
SvREFCNT_inc(arg);
PUSHs(arg);
}
}
int
p5_BIO_puts(bio,in)
BIO *bio;
SV *in;
PREINIT:
char *ptr;
CODE:
ptr=SvPV(in,na);
RETVAL=BIO_puts(bio,ptr);
OUTPUT:
RETVAL
void
p5_BIO_set_callback(bio,cb,...)
BIO *bio;
SV *cb;
PREINIT:
SV *arg=NULL;
SV *arg2=NULL;
CODE:
if (items > 3)
croak("Usage: SSLeay::BIO::set_callback(bio,callback[,arg]");
if (items == 3)
{
arg2=sv_mortalcopy(ST(2));
SvREFCNT_inc(arg2);
BIO_set_ex_data(bio,p5_bio_ex_bio_callback_data,
(char *)arg2);
}
arg=sv_mortalcopy(ST(1));
SvREFCNT_inc(arg);
BIO_set_ex_data(bio,p5_bio_ex_bio_callback,(char *)arg);
printf("%08lx < bio_ptr\n",BIO_get_ex_data(bio,p5_bio_ex_bio_ptr));
BIO_set_callback(bio,p5_bio_callback);
void
p5_BIO_DESTROY(bio)
BIO *bio
PREINIT:
SV *sv;
PPCODE:
pr_name_d("p5_BIO_DESTROY",bio->references);
printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references);
BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
BIO_free_all(bio);
int
p5_BIO_set_ssl(bio,ssl)
BIO *bio;
SSL *ssl;
CODE:
pr_name("p5_BIO_set_ssl");
ssl->references++;
RETVAL=BIO_set_ssl(bio,ssl,BIO_CLOSE);
OUTPUT:
RETVAL
int
p5_BIO_number_read(bio)
BIO *bio;
CODE:
RETVAL=BIO_number_read(bio);
OUTPUT:
RETVAL
int
p5_BIO_number_written(bio)
BIO *bio;
CODE:
RETVAL=BIO_number_written(bio);
OUTPUT:
RETVAL
int
p5_BIO_references(bio)
BIO *bio;
CODE:
RETVAL=bio->references;
OUTPUT:
RETVAL
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$message=SSLeay::BN::new();
$e=SSLeay::BN::new();
$mod=SSLeay::BN::new();
$mod=SSLeay::BN::dec2bn("114381625757888867669235779976146612010218296721242362562561842935706935245733897830597123563958705058989075147599290026879543541");
$e=5;
$d=SSLeay::BN::dec2bn("45752650303155547067694311990458644804087318688496945025024737159778909096647814932594914301288138204957467016445183857236173773");
$message=SSLeay::BN::bin2bn("The magic words are squeamish ossifrage");
$cipher_text= $message->mod_exp($e,$mod);
print $mod."\n";
print $mod->num_bits()."\n";
for (1 .. 1000)
{
$clear= $cipher_text->mod_exp($d,$mod);
}
print $clear->bn2bin()."\n";
BN->new()
BN->dup(a)
BN->rand(bits[,top][,bottom])
BN->hex2bn(a)
BN->bn2hex(a)
BN->dec2bn(a)
BN->bn2dec(a)
BN->bin2bn(a)
BN->bn2bin(a)
BN->mpi2bn(a)
BN->bn2mpi(a)
BN->add(a,b)
BN->sub(a,b)
BN->mul(a,b)
(div,mod)=BN->div(a,b)
BN->mod(a,b)
BN->exp(a,p)
BN->mod_mul(a,b,c)
BN->mod_exp(a,b,c)
BN->is_prime(p,num)
BN->generate_prime(bits,strong,callback)
BN->num_bits(a)
BN->cmp(a,b)
BN->ucmp(a,b)
BN->is_bit_set(a,pos)
BN->set_bit(a,pos)
BN->clear_bit(a,pos)
BN->lshift(a,num)
BN->rshift(a,num)
BN->mask_bits(a,pos)
BN->clear(a)
BN->gcd(a,b)
BN->mod_inverse(a,mod)
#include "p5SSLeay.h"
int sv_to_BIGNUM(var,arg,name)
BIGNUM **var;
SV *arg;
char *name;
{
int ret=1;
if (sv_derived_from(arg,"SSLeay::BN"))
{
IV tmp = SvIV((SV*)SvRV(arg));
*var = (BIGNUM *) tmp;
}
else if (SvIOK(arg)) {
SV *tmp=sv_newmortal();
*var=BN_new();
BN_set_word(*var,SvIV(arg));
sv_setref_pv(tmp,"SSLeay::BN",(void*)*var);
}
else if (SvPOK(arg)) {
char *ptr;
STRLEN len;
SV *tmp=sv_newmortal();
*var=BN_new();
sv_setref_pv(tmp,"SSLeay::BN", (void*)*var);
ptr=SvPV(arg,len);
SvGROW(arg,len+1);
ptr[len]='\0';
BN_dec2bn(var,ptr);
}
else
{
croak(name);
ret=0;
}
return(ret);
}
typedef struct gpc_args_st {
SV *cb;
SV *arg;
} GPC_ARGS;
static void generate_prime_callback(pos,num,arg)
int pos;
int num;
char *arg;
{
dSP ;
int i;
GPC_ARGS *a=(GPC_ARGS *)arg;
ENTER ;
SAVETMPS ;
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSViv(pos)));
XPUSHs(sv_2mortal(newSViv(num)));
XPUSHs(sv_2mortal(newSVsv(a->arg)));
PUTBACK;
i=perl_call_sv(a->cb,G_DISCARD);
SPAGAIN;
PUTBACK;
FREETMPS;
LEAVE;
}
MODULE = SSLeay::BN PACKAGE = SSLeay::BN PREFIX = p5_BN_
VERSIONCHECK: DISABLE
void
p5_BN_new(...)
PREINIT:
BIGNUM *bn;
SV *arg;
PPCODE:
pr_name("p5_BN_new");
EXTEND(sp,1);
PUSHs(sv_newmortal());
bn=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)bn);
void
p5_BN_dup(a)
BIGNUM *a;
PREINIT:
BIGNUM *bn;
PPCODE:
pr_name("p5_BN_dup");
EXTEND(sp,1);
PUSHs(sv_newmortal());
bn=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)bn);
void
p5_BN_rand(bits,...)
int bits;
PREINIT:
int top=1;
int bottom=0;
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_rand");
if ((items < 1) || (items > 3))
croak("Usage: SSLeay::BN::rand(bits[,top_bit][,bottombit]");
if (items >= 2) top=(int)SvIV(ST(0));
if (items >= 3) bottom=(int)SvIV(ST(1));
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
BN_rand(ret,bits,top,bottom);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
void
p5_BN_bin2bn(a)
datum a;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_bin2bn");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_bin2bn(a.dptr,a.dsize,NULL);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
void
p5_BN_bn2bin(a)
BIGNUM *a;
PREINIT:
int i;
PPCODE:
pr_name("p5_BN_bn2bin");
EXTEND(sp,1);
PUSHs(sv_newmortal());
i=BN_num_bytes(a)+2;
sv_setpvn(ST(0),"",1);
SvGROW(ST(0),i+1);
SvCUR_set(ST(0),BN_bn2bin(a,SvPV(ST(0),na)));
void
p5_BN_mpi2bn(a)
datum a;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_mpi2bn");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_mpi2bn(a.dptr,a.dsize,NULL);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
void
p5_BN_bn2mpi(a)
BIGNUM *a;
PREINIT:
int i;
PPCODE:
pr_name("p5_BN_bn2mpi");
EXTEND(sp,1);
PUSHs(sv_newmortal());
i=BN_bn2mpi(a,NULL);
sv_setpvn(ST(0),"",1);
SvGROW(ST(0),i+1);
SvCUR_set(ST(0),BN_bn2mpi(a,SvPV(ST(0),na)));
void
p5_BN_hex2bn(a)
datum a;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_hex2bn");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_hex2bn(&ret,a.dptr);
void
p5_BN_dec2bn(a)
datum a;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_dec2bn");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_dec2bn(&ret,a.dptr);
SV *
p5_BN_bn2hex(a)
BIGNUM *a;
PREINIT:
char *ptr;
int i;
CODE:
pr_name("p5_BN_bn2hex");
ptr=BN_bn2hex(a);
RETVAL=newSVpv("",0);
i=strlen(ptr);
SvGROW(RETVAL,i+1);
memcpy(SvPV(RETVAL,na),ptr,i+1);
SvCUR_set(RETVAL,i);
Free(ptr);
OUTPUT:
RETVAL
SV *
p5_BN_bn2dec(a)
BIGNUM *a;
PREINIT:
char *ptr;
int i;
CODE:
pr_name("p5_BN_bn2dec");
ptr=BN_bn2dec(a);
RETVAL=newSVpv("",0);
i=strlen(ptr);
SvGROW(RETVAL,i+1);
memcpy(SvPV(RETVAL,na),ptr,i+1);
SvCUR_set(RETVAL,i);
Free(ptr);
OUTPUT:
RETVAL
void
p5_BN_add(a,b)
BIGNUM *a;
BIGNUM *b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_add");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_add(ret,a,b);
void
p5_BN_sub(a,b)
BIGNUM *a;
BIGNUM *b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_sub");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_sub(ret,a,b);
void
p5_BN_mul(a,b)
BIGNUM *a;
BIGNUM *b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_mul");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_mul(ret,a,b);
void
p5_BN_div(a,b)
BIGNUM *a;
BIGNUM *b;
PREINIT:
static BN_CTX *ctx=NULL;
BIGNUM *div,*mod;
PPCODE:
pr_name("p5_BN_div");
if (ctx == NULL) ctx=BN_CTX_new();
EXTEND(sp,2);
PUSHs(sv_newmortal());
PUSHs(sv_newmortal());
div=BN_new();
mod=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)div);
sv_setref_pv(ST(1), "SSLeay::BN", (void*)mod);
BN_div(div,mod,a,b,ctx);
void
p5_BN_mod(a,b)
BIGNUM *a;
BIGNUM *b;
PREINIT:
static BN_CTX *ctx=NULL;
BIGNUM *rem;
PPCODE:
pr_name("p5_BN_mod");
if (ctx == NULL) ctx=BN_CTX_new();
EXTEND(sp,1);
PUSHs(sv_newmortal());
rem=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)rem);
BN_mod(rem,a,b,ctx);
void
p5_BN_exp(a,p)
BIGNUM *a;
BIGNUM *p;
PREINIT:
BIGNUM *ret;
static BN_CTX *ctx=NULL;
PPCODE:
pr_name("p5_BN_exp");
if (ctx == NULL) ctx=BN_CTX_new();
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_exp(ret,a,p,ctx);
void
p5_BN_mod_mul(a,b,c)
BIGNUM *a;
BIGNUM *b;
BIGNUM *c;
PREINIT:
static BN_CTX *ctx=NULL;
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_mod_mul");
if (ctx == NULL) ctx=BN_CTX_new();
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_mod_mul(ret,a,b,c,ctx);
void
p5_BN_mod_exp(a,b,c)
BIGNUM *a;
BIGNUM *b;
BIGNUM *c;
PREINIT:
static BN_CTX *ctx=NULL;
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_mod_exp");
if (ctx == NULL) ctx=BN_CTX_new();
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_mod_exp(ret,a,b,c,ctx);
void
p5_BN_generate_prime(...)
PREINIT:
int bits=512;
int strong=0;
BIGNUM *ret=NULL;
SV *callback=NULL;
SV *cb_arg=NULL;
GPC_ARGS arg;
dSP;
PPCODE:
pr_name("p5_BN_generate_prime");
if ((items < 0) || (items > 4))
croak("Usage: SSLeay::BN::generate_prime(a[,strong][,callback][,cb_arg]");
if (items >= 1) bits=(int)SvIV(ST(0));
if (items >= 2) strong=(int)SvIV(ST(1));
if (items >= 3) callback=ST(2);
if (items == 4) cb_arg=ST(3);
if (callback == NULL)
ret=BN_generate_prime(bits,strong,NULL,NULL,NULL,NULL);
else
{
arg.cb=callback;
arg.arg=cb_arg;
ret=BN_generate_prime(bits,strong,NULL,NULL,
generate_prime_callback,(char *)&arg);
}
SPAGAIN;
sp-=items; /* a bit evil that I do this */
EXTEND(sp,1);
PUSHs(sv_newmortal());
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
void
p5_BN_is_prime(p,...)
BIGNUM *p;
PREINIT:
int nchecks=5,ret;
SV *callback=NULL;
SV *cb_arg=NULL;
GPC_ARGS arg;
dSP;
static BN_CTX *ctx=NULL;
PPCODE:
pr_name("p5_BN_is_prime");
if ((items < 1) || (items > 4))
croak("Usage: SSLeay::BN::is_prime(a[,ncheck][,callback][,callback_arg]");
if (ctx == NULL) ctx=BN_CTX_new();
if (items >= 2) nchecks=(int)SvIV(ST(1));
if (items >= 3) callback=ST(2);
if (items >= 4) cb_arg=ST(3);
arg.arg=cb_arg;
if (callback == NULL)
ret=BN_is_prime(p,nchecks,NULL,ctx,NULL);
else
{
arg.cb=callback;
arg.arg=cb_arg;
ret=BN_is_prime(p,nchecks,generate_prime_callback,
ctx,(char *)&arg);
}
SPAGAIN;
sp-=items; /* a bit evil */
PUSHs(sv_2mortal(newSViv(ret)));
int
p5_BN_num_bits(a)
BIGNUM *a;
CODE:
pr_name("p5_BN_num_bits");
RETVAL=BN_num_bits(a);
OUTPUT:
RETVAL
int
p5_BN_cmp(a,b)
BIGNUM *a;
BIGNUM *b;
CODE:
pr_name("p5_BN_cmp");
RETVAL=BN_cmp(a,b);
OUTPUT:
RETVAL
int
p5_BN_ucmp(a,b)
BIGNUM *a;
BIGNUM *b;
CODE:
pr_name("p5_BN_ucmp");
RETVAL=BN_ucmp(a,b);
OUTPUT:
RETVAL
int
p5_BN_is_bit_set(a,b)
BIGNUM *a;
int b;
CODE:
pr_name("p5_BN_is_bit_set");
RETVAL=BN_is_bit_set(a,b);
OUTPUT:
RETVAL
void
p5_BN_set_bit(a,b)
BIGNUM *a;
int b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_set_bit");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_set_bit(ret,b);
void
p5_BN_clear_bit(a,b)
BIGNUM *a;
int b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_clear_bit");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_clear_bit(ret,b);
void
p5_BN_lshift(a,b)
BIGNUM *a;
int b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_lshift");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
if (b == 1)
BN_lshift1(ret,a);
else
BN_lshift(ret,a,b);
void
p5_BN_rshift(a,b)
BIGNUM *a;
int b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_rshift");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
if (b == 1)
BN_rshift1(ret,a);
else
BN_rshift(ret,a,b);
void
p5_BN_mask_bits(a,b)
BIGNUM *a;
int b;
PREINIT:
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_mask_bits");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_mask_bits(ret,b);
void
p5_BN_clear(a)
BIGNUM *a;
PPCODE:
pr_name("p5_BN_clear");
BN_clear(a);
void
p5_BN_gcd(a,b)
BIGNUM *a;
BIGNUM *b;
PREINIT:
static BN_CTX *ctx=NULL;
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_gcd");
if (ctx == NULL) ctx=BN_CTX_new();
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_gcd(ret,a,b,ctx);
void
p5_BN_mod_inverse(a,mod)
BIGNUM *a;
BIGNUM *mod;
PREINIT:
static BN_CTX *ctx=NULL;
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_mod_inverse");
if (ctx == NULL) ctx=BN_CTX_new();
ret=BN_mod_inverse(a,mod,ctx);
EXTEND(sp,1);
PUSHs(sv_newmortal());
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
void
p5_BN_DESTROY(bn)
BIGNUM *bn
CODE:
pr_name("p5_BN_DESTROY");
BN_free(bn);
/* perl/callback.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
SV *new_ref(type,obj,mort)
char *type;
char *obj;
{
SV *ret;
if (mort)
ret=sv_newmortal();
else
ret=newSViv(0);
sv_setref_pv(ret,type,(void *)obj);
return(ret);
}
int ex_new(obj,data,ad,idx,argl,argp)
char *obj;
SV *data;
CRYPTO_EX_DATA *ad;
int idx;
long argl;
char *argp;
{
SV *sv;
fprintf(stderr,"ex_new idx=%d %08X %s\n",idx,obj,argp);
sv=sv_newmortal();
sv_setref_pv(sv,argp,(void *)obj);
CRYPTO_set_ex_data(ad,idx,(char *)sv);
return(1);
}
void ex_cleanup(obj,data,ad,idx,argl,argp)
char *obj;
SV *data;
CRYPTO_EX_DATA *ad;
int idx;
long argl;
char *argp;
{
pr_name("ex_cleanup");
fprintf(stderr,"ex_cleanup %08X %s\n",obj,argp);
if (data != NULL)
SvREFCNT_dec((SV *)data);
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$md=SSLeay::MD::new("md5");
foreach (@SSLeay::Cipher::names)
{
($c=SSLeay::Cipher::new($_)) ||
die "'$_' is an unknown cipher algorithm\n";
$data="012345678abcdefghijklmnopqrstuvwxyz";
$c->init("01234567abcdefghABCDEFGH","zyxwvut",1);
$in =$c->update(substr($data, 0, 5));
$in.=$c->update(substr($data, 5,10));
$in.=$c->update(substr($data,15,1));
$in.=$c->update(substr($data,16));
$in.=$c->final();
$c->init("01234567abcdefghABCDEFGH","zyxwvut",0);
$out=$c->update($in);
$out.=$c->final();
($out eq $data) || die "decrypt for $_ failed:$!\n";
$md->init();
$md->update($in);
$digest=$md->final();
print unpack("H*",$digest);
printf " %2d %2d %2d %s\n", $c->key_length(), $c->iv_length(),
$c->block_size(), $c->name();
}
Cipher::new(name) "des-cbc" etc
Cipher::name()
Cipher::key_length()
Cipher::iv_length()
Cipher::block_size()
Cipher::init(key,iv,enc)
Cipher::update(in)
Cipher::final()
Cipher::cipher(in)
#include "p5SSLeay.h"
int boot_cipher()
{
SSLeay_add_all_ciphers();
return(1);
}
MODULE = SSLeay::Cipher PACKAGE = SSLeay::Cipher PREFIX = p5_EVP_C_
VERSIONCHECK: DISABLE
void
p5_EVP_C_new(...)
PREINIT:
EVP_CIPHER_CTX *ctx;
EVP_CIPHER *c;
char *name;
PPCODE:
if ((items == 1) && SvPOK(ST(0)))
name=SvPV(ST(0),na);
else if ((items == 2) && SvPOK(ST(1)))
name=SvPV(ST(1),na);
else
croak("Usage: SSLeay::Cipher::new(type)");
PUSHs(sv_newmortal());
c=EVP_get_cipherbyname(name);
if (c != NULL)
{
ctx=malloc(sizeof(EVP_CIPHER_CTX));
EVP_EncryptInit(ctx,c,NULL,NULL);
sv_setref_pv(ST(0), "SSLeay::Cipher", (void*)ctx);
}
datum
p5_EVP_C_name(ctx)
EVP_CIPHER_CTX *ctx
CODE:
RETVAL.dptr=OBJ_nid2ln(EVP_CIPHER_CTX_nid(ctx));
RETVAL.dsize=strlen(RETVAL.dptr);
OUTPUT:
RETVAL
int
p5_EVP_C_key_length(ctx)
EVP_CIPHER_CTX *ctx
CODE:
RETVAL=EVP_CIPHER_CTX_key_length(ctx);
OUTPUT:
RETVAL
int
p5_EVP_C_iv_length(ctx)
EVP_CIPHER_CTX *ctx
CODE:
RETVAL=EVP_CIPHER_CTX_iv_length(ctx);
OUTPUT:
RETVAL
int
p5_EVP_C_block_size(ctx)
EVP_CIPHER_CTX *ctx
CODE:
RETVAL=EVP_CIPHER_CTX_block_size(ctx);
OUTPUT:
RETVAL
void
p5_EVP_C_init(ctx,key,iv,enc)
EVP_CIPHER_CTX *ctx
datum key
datum iv
int enc
PREINIT:
char loc_iv[EVP_MAX_IV_LENGTH];
char loc_key[EVP_MAX_KEY_LENGTH];
char *ip=loc_iv,*kp=loc_key;
int i;
memset(loc_iv,0,EVP_MAX_IV_LENGTH);
memset(loc_key,0,EVP_MAX_KEY_LENGTH);
CODE:
i=key.dsize;
if (key.dsize > EVP_CIPHER_CTX_key_length(ctx))
i=EVP_CIPHER_CTX_key_length(ctx);
if (i > 0)
{
memset(kp,0,EVP_MAX_KEY_LENGTH);
memcpy(kp,key.dptr,i);
}
else
kp=NULL;
i=iv.dsize;
if (iv.dsize > EVP_CIPHER_CTX_iv_length(ctx))
i=EVP_CIPHER_CTX_iv_length(ctx);
if (i > 0)
{
memcpy(ip,iv.dptr,i);
memset(ip,0,EVP_MAX_IV_LENGTH);
}
else
ip=NULL;
EVP_CipherInit(ctx,EVP_CIPHER_CTX_cipher(ctx),kp,ip,enc);
memset(loc_key,0,sizeof(loc_key));
memset(loc_iv,0,sizeof(loc_iv));
SV *
p5_EVP_C_cipher(ctx,in)
EVP_CIPHER_CTX *ctx;
datum in;
CODE:
RETVAL=newSVpv("",0);
SvGROW(RETVAL,in.dsize+EVP_CIPHER_CTX_block_size(ctx)+1);
EVP_Cipher(ctx,SvPV(RETVAL,na),in.dptr,in.dsize);
SvCUR_set(RETVAL,in.dsize);
OUTPUT:
RETVAL
SV *
p5_EVP_C_update(ctx, in)
EVP_CIPHER_CTX *ctx
datum in
PREINIT:
int i;
CODE:
RETVAL=newSVpv("",0);
SvGROW(RETVAL,in.dsize+EVP_CIPHER_CTX_block_size(ctx)+1);
EVP_CipherUpdate(ctx,SvPV(RETVAL,na),&i,in.dptr,in.dsize);
SvCUR_set(RETVAL,i);
OUTPUT:
RETVAL
SV *
p5_EVP_C_final(ctx)
EVP_CIPHER_CTX *ctx
PREINIT:
int i;
CODE:
RETVAL=newSVpv("",0);
SvGROW(RETVAL,EVP_CIPHER_CTX_block_size(ctx)+1);
if (!EVP_CipherFinal(ctx,SvPV(RETVAL,na),&i))
sv_setpv(RETVAL,"BAD DECODE");
else
SvCUR_set(RETVAL,i);
OUTPUT:
RETVAL
void
p5_EVP_C_DESTROY(ctx)
EVP_CIPHER_CTX *ctx
CODE:
free((char *)ctx);
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$g=SSLeay::BN::hex2bn("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002");
$p=SSLeay::BN::hex2bn("ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff");
$pub=SSLeay::BN::hex2bn("521b5b72d0a23f5f908eff62741b9c43ac65c47ad264a4f8d62d73dfab4938a6e019f81c28d64efd9b47c1b8188566c6184b6064cc42fac2778bd732678148c6cc7601bfe0ed18da76dd7bb976cd2ff0afc7b20f3f81171e2ea6534de061f929");
$priv=SSLeay::BN::hex2bn("6e15c752af3f4cf6d7425164c451eeba760ec0651d12dc3b0ee5002a95af6191268ca47c0fbb3d836136eee795ae4af3a1adad5e04d0dbb04378cae0406ece23ca3b86839c0fd60064c1019c7d18be4dc0ec4be6c1e9ff6b0f5bd76373585503");
$his=SSLeay::BN::hex2bn("d0fb51cd44a8578f55eb0822ede90f07504f4720d7367ff4bf76c27fedbce79d9204421ff7e86bd1dd02031bce4ceccd1d3e7c62679b6eb5fda8238fd4fe07bff573d552795f0d46f25753c688300fb9ed396792b59a49fdf89c8429124b668e");
$sh=SSLeay::BN::hex2bn("66ec34b09bddf86147f6c6efd5ee4e6691e690eb0e90aceda16a742cad0abe531cb61d057aff362001ca19013215140ca2a1dd8966c78105bacbf2161f9cfbd58d351ff87923de77f9c56851037223d48272565416ee769e65a621cefb90b403");
$g2=SSLeay::BN::hex2bn("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002");
$p2=SSLeay::BN::hex2bn("ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff");
$pub2=SSLeay::BN::hex2bn("d0fb51cd44a8578f55eb0822ede90f07504f4720d7367ff4bf76c27fedbce79d9204421ff7e86bd1dd02031bce4ceccd1d3e7c62679b6eb5fda8238fd4fe07bff573d552795f0d46f25753c688300fb9ed396792b59a49fdf89c8429124b668e");
$priv2=SSLeay::BN::hex2bn("b81d54f52b687669fc8bd8087ac319accc2f94a2feafe09779f4a81e8e01f77290f5bbe84a08003afc4448145be427fad0b9d047889cf361c9dd378b15c1ebd5bda33e051fbd9eba8bf063e2bd836467cddb61f1db5c4b06bea5c9a77fb87b24");
$his2=SSLeay::BN::hex2bn("521b5b72d0a23f5f908eff62741b9c43ac65c47ad264a4f8d62d73dfab4938a6e019f81c28d64efd9b47c1b8188566c6184b6064cc42fac2778bd732678148c6cc7601bfe0ed18da76dd7bb976cd2ff0afc7b20f3f81171e2ea6534de061f929");
$sh2=SSLeay::BN::hex2bn("791faba7a6b592cb68a963945229483dc30f80f5cb295b2b5a59ef618a262d22de0845948a34db83d8bde260b940967ff85593a609e53ee6510aea09b776b4704d5e916917f384458d4790b6e0befcb1cb2f112b850e9ed410a091db80e1db2e");
print "g=".$g->bn2hex."\n";
print "p=".$p->bn2hex."\n";
print "pub=".$pub->bn2hex."\n";
print "priv=".$priv->bn2hex."\n";
print "sh=".$sh->bn2hex."\n";
print "new p - p2 = ".($p-$p2)."\n";
$tmp=$g->mod_exp($priv,$p);
print "XXXXXXXXXXXXXXXX\n";
print "new pub - pub = ".($tmp-$pub)."\n";
$tmp2=$g2->mod_exp($priv2,$p2);
print "XXXXXXXXXXXXXXXX\n";
print $p." pub\n";
print $tmp2." calc pub\n";
print $pub2." txt pub\n";
MD::new(name) "md2", "md5" etc
MD::name()
MD::init()
MD::update(in)
MD::final()
#include "p5SSLeay.h"
int boot_digest()
{
SSLeay_add_all_digests();
return(1);
}
MODULE = SSLeay::MD PACKAGE = SSLeay::MD PREFIX = p5_EVP_MD_
PROTOTYPES: ENABLE
VERSIONCHECK: DISABLE
# SSLeay::MD::new(name) name= md2, md5, sha, sha1, or mdc2
# md->name() - returns the name
# md->init() - reinitalises the digest
# md->update(data) - adds more data to digest
# digest=md->final() - returns digest
#
void
p5_EVP_MD_new(...)
PREINIT:
EVP_MD_CTX *ctx;
EVP_MD *md;
char *name;
PPCODE:
if ((items == 1) && SvPOK(ST(0)))
name=SvPV(ST(0),na);
else if ((items == 2) && SvPOK(ST(1)))
name=SvPV(ST(1),na);
else
croak("Usage: SSLeay::MD::new(type)");
PUSHs(sv_newmortal());
md=EVP_get_digestbyname(name);
if (md != NULL)
{
ctx=malloc(sizeof(EVP_MD_CTX));
EVP_DigestInit(ctx,md);
sv_setref_pv(ST(0), "SSLeay::MD", (void*)ctx);
}
datum
p5_EVP_MD_name(ctx)
EVP_MD_CTX *ctx
CODE:
RETVAL.dptr=OBJ_nid2ln(EVP_MD_type(EVP_MD_CTX_type(ctx)));
RETVAL.dsize=strlen(RETVAL.dptr);
OUTPUT:
RETVAL
void
p5_EVP_MD_init(ctx)
EVP_MD_CTX *ctx
CODE:
EVP_DigestInit(ctx,EVP_MD_CTX_type(ctx));
void
p5_EVP_MD_update(ctx, in)
EVP_MD_CTX *ctx
datum in
CODE:
EVP_DigestUpdate(ctx,in.dptr,in.dsize);
datum
p5_EVP_MD_final(ctx)
EVP_MD_CTX *ctx
PREINIT:
char md[EVP_MAX_MD_SIZE];
int len;
CODE:
EVP_DigestFinal(ctx,md,&len);
RETVAL.dptr=md;
RETVAL.dsize=len;
OUTPUT:
RETVAL
void
p5_EVP_MD_DESTROY(ctx)
EVP_MD_CTX *ctx
CODE:
free((char *)ctx);
ERR::get_error()
ERR::peek_error()
#include "p5SSLeay.h"
int boot_err()
{
SSL_load_error_strings();
return(1);
}
MODULE = SSLeay::ERR PACKAGE = SSLeay::ERR PREFIX = p5_ERR_
PROTOTYPES: ENABLE
VERSIONCHECK: DISABLE
# md->error() - returns the last error in text or numeric context
void
p5_ERR_get_error(...)
PPCODE:
char buf[512];
unsigned long l;
pr_name("p5_ERR_get_code");
EXTEND(sp,1);
PUSHs(sv_newmortal());
l=ERR_get_error();
ERR_error_string(l,buf);
sv_setiv(ST(0),l);
sv_setpv(ST(0),buf);
SvIOK_on(ST(0));
void
p5_ERR_peek_error(...)
PPCODE:
char buf[512];
unsigned long l;
pr_name("p5_ERR_get_code");
EXTEND(sp,1);
PUSHs(sv_newmortal());
l=ERR_peek_error();
ERR_error_string(l,buf);
sv_setiv(ST(0),l);
sv_setpv(ST(0),buf);
SvIOK_on(ST(0));
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
for (7 .. 7926)
{
my $num = SSLeay::BN::dec2bn($_);
print "$_ is ".($num->is_prime ? 'prime' : 'composite'), "\n";
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$num=SSLeay::BN::new();
$shift=SSLeay::BN::new();
print "0\n";
$num=SSLeay::BN::hex2bn("1234329378209857309429670349760347603497603496398");
print "1\n";
$s=SSLeay::BN::hex2bn("59");
print "a\n";
$r=$num->lshift(59);
print "b";
print $num->bn2hex."\n";
print $s->bn2hex."\n";
print $r->bn2hex."\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$bits=512;
$bits=$ARGV[0] if $#ARGV >= 0;
$p=SSLeay::BN::generate_prime($bits/2,0,sub {print STDERR $_[0]?"+":"."});
print "\n";
$q=SSLeay::BN::generate_prime($bits/2,0,sub {print STDERR $_[0]?"+":"."});
print "\n";
$e=SSLeay::BN::hex2bn("10001");
$t1=$p-1;
$t2=$q-1;
($t1->gcd($e) == 1) || die "p failed the gcd test\n";
($t2->gcd($e) == 1) || die "q failed the gcd test\n";
($q,$p)=($p,$q) if ($p < $q);
$n=$p*$q;
$t=($p-1)*($q-1);
($t->gcd($e) == 1) || die "t failed the gcd test\n";
$d=$e->mod_inverse($t);
$dmp1=$d%($p-1);
$dmq1=$d%($q-1);
$iqmp=$q->mod_inverse($p);
print "n =$n\n";
print "e =$e\n";
print "d =$d\n";
print "dmp1=$dmp1\n";
print "dmq1=$dmq1\n";
print "iqmp=$iqmp\n";
$a=SSLeay::BN::bin2bn("This is an RSA test");
print "Test with\n'".$a->bn2bin."' or\n$a\n";
$t1=$a->mod_exp($e,$n);
print "$t1\n";
$t2=$t1->mod_exp($d,$n);
print "'".$t2->bn2bin."'\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
sub mul
{
my($ab,$cd,$num)=@_;
if ($num <= 4096)
{
return($ab*$cd);
}
else
{
my($a,$b,$c,$d,$n,$ac,$bd,$m,$t1,$t2);
$n=$num/2;
$a=$ab->mask_bits($n);
$b=$ab->rshift($n);
$c=$cd->mask_bits($n);
$d=$cd->rshift($n);
$t1=($b-$a);
$t2=($c-$d);
$m= &mul($t1,$t2,$n);
$ac=&mul($a,$c,$n);
$bd=&mul($b,$d,$n);
$m=$m+$ac+$bd;
$m=$m->lshift($n);
$bd=$bd->lshift($num);
$r=$ac+$m+$bd;
return($r);
}
}
$num=4096*32;
$a=SSLeay::BN::rand($num);
$b=SSLeay::BN::rand($num);
#for (1 .. 10)
{
$r=&mul($a,$b,$num);
}
#for (1 .. 10)
{
$rr=$a*$b;
}
$res=$rr-$r;
print $res->bn2hex()."\n";
/* perl/p5SSLeay.h */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
......@@ -55,6 +54,7 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#ifdef __cplusplus
extern "C" {
#endif
......
#include "p5SSLeay.h"
#include "openssl.h"
static int p5_bio_ex_bio_ptr=0;
static int p5_bio_ex_bio_callback=0;
......@@ -60,7 +61,7 @@ int ret;
int boot_bio()
{
p5_bio_ex_bio_ptr=
BIO_get_ex_new_index(0,"SSLeay::BIO",ex_new,NULL,
BIO_get_ex_new_index(0,"OpenSSL::BIO",ex_new,NULL,
ex_cleanup);
p5_bio_ex_bio_callback=
BIO_get_ex_new_index(0,"bio_callback",NULL,NULL,
......@@ -71,7 +72,7 @@ int boot_bio()
return(1);
}
MODULE = SSLeay::BIO PACKAGE = SSLeay::BIO PREFIX = p5_BIO_
MODULE = OpenSSL::BIO PACKAGE = OpenSSL::BIO PREFIX = p5_BIO_
VERSIONCHECK: DISABLE
......@@ -89,8 +90,8 @@ p5_BIO_new_buffer_ssl_connect(...)
else
arg=NULL;
if ((arg == NULL) || !(sv_derived_from(arg,"SSLeay::SSL::CTX")))
croak("Usage: SSLeay::BIO::new_buffer_ssl_connect(SSL_CTX)");
if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
croak("Usage: OpenSSL::BIO::new_buffer_ssl_connect(SSL_CTX)");
else
{
IV tmp=SvIV((SV *)SvRV(arg));
......@@ -115,8 +116,8 @@ p5_BIO_new_ssl_connect(...)
else
arg=NULL;
if ((arg == NULL) || !(sv_derived_from(arg,"SSLeay::SSL::CTX")))
croak("Usage: SSLeay::BIO::new_ssl_connect(SSL_CTX)");
if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
croak("Usage: OpenSSL::BIO::new_ssl_connect(SSL_CTX)");
else
{
IV tmp=SvIV((SV *)SvRV(arg));
......@@ -140,7 +141,7 @@ p5_BIO_new(...)
else if ((items == 2) && SvPOK(ST(1)))
type=SvPV(ST(1),na);
else
croak("Usage: SSLeay::BIO::new(type)");
croak("Usage: OpenSSL::BIO::new(type)");
EXTEND(sp,1);
if (strcmp(type,"connect") == 0)
......@@ -189,7 +190,7 @@ p5_BIO_push(b,bio)
CODE:
/* This reference will be reduced when the reference is
* let go, and then when the BIO_free_all() is called
* inside the SSLeay library by the BIO with this
* inside the OpenSSL library by the BIO with this
* pushed into */
bio->references++;
RETVAL=BIO_push(b,bio);
......@@ -210,12 +211,12 @@ p5_BIO_pop(b)
/* This BIO will either be one created in the
* perl library, in which case it will have a perl
* SV, otherwise it will have been created internally,
* inside SSLeay. For the 'pushed in', it needs
* inside OpenSSL. For the 'pushed in', it needs
* the reference count decememted. */
arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
if (arg == NULL)
{
arg=new_ref("SSLeay::BIO",(char *)bio,0);
arg=new_ref("OpenSSL::BIO",(char *)bio,0);
BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
PUSHs(arg);
}
......@@ -355,7 +356,7 @@ p5_BIO_next_bio(b)
arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
if (arg == NULL)
{
arg=new_ref("SSLeay::BIO",(char *)bio,0);
arg=new_ref("OpenSSL::BIO",(char *)bio,0);
BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
bio->references++;
PUSHs(arg);
......@@ -388,7 +389,7 @@ p5_BIO_set_callback(bio,cb,...)
SV *arg2=NULL;
CODE:
if (items > 3)
croak("Usage: SSLeay::BIO::set_callback(bio,callback[,arg]");
croak("Usage: OpenSSL::BIO::set_callback(bio,callback[,arg]");
if (items == 3)
{
arg2=sv_mortalcopy(ST(2));
......
#include "p5SSLeay.h"
#include "openssl.h"
int sv_to_BIGNUM(var,arg,name)
BIGNUM **var;
......@@ -7,7 +8,7 @@ char *name;
{
int ret=1;
if (sv_derived_from(arg,"SSLeay::BN"))
if (sv_derived_from(arg,"OpenSSL::BN"))
{
IV tmp = SvIV((SV*)SvRV(arg));
*var = (BIGNUM *) tmp;
......@@ -16,14 +17,14 @@ char *name;
SV *tmp=sv_newmortal();
*var=BN_new();
BN_set_word(*var,SvIV(arg));
sv_setref_pv(tmp,"SSLeay::BN",(void*)*var);
sv_setref_pv(tmp,"OpenSSL::BN",(void*)*var);
}
else if (SvPOK(arg)) {
char *ptr;
STRLEN len;
SV *tmp=sv_newmortal();
*var=BN_new();
sv_setref_pv(tmp,"SSLeay::BN", (void*)*var);
sv_setref_pv(tmp,"OpenSSL::BN", (void*)*var);
ptr=SvPV(arg,len);
SvGROW(arg,len+1);
ptr[len]='\0';
......@@ -69,7 +70,7 @@ char *arg;
LEAVE;
}
MODULE = SSLeay::BN PACKAGE = SSLeay::BN PREFIX = p5_BN_
MODULE = OpenSSL::BN PACKAGE = OpenSSL::BN PREFIX = p5_BN_
VERSIONCHECK: DISABLE
......@@ -83,7 +84,7 @@ p5_BN_new(...)
EXTEND(sp,1);
PUSHs(sv_newmortal());
bn=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)bn);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)bn);
void
p5_BN_dup(a)
......@@ -95,7 +96,7 @@ p5_BN_dup(a)
EXTEND(sp,1);
PUSHs(sv_newmortal());
bn=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)bn);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)bn);
void
p5_BN_rand(bits,...)
......@@ -107,14 +108,14 @@ p5_BN_rand(bits,...)
PPCODE:
pr_name("p5_BN_rand");
if ((items < 1) || (items > 3))
croak("Usage: SSLeay::BN::rand(bits[,top_bit][,bottombit]");
croak("Usage: OpenSSL::BN::rand(bits[,top_bit][,bottombit]");
if (items >= 2) top=(int)SvIV(ST(0));
if (items >= 3) bottom=(int)SvIV(ST(1));
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
BN_rand(ret,bits,top,bottom);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
void
p5_BN_bin2bn(a)
......@@ -126,7 +127,7 @@ p5_BN_bin2bn(a)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_bin2bn(a.dptr,a.dsize,NULL);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
void
p5_BN_bn2bin(a)
......@@ -152,7 +153,7 @@ p5_BN_mpi2bn(a)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_mpi2bn(a.dptr,a.dsize,NULL);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
void
p5_BN_bn2mpi(a)
......@@ -178,7 +179,7 @@ p5_BN_hex2bn(a)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_hex2bn(&ret,a.dptr);
void
......@@ -191,7 +192,7 @@ p5_BN_dec2bn(a)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_dec2bn(&ret,a.dptr);
SV *
......@@ -241,7 +242,7 @@ p5_BN_add(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_add(ret,a,b);
void
......@@ -255,7 +256,7 @@ p5_BN_sub(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_sub(ret,a,b);
void
......@@ -263,14 +264,16 @@ p5_BN_mul(a,b)
BIGNUM *a;
BIGNUM *b;
PREINIT:
static BN_CTX *ctx=NULL;
BIGNUM *ret;
PPCODE:
pr_name("p5_BN_mul");
if (ctx == NULL) ctx=BN_CTX_new();
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
BN_mul(ret,a,b);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_mul(ret,a,b,ctx);
void
p5_BN_div(a,b)
......@@ -287,8 +290,8 @@ p5_BN_div(a,b)
PUSHs(sv_newmortal());
div=BN_new();
mod=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)div);
sv_setref_pv(ST(1), "SSLeay::BN", (void*)mod);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)div);
sv_setref_pv(ST(1), "OpenSSL::BN", (void*)mod);
BN_div(div,mod,a,b,ctx);
void
......@@ -304,7 +307,7 @@ p5_BN_mod(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
rem=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)rem);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)rem);
BN_mod(rem,a,b,ctx);
void
......@@ -320,7 +323,7 @@ p5_BN_exp(a,p)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_exp(ret,a,p,ctx);
void
......@@ -337,7 +340,7 @@ p5_BN_mod_mul(a,b,c)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_mod_mul(ret,a,b,c,ctx);
void
......@@ -354,7 +357,7 @@ p5_BN_mod_exp(a,b,c)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_mod_exp(ret,a,b,c,ctx);
void
......@@ -371,20 +374,20 @@ p5_BN_generate_prime(...)
PPCODE:
pr_name("p5_BN_generate_prime");
if ((items < 0) || (items > 4))
croak("Usage: SSLeay::BN::generate_prime(a[,strong][,callback][,cb_arg]");
croak("Usage: OpenSSL::BN::generate_prime(a[,strong][,callback][,cb_arg]");
if (items >= 1) bits=(int)SvIV(ST(0));
if (items >= 2) strong=(int)SvIV(ST(1));
if (items >= 3) callback=ST(2);
if (items == 4) cb_arg=ST(3);
if (callback == NULL)
ret=BN_generate_prime(bits,strong,NULL,NULL,NULL,NULL);
ret=BN_generate_prime(ret,bits,strong,NULL,NULL,NULL,NULL);
else
{
arg.cb=callback;
arg.arg=cb_arg;
ret=BN_generate_prime(bits,strong,NULL,NULL,
ret=BN_generate_prime(ret,bits,strong,NULL,NULL,
generate_prime_callback,(char *)&arg);
}
......@@ -393,7 +396,7 @@ p5_BN_generate_prime(...)
EXTEND(sp,1);
PUSHs(sv_newmortal());
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
void
p5_BN_is_prime(p,...)
......@@ -408,7 +411,7 @@ p5_BN_is_prime(p,...)
PPCODE:
pr_name("p5_BN_is_prime");
if ((items < 1) || (items > 4))
croak("Usage: SSLeay::BN::is_prime(a[,ncheck][,callback][,callback_arg]");
croak("Usage: OpenSSL::BN::is_prime(a[,ncheck][,callback][,callback_arg]");
if (ctx == NULL) ctx=BN_CTX_new();
if (items >= 2) nchecks=(int)SvIV(ST(1));
if (items >= 3) callback=ST(2);
......@@ -477,7 +480,7 @@ p5_BN_set_bit(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_set_bit(ret,b);
void
......@@ -491,7 +494,7 @@ p5_BN_clear_bit(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_clear_bit(ret,b);
void
......@@ -505,7 +508,7 @@ p5_BN_lshift(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
if (b == 1)
BN_lshift1(ret,a);
else
......@@ -522,7 +525,7 @@ p5_BN_rshift(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
if (b == 1)
BN_rshift1(ret,a);
else
......@@ -539,7 +542,7 @@ p5_BN_mask_bits(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_dup(a);
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_mask_bits(ret,b);
void
......@@ -562,7 +565,7 @@ p5_BN_gcd(a,b)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ret=BN_new();
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
BN_gcd(ret,a,b,ctx);
void
......@@ -575,10 +578,10 @@ p5_BN_mod_inverse(a,mod)
PPCODE:
pr_name("p5_BN_mod_inverse");
if (ctx == NULL) ctx=BN_CTX_new();
ret=BN_mod_inverse(a,mod,ctx);
ret=BN_mod_inverse(ret,a,mod,ctx);
EXTEND(sp,1);
PUSHs(sv_newmortal());
sv_setref_pv(ST(0), "SSLeay::BN", (void*)ret);
sv_setref_pv(ST(0), "OpenSSL::BN", (void*)ret);
void
p5_BN_DESTROY(bn)
......
/* perl/callback.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
......
#include "p5SSLeay.h"
#include "openssl.h"
int boot_cipher()
{
......@@ -6,7 +7,7 @@ int boot_cipher()
return(1);
}
MODULE = SSLeay::Cipher PACKAGE = SSLeay::Cipher PREFIX = p5_EVP_C_
MODULE = OpenSSL::Cipher PACKAGE = OpenSSL::Cipher PREFIX = p5_EVP_C_
VERSIONCHECK: DISABLE
......@@ -22,14 +23,14 @@ p5_EVP_C_new(...)
else if ((items == 2) && SvPOK(ST(1)))
name=SvPV(ST(1),na);
else
croak("Usage: SSLeay::Cipher::new(type)");
croak("Usage: OpenSSL::Cipher::new(type)");
PUSHs(sv_newmortal());
c=EVP_get_cipherbyname(name);
if (c != NULL)
{
ctx=malloc(sizeof(EVP_CIPHER_CTX));
EVP_EncryptInit(ctx,c,NULL,NULL);
sv_setref_pv(ST(0), "SSLeay::Cipher", (void*)ctx);
sv_setref_pv(ST(0), "OpenSSL::Cipher", (void*)ctx);
}
datum
......
#include "p5SSLeay.h"
#include "openssl.h"
int boot_digest()
{
......@@ -6,12 +7,12 @@ int boot_digest()
return(1);
}
MODULE = SSLeay::MD PACKAGE = SSLeay::MD PREFIX = p5_EVP_MD_
MODULE = OpenSSL::MD PACKAGE = OpenSSL::MD PREFIX = p5_EVP_MD_
PROTOTYPES: ENABLE
VERSIONCHECK: DISABLE
# SSLeay::MD::new(name) name= md2, md5, sha, sha1, or mdc2
# OpenSSL::MD::new(name) name= md2, md5, sha, sha1, or mdc2
# md->name() - returns the name
# md->init() - reinitalises the digest
# md->update(data) - adds more data to digest
......@@ -30,14 +31,14 @@ p5_EVP_MD_new(...)
else if ((items == 2) && SvPOK(ST(1)))
name=SvPV(ST(1),na);
else
croak("Usage: SSLeay::MD::new(type)");
croak("Usage: OpenSSL::MD::new(type)");
PUSHs(sv_newmortal());
md=EVP_get_digestbyname(name);
if (md != NULL)
{
ctx=malloc(sizeof(EVP_MD_CTX));
EVP_DigestInit(ctx,md);
sv_setref_pv(ST(0), "SSLeay::MD", (void*)ctx);
sv_setref_pv(ST(0), "OpenSSL::MD", (void*)ctx);
}
datum
......
#include "p5SSLeay.h"
#include "openssl.h"
int boot_err()
{
......@@ -6,7 +7,7 @@ int boot_err()
return(1);
}
MODULE = SSLeay::ERR PACKAGE = SSLeay::ERR PREFIX = p5_ERR_
MODULE = OpenSSL::ERR PACKAGE = OpenSSL::ERR PREFIX = p5_ERR_
PROTOTYPES: ENABLE
VERSIONCHECK: DISABLE
......
#include "p5SSLeay.h"
#include "openssl.h"
static int p5_ssl_ex_ssl_ptr=0;
static int p5_ssl_ex_ssl_info_callback=0;
......@@ -44,7 +45,7 @@ int ret;
int boot_ssl()
{
p5_ssl_ex_ssl_ptr=
SSL_get_ex_new_index(0,"SSLeay::SSL",ex_new,NULL,ex_cleanup);
SSL_get_ex_new_index(0,"OpenSSL::SSL",ex_new,NULL,ex_cleanup);
p5_ssl_ex_ssl_info_callback=
SSL_get_ex_new_index(0,"ssl_info_callback",NULL,NULL,
ex_cleanup);
......@@ -57,7 +58,7 @@ int boot_ssl()
return(1);
}
MODULE = SSLeay::SSL PACKAGE = SSLeay::SSL::CTX PREFIX = p5_SSL_CTX_
MODULE = OpenSSL::SSL PACKAGE = OpenSSL::SSL::CTX PREFIX = p5_SSL_CTX_
VERSIONCHECK: DISABLE
......@@ -74,7 +75,7 @@ p5_SSL_CTX_new(...)
else if ((items == 2) && SvPOK(ST(1)))
method=SvPV(ST(1),na);
else
croak("Usage: SSLeay::SSL_CTX::new(type)");
croak("Usage: OpenSSL::SSL_CTX::new(type)");
if (strcmp(method,"SSLv3") == 0)
meth=SSLv3_method();
......@@ -101,7 +102,7 @@ p5_SSL_CTX_new(...)
EXTEND(sp,1);
PUSHs(sv_newmortal());
ctx=SSL_CTX_new(meth);
sv_setref_pv(ST(0), "SSLeay::SSL::CTX", (void*)ctx);
sv_setref_pv(ST(0), "OpenSSL::SSL::CTX", (void*)ctx);
int
p5_SSL_CTX_use_PrivateKey_file(ctx,file,...)
......@@ -113,7 +114,7 @@ p5_SSL_CTX_use_PrivateKey_file(ctx,file,...)
CODE:
pr_name("p5_SSL_CTX_use_PrivateKey_file");
if (items > 3)
croak("SSLeay::SSL::CTX::use_PrivateKey_file(ssl_ctx,file[,type])");
croak("OpenSSL::SSL::CTX::use_PrivateKey_file(ssl_ctx,file[,type])");
if (items == 3)
{
ptr=SvPV(ST(2),na);
......@@ -139,7 +140,7 @@ p5_SSL_CTX_set_options(ctx,...)
for (i=1; i<items; i++)
{
if (!SvPOK(ST(i)))
croak("Usage: SSLeay::SSL_CTX::set_options(ssl_ctx[,option,value]+)");
croak("Usage: OpenSSL::SSL_CTX::set_options(ssl_ctx[,option,value]+)");
ptr=SvPV(ST(i),na);
if (strcmp(ptr,"-info_callback") == 0)
{
......@@ -154,7 +155,7 @@ p5_SSL_CTX_set_options(ctx,...)
}
else
{
croak("SSLeay::SSL_CTX::set_options(): unknown option");
croak("OpenSSL::SSL_CTX::set_options(): unknown option");
}
}
......@@ -167,7 +168,7 @@ p5_SSL_CTX_DESTROY(ctx)
pr_name_d("p5_SSL_CTX_DESTROY",ctx->references);
SSL_CTX_free(ctx);
MODULE = SSLeay::SSL PACKAGE = SSLeay::SSL PREFIX = p5_SSL_
MODULE = OpenSSL::SSL PACKAGE = OpenSSL::SSL PREFIX = p5_SSL_
void
p5_SSL_new(...)
......@@ -180,20 +181,20 @@ p5_SSL_new(...)
PPCODE:
pr_name("p5_SSL_new");
if ((items != 1) && (items != 2))
croak("Usage: SSLeay::SSL::new(ssl_ctx)");
if (sv_derived_from(ST(items-1),"SSLeay::SSL::CTX"))
croak("Usage: OpenSSL::SSL::new(ssl_ctx)");
if (sv_derived_from(ST(items-1),"OpenSSL::SSL::CTX"))
{
IV tmp = SvIV((SV*)SvRV(ST(items-1)));
ctx=(SSL_CTX *)tmp;
sv_ctx=ST(items-1);
}
else
croak("ssl_ctx is not of type SSLeay::SSL::CTX");
croak("ssl_ctx is not of type OpenSSL::SSL::CTX");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ssl=SSL_new(ctx);
sv_setref_pv(ST(0), "SSLeay::SSL", (void*)ssl);
sv_setref_pv(ST(0), "OpenSSL::SSL", (void*)ssl);
/* Now this is being a little hairy, we keep a pointer to
* our perl reference. We need to do a different one
......@@ -317,7 +318,7 @@ p5_SSL_set_options(ssl,...)
for (i=1; i<items; i++)
{
if (!SvPOK(ST(i)))
croak("Usage: SSLeay::SSL::set_options(ssl[,option,value]+)");
croak("Usage: OpenSSL::SSL::set_options(ssl[,option,value]+)");
ptr=SvPV(ST(i),na);
if (strcmp(ptr,"-info_callback") == 0)
{
......@@ -339,7 +340,7 @@ p5_SSL_set_options(ssl,...)
}
else
{
croak("SSLeay::SSL::set_options(): unknown option");
croak("OpenSSL::SSL::set_options(): unknown option");
}
}
......@@ -421,7 +422,7 @@ p5_SSL_get_peer_certificate(ssl)
OUTPUT:
RETVAL
MODULE = SSLeay::SSL PACKAGE = SSLeay::SSL::CIPHER PREFIX = p5_SSL_CIPHER_
MODULE = OpenSSL::SSL PACKAGE = OpenSSL::SSL::CIPHER PREFIX = p5_SSL_CIPHER_
int
p5_SSL_CIPHER_get_bits(sc)
......@@ -452,7 +453,7 @@ p5_SSL_CIPHER_get_name(sc)
OUTPUT:
RETVAL
MODULE = SSLeay::SSL PACKAGE = SSLeay::BIO PREFIX = p5_BIO_
MODULE = OpenSSL::SSL PACKAGE = OpenSSL::BIO PREFIX = p5_BIO_
void
p5_BIO_get_ssl(bio)
......
#include "p5SSLeay.h"
MODULE = SSLeay::X509 PACKAGE = SSLeay::X509 PREFIX = p5_X509_
#include "openssl.h"
MODULE = OpenSSL::X509 PACKAGE = OpenSSL::X509 PREFIX = p5_X509_
PROTOTYPES: ENABLE
VERSIONCHECK: DISABLE
......@@ -15,7 +16,7 @@ p5_X509_new(void )
EXTEND(sp,1);
PUSHs(sv_newmortal());
x509=X509_new();
sv_setref_pv(ST(0),"SSLeay::X509",(void *)x509);
sv_setref_pv(ST(0),"OpenSSL::X509",(void *)x509);
char *
p5_X509_get_subject_name(x509)
......
/* perl/p5SSLeay.h */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
typedef struct datum_st
{
char *dptr;
int dsize;
} datum;
#include "crypto.h"
#include "buffer.h"
#include "bio.h"
#include "evp.h"
#include "err.h"
#include "x509.h"
#include "ssl.h"
#if 0
#define pr_name(name) printf("%s\n",name)
#define pr_name_d(name,p2) printf("%s %d\n",name,p2)
#define pr_name_dd(name,p2,p3) printf("%s %d %d\n",name,p2,p3)
#else
#define pr_name(name)
#define pr_name_d(name,p2)
#define pr_name_dd(name,p2,p3)
#endif
SV *new_ref(char *type, char *obj, int mort);
int ex_new(char *obj,SV *data,CRYPTO_EX_DATA *ad,int idx,long argl,char *argp);
void ex_cleanup(char *obj,SV *data,CRYPTO_EX_DATA *ad,int idx,
long argl,char *argp);
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$bits=512;
$bits=$ARGV[0] if $#ARGV >= 0;
$q=SSLeay::BN::dec2bn("334533373942443239443435463034324139443635374634423531423146313742443038394230324138363038393539303745363034393946353346323345374537463935433635374238353245344341444241344138413244373443323338334431414134363244443532423243423133433537");
$p=SSLeay::BN::dec2bn("3338413942343132463534373734353742343636444439363131313131353843334536434330363934313646414132453044434138413630434631334134443046313735313632344131433437443642434436423642453234383046393732383538444139393131314339303743393939363744443235443332393332394543384630304634323646333735");
$pp=SSLeay::BN::generate_prime($bits/2,0,sub {print STDERR $_[0]?"+":"."});
printf $pp->is_prime."\n";
printf $p->is_prime."\n";
printf $q->is_prime."\n";
printf "p->length=%d\n",$p->num_bits;
printf "q->length=%d\n",$q->num_bits;
$bits=$p->num_bits+$q->num_bits;
$e=SSLeay::BN::hex2bn("10001");
$t1=$p-1;
$t2=$q-1;
($t1->gcd($e) == 1) || die "p failed the gcd test\n";
($t2->gcd($e) == 1) || die "q failed the gcd test\n";
($q,$p)=($p,$q) if ($p < $q);
$n=$p*$q;
$t=($p-1)*($q-1);
($t->gcd($e) == 1) || die "t failed the gcd test\n";
$d=$e->mod_inverse($t);
$dmp1=$d%($p-1);
$dmq1=$d%($q-1);
$iqmp=$q->mod_inverse($p);
print "n =$n\n";
print "e =$e\n";
print "d =$d\n";
print "dmp1=$dmp1\n";
print "dmq1=$dmq1\n";
print "iqmp=$iqmp\n";
$a=SSLeay::BN::bin2bn("This is an RSA test");
print "Test with\n'".$a->bn2bin."' or\n$a\n";
print "<$a>\n";
$t1=$a->mod_exp($e,$n);
print ">$t1>\n";
$t2=$t1->mod_exp($d,$n);
print "<$t2>\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$ssl_ctx=SSL::CTX->new("SSLv3_client");
$ssl_ctx->set_options("-info_callback" =>
sub {
print STDERR $_[0]->state()."\n";
}
);
$conn="localhost:4433";
$conn=$ARGV[0] if $#ARGV >= 0;
$cbio=BIO->new("connect");
$cbio->hostname($conn) || die $ssl->error();
$bbio=BIO->new("buffer");
$sbio=BIO->new("ssl");
$ssl=$ssl_ctx->new_ssl;
$ssl->set_options(-connect_state);
$sbio->set_ssl($ssl);
$sbio->push($cbio);
$bbio->push($sbio);
$bio=$bbio;
#$bio->set_callback(
# sub {
# my($bio,$state,$cmd,$buf,$lart,$ret)=@_;
# print STDERR "$state:$cmd\n";
# return($ret);
# }
# );
$b=$bio;
do {
print STDERR $b->type."\n";
} while ($b=$b->next_bio);
(($ret=$bio->syswrite("GET / HTTP/1.0\r\n\r\n")) > 0) || die $bio->error();
$bio->flush;
$data="";
while (1)
{
$ret=$bio->getline;
$ret =~ s/[\r\n]//g;
print STDERR "$ret\n";
last if $ret eq "";
$server=$1 if $ret=~ /^Server: (.*)/;
}
print "server is $server\n";
$x509=$ssl->get_peer_certificate();
print "version :".$x509->get_version()."\n";
print "serialNumber:".$x509->get_serialNumber()->bn2hex."\n";
print "subject :".$x509->get_subject_name()."\n";
print "issuer :". $x509->get_issuer_name()."\n";
$c=$ssl->get_current_cipher;
($i,$a)=$c->get_bits;
$v=$c->get_version;
$n=$c->get_name;
print "protocol=".$ssl->get_version."\n";
print "bits=$i($a) cipher type=$v cipher=$n\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$ssl_ctx=SSL::CTX->new("SSLv3");
$ssl_ctx->set_options("-info_callback" =>
sub {
print STDERR $_[0]->state()."\n";
}
);
$conn="localhost:4433";
$conn=$ARGV[0] if $#ARGV >= 0;
$cbio=BIO->new("connect");
$cbio->hostname($conn) || die $ssl->error();
$ssl=$ssl_ctx->new_ssl;
$sbio=BIO->new("ssl");
$sbio->set_ssl($ssl);
$ssl->set_options("-connect_state");
$bio=BIO->new("buffer");
$sbio->push($cbio);
$bio->push($sbio);
($bio->do_handshake() > 0) || die $bio->error();
(($ret=$bio->syswrite("GET / HTTP/1.0\r\n\r\n")) > 0) || die $ssl->error();
$bio->flush() || die $bio->error();
$data="";
while ($_=$bio->getline())
{
if (/^Server:/)
{
print;
last;
}
}
if ($bio->peek_error())
{
print "There was an error:".$ssl->error();
}
print "exit\n";
此差异已折叠。
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$ssl_ctx=SSL::CTX->new("SSLv3_client");
#$ssl_ctx->set_options("-info_callback" =>
# sub {
# print STDERR $_[0]->state()."\n";
# }
# );
$conn="localhost:4433";
$conn=$ARGV[0] if $#ARGV >= 0;
print $ssl_ctx."\n";
$bio=BIO->new_buffer_ssl_connect($ssl_ctx);
$bio->hostname($conn) || die $bio->error();
#$bio->set_callback(
# sub {
# my($bio,$state,$cmd,$buf,$lart,$ret)=@_;
# print STDERR "$state:$cmd\n";
# return($ret);
# }
# );
#$b=$bio;
#do {
# print STDERR $b->type."\n";
# } while ($b=$b->next_bio);
(($ret=$bio->syswrite("GET / HTTP/1.0\r\n\r\n")) > 0) || die $bio->error();
$bio->flush;
$data="";
while (1)
{
$ret=$bio->getline;
$ret =~ s/[\r\n]//g;
print STDERR "$ret\n";
last if $ret eq "";
$server=$1 if $ret=~ /^Server: (.*)/;
}
print "server is $server\n";
$x509=$ssl->get_peer_certificate();
print "version :".$x509->get_version()."\n";
print "serialNumber:".$x509->get_serialNumber()->bn2hex."\n";
print "subject :".$x509->get_subject_name()."\n";
print "issuer :". $x509->get_issuer_name()."\n";
$c=$ssl->get_current_cipher;
($i,$a)=$c->get_bits;
$v=$c->get_version;
$n=$c->get_name;
$ssl=$bio->get_ssl();
print "protocol=".$ssl->get_version."\n";
print "bits=$i($a) cipher type=$v cipher=$n\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$ssl_ctx=SSL::CTX->new("SSLv3");
#$ssl_ctx->set_options("-info_callback" =>
# sub {
# print STDERR $_[0]->state()."\n";
# }
# );
$conn="localhost:4433";
$conn=$ARGV[0] if $#ARGV >= 0;
$bio=BIO->new("connect");
$bio->hostname($conn) || die $ssl->error();
#$bbio=BIO->new("buffer");
#$bbio->push($cbio);
#$bio=$bbio;
#$bio->set_callback(
# sub {
# my($bio,$state,$cmd,$buf,$lart,$ret)=@_;
# print STDERR "$state:$cmd\n";
# return($ret);
# }
# );
print STDERR "-1 ABCD\n";
$ssl=$ssl_ctx->new_ssl;
print STDERR "000 ABCD\n";
$ssl->set_bio($bio);
print STDERR "00 ABCD\n";
(($ret=$ssl->connect()) > 0) || die $ssl->error();
print STDERR "0 ABCD\n";
(($ret=$ssl->syswrite("GET / HTTP/1.0\r\n\r\n")) > 0) || die $ssl->error();
print STDERR "1 ABCD\n";
$data="";
while (1)
{
print STDERR "2 ABCD\n";
$ret=$ssl->sysread($buf,1024);
print STDERR "3 ABCD\n";
last if $ret <= 0;
$data.=$buf;
}
print STDERR "4 ABCD\n";
@a=split(/[\r]\n/,$data);
($server)=grep(/^Server:/,@a);
print "$server\n";
$x509=$ssl->get_peer_certificate();
print "subject:".$x509->get_subject_name()."\n";
print "issuer:". $x509->get_issuer_name()."\n";
$c=$ssl->get_current_cipher;
($i,$a)=$c->get_bits;
$v=$c->get_version;
$n=$c->get_name;
print "protocol=".$ssl->get_version."\n";
print "bits=$i($a) cipher type=$v cipher=$n\n";
SSL_CTX::new(method)
SSLv3
SSLv3_client
SSLv3_server
SSLv23
SSLv23_client
SSLv23_server
SSLv2
SSLv2_client
SSLv2_server
SSL_CTX::use_PrivateKey_file(file[,type])
type eq "der" or "pem". Default == 'pem'.
SSL_CTX::set_options(...)
-info_callback function
SSL::new(SSL_CTX)
SSL::connect(); returns 0, -1 or 1
SSL::accept(); return 0, -1 or 1
SSL::sysread(); as per sysread
SSL::syswrite(); as per syswrite
SSL::set_bio(bio);
SSL::set_options(...)
-info_callback function
-connect_state
-accept_state
SSL::state(); the state in numeric and text form.
SSL::references(); debug stuff
SSL::get_peer_certificate()
SSL::do_handshake()
SSL::renegotiate()
SSL::shutdown()
SSL::get_version()
SSL::get_current_cipher();
(key,alg)=SSL_CIPHER::get_bits();
SSL_CIPHER::get_version();
SSL_CIPHER::get_name();
#include "p5SSLeay.h"
static int p5_ssl_ex_ssl_ptr=0;
static int p5_ssl_ex_ssl_info_callback=0;
static int p5_ssl_ex_ssl_ctx_ptr=0;
static int p5_ssl_ctx_ex_ssl_info_callback=0;
typedef struct ssl_ic_args_st {
SV *cb;
SV *arg;
} SSL_IC_ARGS;
static void p5_ssl_info_callback(ssl,mode,ret)
SSL *ssl;
int mode;
int ret;
{
int i;
SV *me,*cb;
me=(SV *)SSL_get_ex_data(ssl,p5_ssl_ex_ssl_ptr);
cb=(SV *)SSL_get_ex_data(ssl,p5_ssl_ex_ssl_info_callback);
if (cb == NULL)
cb=(SV *)SSL_CTX_get_ex_data(
SSL_get_SSL_CTX(ssl),p5_ssl_ctx_ex_ssl_info_callback);
if (cb != NULL)
{
dSP;
PUSHMARK(sp);
XPUSHs(me);
XPUSHs(sv_2mortal(newSViv(mode)));
XPUSHs(sv_2mortal(newSViv(ret)));
PUTBACK;
i=perl_call_sv(cb,G_DISCARD);
}
else
{
croak("Internal error in SSL p5_ssl_info_callback");
}
}
int boot_ssl()
{
p5_ssl_ex_ssl_ptr=
SSL_get_ex_new_index(0,"SSLeay::SSL",ex_new,NULL,ex_cleanup);
p5_ssl_ex_ssl_info_callback=
SSL_get_ex_new_index(0,"ssl_info_callback",NULL,NULL,
ex_cleanup);
p5_ssl_ex_ssl_ctx_ptr=
SSL_get_ex_new_index(0,"ssl_ctx_ptr",NULL,NULL,
ex_cleanup);
p5_ssl_ctx_ex_ssl_info_callback=
SSL_CTX_get_ex_new_index(0,"ssl_ctx_info_callback",NULL,NULL,
ex_cleanup);
return(1);
}
MODULE = SSLeay::SSL PACKAGE = SSLeay::SSL::CTX PREFIX = p5_SSL_CTX_
VERSIONCHECK: DISABLE
void
p5_SSL_CTX_new(...)
PREINIT:
SSL_METHOD *meth;
SSL_CTX *ctx;
char *method;
PPCODE:
pr_name("p5_SSL_CTX_new");
if ((items == 1) && SvPOK(ST(0)))
method=SvPV(ST(0),na);
else if ((items == 2) && SvPOK(ST(1)))
method=SvPV(ST(1),na);
else
croak("Usage: SSLeay::SSL_CTX::new(type)");
if (strcmp(method,"SSLv3") == 0)
meth=SSLv3_method();
else if (strcmp(method,"SSLv3_client") == 0)
meth=SSLv3_client_method();
else if (strcmp(method,"SSLv3_server") == 0)
meth=SSLv3_server_method();
else if (strcmp(method,"SSLv23") == 0)
meth=SSLv23_method();
else if (strcmp(method,"SSLv23_client") == 0)
meth=SSLv23_client_method();
else if (strcmp(method,"SSLv23_server") == 0)
meth=SSLv23_server_method();
else if (strcmp(method,"SSLv2") == 0)
meth=SSLv2_method();
else if (strcmp(method,"SSLv2_client") == 0)
meth=SSLv2_client_method();
else if (strcmp(method,"SSLv2_server") == 0)
meth=SSLv2_server_method();
else
{
croak("Not passed a valid SSL method name, should be 'SSLv[23] [client|server]'");
}
EXTEND(sp,1);
PUSHs(sv_newmortal());
ctx=SSL_CTX_new(meth);
sv_setref_pv(ST(0), "SSLeay::SSL::CTX", (void*)ctx);
int
p5_SSL_CTX_use_PrivateKey_file(ctx,file,...)
SSL_CTX *ctx;
char *file;
PREINIT:
int i=SSL_FILETYPE_PEM;
char *ptr;
CODE:
pr_name("p5_SSL_CTX_use_PrivateKey_file");
if (items > 3)
croak("SSLeay::SSL::CTX::use_PrivateKey_file(ssl_ctx,file[,type])");
if (items == 3)
{
ptr=SvPV(ST(2),na);
if (strcmp(ptr,"der") == 0)
i=SSL_FILETYPE_ASN1;
else
i=SSL_FILETYPE_PEM;
}
RETVAL=SSL_CTX_use_RSAPrivateKey_file(ctx,file,i);
OUTPUT:
RETVAL
int
p5_SSL_CTX_set_options(ctx,...)
SSL_CTX *ctx;
PREINIT:
int i;
char *ptr;
SV *sv;
CODE:
pr_name("p5_SSL_CTX_set_options");
for (i=1; i<items; i++)
{
if (!SvPOK(ST(i)))
croak("Usage: SSLeay::SSL_CTX::set_options(ssl_ctx[,option,value]+)");
ptr=SvPV(ST(i),na);
if (strcmp(ptr,"-info_callback") == 0)
{
SSL_CTX_set_info_callback(ctx,
p5_ssl_info_callback);
sv=sv_mortalcopy(ST(i+1));
SvREFCNT_inc(sv);
SSL_CTX_set_ex_data(ctx,
p5_ssl_ctx_ex_ssl_info_callback,
(char *)sv);
i++;
}
else
{
croak("SSLeay::SSL_CTX::set_options(): unknown option");
}
}
void
p5_SSL_CTX_DESTROY(ctx)
SSL_CTX *ctx
PREINIT:
SV *sv;
PPCODE:
pr_name_d("p5_SSL_CTX_DESTROY",ctx->references);
SSL_CTX_free(ctx);
MODULE = SSLeay::SSL PACKAGE = SSLeay::SSL PREFIX = p5_SSL_
void
p5_SSL_new(...)
PREINIT:
SV *sv_ctx;
SSL_CTX *ctx;
SSL *ssl;
int i;
SV *arg;
PPCODE:
pr_name("p5_SSL_new");
if ((items != 1) && (items != 2))
croak("Usage: SSLeay::SSL::new(ssl_ctx)");
if (sv_derived_from(ST(items-1),"SSLeay::SSL::CTX"))
{
IV tmp = SvIV((SV*)SvRV(ST(items-1)));
ctx=(SSL_CTX *)tmp;
sv_ctx=ST(items-1);
}
else
croak("ssl_ctx is not of type SSLeay::SSL::CTX");
EXTEND(sp,1);
PUSHs(sv_newmortal());
ssl=SSL_new(ctx);
sv_setref_pv(ST(0), "SSLeay::SSL", (void*)ssl);
/* Now this is being a little hairy, we keep a pointer to
* our perl reference. We need to do a different one
* to the one we return because it will have it's reference
* count droped to 0 apon return and if we up its reference
* count, it will never be DESTROYED */
arg=newSVsv(ST(0));
SSL_set_ex_data(ssl,p5_ssl_ex_ssl_ptr,(char *)arg);
SvREFCNT_inc(sv_ctx);
SSL_set_ex_data(ssl,p5_ssl_ex_ssl_ctx_ptr,(char *)sv_ctx);
int
p5_SSL_connect(ssl)
SSL *ssl;
CODE:
RETVAL=SSL_connect(ssl);
OUTPUT:
RETVAL
int
p5_SSL_accept(ssl)
SSL *ssl;
CODE:
RETVAL=SSL_connect(ssl);
OUTPUT:
RETVAL
int
p5_SSL_sysread(ssl,in,num, ...)
SSL *ssl;
SV *in;
int num;
PREINIT:
int i,n,olen;
int offset;
char *p;
CODE:
offset=0;
if (!SvPOK(in))
sv_setpvn(in,"",0);
SvPV(in,olen);
if (items > 3)
{
offset=SvIV(ST(3));
if (offset < 0)
{
if (-offset > olen)
croak("Offset outside string");
offset+=olen;
}
}
if ((num+offset) > olen)
{
SvGROW(in,num+offset+1);
p=SvPV(in,i);
memset(&(p[olen]),0,(num+offset)-olen+1);
}
p=SvPV(in,n);
i=SSL_read(ssl,p+offset,num);
RETVAL=i;
if (i <= 0) i=0;
SvCUR_set(in,offset+i);
OUTPUT:
RETVAL
int
p5_SSL_syswrite(ssl,in, ...)
SSL *ssl;
SV *in;
PREINIT:
char *ptr;
int len,in_len;
int offset=0;
int n;
CODE:
ptr=SvPV(in,in_len);
if (items > 2)
{
len=SvOK(ST(2))?SvIV(ST(2)):in_len;
if (items > 3)
{
offset=SvIV(ST(3));
if (offset < 0)
{
if (-offset > in_len)
croak("Offset outside string");
offset+=in_len;
}
else if ((offset >= in_len) && (in_len > 0))
croak("Offset outside string");
}
if (len >= (in_len-offset))
len=in_len-offset;
}
else
len=in_len;
RETVAL=SSL_write(ssl,ptr+offset,len);
OUTPUT:
RETVAL
void
p5_SSL_set_bio(ssl,bio)
SSL *ssl;
BIO *bio;
CODE:
bio->references++;
SSL_set_bio(ssl,bio,bio);
int
p5_SSL_set_options(ssl,...)
SSL *ssl;
PREINIT:
int i;
char *ptr;
SV *sv;
CODE:
pr_name("p5_SSL_set_options");
for (i=1; i<items; i++)
{
if (!SvPOK(ST(i)))
croak("Usage: SSLeay::SSL::set_options(ssl[,option,value]+)");
ptr=SvPV(ST(i),na);
if (strcmp(ptr,"-info_callback") == 0)
{
SSL_set_info_callback(ssl,
p5_ssl_info_callback);
sv=sv_mortalcopy(ST(i+1));
SvREFCNT_inc(sv);
SSL_set_ex_data(ssl,
p5_ssl_ex_ssl_info_callback,(char *)sv);
i++;
}
else if (strcmp(ptr,"-connect_state") == 0)
{
SSL_set_connect_state(ssl);
}
else if (strcmp(ptr,"-accept_state") == 0)
{
SSL_set_accept_state(ssl);
}
else
{
croak("SSLeay::SSL::set_options(): unknown option");
}
}
void
p5_SSL_state(ssl)
SSL *ssl;
PREINIT:
int state;
PPCODE:
pr_name("p5_SSL_state");
EXTEND(sp,1);
PUSHs(sv_newmortal());
state=SSL_state(ssl);
sv_setpv(ST(0),SSL_state_string_long(ssl));
sv_setiv(ST(0),state);
SvPOK_on(ST(0));
void
p5_SSL_DESTROY(ssl)
SSL *ssl;
CODE:
pr_name_dd("p5_SSL_DESTROY",ssl->references,ssl->ctx->references);
fprintf(stderr,"SSL_DESTROY %d\n",ssl->references);
SSL_free(ssl);
int
p5_SSL_references(ssl)
SSL *ssl;
CODE:
RETVAL=ssl->references;
OUTPUT:
RETVAL
int
p5_SSL_do_handshake(ssl)
SSL *ssl;
CODE:
RETVAL=SSL_do_handshake(ssl);
OUTPUT:
RETVAL
int
p5_SSL_renegotiate(ssl)
SSL *ssl;
CODE:
RETVAL=SSL_renegotiate(ssl);
OUTPUT:
RETVAL
int
p5_SSL_shutdown(ssl)
SSL *ssl;
CODE:
RETVAL=SSL_shutdown(ssl);
OUTPUT:
RETVAL
char *
p5_SSL_get_version(ssl)
SSL *ssl;
CODE:
RETVAL=SSL_get_version(ssl);
OUTPUT:
RETVAL
SSL_CIPHER *
p5_SSL_get_current_cipher(ssl)
SSL *ssl;
CODE:
RETVAL=SSL_get_current_cipher(ssl);
OUTPUT:
RETVAL
X509 *
p5_SSL_get_peer_certificate(ssl)
SSL *ssl
CODE:
RETVAL=SSL_get_peer_certificate(ssl);
OUTPUT:
RETVAL
MODULE = SSLeay::SSL PACKAGE = SSLeay::SSL::CIPHER PREFIX = p5_SSL_CIPHER_
int
p5_SSL_CIPHER_get_bits(sc)
SSL_CIPHER *sc
PREINIT:
int i,ret;
PPCODE:
EXTEND(sp,2);
PUSHs(sv_newmortal());
PUSHs(sv_newmortal());
ret=SSL_CIPHER_get_bits(sc,&i);
sv_setiv(ST(0),(IV)ret);
sv_setiv(ST(1),(IV)i);
char *
p5_SSL_CIPHER_get_version(sc)
SSL_CIPHER *sc
CODE:
RETVAL=SSL_CIPHER_get_version(sc);
OUTPUT:
RETVAL
char *
p5_SSL_CIPHER_get_name(sc)
SSL_CIPHER *sc
CODE:
RETVAL=SSL_CIPHER_get_name(sc);
OUTPUT:
RETVAL
MODULE = SSLeay::SSL PACKAGE = SSLeay::BIO PREFIX = p5_BIO_
void
p5_BIO_get_ssl(bio)
BIO *bio;
PREINIT:
SSL *ssl;
SV *ret;
int i;
PPCODE:
if ((i=BIO_get_ssl(bio,&ssl)) > 0)
{
ret=(SV *)SSL_get_ex_data(ssl,p5_ssl_ex_ssl_ptr);
ret=sv_mortalcopy(ret);
}
else
ret= &sv_undef;
EXTEND(sp,1);
PUSHs(ret);
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$ssl_ctx=SSL::CTX->new("SSLv3");
$ssl_ctx->set_options("-info_callback" =>
sub {
print STDERR $_[0]->state()."\n";
}
);
$ssl_ctx->use_PrivateKey_file("server.pem");
$conn="localhost:4433";
$conn=$ARGV[0] if $#ARGV >= 0;
$bio=BIO->new("connect");
$bio->hostname($conn) || die $ssl->error();
$ssl=$ssl_ctx->new_ssl;
$ssl->set_bio($bio);
(($ret=$ssl->connect()) > 0) || die $ssl->error();
(($ret=$ssl->write("GET / HTTP/1.0\r\n\r\n")) > 0) || die $ssl->error();
while (1)
{
$ret=$ssl->read($buf,10240);
last if ($ret <= 0);
print $buf;
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$ssl_ctx=SSL::CTX->new("SSLv3");
#$ssl_ctx->set_options("-info_callback" =>
# sub {
# print STDOUT $_[0]->state()."\n";
# }
# );
# create a ssl bio
$bssl=BIO->new("ssl");
$bssl->set_ssl($ssl_ctx->new_ssl()) || die $bssl->error();
$bssl->get_ssl->set_options("-connect_state") || die $ssl->error();
$bssl->set_callback(sub { printf "XXXXXXXXXXXXXXXXXXXXXX %d %s\n",$_[1],$_[0]->type; });
# create connect bio
$host="localhost:4433";
$host=$ARGV[0] if $#ARGV >= 0;
$bio=BIO->new("connect");
$bio->hostname($host) || die $bio->error();
# push it in
$bssl->push($bio);
(($ret=$bssl->write("GET / HTTP/1.0\r\n\r\n")) > 0) || die $bssl->error();
while (1)
{
$ret=$bssl->read($buf,10240);
last if ($ret <= 0);
print $buf;
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$a=SSLeay::BN::dec2bn("1231353465324563455");
print "a=$a\n".$a->bn2dec."\n";
$b=SSLeay::BN::dec2bn("98790816238765235");
print "a=$a\nb=$b\n";
print $a->gcd($b)."\n";
30373b8dbfc38d360bda81fad2fb462e 8 0 8 des-ecb
a5f61a73a0894979d46c2481e9f27151 8 8 1 des-cfb
a64a08dc69e79becccde95bed6239fca 8 8 1 des-ofb
553d168193e54100524541f2c473b705 8 8 8 des-cbc
bb75383e4aad6d83418dde16c6cea6f5 16 0 8 des-ede
3ea71cd9a2e50d82d66b433e9471eeb2 16 8 1 des-ede-cfb
3d56b76d43dc8d51647773bc9719a355 16 8 1 des-ede-ofb
eafa89aae63167b9798639c0e31223b4 16 8 8 des-ede-cbc
a952f8c409fb0df75a7df1aa54ba30b8 24 0 8 des-ede3
0badccc43a14d8503d33f32a2345bbd2 24 8 1 des-ede3-cfb
bae638c0e33850d02c792ed0e3d6b600 24 8 1 des-ede3-ofb
ec4522bbefabf0198126683e661325e2 24 8 8 des-ede3-cbc
4431f05d198d8afc003aeec85bea01b9 24 8 8 desx-cbc
606af8d6f30c1fd9c647df5eb716ae0f 16 0 1 rc4
4aaaf7e4bc3fd2caa6318a4852f636f4 5 0 1 rc4-40
77e0851e8c96c4a1e26140d1ec822036 16 0 8 idea-ecb
a28e51e283519fde0e128bcb697bc23e 16 8 1 idea-cfb
17d0e70f07de6c08e9673d52987599ab 16 8 1 idea-ofb
0687cf6ca11ee45f8bf9c29525405a4d 16 8 8 idea-cbc
e2268681a63198fe38282b0a1bb6ed36 16 0 8 rc2-ecb
f48748e6386790e639bbee4fccaa5067 16 8 8 rc2-cbc
f250cfe829ef797d6866e32526ec4fe4 5 8 8 rc2-40-cbc
a372f970b6c346341a2899bb872a7349 16 8 1 rc2-cfb
d2da66102dea6b833f0fbf71e2cb4988 16 8 1 rc2-ofb
237b0ef0e4f7fb28a5708d59773caecf 16 0 8 bf-ecb
c58cf5da90472caf0f0b7fafb0590977 16 8 1 bf-cfb
1f3e49e2e27f9ad177a6a64b09d361ed 16 8 1 bf-ofb
66acaf2cb5f301580c59fa17d005b716 16 8 8 bf-cbc
3548c9fe9fcd13f647ae177a15915af9 16 0 8 cast5-ecb
e8d074ad8cc0d3d828da80ab18452f91 16 8 1 cast5-cfb
5331eb4351c2048c27c8a8901fd29e20 16 8 1 cast5-ofb
8033607fdb68598cc62c379af218eeeb 16 8 8 cast5-cbc
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
($a=SSLeay::BN::new()) || die "unable to make bignum\n";
($b=SSLeay::BN::new()) || die "unable to make bignum\n";
$a=SSLeay::BN::hex2bn("123456789ABCDEF");
$b=SSLeay::BN::hex2bn("123456789ABCDEF");
$mod=SSLeay::BN::hex2bn("fedcba9876543201");
$c=SSLeay::BN::hex2bn("1234");
print "a=".$a->bn2hex()."\n";
print "b=".$b->bn2hex()."\n";
print "c=".$c->bn2hex()."\n";
print $a->mul($b)->bn2hex."\n";
($d,$r)=$b->div($c);
print "($d)($r)\n";
printf "%s x %s + %s\n",$c->bn2hex,$d->bn2hex,$r->bn2hex;
$g=$d;
for (;;)
{
$a=$a->mod_mul($a,$mod);
print $a->bn2hex."\n";
}
30373b8dbfc38d360bda81fad2fb462e 8 0 8 des-ecb
a5f61a73a0894979d46c2481e9f27151 8 8 1 des-cfb
a64a08dc69e79becccde95bed6239fca 8 8 1 des-ofb
553d168193e54100524541f2c473b705 8 8 8 des-cbc
bb75383e4aad6d83418dde16c6cea6f5 16 0 8 des-ede
3ea71cd9a2e50d82d66b433e9471eeb2 16 8 1 des-ede-cfb
3d56b76d43dc8d51647773bc9719a355 16 8 1 des-ede-ofb
eafa89aae63167b9798639c0e31223b4 16 8 8 des-ede-cbc
a952f8c409fb0df75a7df1aa54ba30b8 24 0 8 des-ede3
0badccc43a14d8503d33f32a2345bbd2 24 8 1 des-ede3-cfb
bae638c0e33850d02c792ed0e3d6b600 24 8 1 des-ede3-ofb
ec4522bbefabf0198126683e661325e2 24 8 8 des-ede3-cbc
4431f05d198d8afc003aeec85bea01b9 24 8 8 desx-cbc
606af8d6f30c1fd9c647df5eb716ae0f 16 0 1 rc4
4aaaf7e4bc3fd2caa6318a4852f636f4 5 0 1 rc4-40
77e0851e8c96c4a1e26140d1ec822036 16 0 8 idea-ecb
a28e51e283519fde0e128bcb697bc23e 16 8 1 idea-cfb
17d0e70f07de6c08e9673d52987599ab 16 8 1 idea-ofb
0687cf6ca11ee45f8bf9c29525405a4d 16 8 8 idea-cbc
e2268681a63198fe38282b0a1bb6ed36 16 0 8 rc2-ecb
f48748e6386790e639bbee4fccaa5067 16 8 8 rc2-cbc
f250cfe829ef797d6866e32526ec4fe4 5 8 8 rc2-40-cbc
a372f970b6c346341a2899bb872a7349 16 8 1 rc2-cfb
d2da66102dea6b833f0fbf71e2cb4988 16 8 1 rc2-ofb
237b0ef0e4f7fb28a5708d59773caecf 16 0 8 bf-ecb
c58cf5da90472caf0f0b7fafb0590977 16 8 1 bf-cfb
1f3e49e2e27f9ad177a6a64b09d361ed 16 8 1 bf-ofb
66acaf2cb5f301580c59fa17d005b716 16 8 8 bf-cbc
3548c9fe9fcd13f647ae177a15915af9 16 0 8 cast5-ecb
e8d074ad8cc0d3d828da80ab18452f91 16 8 1 cast5-cfb
5331eb4351c2048c27c8a8901fd29e20 16 8 1 cast5-ofb
8033607fdb68598cc62c379af218eeeb 16 8 8 cast5-cbc
e3a6760eb5e79bf4063cf0791e99842d 16 0 8 rc5-ecb
2f5eab0d0992dcce8615a5a60966391a 16 8 1 rc5-cfb
c5893e49e73342db2957b83b70f23e27 16 8 1 rc5-ofb
683ce60c8b7bf028ec0d3dc0f018a1a4 16 8 8 rc5-cbc
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
@md=();
($c=SSLeay::Cipher::new("idea")) ||
die "'des' is an unknown cipher algorithm\n";
printf "name =%s\n" ,$c->name();
printf "key length=%2d\n",$c->key_length();
printf "iv length =%2d\n",$c->iv_length();
printf "block size=%2d\n",$c->block_size();
$data="1234";
$c->init("01234567","abcdefgh",1);
$in=$c->update($data);
$in.=$c->final();
$c->init("01234567","abcdefgh",0);
$out=$c->update($in);
$out.=$c->final();
print $data;
print " -> ";
print $out;
print "\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
@md=();
($c=SSLeay::Cipher::new("idea")) ||
die "'des' is an unknown cipher algorithm\n";
$key=" ";
$iv=" ";
$c->init($key,$iv,0);
while (<>)
{
print $c->update($_);
}
print $c->final();
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
# 2687145 * 3003 * 10^5072 - 1.
$a=SSLeay::BN::set_word(99);
$b=SSLeay::BN::set_word(100);
$aa=$a->dup;
$bb=$b->dup;
$c=$a*$b;
$bb+=$a;
print "$a*$b=$c\n";
print "$bb\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
# 2687145 * 3003 * 10^5072 - 1.
$a=SSLeay::BN::set_word(2687145);
$b=SSLeay::BN::set_word(3003);
$c=SSLeay::BN::set_word(10);
$d=SSLeay::BN::set_word(5072);
$e=SSLeay::BN::set_word(1);
print $a->bn2hex()."\n";
print $b->bn2hex()."\n";
print $c->bn2hex()."\n";
print $d->bn2hex()."\n";
print $e->bn2hex()."\n";
$f=(($a->mul($b)->mul($c->exp($d)))->sub($e));
#print "$a $b\n";
$c=$a->mul($b);
print "1->".$c->bn2hex()." \n";
$c=$a*$b;
print "2->".$c->bn2hex()." \n";
$a*=$b;
print "3->$a\n";
print $f->bn2hex()." $a\n";
print $a."\n";
print "$a=(($b*$c)/$d);\n";
$a=(($b*$c)/$d);
print "$a\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$num ="a43f6a8885a308d313198a2e03707344a4093822";
$num.="299f31d0082efa98ec4e6c89452821e638d01377";
$num.="be5466cf34e90c6cc0ac29b7c97c50dd3f84d5b5";
$num.="b54709179216d5d98979fb1bd1310ba698dfb5ac";
$num.="2ffd72dbd01adfb7b8e1afed6a267e96ba7c9045";
$num.="f12c7f9924a19947b3916cf70801f2e2858efc16";
$num.="636920d871574e69a458fea3f4933d7e0d95748f";
$num.="728eb658718bcd5882154aee7b54a41dc25a59b5";
$num.="9c30d5392af26013c5d1b023286085f0ca417918";
$num.="b8db38ef8e79dcb0603a180e6c9e0e8bb01e8a3e";
$num.="d71577c1bd314b2778af2fda55605c60e65525f3";
$num.="aa55ab945748986263e8144055ca396a2aab10b6";
$num.="b4cc5c341141e8cea15486af7c8f14a7";
$a=SSLeay::BN::hex2bn($num);
print "num bits =".$a->num_bits."\n";
print $a->is_prime(50,sub {print STDERR $_[0]?"+":"."})."\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$a=SSLeay::BN::dec2bn("1234");
foreach (1..4)
{
$a*=$a;
print $a."\n",$a->bn2dec()."\n";
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
@md=();
foreach ("md2", "md5", "sha", "sha1", "mdc2", "ripemd160")
{
($f=MD->new($_)) ||
die "$_ is an unknown message digest algorithm\n";
push(@md,$f);
}
while (<>)
{
foreach $md (@md)
{ $md->update($_); }
}
foreach (@md)
{
$digest=$_->final();
printf "%-4s=%s\n",$_->name(),unpack("H*",$digest);
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
for ($i=1; $i<1000; $i++)
{
$a.=$i%10;
$y=SSLeay::BN::dec2bn($a);
$z=SSLeay::BN::bn2dec($y);
print "$a\n$y\n$z\n";
}
......@@ -14,83 +14,83 @@ INPUT
T_DATUM
$var.dptr=SvPV($arg,$var.dsize);
T_MD_CTX
if (sv_derived_from($arg, \"SSLeay::MD\")) {
if (sv_derived_from($arg, \"OpenSSL::MD\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (EVP_MD_CTX *) tmp;
}
else
croak(\"$var is not of type SSLeay::MD\")
croak(\"$var is not of type OpenSSL::MD\")
T_CIPHER_CTX
if (sv_derived_from($arg, \"SSLeay::Cipher\")) {
if (sv_derived_from($arg, \"OpenSSL::Cipher\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (EVP_CIPHER_CTX *) tmp;
}
else
croak(\"$var is not of type SSLeay::Cipher\")
croak(\"$var is not of type OpenSSL::Cipher\")
T_BIGNUM
sv_to_BIGNUM(&($var),$arg,\"$var is not of type SSLeay::MD, int or string\")
sv_to_BIGNUM(&($var),$arg,\"$var is not of type OpenSSL::MD, int or string\")
T_SSL_METHOD
if (sv_derived_from($arg, \"SSLeay::SSL::METHOD\")) {
if (sv_derived_from($arg, \"OpenSSL::SSL::METHOD\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (SSL_METHOD *) tmp;
}
else
croak(\"$var is not of type SSLeay::SSL::METHOD\")
croak(\"$var is not of type OpenSSL::SSL::METHOD\")
T_SSL_CTX
if (sv_derived_from($arg, \"SSLeay::SSL::CTX\")) {
if (sv_derived_from($arg, \"OpenSSL::SSL::CTX\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (SSL_CTX *) tmp;
}
else
croak(\"$var is not of type SSLeay::SSL::CTX\")
croak(\"$var is not of type OpenSSL::SSL::CTX\")
T_SSL_CIPHER
if (sv_derived_from($arg, \"SSLeay::SSL::CIPHER\")) {
if (sv_derived_from($arg, \"OpenSSL::SSL::CIPHER\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (SSL_CIPHER *) tmp;
}
else
croak(\"$var is not of type SSLeay::SSL::CIPHER\")
croak(\"$var is not of type OpenSSL::SSL::CIPHER\")
T_SSL
if (sv_derived_from($arg, \"SSLeay::SSL\")) {
if (sv_derived_from($arg, \"OpenSSL::SSL\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (SSL *) tmp;
}
else
croak(\"$var is not of type SSLeay::SSL\")
croak(\"$var is not of type OpenSSL::SSL\")
T_BIO
if (sv_derived_from($arg, \"SSLeay::BIO\")) {
if (sv_derived_from($arg, \"OpenSSL::BIO\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (BIO *) tmp;
}
else
croak(\"$var is not of type SSLeay::BIO\")
croak(\"$var is not of type OpenSSL::BIO\")
T_X509
if (sv_derived_from($arg, \"SSLeay::X509\")) {
if (sv_derived_from($arg, \"OpenSSL::X509\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = (X509 *) tmp;
}
else
croak(\"$var is not of type SSLeay::X509\")
croak(\"$var is not of type OpenSSL::X509\")
OUTPUT
T_DATUM
sv_setpvn($arg,$var.dptr,$var.dsize);
T_MD_CTX
sv_setref_pv($arg, \"SSLeay::MD\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::MD\", (void*)$var);
T_CIPHER_CTX
sv_setref_pv($arg, \"SSLeay::Cipher\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::Cipher\", (void*)$var);
T_BIGNUM
sv_setref_pv($arg, \"SSLeay::BN\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::BN\", (void*)$var);
T_SSL_METHOD
sv_setref_pv($arg, \"SSLeay::SSL::METHOD\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::SSL::METHOD\", (void*)$var);
T_SSL_CTX
sv_setref_pv($arg, \"SSLeay::SSL::CTX\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::SSL::CTX\", (void*)$var);
T_SSL_CIPHER
sv_setref_pv($arg, \"SSLeay::SSL::CIPHER\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::SSL::CIPHER\", (void*)$var);
T_SSL
sv_setref_pv($arg, \"SSLeay::SSL\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::SSL\", (void*)$var);
T_BIO
sv_setref_pv($arg, \"SSLeay::BIO\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::BIO\", (void*)$var);
T_X509
sv_setref_pv($arg, \"SSLeay::X509\", (void*)$var);
sv_setref_pv($arg, \"OpenSSL::X509\", (void*)$var);
X509::new()
X509::get_verson()
X509::get_serial_number()
X509::get_subject_name()
X509::get_issuer_name()
#include "p5SSLeay.h"
MODULE = SSLeay::X509 PACKAGE = SSLeay::X509 PREFIX = p5_X509_
PROTOTYPES: ENABLE
VERSIONCHECK: DISABLE
void
p5_X509_new(void )
PREINIT:
X509 *x509;
SV *arg;
PPCODE:
pr_name("p5_X509_new");
EXTEND(sp,1);
PUSHs(sv_newmortal());
x509=X509_new();
sv_setref_pv(ST(0),"SSLeay::X509",(void *)x509);
char *
p5_X509_get_subject_name(x509)
X509 *x509;
PREINIT:
char *p;
X509_NAME *name;
char buf[1024];
int i;
CODE:
name=X509_get_subject_name(x509);
X509_NAME_oneline(name,buf,sizeof(buf));
p= &(buf[0]);
RETVAL=p;
OUTPUT:
RETVAL
char *
p5_X509_get_issuer_name(x509)
X509 *x509;
PREINIT:
char *p;
X509_NAME *name;
char buf[1024];
int i;
CODE:
name=X509_get_issuer_name(x509);
X509_NAME_oneline(name,buf,sizeof(buf));
p= &(buf[0]);
RETVAL=p;
OUTPUT:
RETVAL
int
p5_X509_get_version(x509)
X509 *x509;
CODE:
RETVAL=X509_get_version(x509);
OUTPUT:
RETVAL
BIGNUM *
p5_X509_get_serialNumber(x509)
X509 *x509;
CODE:
RETVAL=ASN1_INTEGER_to_BN(X509_get_serialNumber(x509),NULL);
OUTPUT:
RETVAL
void
p5_X509_DESTROY(x509)
X509 *x509;
CODE:
pr_name("p5_X509_DESTROY");
X509_free(x509);
/* perl/xstmp.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/*
* This file was generated automatically by xsubpp version 1.9402 from the
* contents of SSLeay.xs. Do not edit this file, edit SSLeay.xs instead.
*
* ANY CHANGES MADE HERE WILL BE LOST!
*
*/
#line 1 "SSLeay.xs"
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
typedef struct datum_st
{
char *dptr;
int dsize;
} datum;
#include "crypto.h"
#include "buffer.h"
#include "bio.h"
#include "evp.h"
#include "err.h"
#include "x509.h"
#include "ssl.h"
#if 0
#define pr_name(name) printf("%s\n",name)
#define pr_name_d(name,p2) printf("%s %d\n",name,p2)
#define pr_name_dd(name,p2,p3) printf("%s %d %d\n",name,p2,p3)
#else
#define pr_name(name)
#define pr_name_d(name,p2)
#define pr_name_dd(name,p2,p3)
#endif
#include "callback.c"
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$message=SSLeay::BN::dec2bn("936345681743241125150760694794510965960940252288797108931456691368672287489405603308617928680920874760917824938589009714909675985261365549781893129784821682998948722");
print $message->bn2hex."\n";
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$a=SSLeay::BN::new();
$a+="1234567";
print $a->bn2hex()."\n";
for (1 .. 20)
{
$a*=$a;
$b=$a->bn2hex();
print " ".$b."\n".length($b)."\n";
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
use Benchmark;
$buf=('x' x (1024*1024));
$buf=('x' x (1024*1024));
@md=();
foreach $name ("md2", "mdc2", "sha", "ripemd160", "sha1", "md5")
{
if (($name eq "md2") || ($name eq "mdc2"))
{ $num=5; }
else { $num=100; }
$t=timeit($num,'&hash($name)');
printf "%6d000 bytes/sec:$name\n",int(($num*1024*1024)/$t->[1]/1000);
}
sub hash
{
my($name)=@_;
my($f,$digest);
($f=MD->new($name)) ||
die "$_ is an unknown message digest algorithm\n";
$f->update($buf);
$digest=$f->final();
}
#!/usr/local/bin/perl
use ExtUtils::testlib;
use SSLeay;
$a=SSLeay::BN::dec2bn("12345678901234567890");
$b=SSLeay::BN::dec2bn("98765432109876543210");
print "a=$a\n";
print "b=$b\n";
$n=$a*$b;
$m=$n+"1223123235345634764534567889";
$l=$m*88888888;
$r=$l/$b;
print "a=$a\n";
print "b=$b\n";
print "n=$n\n";
print "m=$m\n";
print "l=$l\n";
print "r=$r\n";
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册