Permalink
Browse files

added C:G:MPI->mutually_prime($other)

git-svn-id: svn://localhost/Crypt-GCrypt/trunk@88 c2f821fb-fd85-dc11-8383-000bcdcb7a8f
  • Loading branch information...
1 parent 3a2993d commit c87f15e993455a3fa77edee680c0a924df62a9f7 dkg committed Jan 23, 2010
Showing with 27 additions and 1 deletion.
  1. +13 −0 GCrypt.xs
  2. +6 −0 lib/Crypt/GCrypt/MPI.pm
  3. +8 −1 t/20-mpi.t
View
@@ -1100,6 +1100,19 @@ cgm_gcd(sv_gcma, gcmb)
/* FIXME: should we do anything with the return value (1 if gcd == 1)? */
XSRETURN(1);
+bool
+cgm_mutually_prime(gcma, gcmb)
+ Crypt_GCrypt_MPI gcma;
+ Crypt_GCrypt_MPI gcmb;
+ PREINIT:
+ Crypt_GCrypt_MPI gcd;
+ CODE:
+ gcd = gcry_mpi_new(0);
+ RETVAL=gcry_mpi_gcd(gcd, gcma, gcmb);
+ gcry_mpi_release(gcd);
+ OUTPUT:
+ RETVAL
+
void
cgm_dump(sv_gcm)
SV* sv_gcm;
@@ -95,6 +95,12 @@ Compares this object against another Crypt::GCrypt::MPI object,
returning 0 if the two values are equal, positive if this value is
greater, negative if $other is greater.
+=head2 mutually_prime($other)
+
+Compares this object against another Crypt::GCrypt::MPI object,
+returning true only if the two values share no factors in common other
+than 1.
+
=head2 copy()
Returns a new Crypt::GCrypt::MPI object, with the contents identical
View
@@ -4,7 +4,7 @@
#########################
use Test;
-BEGIN { plan tests => 36 }; # <--- number of tests
+BEGIN { plan tests => 39 }; # <--- number of tests
use ExtUtils::testlib;
use Crypt::GCrypt::MPI;
@@ -114,3 +114,10 @@ ok(0 == $x->cmp(Crypt::GCrypt::MPI->new(65537)));
$y->sub($thirtysix);
ok(0 == $y->cmp(Crypt::GCrypt::MPI->new(65429)));
+
+$x = Crypt::GCrypt::MPI->new(15);
+$y = Crypt::GCrypt::MPI->new(16);
+$z = Crypt::GCrypt::MPI->new(3);
+ok($x->mutually_prime($y));
+ok($y->mutually_prime($z));
+ok(!$x->mutually_prime($z));

0 comments on commit c87f15e

Please sign in to comment.