Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cKeyRSA Class Reference

#include <cKeyRSA.h>

Inheritance diagram for GrayLib::cKeyRSA:
GrayLib::cKeyBase GrayLib::cKeyRSA1 Gray::cRefBase Gray::CObject IUnknown

Public Member Functions

 cKeyRSA (PKCS1_VER_TYPE ePadding=PKCS1_VER_15, SSL_Hash_TYPE eHashType=SSL_Hash_NONE)
 
virtual ~cKeyRSA ()
 
bool IsValidPrivateKey () const
 
virtual size_t get_KeySize () const override
 Get key size in bytes. More...
 
virtual int GetKeyValues (cValue *items) const override
 Interface with the debug module. get debug values. More...
 
virtual void SetZeroKey () override
 Secure zero the key. More...
 
void SetCopyKey (const cKeyRSA &src)
 
HRESULT DoRSAPublic (BYTE *pOutput, const BYTE *pInput) const
 
HRESULT DoRSAPrivate (BYTE *pOutput, const BYTE *pInput, IRandomNoise *pRandom) const
 
HRESULT VerifySignatureV15 (SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t nSizeHash, const BYTE *pSig) const
 
HRESULT VerifySignatureV21 (SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t nSizeHash, const BYTE *pSig, SSL_Hash_TYPE mgf1_hash_id, int expected_salt_len) const
 
virtual HRESULT CheckPublicPrivatePair (const cKeyBase *pKeyPrivate) const override
 Check public-private key pair. More...
 
virtual HRESULT VerifySignature (SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t nSizeHash, const BYTE *pSig, size_t nSizeSig) const override
 Verify Key signature. Make const ?? More...
 
virtual HRESULT MakeSignature (BYTE *pSig, SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t nSizeHash, IRandomNoise *pRandom) const override
 Make signature From Key. Make const ?? More...
 
HRESULT DecryptWithKey (BYTE *pOutput, size_t nSizeOut, const BYTE *pInput, size_t nSizeIn, IRandomNoise *pRandom)
 
HRESULT EncryptWithKey (BYTE *pOutput, size_t nSizeOut, const BYTE *pInput, size_t nSizeIn, IRandomNoise *pRandom)
 
bool UpdateReadPrivate ()
 
virtual HRESULT ReadPublicKey (cASNReader &r, cASNBuf *pAlgParams) override
 
virtual HRESULT WritePublicKey (cASNWriterRev &w) const override
 
HRESULT ReadPrivateKeyPVK (const BYTE *pKeyData, int nSize)
 
virtual HRESULT ReadPrivateKey (cASNReader &r, cASNBuf *pAlgParams) override
 Read not encrypted. (already decrypted) More...
 
virtual HRESULT WritePrivateKey (cASNWriterRev &w) const override
 Write not encrypted. (may be encrypted/secured later) More...
 
HRESULT GenerateKeys (BIT_ENUM_t nBits, UINT nExpoMax, IRandomNoise *pRandom)
 
 UNITTEST_FRIEND (cKeyRSA)
 
- Public Member Functions inherited from GrayLib::cKeyBase
virtual ~cKeyBase ()
 
- Public Member Functions inherited from Gray::cRefBase
 cRefBase (int iRefCount=0) noexcept
 
virtual ~cRefBase ()
 
int get_RefCount () const noexcept
 
HASHCODE_t get_HashCode () const noexcept
 
 STDMETHOD_ (HASHCODE_t, get_HashCodeX)() const noexcept
 
virtual void onFinalRelease ()
 
bool isValidObj () const noexcept
 
 STDMETHOD_ (ULONG, AddRef)(void) override
 
 STDMETHOD_ (ULONG, Release)(void) override
 
STDMETHOD() QueryInterface (const IID &riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
 
void IncRefCount ()
 
void DecRefCount ()
 
bool isStaticConstruct () const noexcept
 
void StaticConstruct ()
 
void StaticDestruct ()
 
bool isDestructing () noexcept
 
void SetDestructing ()
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 
- Public Member Functions inherited from GrayLib::cKeyRSA1
 cKeyRSA1 (void)
 
 cKeyRSA1 (const VAL_t &_exp, const VAL_t &_mod)
 
virtual ~cKeyRSA1 (void)
 
bool IsValidKey () const
 
void SetZeroKey ()
 
void SetCopyKey (const cKeyRSA1 &src)
 
void GenerateKeys (OUT VAL_t &d, const VAL_t &p, const VAL_t &q)
 
void GenerateKeys (BIT_ENUM_t nBits, OUT VAL_t &d, OUT VAL_t *pP=nullptr, OUT VAL_t *pQ=nullptr)
 
VAL_t EncryptDecrypt (const VAL_t &source) const
 
HRESULT WritePublicKey (cASNWriterRev &w) const
 
HRESULT ReadPublicKey (cASNReader &r)
 
HRESULT LoadKeyFile (cStreamInput &rInp, const char *pszName=nullptr)
 
HRESULT LoadKeyFile (const FILECHAR_t *pszFileName, const char *pszName=nullptr)
 
 UNITTEST_FRIEND (cKeyRSA1)
 

Public Attributes

size_t m_nSizeBlock
 sizeof(N) in bytes. Block size for DecryptWithKey More...
 
PKCS1_VER_TYPE m_ePadding
 PKCS1_VER_15 for 1.5 padding and PKCS1_VER_21 for OAEP/PSS. More...
 
SSL_Hash_TYPE m_eHashType
 Hash identifier for the EME-OAEP and EMSA-PSS encoding. MGF1. More...
 
VAL_t m_D
 private exponent More...
 
VAL_t m_P
 1st prime factor (private) (r) More...
 
VAL_t m_Q
 2nd prime factor (private) More...
 
VAL_t m_DP
 D % (P - 1) const derived value. More...
 
VAL_t m_DQ
 D % (Q - 1) const derived value. More...
 
VAL_t m_QP
 1 / (Q % P) const derived value. More...
 
cThreadLockMutex m_Mutex
 Thread-safety mutex for mutable cached stuff. More...
 
VAL_t m_RN
 cached R^2 mod N (for public) More...
 
VAL_t m_RP
 cached R^2 mod P for DoRSAPrivate More...
 
VAL_t m_RQ
 cached R^2 mod Q for DoRSAPrivate More...
 
VAL_t m_BlindAdd
 cached blinding value for DoRSAPrivate More...
 
VAL_t m_BlindRemove
 cached un-blinding value for DoRSAPrivate More...
 
- Public Attributes inherited from GrayLib::cKeyRSA1
VAL_t m_N
 modulus of the key (usually public) = multiplication of the 2 primes (pq). More...
 
VAL_t m_E
 exponent of the key (public or private half of the key depending on use.) More...
 

Static Public Attributes

static const int k_nSizeSaltAny = -1
 
- Static Public Attributes inherited from GrayLib::cKeyBase
static const int k_MAX_VALUES = 2
 Maximum number of cValue sent for debugging. More...
 

Protected Member Functions

HRESULT CreateBlindingValues (IRandomNoise *pRandom) const
 
HRESULT EncryptWithKeyV15 (BYTE *pOutput, const BYTE *pInput, size_t nSizeIn, IRandomNoise *pRandom)
 
HRESULT EncryptWithKeyV21 (BYTE *pOutput, const BYTE *pInput, size_t nSizeIn, IRandomNoise *pRandom, const BYTE *pLabel=nullptr, size_t nSizeLabel=0)
 
HRESULT DecryptWithKeyV15 (BYTE *pOutput, size_t output_max_len, const BYTE *pInput, IRandomNoise *pRandom)
 
HRESULT DecryptWithKeyV21 (BYTE *pOutput, size_t output_max_len, const BYTE *pInput, IRandomNoise *pRandom, const BYTE *pLabel=nullptr, size_t nSizeLabel=0)
 
HRESULT MakeSignatureV15 (BYTE *pSig, SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t nSizeHash, IRandomNoise *pRandom) const
 
HRESULT MakeSignatureV21 (BYTE *pSig, SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t nSizeHash, IRandomNoise *pRandom) const
 

Additional Inherited Members

- Public Types inherited from GrayLib::cKeyBase
enum  VALTYPE_TYPE { VALTYPE_NONE = 0 , VALTYPE_RSA = 1 , VALTYPE_ECP = 2 }
 
- Public Types inherited from GrayLib::cKeyRSA1
typedef cBigUnsigned VAL_t
 

Detailed Description

RSA public/private key structure. SSL_Key_RSA

Constructor & Destructor Documentation

◆ cKeyRSA()

GrayLib::cKeyRSA::cKeyRSA ( PKCS1_VER_TYPE  ePadding = PKCS1_VER_15,
SSL_Hash_TYPE  eHashType = SSL_Hash_NONE 
)

Initialize an RSA context

Note
Set PKCS1_VER_21 padding for the RSAES-OAEP encryption scheme and the RSASSA-PSS signature scheme.
  • ePadding = PKCS1_VER_15 or PKCS1_VER_21
  • eHashType = PKCS1_VER_21 hash identifier (ignored when using PKCS1_VER_15 padding).
Choice of padding mode is strictly enforced for private key operations, since there might be security concerns in mixing padding modes. For public key operations it's merely a default value, which can be overridden by calling specific rsa_rsaes_xxx or rsa_rsassa_xxx functions.
The chosen hash is always used for OEAP encryption. For PSS signatures, it's always used for making signatures, but can be overridden (and always is, if set to SSL_Hash_NONE) for verifying them.

◆ ~cKeyRSA()

GrayLib::cKeyRSA::~cKeyRSA ( )
virtual

Member Function Documentation

◆ CheckPublicPrivatePair()

HRESULT GrayLib::cKeyRSA::CheckPublicPrivatePair ( const cKeyBase pKeyPrivate) const
overridevirtual

Check public-private key pair.

Check if contexts holding a public and private key match Check a public-private RSA key pair. Check each of the keys, and make sure they match. this is RSA context holding the public key

  • pKeyPrivate = RSA context holding the private key
    Returns
    0 = successful, or < 0 error code

Implements GrayLib::cKeyBase.

◆ CreateBlindingValues()

HRESULT GrayLib::cKeyRSA::CreateBlindingValues ( IRandomNoise pRandom) const
protected

Generate or update blinding values, see section 10 of: KOCHER, Paul C. Timing attacks on implementations of Diffie-Hellman, RSA, DSS, and other systems. In : Advances in Cryptology—CRYPTO’96. Springer Berlin Heidelberg, 1996. p. 104-113.

◆ DecryptWithKey()

HRESULT GrayLib::cKeyRSA::DecryptWithKey ( BYTE *  pOutput,
size_t  nSizeOut,
const BYTE *  pInput,
size_t  nSizeIn,
IRandomNoise pRandom 
)

Generic wrapper to perform a PKCS#1 decryption using the mode from the context. Do an RSA operation, then remove the message padding

Note
The pOutput buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used) otherwise an error is thrown.

◆ DecryptWithKeyV15()

HRESULT GrayLib::cKeyRSA::DecryptWithKeyV15 ( BYTE *  pOutput,
size_t  output_max_len,
const BYTE *  pInput,
IRandomNoise pRandom 
)
protected

Perform a PKCS#1 v1.5 decryption (RSAES-PKCS1-v1_5-DECRYPT) Use private key to decrypt.

  • pOutput = buffer that will hold the plaintext
  • output_max_len = maximum length of the pOutput buffer
  • pInput = buffer holding the encrypted data
  • pRandom = RNG function (Only needed for RSA_PRIVATE)
    Returns
    0 if successful, or <0 = error code
    Note
    The pOutput buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used) otherwise an error is thrown.

◆ DecryptWithKeyV21()

HRESULT GrayLib::cKeyRSA::DecryptWithKeyV21 ( BYTE *  pOutput,
size_t  output_max_len,
const BYTE *  pInput,
IRandomNoise pRandom,
const BYTE *  pLabel = nullptr,
size_t  nSizeLabel = 0 
)
protected

Perform a PKCS#1 v2.1 OAEP decryption (RSAES-OAEP-DECRYPT)

  • pOutput = buffer that will hold the plaintext
  • output_max_len = maximum length of the pOutput buffer
  • pInput = buffer holding the encrypted data
  • pLabel = buffer holding the custom label to use
  • nSizeLabel = contains the label length
  • pRandom = RNG function (Only needed for RSA_PRIVATE)
    Returns
    0 if successful, or <0 = error code
    Note
    The pOutput buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used) otherwise an error is thrown.

◆ DoRSAPrivate()

HRESULT GrayLib::cKeyRSA::DoRSAPrivate ( BYTE *  pOutput,
const BYTE *  pInput,
IRandomNoise pRandom 
) const

Do an RSA private key operation When using the Chinese Remainder Theorem, we use blinding values.

  • pOutput = pOutput buffer
  • pInput = input buffer
  • pRandom = RNG function (Needed for blinding)
    Returns
    0 if successful, or <0 = error code
    Note
    The pInput and pOutput buffers must be large enough (eg. 128 bytes if RSA-1024 is used).

◆ DoRSAPublic()

HRESULT GrayLib::cKeyRSA::DoRSAPublic ( BYTE *  pOutput,
const BYTE *  pInput 
) const

Do an RSA public key operation

  • pInput = input buffer
  • pOutput = pOutput buffer
    Returns
    0 if successful, <0 = error code
    Note
    This function does NOT take care of message padding. Also, be sure to set pInput[0] = 0 or assure that input is smaller than N.
    The pInput and pOutput buffers must be large enough (eg. 128 bytes if RSA-1024 is used).

◆ EncryptWithKey()

HRESULT GrayLib::cKeyRSA::EncryptWithKey ( BYTE *  pOutput,
size_t  nSizeOut,
const BYTE *  pInput,
size_t  nSizeIn,
IRandomNoise pRandom 
)

Perform a PKCS#1 encryption

Note
The pOutput buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).

◆ EncryptWithKeyV15()

HRESULT GrayLib::cKeyRSA::EncryptWithKeyV15 ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSizeIn,
IRandomNoise pRandom 
)
protected

Perform a PKCS#1 v1.5 encryption (RSAES-PKCS1-v1_5-ENCRYPT) Use public key to encrypt.

  • pOutput = buffer that will hold the ciphertext
  • pInput = buffer holding the data to be encrypted
  • nSizeIn = contains the plaintext length
  • pRandom = RNG function (Needed for padding and RSA_PRIVATE)
    Returns
    0 if successful, or <0 = error code
    Note
    The pOutput buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).

◆ EncryptWithKeyV21()

HRESULT GrayLib::cKeyRSA::EncryptWithKeyV21 ( BYTE *  pOutput,
const BYTE *  pInput,
size_t  nSizeIn,
IRandomNoise pRandom,
const BYTE *  pLabel = nullptr,
size_t  nSizeLabel = 0 
)
protected

Perform a PKCS#1 v2.1 OAEP encryption (RSAES-OAEP-ENCRYPT) Use public key to encrypt.

  • pOutput = buffer that will hold the ciphertext
  • pInput = buffer holding the data to be encrypted
  • nSizeIn = contains the plaintext length
  • pLabel = buffer holding the custom label to use
  • nSizeLabel = contains the label length
  • pRandom = RNG function (Needed for padding and PKCS#1 v2.1 encoding and RSA_PRIVATE)
    Returns
    0 if successful, or <0 = error code
    Note
    The output buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).

◆ GenerateKeys()

HRESULT GrayLib::cKeyRSA::GenerateKeys ( BIT_ENUM_t  nBits,
UINT  nExpoMax,
IRandomNoise pRandom 
)

Generate an RSA key pair. TODO Merge with cKeyRSA1 and cThreadState

  • nBits = size of the public key in bits
  • nExpoMax = public exponent max (e.g., 65537)
  • pRandom = RNG function
    Returns
    0 if successful, or <0 = error code

◆ get_KeySize()

virtual size_t GrayLib::cKeyRSA::get_KeySize ( ) const
inlineoverridevirtual

Get key size in bytes.

Get size of E. (in bytes)

Implements GrayLib::cKeyBase.

◆ GetKeyValues()

virtual int GrayLib::cKeyRSA::GetKeyValues ( cValue items) const
inlineoverridevirtual

Interface with the debug module. get debug values.

Debug info.

Implements GrayLib::cKeyBase.

◆ IsValidPrivateKey()

bool GrayLib::cKeyRSA::IsValidPrivateKey ( ) const

Check a private RSA key

◆ MakeSignature()

HRESULT GrayLib::cKeyRSA::MakeSignature ( BYTE *  pSig,
SSL_Hash_TYPE  eHashType,
const BYTE *  pHash,
size_t  hash_len,
IRandomNoise pRandom 
) const
overridevirtual

Make signature From Key. Make const ??

Generic wrapper to perform a PKCS#1 signature using the mode from the context. Do a private RSA operation to sign a message digest

  • pSig = buffer that will hold the ciphertext
  • eHashType = a HashType_* (use SSL_Hash_NONE for signing raw data)
  • pHash = buffer holding the message digest
  • nSizeHash = message digest length (for SSL_Hash_NONE only)
  • pRandom = RNG parameter (Needed for PKCS#1 v2.1 encoding and for RSA_PRIVATE)
    Returns
    0 if the signing operation was successful, or <0 = error code
    Note
    The "pSig" buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).
    In case of PKCS#1 v2.1 encoding, see comments on MakeSignatureV21() for details on eHashType.

Implements GrayLib::cKeyBase.

◆ MakeSignatureV15()

HRESULT GrayLib::cKeyRSA::MakeSignatureV15 ( BYTE *  pSig,
SSL_Hash_TYPE  eHashType,
const BYTE *  pHash,
size_t  nSizeHash,
IRandomNoise pRandom 
) const
protected

Perform a PKCS#1 v1.5 signature (RSASSA-PKCS1-v1_5-SIGN) PKCS1_VER_15 Do an RSA operation to sign the message digest Use private key to sign.

  • pSig = buffer that will hold the ciphertext
  • eHashType = a HashType_* (use SSL_Hash_NONE for signing raw data)
  • pHash = buffer holding the message digest
  • nSizeHash = message digest length (for SSL_Hash_NONE only)
  • pRandom = RNG function (Only needed for RSA_PRIVATE)
    Returns
    0 if the signing operation was successful, or <0 = error code
    Note
    The "pSig" buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).

◆ MakeSignatureV21()

HRESULT GrayLib::cKeyRSA::MakeSignatureV21 ( BYTE *  pSig,
SSL_Hash_TYPE  eHashType,
const BYTE *  pHash,
size_t  nSizeHash,
IRandomNoise pRandom 
) const
protected

Perform a PKCS#1 v2.1 PSS signature (RSASSA-PSS-SIGN) Use private key to sign.

  • pSig = buffer that will hold the ciphertext
  • eHashType = a HashType_* (use SSL_Hash_NONE for signing raw data)
  • pHash = buffer holding the message digest
  • nSizeHash = message digest length (for SSL_Hash_NONE only)
  • pRandom = RNG function (Needed for PKCS#1 v2.1 encoding and for RSA_PRIVATE)
    Returns
    0 if the signing operation was successful, or an <0 = error code
    Note
    The "pSig" buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).
    The eHashType in the RSA context is the one used for the encoding. eHashType in the function call is the type of hash that is encoded. According to RFC 3447 it is advised to keep both hashes the same.

◆ ReadPrivateKey()

HRESULT GrayLib::cKeyRSA::ReadPrivateKey ( cASNReader r,
cASNBuf pAlgParams 
)
overridevirtual

Read not encrypted. (already decrypted)

Parse a PKCS#1 encoded private RSA key from ASN/DER format. This function parses the RSAPrivateKey (PKCS#1)

RSAPrivateKey ::= SEQUENCE { version Version, modulus INTEGER, – n publicExponent INTEGER, – e privateExponent INTEGER, – d prime1 INTEGER, – r (p?) prime2 INTEGER, – q exponent1 INTEGER, – d mod (p-1) exponent2 INTEGER, – d mod (q-1) coefficient INTEGER, – (inverse of q) mod p otherPrimeInfos OtherPrimeInfos OPTIONAL }

Implements GrayLib::cKeyBase.

◆ ReadPrivateKeyPVK()

HRESULT GrayLib::cKeyRSA::ReadPrivateKeyPVK ( const BYTE *  pKeyData,
int  nSize 
)

Read Windows PVK format. not encrypted.

◆ ReadPublicKey()

virtual HRESULT GrayLib::cKeyRSA::ReadPublicKey ( cASNReader r,
cASNBuf pAlgParams 
)
inlineoverridevirtual

Implements GrayLib::cKeyBase.

◆ SetCopyKey()

void GrayLib::cKeyRSA::SetCopyKey ( const cKeyRSA src)

Copy the components of an RSA key

◆ SetZeroKey()

void GrayLib::cKeyRSA::SetZeroKey ( )
overridevirtual

Secure zero the key.

Free/clear all components of an RSA key

Implements GrayLib::cKeyBase.

◆ UNITTEST_FRIEND()

GrayLib::cKeyRSA::UNITTEST_FRIEND ( cKeyRSA  )

◆ UpdateReadPrivate()

bool GrayLib::cKeyRSA::UpdateReadPrivate ( )

◆ VerifySignature()

HRESULT GrayLib::cKeyRSA::VerifySignature ( SSL_Hash_TYPE  eHashType,
const BYTE *  pHash,
size_t  nSizeHash,
const BYTE *  pSig,
size_t  nSizeSig 
) const
overridevirtual

Verify Key signature. Make const ??

Do an RSA operation and check the message digest Use public key to verify pSig. Generic wrapper to perform a PKCS#1 verification using the mode from the context. Do a public RSA operation and check the message digest

Note
The "pSig" buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).
In case of PKCS#1 v2.1 encoding, see comments on VerifySignatureV21() about eHashType .

Implements GrayLib::cKeyBase.

◆ VerifySignatureV15()

HRESULT GrayLib::cKeyRSA::VerifySignatureV15 ( SSL_Hash_TYPE  eHashType,
const BYTE *  pHash,
size_t  nSizeHash,
const BYTE *  pSig 
) const

Perform a PKCS#1 v1.5 verification (RSASSA-PKCS1-v1_5-VERIFY) Use public key to verify pSig.

  • eHashType = a HashType_* (use SSL_Hash_NONE for signing raw data)
  • pHash = buffer holding the message digest
  • nSizeHash = message digest length (for SSL_Hash_NONE only)
  • pSig = buffer holding the ciphertext
    Returns
    0 if the verify operation was successful, or <0 = error code
    Note
    The "pSig" buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).

◆ VerifySignatureV21()

HRESULT GrayLib::cKeyRSA::VerifySignatureV21 ( SSL_Hash_TYPE  eHashType,
const BYTE *  pHash,
size_t  nSizeHash,
const BYTE *  pSig,
SSL_Hash_TYPE  mgf1_hash_id,
int  expected_salt_len 
) const

Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY) Use public key to verify pSig. (This is the version with "full" options.) Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY) (This is the "simple" version.)

Note
The "pSig" buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).
The eHashType in the RSA context is the one used for the verification. eHashType in the function call is the type of hash that is verified. According to RFC 3447 it is advised to keep both hashes the same. If eHashType in the RSA context is unset, the eHashType from the function call is used. Simplified PKCS#1 v2.1 RSASSA-PSS-VERIFY function
  • eHashType = a HashType_* (use SSL_Hash_NONE for signing raw data)
  • pHash = buffer holding the message digest
  • nSizeHash = message digest length (for SSL_Hash_NONE only)
  • eHashTypeMGF1 = message digest used for mask generation
  • expected_salt_len = Length of the salt used in padding, use RSA_SALT_LEN_ANY to accept any salt length
  • pSig = buffer holding the ciphertext
Returns
0 if the verify operation was successful, or <0 = error code
Note
The "pSig" buffer must be as large as the size of this->m_N (eg. 128 bytes if RSA-1024 is used).
The eHashType in the RSA context is ignored.

◆ WritePrivateKey()

HRESULT GrayLib::cKeyRSA::WritePrivateKey ( cASNWriterRev w) const
overridevirtual

Write not encrypted. (may be encrypted/secured later)

Write private key in ASN/DER format

Implements GrayLib::cKeyBase.

◆ WritePublicKey()

virtual HRESULT GrayLib::cKeyRSA::WritePublicKey ( cASNWriterRev w) const
inlineoverridevirtual

Implements GrayLib::cKeyBase.

Member Data Documentation

◆ k_nSizeSaltAny

const int GrayLib::cKeyRSA::k_nSizeSaltAny = -1
static

◆ m_BlindAdd

VAL_t GrayLib::cKeyRSA::m_BlindAdd
mutable

cached blinding value for DoRSAPrivate

◆ m_BlindRemove

VAL_t GrayLib::cKeyRSA::m_BlindRemove
mutable

cached un-blinding value for DoRSAPrivate

◆ m_D

VAL_t GrayLib::cKeyRSA::m_D

private exponent

◆ m_DP

VAL_t GrayLib::cKeyRSA::m_DP

D % (P - 1) const derived value.

◆ m_DQ

VAL_t GrayLib::cKeyRSA::m_DQ

D % (Q - 1) const derived value.

◆ m_eHashType

SSL_Hash_TYPE GrayLib::cKeyRSA::m_eHashType

Hash identifier for the EME-OAEP and EMSA-PSS encoding. MGF1.

◆ m_ePadding

PKCS1_VER_TYPE GrayLib::cKeyRSA::m_ePadding

PKCS1_VER_15 for 1.5 padding and PKCS1_VER_21 for OAEP/PSS.

◆ m_Mutex

cThreadLockMutex GrayLib::cKeyRSA::m_Mutex
mutable

Thread-safety mutex for mutable cached stuff.

◆ m_nSizeBlock

size_t GrayLib::cKeyRSA::m_nSizeBlock

sizeof(N) in bytes. Block size for DecryptWithKey

◆ m_P

VAL_t GrayLib::cKeyRSA::m_P

1st prime factor (private) (r)

◆ m_Q

VAL_t GrayLib::cKeyRSA::m_Q

2nd prime factor (private)

◆ m_QP

VAL_t GrayLib::cKeyRSA::m_QP

1 / (Q % P) const derived value.

◆ m_RN

VAL_t GrayLib::cKeyRSA::m_RN
mutable

cached R^2 mod N (for public)

◆ m_RP

VAL_t GrayLib::cKeyRSA::m_RP
mutable

cached R^2 mod P for DoRSAPrivate

◆ m_RQ

VAL_t GrayLib::cKeyRSA::m_RQ
mutable

cached R^2 mod Q for DoRSAPrivate


The documentation for this class was generated from the following files: