- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# rabin.h

Go to the documentation of this file.

    00001 #ifndef CRYPTOPP_RABIN_H
    00002 #define CRYPTOPP_RABIN_H
    00003
    00004 /** \file
    00005 */
    00006
    00007 #include "oaep.h"
    00008 #include "pssr.h"
    00009 #include "integer.h"
    00010
    00011 NAMESPACE_BEGIN(CryptoPP)
    00012
    00013 //! _
    00014 class RabinFunction : public TrapdoorFunction, public PublicKey
    00015 {
    00016         typedef RabinFunction ThisClass;
    00017
    00018 public:
    00019         void Initialize(const Integer &n, const Integer &r, const Integer &s)
    00020                 {m_n = n; m_r = r; m_s = s;}
    00021
    00022         void BERDecode(BufferedTransformation &bt);
    00023         void DEREncode(BufferedTransformation &bt) const;
    00024
    00025         Integer ApplyFunction(const Integer &x) const;
    00026         Integer PreimageBound() const {return m_n;}
    00027         Integer ImageBound() const {return m_n;}
    00028
    00029         bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
    00030         bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
    00031         void AssignFrom(const NameValuePairs &source);
    00032
    00033         const Integer& GetModulus() const {return m_n;}
    00034         const Integer& GetQuadraticResidueModPrime1() const {return m_r;}
    00035         const Integer& GetQuadraticResidueModPrime2() const {return m_s;}
    00036
    00037         void SetModulus(const Integer &n) {m_n = n;}
    00038         void SetQuadraticResidueModPrime1(const Integer &r) {m_r = r;}
    00039         void SetQuadraticResidueModPrime2(const Integer &s) {m_s = s;}
    00040
    00041 protected:
    00042         Integer m_n, m_r, m_s;
    00043 };
    00044
    00045 //! _
    00046 class InvertibleRabinFunction : public RabinFunction, public TrapdoorFunctionInverse, public PrivateKey
    00047 {
    00048         typedef InvertibleRabinFunction ThisClass;
    00049
    00050 public:
    00051         void Initialize(const Integer &n, const Integer &r, const Integer &s,
    00052                                                         const Integer &p, const Integer &q, const Integer &u)
    00053                 {m_n = n; m_r = r; m_s = s; m_p = p; m_q = q; m_u = u;}
    00054         void Initialize(RandomNumberGenerator &rng, unsigned int keybits)
    00055                 {GenerateRandomWithKeySize(rng, keybits);}
    00056
    00057         void BERDecode(BufferedTransformation &bt);
    00058         void DEREncode(BufferedTransformation &bt) const;
    00059
    00060         Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
    00061
    00062         bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
    00063         bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
    00064         void AssignFrom(const NameValuePairs &source);
    00065         /*! parameters: (ModulusSize) */
    00066         void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
    00067
    00068         const Integer& GetPrime1() const {return m_p;}
    00069         const Integer& GetPrime2() const {return m_q;}
    00070         const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
    00071
    00072         void SetPrime1(const Integer &p) {m_p = p;}
    00073         void SetPrime2(const Integer &q) {m_q = q;}
    00074         void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
    00075
    00076 protected:
    00077         Integer m_p, m_q, m_u;
    00078 };
    00079
    00080 //! Rabin
    00081 struct Rabin
    00082 {
    00083         static std::string StaticAlgorithmName() {return "Rabin-Crypto++Variant";}
    00084         typedef RabinFunction PublicKey;
    00085         typedef InvertibleRabinFunction PrivateKey;
    00086 };
    00087
    00088 //! Rabin encryption
    00089 template <class STANDARD>
    00090 struct RabinES : public TF_ES<STANDARD, Rabin>
    00091 {
    00092 };
    00093
    00094 //! Rabin signature
    00095 template <class STANDARD, class H>
    00096 struct RabinSS : public TF_SS<STANDARD, H, Rabin>
    00097 {
    00098 };
    00099
    00100 // More typedefs for backwards compatibility
    00101 class SHA1;
    00102 typedef RabinES<OAEP<SHA1> >::Decryptor RabinDecryptor;
    00103 typedef RabinES<OAEP<SHA1> >::Encryptor RabinEncryptor;
    00104
    00105 NAMESPACE_END
    00106
    00107 #endif