summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-11 18:47:47 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-11 18:47:47 +0200
commitf4568a9015f99c40e69c3ced829833155316cf04 (patch)
treea1ea037d11ec448613fd013a0314a702699569d3
parentd5a38318b3876bbedffe52ca3b378b03ad4d995a (diff)
Forgot isPrime implementation.
-rw-r--r--includes/BigInt.h2
-rw-r--r--src/BigInt.cc7
2 files changed, 8 insertions, 1 deletions
diff --git a/includes/BigInt.h b/includes/BigInt.h
index 29a2740..55a5c75 100644
--- a/includes/BigInt.h
+++ b/includes/BigInt.h
@@ -91,7 +91,7 @@ class BigInt {
BigInt & do_modinv(const BigInt & m) throw (GeneralException);
BigInt & do_modpow(const BigInt & a, const BigInt & m) throw (GeneralException);
- bool isPrime() const;
+ bool isPrime() const throw (GeneralException);
String toString(int radix = 10) const;
char * makeString(int radix = 10) const;
diff --git a/src/BigInt.cc b/src/BigInt.cc
index 0c1b1a5..3f4b275 100644
--- a/src/BigInt.cc
+++ b/src/BigInt.cc
@@ -487,6 +487,13 @@ Balau::BigInt & Balau::BigInt::do_modpow(const BigInt & a, const BigInt & m) thr
return *this;
}
+bool Balau::BigInt::isPrime() const throw (GeneralException) {
+ int r = 0;
+ if (mp_prime_is_prime(m_bi, NULL, &r) != CRYPT_OK)
+ throw GeneralException("Error while calling mp_prime_is_prime");
+ return r == LTC_MP_YES;
+}
+
Balau::String Balau::BigInt::toString(int radix) const {
char * out = (char *) alloca(mp_count_bits(m_bi) / (radix >= 10 ? 3 : 1) + 3);
mp_toradix(m_bi, out, radix);