aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/bigint
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/bigint')
-rw-r--r--src/math/bigint/bigint.cpp19
-rw-r--r--src/math/bigint/divide.cpp26
2 files changed, 38 insertions, 7 deletions
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp
index 7ff1183a3..45c351256 100644
--- a/src/math/bigint/bigint.cpp
+++ b/src/math/bigint/bigint.cpp
@@ -107,16 +107,23 @@ void BigInt::grow_to(size_t n)
/*
* Comparison Function
*/
-s32bit BigInt::cmp(const BigInt& n, bool check_signs) const
+s32bit BigInt::cmp(const BigInt& other, bool check_signs) const
{
if(check_signs)
{
- if(n.is_positive() && this->is_negative()) return -1;
- if(n.is_negative() && this->is_positive()) return 1;
- if(n.is_negative() && this->is_negative())
- return (-bigint_cmp(data(), sig_words(), n.data(), n.sig_words()));
+ if(other.is_positive() && this->is_negative())
+ return -1;
+
+ if(other.is_negative() && this->is_positive())
+ return 1;
+
+ if(other.is_negative() && this->is_negative())
+ return (-bigint_cmp(this->data(), this->sig_words(),
+ other.data(), other.sig_words()));
}
- return bigint_cmp(data(), sig_words(), n.data(), n.sig_words());
+
+ return bigint_cmp(this->data(), this->sig_words(),
+ other.data(), other.sig_words());
}
/*
diff --git a/src/math/bigint/divide.cpp b/src/math/bigint/divide.cpp
index c54eb463b..c8b82422a 100644
--- a/src/math/bigint/divide.cpp
+++ b/src/math/bigint/divide.cpp
@@ -7,6 +7,7 @@
#include <botan/divide.h>
#include <botan/internal/mp_core.h>
+#include <botan/internal/mp_asmi.h>
namespace Botan {
@@ -26,6 +27,29 @@ void sign_fixup(const BigInt& x, const BigInt& y, BigInt& q, BigInt& r)
q.flip_sign();
}
+bool division_check(word q, word y2, word y1,
+ word x3, word x2, word x1)
+ {
+ // Compute (y3,y2,y1) = (y2,y1) * q
+
+ word y3 = 0;
+ y1 = word_madd2(q, y1, &y3);
+ y2 = word_madd2(q, y2, &y3);
+
+ // Return (y3,y2,y1) >? (x3,x2,x1)
+
+ if(y3 > x3) return true;
+ if(y3 < x3) return false;
+
+ if(y2 > x2) return true;
+ if(y2 < x2) return false;
+
+ if(y1 > x1) return true;
+ if(y1 < x1) return false;
+
+ return false;
+ }
+
}
/*
@@ -92,7 +116,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
else
q_words[j-t-1] = bigint_divop(x_j0, x_j1, y_t);
- while(bigint_divcore(q_words[j-t-1],
+ while(division_check(q_words[j-t-1],
y_t, y.word_at(t-1),
x_j0, x_j1, r.word_at(j-2)))
{