Platform SDK: Cryptography

CPDuplicateHash

The CPDuplicateHash function makes an exact copy of a hash and its state.

BOOL CPDuplicateHash(
  HCRYPTPROV hUID,          // in
  HCRYPTHASH hHash,         // in
  DWORD *pdwReserved,       // in
  DWORD dwFlags,            // in
  HCRYPTHASH *phHash        // out
);

Parameters

hUID
Handle to a particular key container within the CSP. This handle is obtained by a call to CPAcquireContext.
hHash
The handle to the hash to be duplicated.
pdwReserved
This parameter is reserved for future use and must be NULL.
dwFlags
This parameter is reserved for future use and must be zero.
phHash
The address of the handle to the duplicated hash. Must be the address of a buffer with enough memory allocated to hold the duplicated hash.

Return Values

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE, and the appropriate error code from the following table must be set using SetLastError.

Error Description
ERROR_CALL_
NOT_IMPLEMENTED
This is a new function and existing CSPs might not implement it. This error is returned if the CSP does not support this function.
ERROR_INVALID_
PARAMETER
One of the parameters contains an invalid value. This is most often an illegal pointer.
NTE_BAD_HASH The handle to the original hash is not valid.

Remarks

CPDuplicateHash makes a copy of a hash including its exact state. To generate two different hashes starting with some common hashed data,

  1. create a single hash object
  2. hash the common data to that object
  3. duplicate the object the CPDuplicateHash function.
  4. hash different data to the original hash object and the newly create object

CPDestroyHash must be called to destroy any hashes created with CPDuplicateHash. Destroying the original hash does not cause the duplicate hash to be destroyed. Once a duplicate hash is made, it is separate from the original hash. There is no shared state between the two hashes.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 95 OSR2 or later (or Windows 95 with Internet Explorer 3.02 or later).
  Header: Declared in Wincrypt.h.

See Also

CPDestroyHash, CryptDuplicateHash