[*] Improve PKCS1 OAEP support
This commit is contained in:
parent
600c7b68dc
commit
0461b54045
@ -21,6 +21,12 @@ namespace Aurora::Crypto::RSA
|
|||||||
EPaddingType type,
|
EPaddingType type,
|
||||||
Memory::ByteBuffer &out) = 0;
|
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 AuSPtr<IRSAPublic> ToPublic() = 0;
|
||||||
|
|
||||||
virtual bool ToKey(const RSAMeta &meta, Memory::ByteBuffer &out) = 0;
|
virtual bool ToKey(const RSAMeta &meta, Memory::ByteBuffer &out) = 0;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace Aurora::Crypto::RSA
|
namespace Aurora::Crypto::RSA
|
||||||
{
|
{
|
||||||
// Rememeber: there is no such thing as public decryption
|
// Remember: there is no such thing as public decryption
|
||||||
struct IRSAPublic
|
struct IRSAPublic
|
||||||
{
|
{
|
||||||
virtual bool Verify(const Memory::MemoryViewRead &plainText,
|
virtual bool Verify(const Memory::MemoryViewRead &plainText,
|
||||||
@ -21,6 +21,12 @@ namespace Aurora::Crypto::RSA
|
|||||||
EPaddingType type,
|
EPaddingType type,
|
||||||
Memory::ByteBuffer &out) = 0;
|
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;
|
virtual bool ToKey(ERSAKeyType type, Memory::ByteBuffer &out) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -105,6 +105,14 @@ namespace Aurora::Crypto::RSA
|
|||||||
bool PrivateRSA::Decrypt(const AuMemoryViewRead &payload,
|
bool PrivateRSA::Decrypt(const AuMemoryViewRead &payload,
|
||||||
EPaddingType type,
|
EPaddingType type,
|
||||||
AuByteBuffer &out)
|
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())
|
if (!payload.HasMemory())
|
||||||
{
|
{
|
||||||
@ -119,6 +127,7 @@ namespace Aurora::Crypto::RSA
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bAnnoying = padding == LTC_PKCS_1_OAEP;
|
||||||
const int prng_idx = padding == LTC_PKCS_1_PSS ? ::Crypto::gPrngYarrow : 0;
|
const int prng_idx = padding == LTC_PKCS_1_PSS ? ::Crypto::gPrngYarrow : 0;
|
||||||
if (prng_idx < 0)
|
if (prng_idx < 0)
|
||||||
{
|
{
|
||||||
@ -140,7 +149,7 @@ namespace Aurora::Crypto::RSA
|
|||||||
payload.length,
|
payload.length,
|
||||||
out.writePtr, &len,
|
out.writePtr, &len,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
0, 0, // hash? excuse me?
|
bAnnoying ? ::Crypto::HashMethodToId(method) : 0, -1,
|
||||||
padding,
|
padding,
|
||||||
&stat,
|
&stat,
|
||||||
&this->key_);
|
&this->key_);
|
||||||
|
@ -23,6 +23,11 @@ namespace Aurora::Crypto::RSA
|
|||||||
EPaddingType type,
|
EPaddingType type,
|
||||||
Memory::ByteBuffer &out) override;
|
Memory::ByteBuffer &out) override;
|
||||||
|
|
||||||
|
bool DecryptEx(const Memory::MemoryViewRead &payload,
|
||||||
|
EPaddingType type,
|
||||||
|
Aurora::Hashing::EHashType method,
|
||||||
|
Memory::ByteBuffer &out) override;
|
||||||
|
|
||||||
AuSPtr<IRSAPublic> ToPublic() override;
|
AuSPtr<IRSAPublic> ToPublic() override;
|
||||||
|
|
||||||
bool ToKey(const RSAMeta &meta,
|
bool ToKey(const RSAMeta &meta,
|
||||||
|
@ -88,6 +88,14 @@ namespace Aurora::Crypto::RSA
|
|||||||
bool PublicRSA::Encrypt(const Memory::MemoryViewRead &plainText,
|
bool PublicRSA::Encrypt(const Memory::MemoryViewRead &plainText,
|
||||||
EPaddingType type,
|
EPaddingType type,
|
||||||
AuMemory::ByteBuffer &out)
|
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 {};
|
int iRet {};
|
||||||
prng_state yarrow_prng;
|
prng_state yarrow_prng;
|
||||||
@ -105,6 +113,7 @@ namespace Aurora::Crypto::RSA
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bAnnoying = padding == LTC_PKCS_1_OAEP;
|
||||||
const int prng_idx = padding == LTC_PKCS_1_PSS ? ::Crypto::gPrngYarrow : 0;
|
const int prng_idx = padding == LTC_PKCS_1_PSS ? ::Crypto::gPrngYarrow : 0;
|
||||||
if (prng_idx < 0)
|
if (prng_idx < 0)
|
||||||
{
|
{
|
||||||
@ -133,7 +142,7 @@ namespace Aurora::Crypto::RSA
|
|||||||
out.writePtr, &len,
|
out.writePtr, &len,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
&yarrow_prng, prng_idx,
|
&yarrow_prng, prng_idx,
|
||||||
0, 0,
|
bAnnoying ? ::Crypto::HashMethodToId(method) : 0, -1,
|
||||||
padding,
|
padding,
|
||||||
&this->key_);
|
&this->key_);
|
||||||
if (iRet != CRYPT_OK)
|
if (iRet != CRYPT_OK)
|
||||||
|
@ -24,6 +24,11 @@ namespace Aurora::Crypto::RSA
|
|||||||
EPaddingType type,
|
EPaddingType type,
|
||||||
Memory::ByteBuffer &out) override;
|
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;
|
bool ToKey(ERSAKeyType type, Memory::ByteBuffer &out) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user