The CPDuplicateHash function is used to make an exact copy of a hash and the state the hash is in.
BOOL CPDuplicateHash(
HCRYPTPROV hProv, // in
HCRYPTHASH hHash, // in
DWORD *pdwReserved, // in
DWORD dwFlags, // in
HCRYPTHASH phHash // out
);
If the function succeeds, the return value is TRUE; Otherwise, return FALSE. When FALSE is returned, the appropriate error code (see the following table) must be set via SetLastError.
Error | Description |
---|---|
ERROR_CALL_NOT_IMPLEMENTED | Since this is a new function, existing CSPs may 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. |
CPDuplicateHash is used to make copies of hashes (also known as message digests) and the exact state of the hash. For example a caller may want to generate two hashes, but both hashes have to start with some common data hashed. A hash could be created, the common data hashed, a duplicate made with the CPDuplicateHash function, and then the data unique to each hash would be hashed. The handle to the duplicated hash, phHash, allows the developer to utilize the duplicated hash independently of the original hash.
CPDestroyHash must be called to destroy any hashes that are 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.
CPDestroyHash, CryptDuplicateHash