aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/ec_gfp/curve_gfp.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-02-26 03:41:07 +0000
committerlloyd <[email protected]>2015-02-26 03:41:07 +0000
commit54ef984c3c4728d616a983b96f0dcb1b8c88ae96 (patch)
treeebb2887c8ba45c12f3a4b1f33adf4c91d6da1ebe /src/lib/math/ec_gfp/curve_gfp.cpp
parent2cfcd2ebddcb19647938fffc412fb468608ea89d (diff)
Add specialized reducers for P-192, P-224, P-256 and P-384
Diffstat (limited to 'src/lib/math/ec_gfp/curve_gfp.cpp')
-rw-r--r--src/lib/math/ec_gfp/curve_gfp.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/lib/math/ec_gfp/curve_gfp.cpp b/src/lib/math/ec_gfp/curve_gfp.cpp
index 02265b53a..cb21dd04e 100644
--- a/src/lib/math/ec_gfp/curve_gfp.cpp
+++ b/src/lib/math/ec_gfp/curve_gfp.cpp
@@ -8,6 +8,7 @@
#include <botan/curve_gfp.h>
#include <botan/internal/curve_nistp.h>
#include <botan/internal/mp_core.h>
+#include <botan/internal/mp_asmi.h>
namespace Botan {
@@ -117,25 +118,30 @@ void CurveGFp_Montgomery::curve_sqr(BigInt& z, const BigInt& x,
}
// Default implementation
-void CurveGFp_Repr::normalize(BigInt& x, secure_vector<word>& ws, size_t /*bound*/) const
+void CurveGFp_Repr::normalize(BigInt& x, secure_vector<word>& ws, size_t bound) const
{
const BigInt& p = get_p();
+ const word* prime = p.data();
+ const size_t p_words = get_p_words();
while(x.is_negative())
x += p;
- const size_t p_words = get_p_words();
- const word* prime = p.data();
-
x.grow_to(p_words + 1);
if(ws.size() < p_words + 1)
ws.resize(p_words + 1);
- //FIXME: take into account bound if > 0
- while(true)
+ for(size_t i = 0; bound == 0 || i < bound; ++i)
{
- if(bigint_sub3(&ws[0], x.data(), p_words, prime, p_words)) // borrow?
+ const word* xd = x.data();
+ word borrow = 0;
+
+ for(size_t i = 0; i != p_words; ++i)
+ ws[i] = word_sub(xd[i], prime[i], &borrow);
+ ws[p_words] = word_sub(xd[p_words], 0, &borrow);
+
+ if(borrow)
break;
x.swap_reg(ws);
@@ -145,6 +151,17 @@ void CurveGFp_Repr::normalize(BigInt& x, secure_vector<word>& ws, size_t /*bound
std::shared_ptr<CurveGFp_Repr>
CurveGFp::choose_repr(const BigInt& p, const BigInt& a, const BigInt& b)
{
+#if defined(BOTAN_HAS_CURVEGFP_NISTP_M32)
+ if(p == CurveGFp_P192::prime())
+ return std::shared_ptr<CurveGFp_Repr>(new CurveGFp_P192(a, b));
+ if(p == CurveGFp_P224::prime())
+ return std::shared_ptr<CurveGFp_Repr>(new CurveGFp_P224(a, b));
+ if(p == CurveGFp_P256::prime())
+ return std::shared_ptr<CurveGFp_Repr>(new CurveGFp_P256(a, b));
+ if(p == CurveGFp_P384::prime())
+ return std::shared_ptr<CurveGFp_Repr>(new CurveGFp_P384(a, b));
+#endif
+
if(p == CurveGFp_P521::prime())
return std::shared_ptr<CurveGFp_Repr>(new CurveGFp_P521(a, b));