[*] Improve PKCS1 OAEP support
This commit is contained in:
parent
600c7b68dc
commit
0461b54045
@ -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<IRSAPublic> ToPublic() = 0;
|
||||
|
||||
virtual bool ToKey(const RSAMeta &meta, Memory::ByteBuffer &out) = 0;
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
@ -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_);
|
||||
|
@ -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<IRSAPublic> ToPublic() override;
|
||||
|
||||
bool ToKey(const RSAMeta &meta,
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user