aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/gfpmath/gfp_modulus.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-30 22:46:45 +0000
committerlloyd <[email protected]>2008-09-30 22:46:45 +0000
commitd880999c1c98178043418e990f58e4314fca4a85 (patch)
tree545aa5b2b9e9bb3204e91b1b12ce2e0cb2e1d31b /src/math/gfpmath/gfp_modulus.h
parent13d08cbe978c4cd0de01aa0120c39470508cbbcb (diff)
Move GF(p) math code from pk/ecdsa to math/gfpmath
Diffstat (limited to 'src/math/gfpmath/gfp_modulus.h')
-rw-r--r--src/math/gfpmath/gfp_modulus.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/math/gfpmath/gfp_modulus.h b/src/math/gfpmath/gfp_modulus.h
new file mode 100644
index 000000000..5edf44ba0
--- /dev/null
+++ b/src/math/gfpmath/gfp_modulus.h
@@ -0,0 +1,124 @@
+/******************************************************
+ * Modulus and related data for a specific *
+ * implementation of GF(p) (header file) *
+ * *
+ * (C) 2008 Martin Döring *
+ * Christoph Ludwig *
+ * Falko Strenzke *
+ ******************************************************/
+
+#ifndef BOTAN_MATH_GF_GFP_MODULUS_H_GUARD_
+#define BOTAN_MATH_GF_GFP_MODULUS_H_GUARD_
+
+#include <botan/bigint.h>
+
+namespace Botan
+{
+
+class GFpElement;
+/**
+* This class represents a GFpElement modulus including the modulus related
+* values necessary for the montgomery multiplication.
+*/
+class GFpModulus
+ {
+ friend class GFpElement;
+ private:
+ BigInt m_p; // the modulus itself
+ mutable BigInt m_p_dash;
+ mutable BigInt m_r;
+ mutable BigInt m_r_inv;
+ public:
+
+ /**
+ * Construct a GF(P)-Modulus from a BigInt
+ */
+ GFpModulus(BigInt p)
+ : m_p(p),
+ m_p_dash(),
+ m_r(),
+ m_r_inv()
+ {}
+
+ /**
+ * 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
+ {
+ return(!m_p_dash.is_zero() && !m_r.is_zero() && !m_r_inv.is_zero());
+ }
+
+ /**
+ * Swaps this with another GFpModulus, does not throw.
+ * @param other the GFpModulus to swap *this with.
+ */
+ inline void swap(GFpModulus& other)
+ {
+ m_p.swap(other.m_p);
+ m_p_dash.swap(other.m_p_dash);
+ m_r.swap(other.m_r);
+ m_r_inv.swap(other.m_r_inv);
+ }
+
+ /**
+ * Tells whether the modulus of *this is equal to the argument.
+ * @param mod the modulus to compare this with
+ * @result true if the modulus of *this and the argument are equal.
+ */
+ inline bool p_equal_to(const BigInt& mod) const
+ {
+ return (m_p == mod);
+ }
+
+ /**
+ * Return the modulus of this GFpModulus.
+ * @result the modulus of *this.
+ */
+ inline const BigInt get_p() const
+ {
+ return m_p;
+ }
+
+ /**
+ * returns the montgomery multiplication related value r.
+ * Warning: will be zero if precomputations have not yet been
+ * performed!
+ * @result r
+ */
+ inline const BigInt get_r() const
+ {
+ return m_r;
+ }
+
+ /**
+ * returns the montgomery multiplication related value r^{-1}.
+ * Warning: will be zero if precomputations have not yet been
+ * performed!
+ * @result r^{-1}
+ */
+ inline const BigInt get_r_inv() const
+ {
+ return m_r_inv;
+ }
+
+ /**
+ * returns the montgomery multiplication related value p'.
+ * Warning: will be zero if precomputations have not yet been
+ * performed!
+ * @result p'
+ */
+ inline const BigInt get_p_dash() const
+ {
+ return m_p_dash;
+ }
+ // default cp-ctor, op= are fine
+ };
+
+}
+
+#endif