diff options
Diffstat (limited to 'src/common/Cryptography/RSA.h')
-rw-r--r-- | src/common/Cryptography/RSA.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/common/Cryptography/RSA.h b/src/common/Cryptography/RSA.h index 42849c03e4d..c0066ccbcfa 100644 --- a/src/common/Cryptography/RSA.h +++ b/src/common/Cryptography/RSA.h @@ -16,10 +16,13 @@ */ #include "Define.h" +#include <openssl/objects.h> #include <openssl/rsa.h> #include <string> #include <type_traits> +class BigNumber; + namespace Trinity { namespace Crypto @@ -27,11 +30,13 @@ namespace Crypto class TC_COMMON_API RSA { public: + struct PublicKey {}; + struct PrivateKey {}; + struct NoPadding : std::integral_constant<int32, RSA_NO_PADDING> {}; struct PKCS1Padding : std::integral_constant<int32, RSA_PKCS1_PADDING> {}; - struct PrivateKey {}; - struct PublicKey {}; + struct SHA256 : std::integral_constant<int32, NID_sha256> {}; RSA(); RSA(RSA&& rsa); @@ -44,6 +49,7 @@ public: bool LoadFromString(std::string const& keyPem, KeyTag); uint32 GetOutputSize() const { return uint32(RSA_size(_rsa)); } + BigNumber GetModulus() const; template <typename KeyTag, typename PaddingTag> bool Encrypt(uint8 const* data, std::size_t dataLength, uint8* output, KeyTag, PaddingTag) @@ -51,10 +57,18 @@ public: return Encrypt<KeyTag>(data, dataLength, output, PaddingTag::value); } + template <typename HashTag> + bool Sign(uint8 const* dataHash, std::size_t dataHashLength, uint8* output, HashTag) + { + return Sign(HashTag::value, dataHash, dataHashLength, output); + } + private: template <typename KeyTag> bool Encrypt(uint8 const* data, std::size_t dataLength, uint8* output, int32 paddingType); + bool Sign(int32 hashType, uint8 const* dataHash, std::size_t dataHashLength, uint8* output); + RSA(RSA const& rsa) = delete; RSA& operator=(RSA const& rsa) = delete; |