diff options
author | lloyd <[email protected]> | 2008-10-08 07:16:47 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-08 07:16:47 +0000 |
commit | 66aa83a7e110975ce091559317f06d88d20dd9b1 (patch) | |
tree | c2512992346e52c6e07cd988ab2b352b63641428 /src | |
parent | aaa1e88def2eb052178777e363367d77b6a04a77 (diff) |
Partially merge back with InSiTo in an attemp to trace bugs
Diffstat (limited to 'src')
-rw-r--r-- | src/build-data/buildh.in | 3 | ||||
-rw-r--r-- | src/math/gfpmath/curve_gfp.cpp | 74 | ||||
-rw-r--r-- | src/math/gfpmath/curve_gfp.h | 50 | ||||
-rw-r--r-- | src/math/gfpmath/freestore.h | 207 | ||||
-rw-r--r-- | src/math/gfpmath/gfp_element.cpp | 325 | ||||
-rw-r--r-- | src/math/gfpmath/gfp_element.h | 122 | ||||
-rw-r--r-- | src/math/gfpmath/gfp_modulus.h | 9 | ||||
-rw-r--r-- | src/math/gfpmath/info.txt | 1 |
8 files changed, 513 insertions, 278 deletions
diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in index 3f56ab6f3..8f2f277c8 100644 --- a/src/build-data/buildh.in +++ b/src/build-data/buildh.in @@ -38,6 +38,9 @@ Modules #define BOTAN_COMPILER_HAS_GCC_INLINE_ASM 1 #endif +#define BOTAN_USE_TR1_SHARED_PTR +//#define BOTAN_USE_BOOST_TR1_SHARED_PTR + #ifndef BOTAN_COMPILER_HAS_GCC_INLINE_ASM #define BOTAN_COMPILER_HAS_GCC_INLINE_ASM 0 #endif diff --git a/src/math/gfpmath/curve_gfp.cpp b/src/math/gfpmath/curve_gfp.cpp index 89fa74c49..c5abc2a5f 100644 --- a/src/math/gfpmath/curve_gfp.cpp +++ b/src/math/gfpmath/curve_gfp.cpp @@ -1,39 +1,51 @@ /****************************************************** - * Elliptic curves over GF(p) (source file) * - * * - * (C) 2007 Martin Doering * - * [email protected] * - * Christoph Ludwig * - * [email protected] * - * Falko Strenzke * - * [email protected] * - ******************************************************/ +* Elliptic curves over GF(p) * +* * +* (C) 2007 Martin Doering * +* Christoph Ludwig * +* Falko Strenzke * +* 2008 Jack Lloyd * +******************************************************/ #include <botan/curve_gfp.h> +#include <botan/bigint.h> +#include <assert.h> namespace Botan { -CurveGFp::CurveGFp(GFpElement const& a, GFpElement const& b, - const BigInt& p) : - mA(a), mB(b) +void CurveGFp::set_shrd_mod(SharedPtrConverter<GFpModulus> const mod) { - if(p != mA.get_p() || p != mB.get_p()) - throw Invalid_Argument("could not construct curve: moduli of arguments differ"); + mp_mod = mod.get_shared(); + mA.turn_off_sp_red_mul();// m.m. is not needed, must be trf. back + mB.turn_off_sp_red_mul();// m.m. is not needed, must be trf. back + //ok, above we destroy any evantually computated montg. mult. values, + // but that won´t influence performance in usual applications + mA.set_shrd_mod(mod.get_shared()); + mB.set_shrd_mod(mod.get_shared()); + } +CurveGFp::CurveGFp(const GFpElement& a, const GFpElement& b, + const BigInt& p) + : mA(a), + mB(b) + { + if(!((p == mA.get_p()) && (p == mB.get_p()))) + { + throw Invalid_Argument("could not construct curve: moduli of arguments differ"); + } std::tr1::shared_ptr<GFpModulus> p_mod = std::tr1::shared_ptr<GFpModulus>(new GFpModulus(p)); // the above is the creation of the GFpModuls object which will be shared point-wide // (in the context of a point of course) set_shrd_mod(p_mod); } - // copy constructor -CurveGFp::CurveGFp(CurveGFp const& other) +CurveGFp::CurveGFp(const CurveGFp& other) : mA(other.get_a()), mB(other.get_b()) { mp_mod = std::tr1::shared_ptr<GFpModulus>(new GFpModulus(*other.mp_mod)); - //assert(mp_mod->p_equal_to(mA.get_p())); - //assert(mp_mod->p_equal_to(mB.get_p())); + assert(mp_mod->p_equal_to(mA.get_p())); + assert(mp_mod->p_equal_to(mB.get_p())); set_shrd_mod(mp_mod); if(other.mp_mres_a.get()) { @@ -51,7 +63,7 @@ CurveGFp::CurveGFp(CurveGFp const& other) } // assignment operator -CurveGFp const& CurveGFp::operator=(CurveGFp const& other) +const CurveGFp& CurveGFp::operator=(const CurveGFp& other) { // for exception safety... GFpElement a_tmp = other.mA; @@ -90,7 +102,7 @@ GFpElement const CurveGFp::get_b() const BigInt const CurveGFp::get_p() const { - //assert(mp_mod.get() != 0); + assert(mp_mod.get() != 0); return mp_mod->get_p(); } @@ -104,18 +116,6 @@ void CurveGFp::swap(CurveGFp& other) std::swap(mp_mres_b, other.mp_mres_b); std::swap(mp_mres_one, other.mp_mres_one); } - -void CurveGFp::set_shrd_mod(std::tr1::shared_ptr<GFpModulus> const mod) - { - mp_mod = mod; - mA.turn_off_sp_red_mul();// m.m. is not needed, must be trf. back - mB.turn_off_sp_red_mul();// m.m. is not needed, must be trf. back - //ok, above we destroy any evantually computated montg. mult. values, - // but that won't influence performance in usual applications - mA.set_shrd_mod(mod); - mB.set_shrd_mod(mod); - } - GFpElement const CurveGFp::get_mres_a() const { if(mp_mres_a.get() == 0) @@ -126,7 +126,6 @@ GFpElement const CurveGFp::get_mres_a() const } return GFpElement(*mp_mres_a); } - GFpElement const CurveGFp::get_mres_b() const { if(mp_mres_b.get() == 0) @@ -137,7 +136,6 @@ GFpElement const CurveGFp::get_mres_b() const } return GFpElement(*mp_mres_b); } - std::tr1::shared_ptr<GFpElement const> const CurveGFp::get_mres_one() const { if(mp_mres_one.get() == 0) @@ -148,10 +146,14 @@ std::tr1::shared_ptr<GFpElement const> const CurveGFp::get_mres_one() const } return mp_mres_one; } - -bool operator==(CurveGFp const& lhs, CurveGFp const& rhs) +bool operator==(const CurveGFp& lhs, const CurveGFp& rhs) { return (lhs.get_p() == rhs.get_p() && lhs.get_a() == rhs.get_a() && lhs.get_b() == rhs.get_b()); } +std::ostream& operator<<(std::ostream& output, const CurveGFp& elem) + { + return output << "y^2f = x^3 + (" << elem.get_a() << ")x + (" << elem.get_b() << ")"; + } + } diff --git a/src/math/gfpmath/curve_gfp.h b/src/math/gfpmath/curve_gfp.h index 3024c32d8..3981faf16 100644 --- a/src/math/gfpmath/curve_gfp.h +++ b/src/math/gfpmath/curve_gfp.h @@ -9,12 +9,12 @@ ******************************************************/ -#ifndef BOTAN_EC_CURVE_GFP_H__ -#define BOTAN_EC_CURVE_GFP_H__ +#ifndef BOTAN_GFP_CURVE_H__ +#define BOTAN_GFP_CURVE_H__ -#include <botan/gfp_element.h> #include <botan/bigint.h> -#include <tr1/memory> +#include <botan/gfp_element.h> +#include <iostream> namespace Botan { @@ -24,26 +24,27 @@ namespace Botan { class CurveGFp { public: + /** * Construct the elliptic curve E: y^2 = x^3 + ax + b over GF(p) * @param a first coefficient * @param b second coefficient * @param p prime number of the field */ - CurveGFp(GFpElement const& a, GFpElement const& b, + CurveGFp(const GFpElement& a, const GFpElement& b, const BigInt& p); /** * Copy constructor * @param other The curve to clone */ - CurveGFp(CurveGFp const& other); + CurveGFp(const CurveGFp& other); /** * Assignment operator * @param other The curve to use as source for the assignment */ - CurveGFp const& operator=(CurveGFp const& other); + const CurveGFp& operator=(const CurveGFp& other); /** * Set the shared GFpModulus object. @@ -54,7 +55,7 @@ class CurveGFp * @param mod a shared pointer to a GFpModulus object suitable for * *this. */ - void set_shrd_mod(std::tr1::shared_ptr<GFpModulus> const mod); + void set_shrd_mod(SharedPtrConverter<GFpModulus> const mod); // getters @@ -81,20 +82,20 @@ class CurveGFp /** * Get the GFpElement coefficient b transformed - * to it´s m-residue. This can be used for efficency reasons: the curve + * to its m-residue. This can be used for efficency reasons: the curve * stores the transformed version after the first invocation of this * function. - * @result the coefficient b, transformed to it´s m-residue + * @result the coefficient b, transformed to its m-residue */ GFpElement const get_mres_b() const; /** * Get the GFpElement 1 transformed - * to it´s m-residue. This can be used for efficency reasons: the curve + * to its m-residue. This can be used for efficency reasons: the curve * stores the transformed version after the first invocation of this * function. - * @result the GFpElement 1, transformed to it´s m-residue + * @result the GFpElement 1, transformed to its m-residue */ std::tr1::shared_ptr<GFpElement const> const get_mres_one() const; @@ -137,11 +138,14 @@ class CurveGFp }; // relational operators -bool operator==(CurveGFp const& lhs, CurveGFp const& rhs); -inline bool operator!=(CurveGFp const& lhs, CurveGFp const& rhs) { +bool operator==(const CurveGFp& lhs, const CurveGFp& rhs); +inline bool operator!=(const CurveGFp& lhs, const CurveGFp& rhs) { return !operator==(lhs, rhs); } +// io operators +std::ostream& operator<<(std::ostream& output, const CurveGFp& elem); + // swaps the states of curve1 and curve2, does not throw! // cf. Meyers, Item 25 inline @@ -149,17 +153,21 @@ void swap(CurveGFp& curve1, CurveGFp& curve2) { curve1.swap(curve2); } -} +} // namespace Botan + namespace std { -template<> inline void swap<Botan::CurveGFp>( +// swaps the states of curve1 and curve2, does not throw! +// cf. Meyers, Item 25 +template<> +inline +void swap<Botan::CurveGFp>( Botan::CurveGFp& curve1, - Botan::CurveGFp& curve2) - { - curve1.swap(curve2); - } - + Botan::CurveGFp& curve2) { +curve1.swap(curve2); } +} // namespace std + #endif diff --git a/src/math/gfpmath/freestore.h b/src/math/gfpmath/freestore.h new file mode 100644 index 000000000..99025f4e3 --- /dev/null +++ b/src/math/gfpmath/freestore.h @@ -0,0 +1,207 @@ +/************************************************* + * mixin class to force that all instances * + * allocated on the free store are referenced * + * through smart pointers. * + * (C) 2007 Christoph Ludwig * + * [email protected] * + *************************************************/ + +#ifndef BOTAN_FREESTORE_H__ +#define BOTAN_FREESTORE_H__ + +#if defined(BOTAN_USE_TR1_SHARED_PTR) + #include <tr1/memory> +#elif defined(BOTAN_USE_BOOST_TR1_SHARED_PTR) + #include <boost/tr1/memory.hpp> +#else + #error "Please choose a shared_ptr implementation" +#endif + +// Boost headers +#include <boost/preprocessor/arithmetic/inc.hpp> +#include <boost/preprocessor/repetition/enum_binary_params.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/repeat.hpp> +#include <boost/preprocessor/stringize.hpp> + +#ifndef BOTAN_CREATE_PTR_MAX_ARITY +#define BOTAN_CREATE_PTR_MAX_ARITY 10 +#endif + +namespace Botan { + +template<typename T> +class SharedPtrConverter + { + public: + typedef std::tr1::shared_ptr<T> SharedPtr; + + SharedPtrConverter() : ptr() {}; + SharedPtrConverter(SharedPtrConverter const& other) + : ptr(other.ptr) {}; + + template<typename Ptr> + SharedPtrConverter(Ptr p) + : ptr(p) {}; + + SharedPtr const& get_ptr() const { return this->ptr; } + SharedPtr get_ptr() { return this->ptr; } + + SharedPtr const& get_shared() const { return this->ptr; } + SharedPtr get_shared() { return this->ptr; } + + private: + SharedPtr ptr; + }; + +/* +* Create an object of type T on the free store by means of the +* default constructor and return an auto_ptr to this object. +*/ +template <class T> +std::auto_ptr<T> create_auto_ptr() + { + T* raw = new T(); + return std::auto_ptr<T>(raw); + } + +/* +* Create an object of type T on the free store by means of the +* default constructor and return a shared_ptr to this object. +*/ +template <class T> +std::tr1::shared_ptr<T> create_shared_ptr() + { + T* raw = new T(); + return std::tr1::shared_ptr<T>(raw); + } + +/* +* Provide overloads of create_auto_ptr and create_shared_ptr for up to +* BOTAN_CREATE_PTR_MAX_ARITY constructor parameters. +* +* The code below defines +* template<class T, typename A1> +* std::auto_ptr<T> create_auto_ptr(A1 p1); +* +* template<class T, typename A1, typename A2> +* std::auto_ptr<T> create_auto_ptr(A1 p1, A2 p2); +* +* and so on up to +* +* template<class T, typename A1, typename A2, ..., typename An> +* std::auto_ptr<T> create_auto_ptr(A1 p1, A2 p2, ..., An pn); +* +* where n = BOTAN_CREATE_PTR_MAX_ARITY. The code also defines similar +* function template overloads for create_shared_pt. +* +* The idea for the preprocessor code is taken from: +* Grenyer, Paul: "All Heap No Leak". Overload, Issue 60, ACCU, Sept. 2004. +* Available at <URL:http://www.accu.org/index.php/journals/306>. +*/ +// Doxygen cannot handle the preprocessor code +# ifndef DOXYGEN_IS_PARSING +# define BOTAN_CREATE_PTR(z, n, _) \ + template<class T, \ + BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename A)> \ + std::auto_ptr<T> \ + create_auto_ptr(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n), A, p)) { \ + T* raw = new T(BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), p)); \ + return std::auto_ptr<T>(raw); \ + } \ + \ + template<class T, \ + BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename A)> \ + std::tr1::shared_ptr<T> \ + create_shared_ptr(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n), A, p)) { \ + T* raw = new T(BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), p)); \ + return std::tr1::shared_ptr<T>(raw); \ + } \ + /**/ +BOOST_PP_REPEAT(BOTAN_CREATE_PTR_MAX_ARITY, BOTAN_CREATE_PTR, ~) +# if 0 +; // make emacs' and other editors' auto-indentation happy... +# endif +# undef BOTAN_CREATE_PTR +# else +//! Preprocessor generated factory functions that return auto_ptr<T> +template<typename T, typename P1, typename P2, typename P3, ... > +std::auto_ptr<T> create_auto_ptr(P1 p1, P2 p2, P3 p3, ...); + +//! Preprocessor generated factory functions that return shared_ptr<T> +template<typename T, typename P1, typename P2, typename P3, ... > +std::tr1::shared_ptr<T> create_shared_ptr(P1 p1, P2 p2, P3 p3, ...); + +# endif // DOXYGEN_IS_PARSING + + + +/* +* Freestore enforces that all objects (including objects of derived types) +* can no longer be allocated on the free store by means of the +* new (or new[]) operator, but only via one of the overloads +* of function template Botan::create_ptr. +*/ +class Freestore + { + private: + static + inline + void* operator new(std::size_t size) throw (std::bad_alloc) + { + return ::operator new(size); + } + + static + inline + void* operator new[](std::size_t size) throw (std::bad_alloc) + { + return ::operator new[](size); + } + + template <class T> + friend + std::auto_ptr<T> create_auto_ptr(); + + template <class T> + friend + std::tr1::shared_ptr<T> create_shared_ptr(); + +# ifndef DOXYGEN_IS_PARSING +# define BOTAN_FREESTORE_FRIEND_CREATE_PTR(z, n, _) \ + template<class T, \ + BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename A)> \ + friend \ + std::auto_ptr<T> \ + create_auto_ptr(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n), A, p)); \ + \ + template<class T, \ + BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename A)> \ + friend \ + std::tr1::shared_ptr<T> \ + create_shared_ptr(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n), A, p)); \ + /**/ + BOOST_PP_REPEAT(BOTAN_CREATE_PTR_MAX_ARITY, BOTAN_FREESTORE_FRIEND_CREATE_PTR, ~) +# if 0 + ; // make emacs' auto-indentation happy... +# endif +# undef BOTAN_FREESTORE_FRIEND_CREATE_PTR +# else + template<typename T, typename P1, typename P2, typename P3, ... > + friend + std::auto_ptr<T> create_auto_ptr(P1 p1, P2 p2, P3 p3, ...); + + template<typename T, typename P1, typename P2, typename P3, ... > + friend + std::tr1::shared_ptr<T> create_shared_ptr(P1 p1, P2 p2, P3 p3, ...); +# endif // DOXYGEN_IS_PARSING + + + public: + // implicitly defined constructors and assignment operator are + // fine. + }; + +} + +#endif diff --git a/src/math/gfpmath/gfp_element.cpp b/src/math/gfpmath/gfp_element.cpp index 686cc338b..939f03177 100644 --- a/src/math/gfpmath/gfp_element.cpp +++ b/src/math/gfpmath/gfp_element.cpp @@ -1,7 +1,7 @@ /****************************************************** * Arithmetic for prime fields GF(p) (source file) * * * - * (C) 2007 Martin Doering * + * (C) 2007 Martin Döring * * Christoph Ludwig * @@ -12,54 +12,16 @@ #include <botan/gfp_element.h> #include <botan/numthry.h> #include <botan/def_powm.h> +#include <botan/mp_types.h> #include <botan/mp_asm.h> #include <botan/mp_asmi.h> -#include <botan/mp_core.h> +#include <assert.h> namespace Botan { namespace { -/** -*calculates R=b^n (here b=2) with R>m (and R beeing as small as possible) for an odd modulus m. -* no check for oddity is performed! -*/ -BigInt montgm_calc_r_oddmod(const BigInt& prime) - { - u32bit n = prime.sig_words(); - BigInt result(1); - result <<= n*BOTAN_MP_WORD_BITS; - return result; - - } - -/** -*calculates m' with r*r^-1 - m*m' = 1 -* where r^-1 is the multiplicative inverse of r to the modulus m -*/ -BigInt montgm_calc_m_dash(const BigInt& r, const BigInt& m, const BigInt& r_inv ) - { - BigInt result = ((r * r_inv) - BigInt(1))/m; - return result; - } -BigInt montg_trf_to_mres(const BigInt& ord_res, const BigInt& r, const BigInt& m) - { - BigInt result(ord_res); - result *= r; - result %= m; - return result; - } -BigInt montg_trf_to_ordres(const BigInt& m_res, const BigInt& m, const BigInt& r_inv) - { - BigInt result(m_res); - result *= r_inv; - result %= m; - return result; - } - -void inner_montg_mult_sos(word result[], const word* a_bar, - const word* b_bar, const word* n, - const word* n_dash, u32bit s) +void inner_montg_mult_sos(word result[], const word* a_bar, const word* b_bar, const word* n, const word* n_dash, u32bit s) { SecureVector<word> t; t.grow_to(2*s+1); @@ -70,6 +32,10 @@ void inner_montg_mult_sos(word result[], const word* a_bar, word S = 0; for (u32bit j=0; j<s; j++) { + // we use: + // word word_madd3(word a, word b, word c, word d, word* carry) + // returns a * b + c + d and resets the carry (not using it as input) + S = word_madd3(a_bar[j], b_bar[i], t[i+j], &C); t[i+j] = S; } @@ -83,8 +49,8 @@ void inner_montg_mult_sos(word result[], const word* a_bar, // returns a * b + c, resets the carry word C = 0; - word m = word_madd2(t[i], n_dash[0], &C); - // C = 0; ??? + word unused_carry = 0; + word m = word_madd2(t[i], n_dash[0], &unused_carry); for (u32bit j=0; j<s; j++) { @@ -119,7 +85,7 @@ void inner_montg_mult_sos(word result[], const word* a_bar, } D = word_sub(u[s], 0, &B); t[s] = D; - if (B == 0) + if(B == 0) { for (u32bit i=0; i<s; i++) { @@ -135,13 +101,13 @@ void inner_montg_mult_sos(word result[], const word* a_bar, } } -void montg_mult(BigInt& result, BigInt& a_bar, BigInt& b_bar, const BigInt& m, const BigInt& m_dash, const BigInt ) +void montg_mult(BigInt& result, BigInt& a_bar, BigInt& b_bar, const BigInt& m, const BigInt& m_dash, const BigInt) { - if (m.is_zero() || m_dash.is_zero()) + if(m.is_zero() || m_dash.is_zero()) { throw Invalid_Argument("montg_mult(): neither modulus nor m_dash may be zero (and one of them was)"); } - if (a_bar.is_zero() || b_bar.is_zero()) + if(a_bar.is_zero() || b_bar.is_zero()) { result = 0; } @@ -155,24 +121,57 @@ void montg_mult(BigInt& result, BigInt& a_bar, BigInt& b_bar, const BigInt& m, c } +/** +*calculates R=b^n (here b=2) with R>m (and R beeing as small as possible) for an odd modulus m. +* no check for oddity is performed! +*/ +BigInt montgm_calc_r_oddmod(const BigInt& prime) + { + u32bit n = prime.sig_words(); + BigInt result(1); + result <<= n*BOTAN_MP_WORD_BITS; + return result; + + } + +/** +*calculates m' with r*r^-1 - m*m' = 1 +* where r^-1 is the multiplicative inverse of r to the modulus m +*/ +BigInt montgm_calc_m_dash(const BigInt& r, const BigInt& m, const BigInt& r_inv) + { + BigInt result = ((r * r_inv) - BigInt(1))/m; + return result; + } +BigInt montg_trf_to_mres(const BigInt& ord_res, const BigInt& r, const BigInt& m) + { + BigInt result(ord_res); + result *= r; + result %= m; + return result; + } +BigInt montg_trf_to_ordres(const BigInt& m_res, const BigInt& m, const BigInt& r_inv) + { + BigInt result(m_res); + result *= r_inv; + result %= m; + return result; + } + } -GFpElement::GFpElement ( const BigInt& p, const BigInt& value, bool use_montgm) +GFpElement::GFpElement(const BigInt& p, const BigInt& value, bool use_montgm) : mp_mod(), m_value(value %p), m_use_montgm(use_montgm), m_is_trf(false) { - //assert(mp_mod.get() == 0); + assert(mp_mod.get() == 0); mp_mod = std::tr1::shared_ptr<GFpModulus>(new GFpModulus(p)); - //assert(mp_mod->m_p_dash == 0); - if (m_use_montgm) - { + assert(mp_mod->m_p_dash == 0); + if(m_use_montgm) ensure_montgm_precomp(); - - } - } GFpElement::GFpElement(std::tr1::shared_ptr<GFpModulus> const mod, const BigInt& value, bool use_montgm) @@ -181,18 +180,18 @@ GFpElement::GFpElement(std::tr1::shared_ptr<GFpModulus> const mod, const BigInt& m_use_montgm(use_montgm), m_is_trf(false) { - //assert(mp_mod.get() == 0); + assert(mp_mod.get() == 0); mp_mod = mod; } -GFpElement::GFpElement ( GFpElement const& other ) - : m_value ( other.m_value ), +GFpElement::GFpElement(const GFpElement& other) + : m_value(other.m_value), m_use_montgm(other.m_use_montgm), m_is_trf(other.m_is_trf) { //creates an independent copy - //assert((other.m_is_trf && other.m_use_montgm) || !other.m_is_trf); + assert((other.m_is_trf && other.m_use_montgm) || !other.m_is_trf); mp_mod.reset(new GFpModulus(*other.mp_mod)); // copy-ctor of GFpModulus } @@ -203,7 +202,7 @@ void GFpElement::turn_on_sp_red_mul() const } void GFpElement::turn_off_sp_red_mul() const { - if (m_is_trf) + if(m_is_trf) { trf_to_ordres(); // will happen soon anyway, so we can do it here already @@ -213,7 +212,7 @@ void GFpElement::turn_off_sp_red_mul() const } void GFpElement::ensure_montgm_precomp() const { - if ((!mp_mod->m_r.is_zero()) && (!mp_mod->m_r_inv.is_zero()) && (!mp_mod->m_p_dash.is_zero())) + if((!mp_mod->m_r.is_zero()) && (!mp_mod->m_r_inv.is_zero()) && (!mp_mod->m_p_dash.is_zero())) { // values are already set, nothing more to do } @@ -233,9 +232,9 @@ void GFpElement::ensure_montgm_precomp() const mp_mod->m_r_inv = tmp_r_inv; mp_mod->m_p_dash = tmp_p_dash; - //assert(!mp_mod->m_r.is_zero()); - //assert(!mp_mod->m_r_inv.is_zero()); - //assert(!mp_mod->m_p_dash.is_zero()); + assert(!mp_mod->m_r.is_zero()); + assert(!mp_mod->m_r_inv.is_zero()); + assert(!mp_mod->m_p_dash.is_zero()); } } @@ -246,49 +245,49 @@ void GFpElement::set_shrd_mod(std::tr1::shared_ptr<GFpModulus> const p_mod) } void GFpElement::trf_to_mres() const { - if (!m_use_montgm) + if(!m_use_montgm) { throw Illegal_Transformation("GFpElement is not allowed to be transformed to m-residue"); } - //assert(m_is_trf == false); - //assert(!mp_mod->m_r_inv.is_zero()); - //assert(!mp_mod->m_p_dash.is_zero()); + assert(m_is_trf == false); + assert(!mp_mod->m_r_inv.is_zero()); + assert(!mp_mod->m_p_dash.is_zero()); m_value = montg_trf_to_mres(m_value, mp_mod->m_r, mp_mod->m_p); m_is_trf = true; } void GFpElement::trf_to_ordres() const { - //assert(m_is_trf == true); + assert(m_is_trf == true); m_value = montg_trf_to_ordres(m_value, mp_mod->m_p, mp_mod->m_r_inv); m_is_trf = false; } -bool GFpElement::align_operands_res(GFpElement const& lhs, GFpElement const& rhs) //static +bool GFpElement::align_operands_res(const GFpElement& lhs, const GFpElement& rhs) //static { - //assert(lhs.mp_mod->m_p == rhs.mp_mod->m_p); - if (lhs.m_use_montgm && rhs.m_use_montgm) + assert(lhs.mp_mod->m_p == rhs.mp_mod->m_p); + if(lhs.m_use_montgm && rhs.m_use_montgm) { - //assert(rhs.mp_mod->m_p_dash == lhs.mp_mod->m_p_dash); - //assert(rhs.mp_mod->m_r == lhs.mp_mod->m_r); - //assert(rhs.mp_mod->m_r_inv == lhs.mp_mod->m_r_inv); - if (!lhs.m_is_trf && !rhs.m_is_trf) + assert(rhs.mp_mod->m_p_dash == lhs.mp_mod->m_p_dash); + assert(rhs.mp_mod->m_r == lhs.mp_mod->m_r); + assert(rhs.mp_mod->m_r_inv == lhs.mp_mod->m_r_inv); + if(!lhs.m_is_trf && !rhs.m_is_trf) { return false; } - else if (lhs.m_is_trf && rhs.m_is_trf) + else if(lhs.m_is_trf && rhs.m_is_trf) { return true; } else // one is transf., the other not { - if (!lhs.m_is_trf) + if(!lhs.m_is_trf) { lhs.trf_to_mres(); - //assert(rhs.m_is_trf==true); + assert(rhs.m_is_trf==true); return true; } - //assert(rhs.m_is_trf==false); - //assert(lhs.m_is_trf==true); + assert(rhs.m_is_trf==false); + assert(lhs.m_is_trf==true); rhs.trf_to_mres(); // the only possibility left... return true; } @@ -296,21 +295,21 @@ bool GFpElement::align_operands_res(GFpElement const& lhs, GFpElement const& rhs else // at least one of them does not use mm // (so it is impossible that both use it) { - if (lhs.m_is_trf) + if(lhs.m_is_trf) { lhs.trf_to_ordres(); - //assert(rhs.m_is_trf == false); + assert(rhs.m_is_trf == false); return false; } - if (rhs.m_is_trf) + if(rhs.m_is_trf) { rhs.trf_to_ordres(); - //assert(lhs.m_is_trf == false); + assert(lhs.m_is_trf == false); return false; } return false; } - //assert(false); + assert(false); } bool GFpElement::is_trf_to_mres() const @@ -325,23 +324,23 @@ BigInt const GFpElement::get_p() const BigInt const GFpElement::get_value() const { - if (m_is_trf) + if(m_is_trf) { - //assert(m_use_montgm); + assert(m_use_montgm); trf_to_ordres(); } return m_value; } BigInt const GFpElement::get_mres() const { - if (!m_use_montgm) + if(!m_use_montgm) { // does the following exception really make sense? // wouldn´t it be better to simply turn on montg.mult. when // this explicit request is made? throw Illegal_Transformation("GFpElement is not allowed to be transformed to m-residue"); } - if (!m_is_trf) + if(!m_is_trf) { trf_to_mres(); @@ -349,7 +348,7 @@ BigInt const GFpElement::get_mres() const } return m_value; } -GFpElement const& GFpElement::operator= ( GFpElement const& other ) +const GFpElement& GFpElement::operator=(const GFpElement& other) { m_value.grow_reg(other.m_value.size()); // grow first for exception safety @@ -366,7 +365,7 @@ GFpElement const& GFpElement::operator= ( GFpElement const& other ) // precomputed values. // we also deal with the case were the pointers themsevles are equal: - if (mp_mod.get() == other.mp_mod.get()) + if(mp_mod.get() == other.mp_mod.get()) { // everything ok, we are in the same sharing group anyway, nothing to do m_value = other.m_value; // cannot throw @@ -374,7 +373,7 @@ GFpElement const& GFpElement::operator= ( GFpElement const& other ) m_is_trf = other.m_is_trf; return *this; } - if (mp_mod->m_p != other.mp_mod->m_p) + if(mp_mod->m_p != other.mp_mod->m_p) { // the moduli are different, this is a special case // which will not occur in usual applications, @@ -398,7 +397,7 @@ GFpElement const& GFpElement::operator= ( GFpElement const& other ) // the moduli are equal, but we deal with different sharing groups. // we will NOT fuse the sharing goups // and we will NOT reset already precomputed values - if (mp_mod->has_precomputations()) + if(mp_mod->has_precomputations()) { // our own sharing group already has precomputed values, // so nothing to do. @@ -407,7 +406,7 @@ GFpElement const& GFpElement::operator= ( GFpElement const& other ) else { // let´s see whether the argument has something for us... - if (other.mp_mod->has_precomputations()) + if(other.mp_mod->has_precomputations()) { // fetch them for our sharing group // exc. safety note: grow first @@ -427,9 +426,9 @@ GFpElement const& GFpElement::operator= ( GFpElement const& other ) } -void GFpElement::share_assign(GFpElement const& other) +void GFpElement::share_assign(const GFpElement& other) { - //assert((other.m_is_trf && other.m_use_montgm) || !other.m_is_trf); + assert((other.m_is_trf && other.m_use_montgm) || !other.m_is_trf); // use grow_to to make it exc safe m_value.grow_reg(other.m_value.size()); @@ -440,24 +439,24 @@ void GFpElement::share_assign(GFpElement const& other) mp_mod = other.mp_mod; // cannot throw } -GFpElement& GFpElement::operator+= ( GFpElement const& rhs ) +GFpElement& GFpElement::operator+=(const GFpElement& rhs) { GFpElement::align_operands_res(*this, rhs); workspace = m_value; workspace += rhs.m_value; - if (workspace >= mp_mod->m_p) + if(workspace >= mp_mod->m_p) { workspace -= mp_mod->m_p; } m_value = workspace; - //assert(m_value < mp_mod->m_p); - //assert(m_value >= 0); + assert(m_value < mp_mod->m_p); + assert(m_value >= 0); return *this; } -GFpElement& GFpElement::operator-= ( GFpElement const& rhs ) +GFpElement& GFpElement::operator-=(const GFpElement& rhs) { GFpElement::align_operands_res(*this, rhs); @@ -465,17 +464,17 @@ GFpElement& GFpElement::operator-= ( GFpElement const& rhs ) workspace -= rhs.m_value; - if (workspace.is_negative()) + if(workspace.is_negative()) { workspace += mp_mod->m_p; } m_value = workspace; - //assert(m_value < mp_mod->m_p); - //assert(m_value >= 0); + assert(m_value < mp_mod->m_p); + assert(m_value >= 0); return *this; - } + GFpElement& GFpElement::operator*= (u32bit rhs) { workspace = m_value; @@ -484,22 +483,23 @@ GFpElement& GFpElement::operator*= (u32bit rhs) m_value = workspace; return *this; } -GFpElement& GFpElement::operator*= ( GFpElement const& rhs ) + +GFpElement& GFpElement::operator*=(const GFpElement& rhs) { - //assert(rhs.mp_mod->m_p == mp_mod->m_p); + assert(rhs.mp_mod->m_p == mp_mod->m_p); // here, we do not use align_operands_res() for one simple reason: // we want to enforce the transformation to an m-residue, otherwise it would // never happen - if (m_use_montgm && rhs.m_use_montgm) + if(m_use_montgm && rhs.m_use_montgm) { - //assert(rhs.mp_mod->m_p == mp_mod->m_p); // is montgm. mult is on, then precomps must be there - //assert(rhs.mp_mod->m_p_dash == mp_mod->m_p_dash); - //assert(rhs.mp_mod->m_r == mp_mod->m_r); - if (!m_is_trf) + assert(rhs.mp_mod->m_p == mp_mod->m_p); // is montgm. mult is on, then precomps must be there + assert(rhs.mp_mod->m_p_dash == mp_mod->m_p_dash); + assert(rhs.mp_mod->m_r == mp_mod->m_r); + if(!m_is_trf) { trf_to_mres(); } - if (!rhs.m_is_trf) + if(!rhs.m_is_trf) { rhs.trf_to_mres(); } @@ -508,14 +508,14 @@ GFpElement& GFpElement::operator*= ( GFpElement const& rhs ) } else // ordinary multiplication { - if (m_is_trf) + if(m_is_trf) { - //assert(m_use_montgm); + assert(m_use_montgm); trf_to_ordres(); } - if (rhs.m_is_trf) + if(rhs.m_is_trf) { - //assert(rhs.m_use_montgm); + assert(rhs.m_use_montgm); rhs.trf_to_ordres(); } workspace = m_value; @@ -525,14 +525,15 @@ GFpElement& GFpElement::operator*= ( GFpElement const& rhs ) } return *this; } -GFpElement& GFpElement::operator/= ( GFpElement const& rhs ) + +GFpElement& GFpElement::operator/=(const GFpElement& rhs) { bool use_mres = GFpElement::align_operands_res(*this, rhs); - //assert((this->m_is_trf && rhs.m_is_trf) || !(this->m_is_trf && rhs.m_is_trf) ); + assert((this->m_is_trf && rhs.m_is_trf) || !(this->m_is_trf && rhs.m_is_trf)); // (internal note: see C86) - if (use_mres) + if(use_mres) { - //assert(m_use_montgm && rhs.m_use_montgm); + assert(m_use_montgm && rhs.m_use_montgm); GFpElement rhs_ordres(rhs); rhs_ordres.trf_to_ordres(); rhs_ordres.inverse_in_place(); @@ -550,47 +551,55 @@ GFpElement& GFpElement::operator/= ( GFpElement const& rhs ) } return *this; } + bool GFpElement::is_zero() { return (m_value.is_zero()); // this is correct because x_bar = x * r = x = 0 for x = 0 } + GFpElement& GFpElement::inverse_in_place() { m_value = inverse_mod(m_value, mp_mod->m_p); - if (m_is_trf) + if(m_is_trf) { - //assert(m_use_montgm); + assert(m_use_montgm); m_value *= mp_mod->m_r; m_value *= mp_mod->m_r; m_value %= mp_mod->m_p; } - //assert(m_value <= mp_mod->m_p); + assert(m_value <= mp_mod->m_p); return *this; - } + GFpElement& GFpElement::negate() { m_value = mp_mod->m_p - m_value; - //assert(m_value <= mp_mod->m_p); + assert(m_value <= mp_mod->m_p); return *this; } -void GFpElement::swap ( GFpElement& other ) + +void GFpElement::swap(GFpElement& other) { - m_value.swap ( other.m_value ); + m_value.swap(other.m_value); mp_mod.swap(other.mp_mod); std::swap<bool>(m_use_montgm,other.m_use_montgm); std::swap<bool>(m_is_trf,other.m_is_trf); } -bool operator== ( GFpElement const& lhs, GFpElement const& rhs ) +std::ostream& operator<<(std::ostream& output, const GFpElement& elem) + { + return output << elem.get_p() << "," << elem.get_value(); + } + +bool operator==(const GFpElement& lhs, const GFpElement& rhs) { // for effeciency reasons we firstly check whether //the modulus pointers are different in the first place: - if (lhs.get_ptr_mod() != rhs.get_ptr_mod()) + if(lhs.get_ptr_mod() != rhs.get_ptr_mod()) { - if (lhs.get_p() != rhs.get_p()) + if(lhs.get_p() != rhs.get_p()) { return false; } @@ -598,7 +607,7 @@ bool operator== ( GFpElement const& lhs, GFpElement const& rhs ) // so the modulus is equal, now check the values bool use_mres = GFpElement::align_operands_res(lhs, rhs); - if (use_mres) + if(use_mres) { return (lhs.get_mres() == rhs.get_mres()); } @@ -608,67 +617,75 @@ bool operator== ( GFpElement const& lhs, GFpElement const& rhs ) } } -GFpElement operator+ ( GFpElement const& lhs, GFpElement const& rhs ) +GFpElement operator+(const GFpElement& lhs, const GFpElement& rhs) { // consider the case that lhs and rhs both use montgm: // then += returns an element which uses montgm. // thus the return value of op+ here will be an element // using montgm in this case // NOTE: the rhs might be transformed when using op+, the lhs never - GFpElement result ( lhs ); + GFpElement result(lhs); result += rhs; return result; } -GFpElement operator- ( GFpElement const& lhs, GFpElement const& rhs ) + +GFpElement operator-(const GFpElement& lhs, const GFpElement& rhs) { - GFpElement result ( lhs ); + GFpElement result(lhs); result -= rhs; return result; // NOTE: the rhs might be transformed when using op-, the lhs never } -GFpElement operator- ( GFpElement const& lhs ) + +GFpElement operator-(const GFpElement& lhs) { - return ( GFpElement ( lhs ) ).negate(); + return(GFpElement(lhs)).negate(); } -GFpElement operator* ( GFpElement const& lhs, GFpElement const& rhs ) + +GFpElement operator*(const GFpElement& lhs, const GFpElement& rhs) { // consider the case that lhs and rhs both use montgm: // then *= returns an element which uses montgm. // thus the return value of op* here will be an element // using montgm in this case - GFpElement result ( lhs ); + GFpElement result(lhs); result *= rhs; return result; } -GFpElement operator*(GFpElement const& lhs, u32bit rhs) + +GFpElement operator*(const GFpElement& lhs, u32bit rhs) { GFpElement result(lhs); result *= rhs; return result; - } -GFpElement operator*(u32bit lhs, GFpElement const& rhs ) + +GFpElement operator*(u32bit lhs, const GFpElement& rhs) { return rhs*lhs; } -GFpElement operator/ ( GFpElement const& lhs, GFpElement const& rhs ) + +GFpElement operator/(const GFpElement& lhs, const GFpElement& rhs) { GFpElement result (lhs); result /= rhs; return result; } -SecureVector<byte> FE2OSP ( GFpElement const& elem ) + +SecureVector<byte> FE2OSP(const GFpElement& elem) { - return BigInt::encode_1363 ( elem.get_value(), elem.get_p().bytes() ); + return BigInt::encode_1363(elem.get_value(), elem.get_p().bytes()); } -GFpElement OS2FEP ( MemoryRegion<byte> const& os, BigInt p ) - { - return GFpElement ( p, BigInt::decode ( os.begin(), os.size() ) ); +GFpElement OS2FEP(MemoryRegion<byte> const& os, BigInt p) + { + return GFpElement(p, BigInt::decode(os.begin(), os.size())); } -GFpElement inverse ( GFpElement const& elem ) + +GFpElement inverse(const GFpElement& elem) { - return GFpElement ( elem ).inverse_in_place(); + return GFpElement(elem).inverse_in_place(); } -} // namespace Botan +} + diff --git a/src/math/gfpmath/gfp_element.h b/src/math/gfpmath/gfp_element.h index e9850df30..d576363ac 100644 --- a/src/math/gfpmath/gfp_element.h +++ b/src/math/gfpmath/gfp_element.h @@ -1,41 +1,42 @@ /****************************************************** * Arithmetic for prime fields GF(p) (header file) * * * - * (C) 2007 Martin Döring * -* [email protected] * -* Christoph Ludwig * -* [email protected] * -* Falko Strenzke * -* [email protected] * -******************************************************/ + * (C) 2007 Martin Doering * + * [email protected] * + * Christoph Ludwig * + * [email protected] * + * Falko Strenzke * + * [email protected] * + ******************************************************/ -#ifndef BOTAN_MATH_GF_GFP_ELEMENT_H_GUARD_ -#define BOTAN_MATH_GF_GFP_ELEMENT_H_GUARD_ +#ifndef BOTAN_GFP_ELEMENT_H__ +#define BOTAN_GFP_ELEMENT_H__ -#include <botan/gfp_modulus.h> #include <botan/bigint.h> -#include <tr1/memory> +#include <botan/gfp_modulus.h> +#include <botan/freestore.h> +#include <iostream> -namespace Botan -{ +namespace Botan { struct Illegal_Transformation : public Exception -{ - Illegal_Transformation(const std::string& err = "Requested transformation is not possible") - : Exception(err) {} -}; + { + Illegal_Transformation(const std::string& err = + "Requested transformation is not possible") + : Exception(err) {} + }; /** -* This class represents one element in GF(p). Enables the convenient, transparent use -* of the montgomery multiplication. -*/ + * This class represents one element in GF(p). Enables the convenient, transparent use + * of the montgomery multiplication. + */ class GFpElement { - private: std::tr1::shared_ptr<GFpModulus> mp_mod; mutable BigInt m_value; // ordinary residue or m-residue respectively mutable BigInt workspace; + // ***************************************** // data members for montgomery multiplication mutable bool m_use_montgm; @@ -44,22 +45,20 @@ class GFpElement // the actual value (in this case mValue doesn´t) mutable bool m_is_trf; - void ensure_montgm_precomp() const; void trf_to_mres() const; void trf_to_ordres() const; public: - /** construct an element of GF(p) with the given value. - * use_montg defaults to false and determines wether Montgomery multiplications - * will be use when applying operators '*' , '*='. + * use_montg defaults to false and determines wether Montgomery + * multiplications will be use when applying operators *, *= * @param p the prime number of the field * @param value the element value * @param use_montgm whether this object will use Montgomery multiplication */ - explicit GFpElement ( const BigInt& p, const BigInt& value, bool use_montgm = false ); + explicit GFpElement (const BigInt& p, const BigInt& value, bool use_montgm = false ); /** construct an element of GF(p) with the given value (defaults to 0). @@ -80,7 +79,7 @@ class GFpElement * Copy constructor * @param other The element to clone */ - GFpElement ( GFpElement const& other ); + GFpElement ( const GFpElement& other ); /** * Assignment operator. @@ -89,7 +88,7 @@ class GFpElement * * @param other The element to assign to our object */ - GFpElement const& operator= ( GFpElement const& other ); + const GFpElement& operator= ( const GFpElement& other ); /** * Works like the assignment operator, but lets @@ -99,7 +98,7 @@ class GFpElement * the shared GFpModulus objects! * @param other The element to assign to our object */ - void share_assign(GFpElement const& other); + void share_assign(const GFpElement& other); /** * Switch Montgomery multiplcation optimizations ON @@ -116,27 +115,27 @@ class GFpElement * @param rhs the GFpElement to add to the local value * @result *this */ - GFpElement& operator+= ( GFpElement const& rhs ); + GFpElement& operator+= ( const GFpElement& rhs ); /** * -= Operator * @param rhs the GFpElement to subtract from the local value * @result *this */ - GFpElement& operator-= ( GFpElement const& rhs ); + GFpElement& operator-= ( const GFpElement& rhs ); /** * *= Operator * @param rhs the GFpElement to multiply with the local value * @result *this */ - GFpElement& operator*= ( GFpElement const& rhs ); + GFpElement& operator*= ( const GFpElement& rhs ); /** * /= Operator * @param rhs the GFpElement to divide the local value by * @result *this */ - GFpElement& operator/= ( GFpElement const& rhs ); + GFpElement& operator/= ( const GFpElement& rhs ); /** * *= Operator @@ -235,7 +234,7 @@ class GFpElement * @result true if both are transformed to their m-residue, * false it both are transformed to their normal residue. */ - static bool align_operands_res(GFpElement const& lhs, GFpElement const& rhs); + static bool align_operands_res(const GFpElement& lhs, const GFpElement& rhs); //friend declarations for non-member functions @@ -245,6 +244,8 @@ class GFpElement * @param elem the object to write * @result the output stream */ + friend std::ostream& operator<< ( std::ostream& output, const GFpElement& elem ); + friend class Point_Coords_GFp; /** @@ -256,53 +257,48 @@ class GFpElement }; // relational operators -bool operator== ( GFpElement const& lhs, GFpElement const& rhs ); -inline bool operator!= ( GFpElement const& lhs, GFpElement const& rhs ) +bool operator== ( const GFpElement& lhs, const GFpElement& rhs ); +inline bool operator!= ( const GFpElement& lhs, const GFpElement& rhs ) { return !operator== ( lhs, rhs ); } // arithmetic operators -GFpElement operator+ ( GFpElement const& lhs, GFpElement const& rhs ); -GFpElement operator- ( GFpElement const& lhs, GFpElement const& rhs ); -GFpElement operator- ( GFpElement const& lhs ); +GFpElement operator+ ( const GFpElement& lhs, const GFpElement& rhs ); +GFpElement operator- ( const GFpElement& lhs, const GFpElement& rhs ); +GFpElement operator- ( const GFpElement& lhs ); + +GFpElement operator* ( const GFpElement& lhs, const GFpElement& rhs ); +GFpElement operator/ ( const GFpElement& lhs, const GFpElement& rhs ); +GFpElement operator* (const GFpElement& lhs, u32bit rhs); +GFpElement operator* (u32bit rhs, const GFpElement& lhs); -GFpElement operator* ( GFpElement const& lhs, GFpElement const& rhs ); -GFpElement operator/ ( GFpElement const& lhs, GFpElement const& rhs ); -GFpElement operator* (GFpElement const& lhs, u32bit rhs); -GFpElement operator* (u32bit rhs, GFpElement const& lhs); +// io operators +std::ostream& operator<< ( std::ostream& output, const GFpElement& elem ); // return (*this)^(-1) -GFpElement inverse ( GFpElement const& elem ); +GFpElement inverse ( const GFpElement& elem ); // encoding and decoding -SecureVector<byte> FE2OSP ( GFpElement const& elem ); -GFpElement OS2FEP ( MemoryRegion<byte> const& os, BigInt p ); - +SecureVector<byte> FE2OSP ( const GFpElement& elem ); +GFpElement OS2FEP ( MemoryRegion<byte> const& os, BigInt p); -// swaps the states of elem1 and elem2, does not throw! -// cf. Meyers, Item 25 -inline -void swap ( GFpElement& elem1, GFpElement& elem2 ) +inline void swap(GFpElement& x, GFpElement& y) { - elem1.swap ( elem2 ); + x.swap(y); } -} // namespace Botan +} -namespace std -{ +namespace std { -// swaps the states of elem1 and elem2, does not throw! -// cf. Meyers, Item 25 -template<> -inline -void swap< Botan::GFpElement>(Botan::GFpElement& elem1, - Botan::GFpElement& elem2) +template<> inline +void swap<Botan::GFpElement>(Botan::GFpElement& x, + Botan::GFpElement& y) { - elem1.swap(elem2); + x.swap(y); } -} // namespace std +} #endif diff --git a/src/math/gfpmath/gfp_modulus.h b/src/math/gfpmath/gfp_modulus.h index 5edf44ba0..2bf48b8b6 100644 --- a/src/math/gfpmath/gfp_modulus.h +++ b/src/math/gfpmath/gfp_modulus.h @@ -10,8 +10,8 @@ ******************************************************/ -#ifndef BOTAN_MATH_GF_GFP_MODULUS_H_GUARD_ -#define BOTAN_MATH_GF_GFP_MODULUS_H_GUARD_ +#ifndef BOTAN_GFP_MODULUS_H__ +#define BOTAN_GFP_MODULUS_H__ #include <botan/bigint.h> @@ -44,8 +44,8 @@ class GFpModulus {} /** - * Tells whether the precomputations necessary for the use of the montgomery - * multiplication have yet been established. + * Tells whether the precomputations necessary for the use of the + * montgomery multiplication have yet been established. * @result true if the precomputated value are already available. */ inline bool has_precomputations() const @@ -122,3 +122,4 @@ class GFpModulus } #endif + diff --git a/src/math/gfpmath/info.txt b/src/math/gfpmath/info.txt index 9c62d7761..e00c6c020 100644 --- a/src/math/gfpmath/info.txt +++ b/src/math/gfpmath/info.txt @@ -17,4 +17,5 @@ gfp_element.h gfp_modulus.h point_gfp.cpp point_gfp.h +freestore.h </add> |