make update
[openssl.git] / perl / openssl_bn.xs
index c15be37..6817cfb 100644 (file)
@@ -1,4 +1,5 @@
-#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,8 +70,9 @@ char *arg;
        LEAVE;
        }
 
-MODULE =  SSLeay::BN   PACKAGE = SSLeay::BN    PREFIX = p5_BN_
+MODULE =  OpenSSL::BN  PACKAGE = OpenSSL::BN   PREFIX = p5_BN_
 
+PROTOTYPES: ENABLE
 VERSIONCHECK: DISABLE
 
 void
@@ -83,7 +85,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 +97,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 +109,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 +128,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)
@@ -140,7 +142,7 @@ p5_BN_bn2bin(a)
                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)));
+               SvCUR_set(ST(0),BN_bn2bin(a,SvPV_nolen(ST(0))));
 
 void
 p5_BN_mpi2bn(a)
@@ -152,7 +154,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)
@@ -166,7 +168,7 @@ p5_BN_bn2mpi(a)
                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)));
+               SvCUR_set(ST(0),BN_bn2mpi(a,SvPV_nolen(ST(0))));
 
 void
 p5_BN_hex2bn(a)
@@ -178,7 +180,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 +193,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 *
@@ -206,9 +208,9 @@ p5_BN_bn2hex(a)
                RETVAL=newSVpv("",0);
                i=strlen(ptr);
                SvGROW(RETVAL,i+1);
-               memcpy(SvPV(RETVAL,na),ptr,i+1);
+               memcpy(SvPV_nolen(RETVAL),ptr,i+1);
                SvCUR_set(RETVAL,i);
-               Free(ptr);
+               OPENSSL_free(ptr);
        OUTPUT:
                RETVAL
 
@@ -224,9 +226,9 @@ p5_BN_bn2dec(a)
                RETVAL=newSVpv("",0);
                i=strlen(ptr);
                SvGROW(RETVAL,i+1);
-               memcpy(SvPV(RETVAL,na),ptr,i+1);
+               memcpy(SvPV_nolen(RETVAL),ptr,i+1);
                SvCUR_set(RETVAL,i);
-               Free(ptr);
+               OPENSSL_free(ptr);
        OUTPUT:
                RETVAL
 
@@ -241,7 +243,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 +257,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 +265,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 +291,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 +308,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 +324,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 +341,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 +358,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 +375,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 +397,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 +412,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 +481,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 +495,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 +509,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 +526,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 +543,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 +566,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 +579,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)