Warning, file /include/cryptopp/rw.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef CRYPTOPP_RW_H
0013 #define CRYPTOPP_RW_H
0014
0015 #include "cryptlib.h"
0016 #include "pubkey.h"
0017 #include "integer.h"
0018
0019 NAMESPACE_BEGIN(CryptoPP)
0020
0021
0022
0023 class CRYPTOPP_DLL RWFunction : public TrapdoorFunction, public PublicKey
0024 {
0025 typedef RWFunction ThisClass;
0026
0027 public:
0028
0029
0030
0031 void Initialize(const Integer &n)
0032 {m_n = n;}
0033
0034 void BERDecode(BufferedTransformation &bt);
0035 void DEREncode(BufferedTransformation &bt) const;
0036
0037 void Save(BufferedTransformation &bt) const
0038 {DEREncode(bt);}
0039 void Load(BufferedTransformation &bt)
0040 {BERDecode(bt);}
0041
0042 Integer ApplyFunction(const Integer &x) const;
0043 Integer PreimageBound() const {return ++(m_n>>1);}
0044 Integer ImageBound() const {return m_n;}
0045
0046 bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
0047 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
0048 void AssignFrom(const NameValuePairs &source);
0049
0050 const Integer& GetModulus() const {return m_n;}
0051 void SetModulus(const Integer &n) {m_n = n;}
0052
0053 protected:
0054 Integer m_n;
0055 };
0056
0057
0058
0059 class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey
0060 {
0061 typedef InvertibleRWFunction ThisClass;
0062
0063 public:
0064
0065 InvertibleRWFunction() : m_precompute(false) {}
0066
0067
0068
0069
0070
0071
0072
0073 void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u);
0074
0075
0076
0077
0078
0079
0080
0081 void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
0082 {GenerateRandomWithKeySize(rng, modulusBits);}
0083
0084 void BERDecode(BufferedTransformation &bt);
0085 void DEREncode(BufferedTransformation &bt) const;
0086
0087 void Save(BufferedTransformation &bt) const
0088 {DEREncode(bt);}
0089 void Load(BufferedTransformation &bt)
0090 {BERDecode(bt);}
0091
0092 Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
0093
0094
0095 bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
0096 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
0097 void AssignFrom(const NameValuePairs &source);
0098
0099 void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
0100
0101 const Integer& GetPrime1() const {return m_p;}
0102 const Integer& GetPrime2() const {return m_q;}
0103 const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
0104
0105 void SetPrime1(const Integer &p) {m_p = p;}
0106 void SetPrime2(const Integer &q) {m_q = q;}
0107 void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
0108
0109 virtual bool SupportsPrecomputation() const {return true;}
0110 virtual void Precompute(unsigned int unused = 0) {CRYPTOPP_UNUSED(unused); PrecomputeTweakedRoots();}
0111 virtual void Precompute(unsigned int unused = 0) const {CRYPTOPP_UNUSED(unused); PrecomputeTweakedRoots();}
0112
0113 virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation);
0114 virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const;
0115
0116 protected:
0117 void PrecomputeTweakedRoots() const;
0118
0119 protected:
0120 Integer m_p, m_q, m_u;
0121
0122 mutable Integer m_pre_2_9p, m_pre_2_3q, m_pre_q_p;
0123 mutable bool m_precompute;
0124 };
0125
0126
0127
0128 struct RW
0129 {
0130 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RW";}
0131 typedef RWFunction PublicKey;
0132 typedef InvertibleRWFunction PrivateKey;
0133 };
0134
0135
0136
0137
0138
0139 template <class STANDARD, class H>
0140 struct RWSS : public TF_SS<RW, STANDARD, H>
0141 {
0142 };
0143
0144 NAMESPACE_END
0145
0146 #endif