00001 #ifndef CRYPTOPP_RW_H
00002 #define CRYPTOPP_RW_H
00003
00004
00005
00006
00007
00008
00009 #include "pubkey.h"
00010
00011 NAMESPACE_BEGIN(CryptoPP)
00012
00013
00014 class CRYPTOPP_DLL RWFunction : public TrapdoorFunction, public PublicKey
00015 {
00016 typedef RWFunction ThisClass;
00017
00018 public:
00019 void Initialize(const Integer &n)
00020 {m_n = n;}
00021
00022 void BERDecode(BufferedTransformation &bt);
00023 void DEREncode(BufferedTransformation &bt) const;
00024
00025 void Save(BufferedTransformation &bt) const
00026 {DEREncode(bt);}
00027 void Load(BufferedTransformation &bt)
00028 {BERDecode(bt);}
00029
00030 Integer ApplyFunction(const Integer &x) const;
00031 Integer PreimageBound() const {return ++(m_n>>1);}
00032 Integer ImageBound() const {return m_n;}
00033
00034 bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
00035 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
00036 void AssignFrom(const NameValuePairs &source);
00037
00038 const Integer& GetModulus() const {return m_n;}
00039 void SetModulus(const Integer &n) {m_n = n;}
00040
00041 protected:
00042 Integer m_n;
00043 };
00044
00045
00046 class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey
00047 {
00048 typedef InvertibleRWFunction ThisClass;
00049
00050 public:
00051 void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u)
00052 {m_n = n; m_p = p; m_q = q; m_u = u;}
00053
00054 void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
00055 {GenerateRandomWithKeySize(rng, modulusBits);}
00056
00057 void BERDecode(BufferedTransformation &bt);
00058 void DEREncode(BufferedTransformation &bt) const;
00059
00060 void Save(BufferedTransformation &bt) const
00061 {DEREncode(bt);}
00062 void Load(BufferedTransformation &bt)
00063 {BERDecode(bt);}
00064
00065 Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
00066
00067
00068 bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
00069 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
00070 void AssignFrom(const NameValuePairs &source);
00071
00072 void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
00073
00074 const Integer& GetPrime1() const {return m_p;}
00075 const Integer& GetPrime2() const {return m_q;}
00076 const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
00077
00078 void SetPrime1(const Integer &p) {m_p = p;}
00079 void SetPrime2(const Integer &q) {m_q = q;}
00080 void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
00081
00082 protected:
00083 Integer m_p, m_q, m_u;
00084 };
00085
00086
00087 struct RW
00088 {
00089 static std::string StaticAlgorithmName() {return "RW";}
00090 typedef RWFunction PublicKey;
00091 typedef InvertibleRWFunction PrivateKey;
00092 };
00093
00094
00095 template <class STANDARD, class H>
00096 struct RWSS : public TF_SS<STANDARD, H, RW>
00097 {
00098 };
00099
00100 NAMESPACE_END
00101
00102 #endif