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

#include <cKeyECPPair.h>

Inheritance diagram for GrayLib::cKeyECPPair:
GrayLib::cKeyBase Gray::cRefBase Gray::CObject IUnknown GrayLib::cKeyECDSA

Public Member Functions

 cKeyECPPair () noexcept
 
virtual ~cKeyECPPair ()
 
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 cKeyECPPair &key)
 
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 GenerateKeys (ECPGroup_TYPE eECPGroupId, IRandomNoise *pRandom)
 
HRESULT WriteECParameters (cASNWriterRev &w) const
 
virtual HRESULT ReadPrivateKey (cASNReader &r, cASNBuf *pAlgParams) override
 Read not encrypted. (already decrypted) More...
 
virtual HRESULT ReadPublicKey (cASNReader &r, cASNBuf *pAlgParams) override
 
virtual HRESULT WritePrivateKey (cASNWriterRev &w) const override
 Write not encrypted. (may be encrypted/secured later) More...
 
virtual HRESULT WritePublicKey (cASNWriterRev &w) const override
 
 UNITTEST_FRIEND (cKeyECPPair)
 
- 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 Attributes

cECPGroup m_grp
 Elliptic curve and base point. More...
 
cBigInteger m_d
 our secret value More...
 
cECPPoint m_Q
 our public value More...
 

Protected Member Functions

HRESULT MakeSignatureSeed (BYTE *pOut, const cBigInteger &d, const BYTE *buf, size_t nSizeBuf) const
 
HRESULT MakeSignatureDer (cASNWriterRev &w, const cBigInteger &r, const cBigInteger &s) const
 

Static Protected Member Functions

static HRESULT GRAYCALL ReadECParameters (cASNReader &r, OUT cASNBuf &params)
 

Additional Inherited Members

- Public Types inherited from GrayLib::cKeyBase
enum  VALTYPE_TYPE { VALTYPE_NONE = 0 , VALTYPE_RSA = 1 , VALTYPE_ECP = 2 }
 
- Static Public Attributes inherited from GrayLib::cKeyBase
static const int k_MAX_VALUES = 2
 Maximum number of cValue sent for debugging. More...
 

Detailed Description

ECP key pair structure. SSL_Key_ECKEY or SSL_Key_ECKEY_DH A generic key pair that could be used for ECDSA, fixed ECDH, etc. base for class cKeyECDSA.

Constructor & Destructor Documentation

◆ cKeyECPPair()

GrayLib::cKeyECPPair::cKeyECPPair ( )
inlinenoexcept

◆ ~cKeyECPPair()

virtual GrayLib::cKeyECPPair::~cKeyECPPair ( )
inlinevirtual

Member Function Documentation

◆ CheckPublicPrivatePair()

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

Check public-private key pair.

Check a public-private key pair

  • pKeyPrivate = Keypair structure holding a private (plus public) key
    Returns
    0 if successful (keys are valid and match)

Implements GrayLib::cKeyBase.

◆ GenerateKeys()

HRESULT GrayLib::cKeyECPPair::GenerateKeys ( ECPGroup_TYPE  eECPGroupId,
IRandomNoise pRandom 
)

Generate a keypair

  • eECPGroupId = ECP group identifier
  • pRandom = RNG function
    Returns
    0 if successful, <0 = error.

◆ get_KeySize()

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

Get key size in bytes.

Implements GrayLib::cKeyBase.

◆ GetKeyValues()

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

Interface with the debug module. get debug values.

Implements GrayLib::cKeyBase.

◆ MakeSignature()

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

Make signature From Key. Make const ??

< first integer from signature

< second integer from signature

Implements GrayLib::cKeyBase.

Reimplemented in GrayLib::cKeyECDSA.

◆ MakeSignatureDer()

HRESULT GrayLib::cKeyECPPair::MakeSignatureDer ( cASNWriterRev w,
const cBigInteger r,
const cBigInteger s 
) const
protected

Convert a signature (given by context) to ASN.1 RFC 4492 page 20: Ecdsa-Sig-Value ::= SEQUENCE { r INTEGER, s INTEGER }

◆ MakeSignatureSeed()

HRESULT GrayLib::cKeyECPPair::MakeSignatureSeed ( BYTE *  pOut,
const cBigInteger d,
const BYTE *  buf,
size_t  nSizeBuf 
) const
protected

Compute ECDSA signature of a previously hashed message (deterministic version)

  • d = Use private key and message hash (reduced) to initialize HMAC_DRBG ASSUME pOut is big enough <= 2 * cECPGroup::k_ECP_MAX_BYTES
    Returns
    size of pOut if successful,

◆ ReadECParameters()

HRESULT GRAYCALL GrayLib::cKeyECPPair::ReadECParameters ( cASNReader r,
OUT cASNBuf params 
)
staticprotected

Minimally parse an ECParameters buffer to and cASNBuf

ECParameters ::= CHOICE { namedCurve OBJECT IDENTIFIER specifiedCurve SpecifiedECDomain – = SEQUENCE { ... } – implicitCurve nullptr }

◆ ReadPrivateKey()

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

Read not encrypted. (already decrypted)

Parse a SEC1 (DER) encoded private EC key RFC 5915, or SEC1 Appendix C.4

Implements GrayLib::cKeyBase.

◆ ReadPublicKey()

HRESULT GrayLib::cKeyECPPair::ReadPublicKey ( cASNReader r,
cASNBuf pAlgParams 
)
overridevirtual

EC public key is an EC point The caller is responsible for clearing the structure upon failure if desired. Take care to pass along the possible E_NOTIMPL return code of ReadPointBinary() and leave p in a usable state.

Implements GrayLib::cKeyBase.

◆ SetCopyKey()

void GrayLib::cKeyECPPair::SetCopyKey ( const cKeyECPPair key)
inline

Set an ECDSA context from a cKeyECPPair

◆ SetZeroKey()

virtual void GrayLib::cKeyECPPair::SetZeroKey ( )
inlineoverridevirtual

Secure zero the key.

set empty on failure.

Implements GrayLib::cKeyBase.

◆ UNITTEST_FRIEND()

GrayLib::cKeyECPPair::UNITTEST_FRIEND ( cKeyECPPair  )

◆ VerifySignature()

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

Verify Key signature. Make const ??

Read and check signature

< first integer from signature

< second integer from signature

Implements GrayLib::cKeyBase.

◆ WriteECParameters()

HRESULT GrayLib::cKeyECPPair::WriteECParameters ( cASNWriterRev w) const

ECParameters ::= CHOICE { namedCurve OBJECT IDENTIFIER }

◆ WritePrivateKey()

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

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

RFC 5915, or SEC1 Appendix C.4

ECPrivateKey ::= SEQUENCE { version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1), privateKey OCTET STRING, parameters [0] ECParameters {{ NamedCurve }} OPTIONAL, publicKey [1] BIT STRING OPTIONAL }

Implements GrayLib::cKeyBase.

◆ WritePublicKey()

HRESULT GrayLib::cKeyECPPair::WritePublicKey ( cASNWriterRev w) const
overridevirtual

EC public key is an EC point

Implements GrayLib::cKeyBase.

Member Data Documentation

◆ m_d

cBigInteger GrayLib::cKeyECPPair::m_d

our secret value

◆ m_grp

cECPGroup GrayLib::cKeyECPPair::m_grp

Elliptic curve and base point.

◆ m_Q

cECPPoint GrayLib::cKeyECPPair::m_Q

our public value


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