Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.5 KiB

  1. #ifndef CRYPTOPP_RW_H
  2. #define CRYPTOPP_RW_H
  3. /** \file
  4. This file contains classes that implement the
  5. Rabin-Williams signature schemes as defined in IEEE P1363.
  6. */
  7. #include "pubkey.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! _
  10. class CRYPTOPP_DLL RWFunction : public TrapdoorFunction, public PublicKey
  11. {
  12. typedef RWFunction ThisClass;
  13. public:
  14. void Initialize(const Integer &n)
  15. {m_n = n;}
  16. void BERDecode(BufferedTransformation &bt);
  17. void DEREncode(BufferedTransformation &bt) const;
  18. Integer ApplyFunction(const Integer &x) const;
  19. Integer PreimageBound() const {return ++(m_n>>1);}
  20. Integer ImageBound() const {return m_n;}
  21. bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
  22. bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
  23. void AssignFrom(const NameValuePairs &source);
  24. const Integer& GetModulus() const {return m_n;}
  25. void SetModulus(const Integer &n) {m_n = n;}
  26. protected:
  27. Integer m_n;
  28. };
  29. //! _
  30. class CRYPTOPP_DLL InvertibleRWFunction : public RWFunction, public TrapdoorFunctionInverse, public PrivateKey
  31. {
  32. typedef InvertibleRWFunction ThisClass;
  33. public:
  34. void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u)
  35. {m_n = n; m_p = p; m_q = q; m_u = u;}
  36. // generate a random private key
  37. void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
  38. {GenerateRandomWithKeySize(rng, modulusBits);}
  39. void BERDecode(BufferedTransformation &bt);
  40. void DEREncode(BufferedTransformation &bt) const;
  41. Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
  42. // GeneratibleCryptoMaterial
  43. bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
  44. bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
  45. void AssignFrom(const NameValuePairs &source);
  46. /*! parameters: (ModulusSize) */
  47. void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
  48. const Integer& GetPrime1() const {return m_p;}
  49. const Integer& GetPrime2() const {return m_q;}
  50. const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
  51. void SetPrime1(const Integer &p) {m_p = p;}
  52. void SetPrime2(const Integer &q) {m_q = q;}
  53. void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
  54. protected:
  55. Integer m_p, m_q, m_u;
  56. };
  57. //! RW
  58. struct RW
  59. {
  60. static std::string StaticAlgorithmName() {return "RW";}
  61. typedef RWFunction PublicKey;
  62. typedef InvertibleRWFunction PrivateKey;
  63. };
  64. //! RWSS
  65. template <class STANDARD, class H>
  66. struct RWSS : public TF_SS<STANDARD, H, RW>
  67. {
  68. };
  69. NAMESPACE_END
  70. #endif