ECDSADigestEngine.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // ECDSADigestEngine.h
  3. //
  4. //
  5. // Library: Crypto
  6. // Package: ECDSA
  7. // Module: ECDSADigestEngine
  8. //
  9. // Definition of the ECDSADigestEngine class.
  10. //
  11. // Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
  12. // and Contributors.
  13. //
  14. // SPDX-License-Identifier: BSL-1.0
  15. //
  16. #ifndef Crypto_ECDSADigestEngine_INCLUDED
  17. #define Crypto_ECDSADigestEngine_INCLUDED
  18. #include "Poco/Crypto/Crypto.h"
  19. #include "Poco/Crypto/ECKey.h"
  20. #include "Poco/DigestEngine.h"
  21. #include "Poco/Crypto/DigestEngine.h"
  22. #include <istream>
  23. #include <ostream>
  24. namespace Poco {
  25. namespace Crypto {
  26. class Crypto_API ECDSADigestEngine: public Poco::DigestEngine
  27. /// This class implements a Poco::DigestEngine that can be
  28. /// used to compute a secure digital signature.
  29. ///
  30. /// First another Poco::Crypto::DigestEngine is created and
  31. /// used to compute a cryptographic hash of the data to be
  32. /// signed. Then, the hash value is encrypted, using
  33. /// the ECDSA private key.
  34. ///
  35. /// To verify a signature, pass it to the verify()
  36. /// member function. It will decrypt the signature
  37. /// using the ECDSA public key and compare the resulting
  38. /// hash with the actual hash of the data.
  39. {
  40. public:
  41. ECDSADigestEngine(const ECKey& key, const std::string &name);
  42. /// Creates the ECDSADigestEngine with the given ECDSA key,
  43. /// using the hash algorithm with the given name
  44. /// (e.g., "SHA1", "SHA256", "SHA512", etc.).
  45. /// See the OpenSSL documentation for a list of supported digest algorithms.
  46. ///
  47. /// Throws a Poco::NotFoundException if no algorithm with the given name exists.
  48. ~ECDSADigestEngine();
  49. /// Destroys the ECDSADigestEngine.
  50. std::size_t digestLength() const;
  51. /// Returns the length of the digest in bytes.
  52. void reset();
  53. /// Resets the engine so that a new
  54. /// digest can be computed.
  55. const DigestEngine::Digest& digest();
  56. /// Finishes the computation of the digest
  57. /// (the first time it's called) and
  58. /// returns the message digest.
  59. ///
  60. /// Can be called multiple times.
  61. const DigestEngine::Digest& signature();
  62. /// Signs the digest using the ECDSADSA algorithm
  63. /// and the private key (the first time it's
  64. /// called) and returns the result.
  65. ///
  66. /// Can be called multiple times.
  67. bool verify(const DigestEngine::Digest& signature);
  68. /// Verifies the data against the signature.
  69. ///
  70. /// Returns true if the signature can be verified, false otherwise.
  71. protected:
  72. void updateImpl(const void* data, std::size_t length);
  73. private:
  74. ECKey _key;
  75. Poco::Crypto::DigestEngine _engine;
  76. Poco::DigestEngine::Digest _digest;
  77. Poco::DigestEngine::Digest _signature;
  78. };
  79. } } // namespace Poco::Crypto
  80. #endif // Crypto_ECDSADigestEngine_INCLUDED