Changeset 10271 for lang/perl/Crypt-DH-GMP
- Timestamp:
- 04/24/08 12:20:12 (5 years ago)
- Location:
- lang/perl/Crypt-DH-GMP/trunk
- Files:
-
- 1 added
- 2 modified
-
GMP.xs (modified) (7 diffs)
-
t/01-dh.t (modified) (1 diff)
-
t/99-binhack.t (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Crypt-DH-GMP/trunk/GMP.xs
r10267 r10271 30 30 31 31 static inline 32 char *DH_mpz2sv_str(mpz_t *v, unsigned int base )32 char *DH_mpz2sv_str(mpz_t *v, unsigned int base, unsigned int *length) 33 33 { 34 34 STRLEN len = 0; … … 43 43 Renew(buf, len - 1, char); /* got one shorter than expected */ 44 44 } 45 46 if (length != NULL) 47 *length = len; 48 45 49 return buf; 46 50 } … … 108 112 mpz_init_set_str(mpz_pub_key, pub_key, 0); 109 113 mpz_powm(mpz_ret, mpz_pub_key, DH_PRIVKEY(dh), DH_P(dh)); 110 RETVAL = DH_mpz2sv_str(&mpz_ret, 10 );114 RETVAL = DH_mpz2sv_str(&mpz_ret, 10, NULL); 111 115 mpz_clear(mpz_ret); 112 116 mpz_clear(mpz_pub_key); … … 118 122 DH_gmp_t *dh; 119 123 CODE: 120 RETVAL = DH_mpz2sv_str(DH_PRIVKEY_PTR(dh), 10 );124 RETVAL = DH_mpz2sv_str(DH_PRIVKEY_PTR(dh), 10, NULL); 121 125 OUTPUT: 122 126 RETVAL … … 126 130 DH_gmp_t *dh; 127 131 CODE: 128 RETVAL = DH_mpz2sv_str(DH_PUBKEY_PTR(dh), 10); 132 RETVAL = DH_mpz2sv_str(DH_PUBKEY_PTR(dh), 10, NULL); 133 OUTPUT: 134 RETVAL 135 136 char * 137 DH_gmp_pub_key_twoc(dh) 138 DH_gmp_t *dh; 139 PREINIT: 140 unsigned int len = 0; 141 unsigned int pad = 0; 142 char *buf; 143 CODE: 144 buf = DH_mpz2sv_str(DH_PUBKEY_PTR(dh), 2, &len); 145 pad = (8 - len % 8); 146 if (pad <= 0 && *buf == '1') { 147 pad = 8; 148 } 149 150 if (pad > 0) { 151 unsigned int ipad = 0; 152 char *tmp; 153 Newxz(tmp, len + pad, char); 154 for (ipad = 0; ipad < pad; ipad++) 155 *(tmp + ipad) = '0'; 156 Copy(buf, tmp + pad, len + 1, char); 157 Safefree(buf); 158 buf = tmp; 159 } 160 RETVAL = buf; 129 161 OUTPUT: 130 162 RETVAL … … 136 168 STRLEN n_a; 137 169 CODE: 138 RETVAL = DH_mpz2sv_str(DH_G_PTR(dh), 10 );170 RETVAL = DH_mpz2sv_str(DH_G_PTR(dh), 10, NULL); 139 171 if (items > 1) { 140 172 mpz_init_set_str( DH_G(dh), (char *) SvPV(ST(1), n_a), 0 ); … … 149 181 STRLEN n_a; 150 182 CODE: 151 RETVAL = DH_mpz2sv_str(DH_P_PTR(dh), 10 );183 RETVAL = DH_mpz2sv_str(DH_P_PTR(dh), 10, NULL); 152 184 if (items > 1) { 153 185 mpz_init_set_str( DH_P(dh), (char *) SvPV(ST(1), n_a), 0 ); -
lang/perl/Crypt-DH-GMP/trunk/t/01-dh.t
r9443 r10271 22 22 ); 23 23 24 =head125 my $num = '10000000000000000001';26 my @try = ($num, Math::BigInt->new($num));27 push @try, Math::Pari->new($num) if $has_pari;28 for my $try (@try) {29 my $type = 'any2bigint(' . (ref($try) || 'scalar') . ')';30 my $val = Crypt::DH::_any2bigint($try);31 ok($val, $type . ' returns a defined value');32 is(ref($val), 'Math::BigInt', $type . ' returns a Math::BigInt');33 is($val->bstr, $num, $type . ' returns the correct value');34 }35 =cut36 37 24 for my $pg (@pgs) { 38 25 my $dh1 = Crypt::DH::GMP->new(g => $pg->{g}, p => $pg->{p});
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)