Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

rabin.h

Go to the documentation of this file.
00001 #ifndef CRYPTOPP_RABIN_H
00002 #define CRYPTOPP_RABIN_H
00003 
00007 #include "oaep.h"
00008 #include "pssr.h"
00009 #include "integer.h"
00010 
00011 NAMESPACE_BEGIN(CryptoPP)
00012 
00014 class RabinFunction : virtual public TrapdoorFunction
00015 {
00016 public:
00017         RabinFunction(const Integer &n, const Integer &r, const Integer &s);
00018         RabinFunction(BufferedTransformation &bt);
00019         void DEREncode(BufferedTransformation &bt) const;
00020 
00021         Integer ApplyFunction(const Integer &x) const;
00022         Integer PreimageBound() const {return n;}
00023         Integer ImageBound() const {return n;}
00024 
00025         const Integer& GetModulus() const {return n;}
00026         const Integer& GetQuadraticResidueModPrime1() const {return r;}
00027         const Integer& GetQuadraticResidueModPrime2() const {return s;}
00028 
00029 protected:
00030         RabinFunction() {}      // to be used only by InvertibleRabinFunction
00031         Integer n, r, s;        // these are only modified in constructors
00032 };
00033 
00035 class InvertibleRabinFunction : public RabinFunction, public InvertibleTrapdoorFunction
00036 {
00037 public:
00038         InvertibleRabinFunction(const Integer &n, const Integer &r, const Integer &s,
00039                                                         const Integer &p, const Integer &q, const Integer &u);
00040         // generate a random private key
00041         InvertibleRabinFunction(RandomNumberGenerator &rng, unsigned int keybits);
00042         InvertibleRabinFunction(BufferedTransformation &bt);
00043         void DEREncode(BufferedTransformation &bt) const;
00044 
00045         Integer CalculateInverse(const Integer &x) const;
00046 
00047         const Integer& GetPrime1() const {return p;}
00048         const Integer& GetPrime2() const {return q;}
00049 
00050 protected:
00051         Integer p, q, u;
00052 };
00053 
00055 template <class B>
00056 class RabinPrivateKeyTemplate : public B
00057 {
00058 public:
00059         RabinPrivateKeyTemplate(const Integer &n, const Integer &r, const Integer &s,
00060                                         const Integer &p, const Integer &q, const Integer &u)
00061                 : PublicKeyBaseTemplate<InvertibleRabinFunction>(
00062                         InvertibleRabinFunction(n, r, s, p, q, u)) {}
00063 
00064         RabinPrivateKeyTemplate(RandomNumberGenerator &rng, unsigned int keybits)
00065                 : PublicKeyBaseTemplate<InvertibleRabinFunction>(
00066                         InvertibleRabinFunction(rng, keybits)) {}
00067 
00068         RabinPrivateKeyTemplate(BufferedTransformation &bt)
00069                 : PublicKeyBaseTemplate<InvertibleRabinFunction>(bt) {}
00070 };
00071 
00073 template <class B, class V>
00074 class RabinPublicKeyTemplate : public B
00075 {
00076 public:
00077         RabinPublicKeyTemplate(const Integer &n, const Integer &r, const Integer &s)
00078                 : PublicKeyBaseTemplate<RabinFunction>(RabinFunction(n, r, s)) {}
00079 
00080         RabinPublicKeyTemplate(const V &priv)
00081                 : PublicKeyBaseTemplate<RabinFunction>(priv.GetTrapdoorFunction()) {}
00082 
00083         RabinPublicKeyTemplate(BufferedTransformation &bt)
00084                 : PublicKeyBaseTemplate<RabinFunction>(bt) {}
00085 };
00086 
00087 class SHA;
00088 
00090 typedef RabinPrivateKeyTemplate<DecryptorTemplate<OAEP<SHA>, InvertibleRabinFunction> >
00091         RabinDecryptor;
00093 typedef RabinPublicKeyTemplate<EncryptorTemplate<OAEP<SHA>, RabinFunction>, RabinDecryptor>
00094         RabinEncryptor;
00095 
00096 // simulate template typedef
00097 #define RabinSignerWith(H) RabinPrivateKeyTemplate<SignerWithRecoveryTemplate<InvertibleRabinFunction, PSSR<H> > >
00098 #define RabinVerifierWith(H) RabinPublicKeyTemplate<VerifierWithRecoveryTemplate<RabinFunction, PSSR<H> >, RabinSignerWith(H) >
00099 
00100 NAMESPACE_END
00101 
00102 #endif

Generated at Mon Jan 15 01:16:35 2001 for Crypto++ by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000