xtrcrypt.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef CRYPTOPP_XTRCRYPT_H
  2. #define CRYPTOPP_XTRCRYPT_H
  3. /// \file
  4. /// \brief XTR public key system
  5. /// \sa "The XTR public key system" by Arjen K. Lenstra and Eric R. Verheul
  6. #include "cryptlib.h"
  7. #include "xtr.h"
  8. #include "integer.h"
  9. NAMESPACE_BEGIN(CryptoPP)
  10. /// \brief XTR-DH with key validation
  11. class XTR_DH : public SimpleKeyAgreementDomain, public CryptoParameters
  12. {
  13. typedef XTR_DH ThisClass;
  14. public:
  15. XTR_DH(const Integer &p, const Integer &q, const GFP2Element &g);
  16. XTR_DH(RandomNumberGenerator &rng, unsigned int pbits, unsigned int qbits);
  17. XTR_DH(BufferedTransformation &domainParams);
  18. void DEREncode(BufferedTransformation &domainParams) const;
  19. bool Validate(RandomNumberGenerator &rng, unsigned int level) const;
  20. bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
  21. void AssignFrom(const NameValuePairs &source);
  22. CryptoParameters & AccessCryptoParameters() {return *this;}
  23. unsigned int AgreedValueLength() const {return 2*m_p.ByteCount();}
  24. unsigned int PrivateKeyLength() const {return m_q.ByteCount();}
  25. unsigned int PublicKeyLength() const {return 2*m_p.ByteCount();}
  26. void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const;
  27. void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const;
  28. bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const;
  29. const Integer &GetModulus() const {return m_p;}
  30. const Integer &GetSubgroupOrder() const {return m_q;}
  31. const GFP2Element &GetSubgroupGenerator() const {return m_g;}
  32. void SetModulus(const Integer &p) {m_p = p;}
  33. void SetSubgroupOrder(const Integer &q) {m_q = q;}
  34. void SetSubgroupGenerator(const GFP2Element &g) {m_g = g;}
  35. private:
  36. unsigned int ExponentBitLength() const;
  37. Integer m_p, m_q;
  38. GFP2Element m_g;
  39. };
  40. NAMESPACE_END
  41. #endif