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.

107 lines
3.1 KiB

  1. #ifndef CRYPTOPP_RABIN_H
  2. #define CRYPTOPP_RABIN_H
  3. /** \file
  4. */
  5. #include "oaep.h"
  6. #include "pssr.h"
  7. #include "integer.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! _
  10. class RabinFunction : public TrapdoorFunction, public PublicKey
  11. {
  12. typedef RabinFunction ThisClass;
  13. public:
  14. void Initialize(const Integer &n, const Integer &r, const Integer &s)
  15. {m_n = n; m_r = r; m_s = s;}
  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;}
  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. const Integer& GetQuadraticResidueModPrime1() const {return m_r;}
  26. const Integer& GetQuadraticResidueModPrime2() const {return m_s;}
  27. void SetModulus(const Integer &n) {m_n = n;}
  28. void SetQuadraticResidueModPrime1(const Integer &r) {m_r = r;}
  29. void SetQuadraticResidueModPrime2(const Integer &s) {m_s = s;}
  30. protected:
  31. Integer m_n, m_r, m_s;
  32. };
  33. //! _
  34. class InvertibleRabinFunction : public RabinFunction, public TrapdoorFunctionInverse, public PrivateKey
  35. {
  36. typedef InvertibleRabinFunction ThisClass;
  37. public:
  38. void Initialize(const Integer &n, const Integer &r, const Integer &s,
  39. const Integer &p, const Integer &q, const Integer &u)
  40. {m_n = n; m_r = r; m_s = s; m_p = p; m_q = q; m_u = u;}
  41. void Initialize(RandomNumberGenerator &rng, unsigned int keybits)
  42. {GenerateRandomWithKeySize(rng, keybits);}
  43. void BERDecode(BufferedTransformation &bt);
  44. void DEREncode(BufferedTransformation &bt) const;
  45. Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const;
  46. bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
  47. bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
  48. void AssignFrom(const NameValuePairs &source);
  49. /*! parameters: (ModulusSize) */
  50. void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg);
  51. const Integer& GetPrime1() const {return m_p;}
  52. const Integer& GetPrime2() const {return m_q;}
  53. const Integer& GetMultiplicativeInverseOfPrime2ModPrime1() const {return m_u;}
  54. void SetPrime1(const Integer &p) {m_p = p;}
  55. void SetPrime2(const Integer &q) {m_q = q;}
  56. void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;}
  57. protected:
  58. Integer m_p, m_q, m_u;
  59. };
  60. //! Rabin
  61. struct Rabin
  62. {
  63. static std::string StaticAlgorithmName() {return "Rabin-Crypto++Variant";}
  64. typedef RabinFunction PublicKey;
  65. typedef InvertibleRabinFunction PrivateKey;
  66. };
  67. //! Rabin encryption
  68. template <class STANDARD>
  69. struct RabinES : public TF_ES<STANDARD, Rabin>
  70. {
  71. };
  72. //! Rabin signature
  73. template <class STANDARD, class H>
  74. struct RabinSS : public TF_SS<STANDARD, H, Rabin>
  75. {
  76. };
  77. // More typedefs for backwards compatibility
  78. class SHA1;
  79. typedef RabinES<OAEP<SHA1> >::Decryptor RabinDecryptor;
  80. typedef RabinES<OAEP<SHA1> >::Encryptor RabinEncryptor;
  81. NAMESPACE_END
  82. #endif