Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
p6cryptokey.h
Go to the documentation of this file.
1 
13 #ifndef P6CRYPTOKEY_H__
14 #define P6CRYPTOKEY_H__ 1
15 
16 #include "p6random.h"
17 #include "p6crypto.h"
18 
19 namespace P6R {
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
35 const P6CRYPTOKEYFLAGS P6CKF_NONE = 0x00000000;
36 const P6CRYPTOKEYFLAGS P6CKF_FORCENEWIV = 0x00000001;
37 
49 typedef enum {
55 
56 
72 typedef enum {
79 
80 
86 interface p6ICryptoKeyInit : public p6ICom
87 {
101  P6COMMETHOD initialize( P6CRYPTOKEYFLAGS flags, p6IRandom* pRandom ) = 0;
102 
120  P6COMMETHOD loadKey( const P6WCHAR* pszFilename ) = 0;
121 
139  P6COMMETHOD loadKeyFromBuffer( const P6VOID* pBuffer, P6UINT32 cBuffer ) = 0;
140 
157  P6COMMETHOD loadRawSymetricKey( const P6VOID* pBuffer, P6UINT32 cBuffer, P6UINT32 keySize ) = 0;
158 
176  P6COMMETHOD loadPKCS8Key( const P6VOID* pBuffer, P6UINT32 cBuffer, P6UINT32 keySize ) = 0;
177 
195  P6COMMETHOD loadPublicPKCS1Key( const P6VOID* pBuffer, P6UINT32 cBuffer, P6UINT32 keySize ) = 0;
196 
214  P6COMMETHOD loadPrivatePKCS1Key( const P6VOID* pBuffer, P6UINT32 cBuffer, P6UINT32 keySize ) = 0;
215 
238  P6COMMETHOD loadRawPublicDSAKey( const P6UCHAR* pP, P6UINT32 pLength,
239  const P6UCHAR* pQ, P6UINT32 qLength,
240  const P6UCHAR* pG, P6UINT32 gLength,
241  const P6UCHAR* pY, P6UINT32 yLength ) = 0;
242 
265  P6COMMETHOD loadRawPrivateDSAKey( const P6UCHAR* pP, P6UINT32 pLength,
266  const P6UCHAR* pQ, P6UINT32 qLength,
267  const P6UCHAR* pG, P6UINT32 gLength,
268  const P6UCHAR* pX, P6UINT32 xLength ) = 0;
269 
288  P6COMMETHOD loadRawPublicRSAKey( const P6UCHAR* pE, P6UINT32 eLength, const P6UCHAR* pN, P6UINT32 nLength ) = 0;
289 
321  const P6R::P6UCHAR* pD, P6R::P6UINT32 dLength,
322  const P6R::P6UCHAR* pE, P6R::P6UINT32 eLength,
323  const P6R::P6UCHAR* pP, P6R::P6UINT32 pLength,
324  const P6R::P6UCHAR* pQ, P6R::P6UINT32 qLength,
325  const P6R::P6UCHAR* pPrimeExpP, P6R::P6UINT32 epLength,
326  const P6R::P6UCHAR* pPrimeExpQ, P6R::P6UINT32 eqLength,
327  const P6R::P6UCHAR* pCRT, P6R::P6UINT32 cLength ) = 0;
328 };
329 
330 // {7AAB1F32-075B-4B8D-B0E6-E4CE822882B7}
331 #define IF_p6ICryptoKeyInit {0x7AAB1F32,0x075B,0x4B8D,{0xB0,0xE6,0xE4,0xCE,0x82,0x28,0x82,0xB7}}
332 
333 
356 typedef enum {
367 
368 
374 interface p6ICryptoKeyGetMeta : public p6ICom
375 {
393  P6COMMETHOD getDescriptiveLabel( P6WCHAR* pLabel, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
394 
412  P6COMMETHOD getUse( P6WCHAR* pUse, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
413 
426  P6COMMETHOD getState( P6CRYPTOKEYSTATE* pState ) = 0;
427 
445  P6COMMETHOD getStateAsString( P6WCHAR* pState, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
446 
459  P6COMMETHOD getCipher( P6CRYPTOCIPHER* pCipher ) = 0;
460 
478  P6COMMETHOD getCipherAsString( P6WCHAR* pCipher, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
479 
493  P6COMMETHOD getStateDate( P6CRYPTOKEYSTATE state, P6TIME* pDate ) = 0;
494 
507  P6COMMETHOD getExpiredDate( P6TIME* pExpire ) = 0;
508 
521  P6COMMETHOD getRenewalDate( P6TIME* pRenewal ) = 0;
522 
535  P6COMMETHOD getLastUpdated( P6TIME* pUpdated ) = 0;
536 
554  P6COMMETHOD getStateString( P6CRYPTOKEYSTATE state, P6WCHAR* pState, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
555 
573  P6COMMETHOD getCipherString( P6CRYPTOCIPHER cipher, P6WCHAR* pCipher, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
574 };
575 
576 // {8F3C646F-98B2-493d-8C10-0E71092064FF}
577 #define IF_p6ICryptoKeyGetMeta {0x8f3c646f,0x98b2,0x493d,{0x8c,0x10,0xe,0x71,0x9,0x20,0x64,0xff}}
578 
579 
585 interface p6ICryptoKeySetMeta : public p6ICom
586 {
600  P6COMMETHOD setDescriptiveLabel( const P6WCHAR* pLabel, P6UINT32 cBuffer ) = 0;
601 
615  P6COMMETHOD setUse( const P6WCHAR* pUse, P6UINT32 cBuffer ) = 0;
616 
628 
643  P6COMMETHOD setStateAsString( const P6WCHAR* pState ) = 0;
644 
655  P6COMMETHOD setCipher( P6CRYPTOCIPHER cipher ) = 0;
656 
671  P6COMMETHOD setCipherAsString( const P6WCHAR* pCipher ) = 0;
672 
684  P6COMMETHOD setStateDate( P6CRYPTOKEYSTATE state, P6TIME dateTime ) = 0;
685 
698  P6COMMETHOD setExpiredDate( P6TIME expire ) = 0;
699 
711  P6COMMETHOD setRenewalDate( P6TIME renewal ) = 0;
712 
723  P6COMMETHOD setLastUpdated( P6TIME updated ) = 0;
724 };
725 
726 // {CB3DCA8C-FA0E-41eb-8538-FC3A07D1A38A}
727 #define IF_p6ICryptoKeySetMeta {0xcb3dca8c,0xfa0e,0x41eb,{0x85,0x38,0xfc,0x3a,0x7,0xd1,0xa3,0x8a}}
728 
729 
730 
749 static const P6CRYPTOKEYMASK P6CKM_NONE = 0x00000000;
750 static const P6CRYPTOKEYMASK P6CKM_CLASS = 0x00000001;
751 static const P6CRYPTOKEYMASK P6CKM_TYPE = 0x00000002;
752 static const P6CRYPTOKEYMASK P6CKM_SIZE = 0x00000004;
753 static const P6CRYPTOKEYMASK P6CKM_GUID = 0x00000008;
754 static const P6CRYPTOKEYMASK P6CKM_VERSION = 0x00000010;
755 
772 typedef struct {
773  P6CRYPTOKEYMASK mask;
780 
781 
787 interface p6ICryptoKey : public p6ICom
788 {
807  P6COMMETHOD getInfo( P6CRYPTOKEYCLASS* pClass, P6CRYPTOKEYTYPE* pType, P6UUID* pGuid, P6INT32* pKeySize, P6INT32* pVersion ) = 0;
808 
849  P6COMMETHOD getDSAPublicKey( P6BSTR* pP, P6BSTR* pQ, P6BSTR* pG, P6BSTR* pY ) = 0;
850 
891  P6COMMETHOD getDSAPrivateKey( P6BSTR* pP, P6BSTR* pQ, P6BSTR* pG, P6BSTR* pX ) = 0;
892 
920  P6COMMETHOD getRSAPublicKey( P6BSTR* pN, P6BSTR* pE ) = 0;
921 
985  P6COMMETHOD getRSAPrivateKey( P6BSTR* pN, P6BSTR* pD, P6BSTR* pE, P6BSTR* pP, P6BSTR* pQ, P6BSTR* pPrimeExpP, P6BSTR* pPrimeExpQ, P6BSTR* pCRT ) = 0;
986 
1005  P6COMMETHOD getKeyPKCS8( P6UCHAR* pBuffer, P6UINT32 cBuffer, P6BOOL wantPEM, P6UINT32* pWritten ) = 0;
1006 
1025  P6COMMETHOD getKeyPKCS1( P6UCHAR* pBuffer, P6UINT32 cBuffer, P6BOOL wantPEM, P6UINT32* pWritten ) = 0;
1026 
1044  P6COMMETHOD getSymetricKey( P6UCHAR* pBuffer, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
1045 
1063  P6COMMETHOD getSymetricIV( P6UCHAR* pBuffer, P6UINT32 cBuffer, P6UINT32* pWritten ) = 0;
1064 
1083  P6COMMETHOD validateKey( P6CRYPTOKEYINFO* pKeyInfo ) = 0;
1084 
1096  P6COMMETHOD serializeToFile( const P6WCHAR* pFile ) = 0;
1097 
1117  P6COMMETHOD serializeToBuffer( P6VOID* pBuffer, P6UINT32 cBuffer, P6UINT32* pcBytesWritten ) = 0;
1118 
1131  P6COMMETHOD isEquals( p6ICryptoKey* pOtherKey, P6BOOL* pbEqual ) = 0;
1132 };
1133 
1134 // {A8E297EE-8F07-4D33-AD7F-CC642B52E765}
1135 #define IF_p6ICryptoKey {0xA8E297EE,0x8F07,0x4D33,{0xAD,0x7F,0xCC,0x64,0x2B,0x52,0xE7,0x65}}
1136 
1137 // {D797AD3A-1CD8-4A78-AF7E-3EE03B1AD897}
1138 #define COMP_p6CryptoKey {0xD797AD3A,0x1CD8,0x4A78,{0xAF,0x7E,0x3E,0xE0,0x3B,0x1A,0xD8,0x97}}
1139 
1140 #ifdef __cplusplus
1141 }
1142 #endif
1143 
1144 } // namespace
1145 
1146 #endif
1147 
virtual P6R::P6ERR getState(P6CRYPTOKEYSTATE *pState)=0
This method retrieves the current state of the key (see reference 1).
virtual P6R::P6ERR loadPKCS8Key(const P6VOID *pBuffer, P6UINT32 cBuffer, P6UINT32 keySize)=0
Load the PKCS#8 encoded private key (either in PEM format or binary ASN.1 format).
const P6CRYPTOKEYFLAGS P6CKF_FORCENEWIV
Definition: p6cryptokey.h:36
virtual P6R::P6ERR getUse(P6WCHAR *pUse, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
This method retrieves the human or machine readable description on how key is to be used (e...
virtual P6R::P6ERR initialize(P6CRYPTOKEYFLAGS flags, p6IRandom *pRandom)=0
Place the object in a state to load one or more crypto keys.
virtual P6R::P6ERR setExpiredDate(P6TIME expire)=0
This method assigns the time that a key’s useful lifetime is terminated permanently.
unsigned char P6UCHAR
Definition: p6types.h:74
virtual P6R::P6ERR getLastUpdated(P6TIME *pUpdated)=0
This method retrieves the time that the key (or its meta data) was last updated.
Cryptography component definitions.
This interface provides key metadata infrormation and key access.
Definition: p6cryptokey.h:787
P6UINT32 P6CRYPTOKEYFLAGS
P6CRYPTOKEYFLAGS.
Definition: p6cryptokey.h:34
unsigned int P6UINT32
Definition: p6types.h:40
virtual P6R::P6ERR loadRawPublicDSAKey(const P6UCHAR *pP, P6UINT32 pLength, const P6UCHAR *pQ, P6UINT32 qLength, const P6UCHAR *pG, P6UINT32 gLength, const P6UCHAR *pY, P6UINT32 yLength)=0
This method loads the standard parts of a DSA (DSS) public key from a set of buffers.
virtual P6R::P6ERR setCipher(P6CRYPTOCIPHER cipher)=0
This method assignes the cipher algorthm to be used with the key (e.g., CIPHER_AES_CTR [counter mode]...
virtual P6R::P6ERR validateKey(P6CRYPTOKEYINFO *pKeyInfo)=0
This method is used to validate the keys metadata against the provided parameter. ...
virtual P6R::P6ERR setRenewalDate(P6TIME renewal)=0
This method retrieves the time when the key life's time was extended.
Used to initialize and load a crypto key from a file or buffers.
Definition: p6cryptokey.h:86
virtual P6R::P6ERR getExpiredDate(P6TIME *pExpire)=0
This method retrieves the time that a key’s useful lifetime is terminated permanently.
virtual P6R::P6ERR getDSAPublicKey(P6BSTR *pP, P6BSTR *pQ, P6BSTR *pG, P6BSTR *pY)=0
This method retrieves the standard parts of a DSA (DSS) public key.
virtual P6R::P6ERR serializeToFile(const P6WCHAR *pFile)=0
Write the key in this component to the file defined in the parameter.
virtual P6R::P6ERR getKeyPKCS1(P6UCHAR *pBuffer, P6UINT32 cBuffer, P6BOOL wantPEM, P6UINT32 *pWritten)=0
This method retrieves a RSA private or public key in the PKCS#1 format (unencrypted format)...
P6CRYPTOKEYCLASS
Used to categorize keys:
Definition: p6cryptokey.h:49
bool P6BOOL
Boolean type.
Definition: p6types.h:101
virtual P6R::P6ERR getInfo(P6CRYPTOKEYCLASS *pClass, P6CRYPTOKEYTYPE *pType, P6UUID *pGuid, P6INT32 *pKeySize, P6INT32 *pVersion)=0
This method returns the key's metadata.
virtual P6R::P6ERR getKeyPKCS8(P6UCHAR *pBuffer, P6UINT32 cBuffer, P6BOOL wantPEM, P6UINT32 *pWritten)=0
This method retrieves a private key in the PKCS#8 format (unencrypted format).
virtual P6R::P6ERR getCipher(P6CRYPTOCIPHER *pCipher)=0
This method retrieves the cipher algorthm to be used with the key (e.g., CIPHER_AES_CTR [counter mode...
P6CRYPTOKEYTYPE
Used to categorize keys:
Definition: p6cryptokey.h:72
virtual P6R::P6ERR setUse(const P6WCHAR *pUse, P6UINT32 cBuffer)=0
This method assigns a value for the human or machine readable description on how key is to be used (e...
virtual P6R::P6ERR serializeToBuffer(P6VOID *pBuffer, P6UINT32 cBuffer, P6UINT32 *pcBytesWritten)=0
Write the key in this component to the provided buffer.
virtual P6R::P6ERR isEquals(p6ICryptoKey *pOtherKey, P6BOOL *pbEqual)=0
Is the key in the 'pOtherKey' parameter the same as the key stored in this component.
virtual P6R::P6ERR getDescriptiveLabel(P6WCHAR *pLabel, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
This method retrieves the "human readable set of descriptions for the key" (see reference 1)...
virtual P6R::P6ERR getSymetricKey(P6UCHAR *pBuffer, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
This method retrieves the raw bits of a symetric key (i.e., no metadata and not base64 encoded – see ...
virtual P6R::P6ERR getDSAPrivateKey(P6BSTR *pP, P6BSTR *pQ, P6BSTR *pG, P6BSTR *pX)=0
This method retrieves the standard parts of a DSA (DSS) private key.
Used to set extended key meta data as defined in reference 1 above.
Definition: p6cryptokey.h:585
virtual P6R::P6ERR setState(P6CRYPTOKEYSTATE state)=0
This method modifes the current state of the key (see reference 1).
[p6]COM Cryptographic Random Number Generator.
virtual P6R::P6ERR loadPublicPKCS1Key(const P6VOID *pBuffer, P6UINT32 cBuffer, P6UINT32 keySize)=0
Load the PKCS#1 encoded public key (either in PEM format or binary ASN.1 format). ...
P6CRYPTOCIPHER
Cipher Type.
Definition: p6crypto.h:99
wchar_t P6WCHAR
Wide character type see p6i18n.h.
Definition: p6types.h:76
int P6INT32
Definition: p6types.h:41
P6CRYPTOKEYMASK mask
Definition: p6cryptokey.h:773
The base interface all [p6]COM components must derive from and implement.
Definition: p6comdef.h:96
P6CRYPTOKEYTYPE keyType
Definition: p6cryptokey.h:775
virtual P6R::P6ERR loadPrivatePKCS1Key(const P6VOID *pBuffer, P6UINT32 cBuffer, P6UINT32 keySize)=0
Load the PKCS#1 encoded private key (either in PEM format or binary ASN.1 format).
virtual P6R::P6ERR getStateAsString(P6WCHAR *pState, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
This method retrieves the current state as a string.
virtual P6R::P6ERR getRSAPublicKey(P6BSTR *pN, P6BSTR *pE)=0
This method retrieves the standard parts of a RSA public key.
virtual P6R::P6ERR setCipherAsString(const P6WCHAR *pCipher)=0
This method allows the caller to set the cipher by providing a string value.
Provides a cryptographically strong random number generator.
Definition: p6random.h:70
Binary string.
Definition: p6types.h:154
const P6CRYPTOKEYFLAGS P6CKF_NONE
Definition: p6cryptokey.h:35
P6CRYPTOKEYSTATE
The current state of the key as defined in: NIST DRAFT Special Publication 800-130, A Framework for Designing Cryptographic Key Management Systems, June 15, 2010.
Definition: p6cryptokey.h:356
A universally unique indentifier (UUID).
Definition: p6types.h:131
virtual P6R::P6ERR loadKeyFromBuffer(const P6VOID *pBuffer, P6UINT32 cBuffer)=0
This function does the same operation as the loadKey() method except that the key data resides in a b...
virtual P6R::P6ERR loadRawPrivateDSAKey(const P6UCHAR *pP, P6UINT32 pLength, const P6UCHAR *pQ, P6UINT32 qLength, const P6UCHAR *pG, P6UINT32 gLength, const P6UCHAR *pX, P6UINT32 xLength)=0
This method loads the standard parts of a DSA (DSS) private key from a set of buffers.
virtual P6R::P6ERR setStateDate(P6CRYPTOKEYSTATE state, P6TIME dateTime)=0
This method assigns the time that the key placed in a specific key state.
virtual P6R::P6ERR getCipherString(P6CRYPTOCIPHER cipher, P6WCHAR *pCipher, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
Return the string representation of the cipher input parameter.
virtual P6R::P6ERR getRenewalDate(P6TIME *pRenewal)=0
This method retrieves the time when the key life's time was extended (i.e., when the setExpiredDate()...
#define P6COMMETHOD
Definition: p6types.h:872
virtual P6R::P6ERR loadKey(const P6WCHAR *pszFilename)=0
This function reads the crypto key from the specified file.
P6INT64 P6TIME
The wallclock time represented as the number of microseconds since midnight January 1 1970 UTC...
Definition: p6types.h:228
virtual P6R::P6ERR getRSAPrivateKey(P6BSTR *pN, P6BSTR *pD, P6BSTR *pE, P6BSTR *pP, P6BSTR *pQ, P6BSTR *pPrimeExpP, P6BSTR *pPrimeExpQ, P6BSTR *pCRT)=0
This method retrieves the standard parts of a RSA private key.
P6CRYPTOKEYCLASS keyClass
Definition: p6cryptokey.h:774
virtual P6R::P6ERR loadRawSymetricKey(const P6VOID *pBuffer, P6UINT32 cBuffer, P6UINT32 keySize)=0
Load the random bytes that comprise a symetric key into the component.
virtual P6R::P6ERR loadRawPublicRSAKey(const P6UCHAR *pE, P6UINT32 eLength, const P6UCHAR *pN, P6UINT32 nLength)=0
This method loads the standard parts of a RSA public key from a set of buffers.
virtual P6R::P6ERR setStateAsString(const P6WCHAR *pState)=0
This method allows the caller to set the state by providing a string value.
P6UINT32 P6CRYPTOKEYMASK
P6CRYPTOKEYMASK.
Definition: p6cryptokey.h:748
Used to obtain extended key meta data as defined in reference 1 above.
Definition: p6cryptokey.h:374
virtual P6R::P6ERR getSymetricIV(P6UCHAR *pBuffer, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
This method retrieves the raw bits of a symetric initialization vector (IV).
void P6VOID
Definition: p6types.h:75
virtual P6R::P6ERR getCipherAsString(P6WCHAR *pCipher, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
This method retrieves the current algorith to be used with the key as a string.
When a key is written to a file it is stamped with a set of meta data that define the key...
Definition: p6cryptokey.h:772
virtual P6R::P6ERR setLastUpdated(P6TIME updated)=0
This method assigns the time that the key (or its meta data) was last updated.
virtual P6R::P6ERR loadRawPrivateRSAKey(const P6R::P6UCHAR *pN, P6R::P6UINT32 nLength, const P6R::P6UCHAR *pD, P6R::P6UINT32 dLength, const P6R::P6UCHAR *pE, P6R::P6UINT32 eLength, const P6R::P6UCHAR *pP, P6R::P6UINT32 pLength, const P6R::P6UCHAR *pQ, P6R::P6UINT32 qLength, const P6R::P6UCHAR *pPrimeExpP, P6R::P6UINT32 epLength, const P6R::P6UCHAR *pPrimeExpQ, P6R::P6UINT32 eqLength, const P6R::P6UCHAR *pCRT, P6R::P6UINT32 cLength)=0
This method loads the standard parts of a RSA private key from a set of buffers.
virtual P6R::P6ERR setDescriptiveLabel(const P6WCHAR *pLabel, P6UINT32 cBuffer)=0
This method assigns a value for the "human readable set of descriptions for the key" (see reference 1...
virtual P6R::P6ERR getStateDate(P6CRYPTOKEYSTATE state, P6TIME *pDate)=0
This method retrieves the time that the key was placed in a specific key state.
virtual P6R::P6ERR getStateString(P6CRYPTOKEYSTATE state, P6WCHAR *pState, P6UINT32 cBuffer, P6UINT32 *pWritten)=0
Return the string representation of a key state value passed in as an input parameter.