/* * Modular Reducer * (C) 1999-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ #ifndef BOTAN_MODULAR_REDUCER_H__ #define BOTAN_MODULAR_REDUCER_H__ #include namespace Botan { /* * Modular Reducer */ class BOTAN_DLL Modular_Reducer { public: const BigInt& get_modulus() const { return modulus; } BigInt reduce(const BigInt& x) const; /** * Multiply mod p */ BigInt multiply(const BigInt& x, const BigInt& y) const { return reduce(x * y); } /** * Square mod p */ BigInt square(const BigInt& x) const { return reduce(Botan::square(x)); } /** * Cube mod p */ BigInt cube(const BigInt& x) const { return multiply(x, this->square(x)); } bool initialized() const { return (mod_words != 0); } Modular_Reducer() { mod_words = 0; } Modular_Reducer(const BigInt& mod); private: BigInt modulus, modulus_2, mu; u32bit mod_words, mod2_words, mu_words; }; } #endif