Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cKeyBase.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cKeyBase_H
7 #define _INC_cKeyBase_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../Hash/cHashCode.h"
16 
17 namespace GrayLib
18 {
19  class cASNBuf;
20  class cASNReader;
21  class cASNWriterRev;
22 
24  {
27 
33 
35 
37  };
38 
39  struct cKeySigAlg
40  {
44  public:
47  public:
49  : m_eHashType(eHashType)
50  , m_eKeyType(eKeyType)
51  {
52  }
53  };
54 
55  class GRAYLIB_LINK cKeyBase : public cRefBase, public CObject // for cObjectFactory.
56  {
61 
62  public:
64  {
66  VALTYPE_NONE = 0,
67  VALTYPE_RSA = 1,
68  VALTYPE_ECP = 2,
69  };
70 
71  static const int k_MAX_VALUES = 2;
72 
73  struct cValue // Static init.
74  {
78  const char* m_pszName;
79  const void* m_pValue;
80  };
81 
82  virtual ~cKeyBase()
83  {
85  }
86 
87  // virtual bool HasKeyValueType(KEYVAL_TYPE eType) = 0;
88 
90  virtual size_t get_KeySize() const = 0;
91 
93  virtual int GetKeyValues(cValue* items) const = 0;
94 
96  virtual HRESULT CheckPublicPrivatePair(const cKeyBase* pKeyPrivate) const = 0;
97 
99  virtual HRESULT VerifySignature(SSL_Hash_TYPE eHashType, const BYTE* pHash, size_t nSizeHash, const BYTE* pSig, size_t nSizeSig) const = 0;
100 
102  virtual HRESULT MakeSignature(BYTE* pSig, SSL_Hash_TYPE eHashType, const BYTE* pHash, size_t hash_len, IRandomNoise* pRandom) const = 0;
103 
105  virtual void SetZeroKey() = 0;
106 
107  virtual HRESULT ReadPublicKey(cASNReader& r, cASNBuf* pAlgParams = nullptr) = 0;
108  virtual HRESULT WritePublicKey(cASNWriterRev& w) const = 0;
109 
111  virtual HRESULT ReadPrivateKey(cASNReader& r, cASNBuf* pAlgParams = nullptr) = 0;
113  virtual HRESULT WritePrivateKey(cASNWriterRev& w) const = 0;
114  };
115 }
116 
117 #endif
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cASN.h:78
Definition: cASNReader.h:22
Definition: cASNWriterRev.h:22
Definition: cKeyBase.h:56
virtual int GetKeyValues(cValue *items) const =0
Interface with the debug module. get debug values.
virtual size_t get_KeySize() const =0
Get key size in bytes.
virtual HRESULT CheckPublicPrivatePair(const cKeyBase *pKeyPrivate) const =0
Check public-private key pair.
VALTYPE_TYPE
Definition: cKeyBase.h:64
virtual HRESULT ReadPrivateKey(cASNReader &r, cASNBuf *pAlgParams=nullptr)=0
Read not encrypted. (already decrypted)
virtual void SetZeroKey()=0
Secure zero the key.
virtual HRESULT VerifySignature(SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t nSizeHash, const BYTE *pSig, size_t nSizeSig) const =0
Verify Key signature. Make const ??
virtual HRESULT MakeSignature(BYTE *pSig, SSL_Hash_TYPE eHashType, const BYTE *pHash, size_t hash_len, IRandomNoise *pRandom) const =0
Make signature From Key. Make const ??
virtual HRESULT WritePrivateKey(cASNWriterRev &w) const =0
Write not encrypted. (may be encrypted/secured later)
virtual HRESULT ReadPublicKey(cASNReader &r, cASNBuf *pAlgParams=nullptr)=0
virtual HRESULT WritePublicKey(cASNWriterRev &w) const =0
virtual ~cKeyBase()
Definition: cKeyBase.h:82
Definition: cObject.h:67
Definition: cRefPtr.h:22
Definition: cMesh.h:22
SSL_Key_TYPE
Definition: cKeyBase.h:24
@ SSL_Key_ECDSA
SSL_KeyExchange_ECDHE_ECDSA.
Definition: cKeyBase.h:32
@ SSL_Key_RSASSA_PSS
OID_RSASSA_PSS "RSASSA-PSS" used for signing.
Definition: cKeyBase.h:34
@ SSL_Key_ECKEY_DH
OID_EC_ALG_ECDH.
Definition: cKeyBase.h:31
@ SSL_Key_RSA
SSL_KeyExchange_RSA = "PRIVATE KEY" = k_pszPEM_PK.
Definition: cKeyBase.h:29
@ SSL_Key_NONE
Definition: cKeyBase.h:28
@ SSL_Key_ECKEY
SSL_KeyExchange_ECDH_RSA = "EC PRIVATE KEY" = k_pszPEM_EC.
Definition: cKeyBase.h:30
@ SSL_Key_QTY
Definition: cKeyBase.h:36
SSL_Hash_TYPE
Definition: cHashCode.h:23
@ SSL_Hash_NONE
Definition: cHashCode.h:30
Definition: cKeyBase.h:74
const char * m_pszName
Definition: cKeyBase.h:78
const void * m_pValue
e.g. const cBigInt* if VALTYPE_RSA
Definition: cKeyBase.h:79
VALTYPE_TYPE m_eValueType
type of value.
Definition: cKeyBase.h:77
Definition: cKeyBase.h:40
SSL_Key_TYPE m_eKeyType
Internal representation of the Public Key algorithm of the signature algorithm, e....
Definition: cKeyBase.h:46
cKeySigAlg(SSL_Hash_TYPE eHashType=SSL_Hash_NONE, SSL_Key_TYPE eKeyType=SSL_Key_NONE)
Definition: cKeyBase.h:48
SSL_Hash_TYPE m_eHashType
Internal representation of the Hash algorithm of the signature algorithm, e.g. HashType_SHA256.
Definition: cKeyBase.h:45
Definition: cRandom.h:19