Add pgs color type setting
[xy_vsfilter.git] / include / atl / atlcrypt.h
blob8e8ac7d4e3187e61072f22e25ff878fc27cf64ac
1 // This is a part of the Active Template Library.
2 // Copyright (C) Microsoft Corporation
3 // All rights reserved.
4 //
5 // This source code is only intended as a supplement to the
6 // Active Template Library Reference and related
7 // electronic documentation provided with the library.
8 // See these sources for detailed information regarding the
9 // Active Template Library product.
11 #ifndef __ATLCRYPT_H__
12 #define __ATLCRYPT_H__
14 #pragma once
16 #include <atlchecked.h>
17 #include <wincrypt.h>
20 #pragma pack(push,_ATL_PACKING)
21 namespace ATL
24 class CCryptKey;
26 class CCryptProv
28 protected:
29 HCRYPTPROV m_hProv;
31 public:
32 CCryptProv() throw();
33 CCryptProv( const CCryptProv& prov ) throw();
34 explicit CCryptProv( HCRYPTPROV hProv, BOOL bTakeOwnership = FALSE ) throw();
35 ~CCryptProv() throw();
37 CCryptProv& operator=( const CCryptProv& prov ) throw();
39 HRESULT AddRef() throw();
40 void Attach( HCRYPTPROV hProv, BOOL bTakeOwnership = FALSE ) throw();
41 HCRYPTPROV Detach() throw();
42 HRESULT Release() throw();
45 HRESULT Initialize(DWORD dwProviderType = PROV_RSA_FULL,
46 LPCTSTR szContainer = NULL, LPCTSTR szProvider = MS_DEF_PROV,
47 DWORD dwFlags = 0) throw();
48 HRESULT InitVerifyContext(DWORD dwProviderType = PROV_RSA_FULL,
49 LPCTSTR szProvider = MS_DEF_PROV, DWORD dwFlags = 0) throw();
50 HRESULT InitCreateKeySet(DWORD dwProviderType = PROV_RSA_FULL,
51 LPCTSTR szContainer = NULL, LPCTSTR szProvider = MS_DEF_PROV,
52 DWORD dwFlags = 0) throw();
54 HRESULT DeleteKeySet(DWORD dwProviderType = PROV_RSA_FULL,
55 LPCTSTR szContainer = NULL, LPCTSTR szProvider = MS_DEF_PROV,
56 DWORD dwFlags = 0) throw();
58 HRESULT Uninitialize();
60 HRESULT GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags = 0) throw();
61 HRESULT SetParam( DWORD dwParam, BYTE* pbData, DWORD dwFlags = 0) throw();
62 HRESULT GetName(__out_ecount_part_z(*pdwLength, *pdwLength) LPSTR szBuf, __inout DWORD * pdwLength) throw();
63 HRESULT GetContainer(__out_ecount_part_z(*pdwLength, *pdwLength) LPSTR szBuf, __inout DWORD * pdwLength) throw();
64 HRESULT GetImpType(DWORD * pdwImpType) throw();
65 HRESULT GetVersion(DWORD * pdwVersion) throw();
66 HRESULT GetProvType(DWORD * pdwType) throw();
67 HRESULT GetSecurityDesc(SECURITY_INFORMATION * pSecInfo) throw();
68 HRESULT SetSecurityDesc(SECURITY_INFORMATION SecInfo) throw();
70 HRESULT GenRandom(ULONG nLength, BYTE* pbBuffer ) throw();
72 inline HCRYPTPROV GetHandle() throw()
74 return m_hProv;
76 }; // class CCryptProv
79 // class CCryptHash
80 // Provides base functionality of hashes.
81 class CCryptHash
83 protected:
84 HCRYPTHASH m_hHash;
86 public:
87 CCryptHash() throw();
88 CCryptHash( const CCryptHash& hash ) throw();
89 explicit CCryptHash( HCRYPTHASH hHash, BOOL bTakeOwnership = FALSE ) throw();
90 ~CCryptHash() throw();
92 void Attach( HCRYPTHASH hHash, BOOL bTakeOwnership = FALSE ) throw();
93 void Destroy() throw();
94 HCRYPTHASH Detach() throw();
95 HCRYPTHASH Duplicate() const throw();
97 HRESULT Uninitialize() throw();
98 HRESULT Detach(HCRYPTHASH * phHash) throw();
99 HRESULT AddData(const BYTE * pbData, DWORD dwDataLen, DWORD dwFlags = 0) throw();
100 HRESULT AddString(LPCTSTR szData, DWORD dwFlags = 0) throw();
101 HRESULT GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags = 0) throw();
102 HRESULT SetParam(DWORD dwParam, BYTE * pbData, DWORD dwFlags = 0) throw();
103 HRESULT GetAlgId(ALG_ID * pAlgId) throw();
104 HRESULT GetSize(DWORD * pdwSize) throw();
105 HRESULT GetValue(BYTE * pBuf, DWORD * pdwSize) throw();
106 HRESULT SetValue(BYTE * pBuf) throw();
107 HRESULT Sign(
108 BYTE * pbSignature,
109 DWORD * pdwSigLen,
110 DWORD dwFlags = 0,
111 DWORD dwKeySpec = AT_SIGNATURE) throw();
112 HRESULT VerifySignature(
113 const BYTE * pbSignature,
114 DWORD pdwSignLen,
115 CCryptKey &PubKey,
116 DWORD dwFlags = 0) throw();
118 inline HCRYPTHASH GetHandle()
120 return m_hHash;
122 static CCryptHash EmptyHash;
124 }; // class CCryptHash
126 // class CCryptKey
127 // Provides the functionality for cryptographic keys, i.e. encrypting, decrypting.
128 class CCryptKey
130 protected:
131 HCRYPTKEY m_hKey;
133 public:
134 CCryptKey() throw();
135 CCryptKey( const CCryptKey& key ) throw();
136 explicit CCryptKey( HCRYPTKEY hKey, BOOL bTakeOwnership = FALSE ) throw();
137 ~CCryptKey() throw();
139 void Attach( HCRYPTKEY hKey, BOOL bTakeOwnership = FALSE ) throw();
140 void Destroy() throw();
141 HCRYPTKEY Detach() throw();
142 HCRYPTKEY Duplicate() const throw();
144 HRESULT Uninitialize() throw();
145 HRESULT Encrypt(
146 BOOL final,
147 BYTE * pbData,
148 DWORD * pdwDataLen,
149 DWORD dwBufLen,
150 CCryptHash &Hash = CCryptHash::EmptyHash) throw();
152 HRESULT Encrypt(
153 const BYTE * pbPlainText,
154 DWORD dwPlainTextLen,
155 BYTE * pbCipherText,
156 DWORD * pdwCipherTextLen,
157 CCryptHash &Hash = CCryptHash::EmptyHash) throw();
159 HRESULT Decrypt(
160 BOOL final,
161 BYTE * pbData,
162 DWORD * pdwDataLen,
163 CCryptHash &Hash = CCryptHash::EmptyHash) throw();
164 HRESULT Decrypt(
165 const BYTE * pbCipherText,
166 DWORD dwCipherTextLen,
167 BYTE * pbPlainText,
168 DWORD * pdwPlainTextLen,
169 CCryptHash &Hash = CCryptHash::EmptyHash) throw();
170 HRESULT EncryptString(
171 LPCTSTR szPlainText,
172 BYTE * pbCipherText,
173 DWORD * pdwCipherTextLen,
174 CCryptHash &Hash = CCryptHash::EmptyHash) throw();
175 HRESULT ExportSimpleBlob(
176 CCryptKey &ExpKey,
177 DWORD dwFlags,
178 BYTE * pbData,
179 DWORD * pdwDataLen) throw();
180 HRESULT ExportPublicKeyBlob(
181 CCryptKey &ExpKey,
182 DWORD dwFlags,
183 BYTE * pbData,
184 DWORD * pdwDataLen) throw();
185 HRESULT ExportPrivateKeyBlob(
186 CCryptKey &ExpKey,
187 DWORD dwFlags,
188 BYTE * pbData,
189 DWORD * pdwDataLen) throw();
190 HRESULT GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags = 0) throw();
191 HRESULT SetParam(DWORD dwParam, BYTE * pbData, DWORD dwFlags = 0) throw();
192 HRESULT GetAlgId(ALG_ID * pAlgId) throw();
193 HRESULT SetAlgId(ALG_ID AlgId, DWORD dwFlags) throw();
194 HRESULT GetBlockLength(DWORD * pdwBlockLen) throw();
195 HRESULT GetKeyLength(DWORD * pdwKeyLen) throw();
196 HRESULT GetSalt(BYTE * pbSalt, DWORD * pdwLength) throw();
197 HRESULT SetSalt(BYTE * pbSalt) throw();
198 HRESULT SetSaltEx(_CRYPTOAPI_BLOB * pBlobSalt) throw();
199 HRESULT GetPermissions(DWORD * pdwPerms) throw();
200 HRESULT SetPermissions(DWORD dwPerms) throw();
201 HRESULT GetP(BYTE * pbP, DWORD * pdwLength) throw();
202 HRESULT SetP(_CRYPTOAPI_BLOB * pBlobP) throw();
203 HRESULT SetP(BYTE * pbP, DWORD dwLength) throw();
204 HRESULT GetQ(BYTE * pbQ, DWORD * pdwLength) throw();
205 HRESULT SetQ(_CRYPTOAPI_BLOB * pBlobQ) throw();
206 HRESULT SetQ(BYTE * pbQ, DWORD dwLength) throw();
207 HRESULT GetG(BYTE * pbG, DWORD * pdwLength) throw();
208 HRESULT SetG(_CRYPTOAPI_BLOB * pBlobG) throw();
209 HRESULT SetG(BYTE * pbG, DWORD dwLength) throw();
210 HRESULT SetX() throw();
211 HRESULT GetEffKeyLen(DWORD * pdwEffKeyLen) throw();
212 HRESULT SetEffKeyLen(DWORD dwEffKeyLen) throw();
213 HRESULT GetPadding(DWORD * pdwPadding) throw();
214 HRESULT SetPadding(DWORD dwPadding) throw();
215 HRESULT GetIV(BYTE * pbIV, DWORD * pdwLength) throw();
216 HRESULT SetIV(BYTE * pbIV) throw();
217 HRESULT GetMode(DWORD * pdwMode) throw();
218 HRESULT SetMode(DWORD dwMode) throw();
219 HRESULT GetModeBits(DWORD * pdwModeBits) throw();
220 HRESULT SetModeBits(DWORD dwModeBits) throw();
222 inline HCRYPTKEY GetHandle() throw()
224 return m_hKey;
227 static CCryptKey EmptyKey;
228 }; // class CCryptKey
232 // Specific instances of Keys and Hashes
234 // class CCryptDerivedKey
235 // A key that is derived from a hashed password. Two keys derived
236 // from the same password will be identical.
237 class CCryptDerivedKey : public CCryptKey
239 public:
240 HRESULT Initialize(
241 CCryptProv &Prov,
242 CCryptHash &Hash,
243 ALG_ID algid = CALG_RC4,
244 DWORD dwFlags = CRYPT_EXPORTABLE) throw();
245 }; // class CCryptDerivedKey
247 // class CCryptRandomKey
248 // A randomly generated key. Can be used internally by a program
249 // to protect data during execution, or can be exported with Crypt.Export
251 // Currently it is possible to pass in AT_KEYEXCHANGE or AT_SIGNATURE
252 // for algid, but these two will generate keys for the current key set, and
253 // the resulting handle can only be used for exporting and importing keys or
254 // signing hashes.
255 class CCryptRandomKey : public CCryptKey
257 public:
258 HRESULT Initialize(
259 CCryptProv &Prov,
260 ALG_ID algid = CALG_RC4,
261 DWORD dwFlags = CRYPT_EXPORTABLE) throw();
262 }; // class CCryptRandomKey
264 // class CCryptUserExKey
265 // Obtains the user's key exchange key pair.
266 class CCryptUserExKey : public CCryptKey
268 public:
269 HRESULT Initialize(CCryptProv &Prov) throw();
270 HRESULT Create(CCryptProv &Prov) throw();
271 }; // class CCryptUserExKey
273 // class CCryptUserSigKey
274 // Obtains the user's signature key pair
275 class CCryptUserSigKey : public CCryptKey
277 public:
278 HRESULT Initialize(CCryptProv &Prov) throw();
279 HRESULT Create(CCryptProv &Prov) throw();
280 }; // class CCryptUserSigKey
282 // class CCryptImportKey
283 // Forms a key from an imported key blob
284 class CCryptImportKey : public CCryptKey
286 public:
287 HRESULT Initialize(
288 CCryptProv &Prov,
289 BYTE * pbData,
290 DWORD dwDataLen,
291 CCryptKey &PubKey,
292 DWORD dwFlags) throw();
293 }; // class CCryptImportKey
296 // class CCryptHash
297 // A generic hash that may or may not take a key.
298 class CCryptKeyedHash : public CCryptHash
300 public:
302 HRESULT Initialize(CCryptProv &Prov, ALG_ID Algid, CCryptKey &Key, DWORD dwFlags) throw();
303 }; // class CCryptKeyedHash
305 // class CCryptMD5Hash
306 // RSA's MD5 hash (RSA's most recent hash as of 9/7/99);
307 class CCryptMD5Hash : public CCryptHash
309 public:
311 HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
312 }; // class CCryptMD5Hash
314 // class CCryptMD4Hash
315 // RSA's MD4 hash
316 class CCryptMD4Hash : public CCryptHash
318 public:
320 HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
321 }; // class CCryptMD4Hash
324 // class CCryptMD2Hash
325 // RSA's MD2 hash
326 class CCryptMD2Hash : public CCryptHash
328 public:
330 HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
331 }; // class CCryptMD2Hash
334 // class CCryptSHAHash
335 // The Secure Hash Algorithm hash, from NIST and NSA. Technically, SHA-1.
336 class CCryptSHAHash : public CCryptHash
338 public:
340 HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
341 }; // class CCryptSHAHash
343 // The Secure Hash Algorithm, from NIST and NSA. Identical to CCryptSHA
344 typedef CCryptSHAHash CCryptSHA1Hash;
347 // class CCryptHMACHash
348 // Hash-base Message Authentication Code keyed hash
349 class CCryptHMACHash : public CCryptHash
351 public:
352 HRESULT Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText = NULL) throw();
353 }; // class CCryptHMACHash
355 // class CCryptMACHash
356 // Message Authentication Code keyed hash. Believed to be less secure than HMAC
357 class CCryptMACHash : public CCryptHash
359 public:
360 HRESULT Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText = NULL) throw();
361 }; // class CCryptMACHash
363 // class CCryptSSL3SHAMD5Hash
364 // Hash algorithm used by Secure Socket Layer
365 class CCryptSSL3SHAMD5Hash : public CCryptHash
367 public:
368 HRESULT Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText = NULL) throw();
369 }; // class CCryptSSl3SHAMD5Hash
371 }; // namespace ATL
374 #include <atlcrypt.inl>
375 #pragma pack(pop)
376 #endif // __ATLCRYPT_H__