diff --git a/Include/Aurora/Crypto/RSA/IRSAPrivate.hpp b/Include/Aurora/Crypto/RSA/IRSAPrivate.hpp index 3dc30549..2f532c23 100644 --- a/Include/Aurora/Crypto/RSA/IRSAPrivate.hpp +++ b/Include/Aurora/Crypto/RSA/IRSAPrivate.hpp @@ -17,10 +17,16 @@ namespace Aurora::Crypto::RSA EPaddingType type, Memory::ByteBuffer &out) = 0; - virtual bool Decrypt(const Memory::MemoryViewRead &payload, - EPaddingType type, + virtual bool Decrypt(const Memory::MemoryViewRead &payload, + EPaddingType type, Memory::ByteBuffer &out) = 0; + // PKCS1 OAEP + virtual bool DecryptEx(const Memory::MemoryViewRead &payload, + EPaddingType type, + Aurora::Hashing::EHashType method, + Memory::ByteBuffer &out) = 0; + virtual AuSPtr ToPublic() = 0; virtual bool ToKey(const RSAMeta &meta, Memory::ByteBuffer &out) = 0; diff --git a/Include/Aurora/Crypto/RSA/IRSAPublic.hpp b/Include/Aurora/Crypto/RSA/IRSAPublic.hpp index 2e99c946..9d74f790 100644 --- a/Include/Aurora/Crypto/RSA/IRSAPublic.hpp +++ b/Include/Aurora/Crypto/RSA/IRSAPublic.hpp @@ -9,7 +9,7 @@ namespace Aurora::Crypto::RSA { - // Rememeber: there is no such thing as public decryption + // Remember: there is no such thing as public decryption struct IRSAPublic { virtual bool Verify(const Memory::MemoryViewRead &plainText, @@ -18,9 +18,15 @@ namespace Aurora::Crypto::RSA EPaddingType type) = 0; virtual bool Encrypt(const Memory::MemoryViewRead &plainText, - EPaddingType type, + EPaddingType type, Memory::ByteBuffer &out) = 0; + // PKCS1 OAEP + virtual bool EncryptEx(const Memory::MemoryViewRead &plainText, + EPaddingType type, + Aurora::Hashing::EHashType method, + Memory::ByteBuffer &out) = 0; + virtual bool ToKey(ERSAKeyType type, Memory::ByteBuffer &out) = 0; }; } \ No newline at end of file diff --git a/Source/Crypto/RSA/RSAPrivate.cpp b/Source/Crypto/RSA/RSAPrivate.cpp index 853ea151..7eb1b134 100644 --- a/Source/Crypto/RSA/RSAPrivate.cpp +++ b/Source/Crypto/RSA/RSAPrivate.cpp @@ -103,8 +103,16 @@ namespace Aurora::Crypto::RSA } bool PrivateRSA::Decrypt(const AuMemoryViewRead &payload, - EPaddingType type, + EPaddingType type, AuByteBuffer &out) + { + return DecryptEx(payload, type, AuHashing::kEHashTypeInvalid, out); + } + + bool PrivateRSA::DecryptEx(const Memory::MemoryViewRead &payload, + EPaddingType type, + Aurora::Hashing::EHashType method, + Memory::ByteBuffer &out) { if (!payload.HasMemory()) { @@ -119,6 +127,7 @@ namespace Aurora::Crypto::RSA return false; } + bool bAnnoying = padding == LTC_PKCS_1_OAEP; const int prng_idx = padding == LTC_PKCS_1_PSS ? ::Crypto::gPrngYarrow : 0; if (prng_idx < 0) { @@ -140,7 +149,7 @@ namespace Aurora::Crypto::RSA payload.length, out.writePtr, &len, NULL, 0, - 0, 0, // hash? excuse me? + bAnnoying ? ::Crypto::HashMethodToId(method) : 0, -1, padding, &stat, &this->key_); diff --git a/Source/Crypto/RSA/RSAPrivate.hpp b/Source/Crypto/RSA/RSAPrivate.hpp index 3de72d3b..bb4e60f0 100644 --- a/Source/Crypto/RSA/RSAPrivate.hpp +++ b/Source/Crypto/RSA/RSAPrivate.hpp @@ -23,6 +23,11 @@ namespace Aurora::Crypto::RSA EPaddingType type, Memory::ByteBuffer &out) override; + bool DecryptEx(const Memory::MemoryViewRead &payload, + EPaddingType type, + Aurora::Hashing::EHashType method, + Memory::ByteBuffer &out) override; + AuSPtr ToPublic() override; bool ToKey(const RSAMeta &meta, diff --git a/Source/Crypto/RSA/RSAPublic.cpp b/Source/Crypto/RSA/RSAPublic.cpp index d858ae27..d0c1e484 100644 --- a/Source/Crypto/RSA/RSAPublic.cpp +++ b/Source/Crypto/RSA/RSAPublic.cpp @@ -86,8 +86,16 @@ namespace Aurora::Crypto::RSA } bool PublicRSA::Encrypt(const Memory::MemoryViewRead &plainText, - EPaddingType type, + EPaddingType type, AuMemory::ByteBuffer &out) + { + return EncryptEx(plainText, type, AuHashing::kEHashTypeInvalid, out); + } + + bool PublicRSA::EncryptEx(const Memory::MemoryViewRead &plainText, + EPaddingType type, + Aurora::Hashing::EHashType method, + Memory::ByteBuffer &out) { int iRet {}; prng_state yarrow_prng; @@ -105,6 +113,7 @@ namespace Aurora::Crypto::RSA return false; } + bool bAnnoying = padding == LTC_PKCS_1_OAEP; const int prng_idx = padding == LTC_PKCS_1_PSS ? ::Crypto::gPrngYarrow : 0; if (prng_idx < 0) { @@ -133,7 +142,7 @@ namespace Aurora::Crypto::RSA out.writePtr, &len, NULL, 0, &yarrow_prng, prng_idx, - 0, 0, + bAnnoying ? ::Crypto::HashMethodToId(method) : 0, -1, padding, &this->key_); if (iRet != CRYPT_OK) diff --git a/Source/Crypto/RSA/RSAPublic.hpp b/Source/Crypto/RSA/RSAPublic.hpp index b02e8bf4..4fe9ab50 100644 --- a/Source/Crypto/RSA/RSAPublic.hpp +++ b/Source/Crypto/RSA/RSAPublic.hpp @@ -24,6 +24,11 @@ namespace Aurora::Crypto::RSA EPaddingType type, Memory::ByteBuffer &out) override; + bool EncryptEx(const Memory::MemoryViewRead &plainText, + EPaddingType type, + Aurora::Hashing::EHashType method, + Memory::ByteBuffer &out) override; + bool ToKey(ERSAKeyType type, Memory::ByteBuffer &out) override; private: