The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

BCryptDuplicateHash function

The BCryptDuplicateHash function duplicates an existing hash or Message Authentication Code (MAC) object. The duplicate object contains all state and data contained in the original object at the point of duplication.


NTSTATUS WINAPI BCryptDuplicateHash(
  _Out_ BCRYPT_HASH_HANDLE *phNewHash,
  _Out_ PUCHAR             pbHashObject,
  _In_  ULONG              cbHashObject,
  _In_  ULONG              dwFlags


hHash [in]

The handle of the hash or MAC object to duplicate.

phNewHash [out]

A pointer to a BCRYPT_HASH_HANDLE value that receives the handle that represents the duplicate hash or MAC object.

pbHashObject [out]

A pointer to a buffer that receives the duplicate hash or MAC object. The cbHashObject parameter contains the size of this buffer. The required size of this buffer can be obtained by calling the BCryptGetProperty function to get the BCRYPT_OBJECT_LENGTH property. This will provide the size of the hash object for the specified algorithm.

When the duplicate hash handle is released, free this memory.

cbHashObject [in]

The size, in bytes, of the pbHashObject buffer.

dwFlags [in]

A set of flags that modify the behavior of this function. No flags are currently defined, so this parameter should be zero.

Return value

Returns a status code that indicates the success or failure of the function.

Possible return codes include, but are not limited to, the following.

Return codeDescription

The function was successful.


The size of the hash object specified by the cbHashObject parameter is not large enough to hold the hash object.


The hash handle in the hHash parameter is not valid.


One or more parameters are not valid.



This function is useful when computing a hash or MAC over a block of common data. After the common data has been processed, the hash or MAC object can be duplicated, and then the unique data can be added to the individual objects.

Depending on what processor modes a provider supports, BCryptDuplicateHash can be called either from user mode or kernel mode. Kernel mode callers can execute either at PASSIVE_LEVEL IRQL or DISPATCH_LEVEL IRQL. If the current IRQL level is DISPATCH_LEVEL, the handle provided in the hHash parameter must be derived from an algorithm handle returned by a provider that was opened by using the BCRYPT_PROV_DISPATCH flag, and any pointers passed to the BCryptDestroyKey function must refer to nonpaged (or locked) memory.

To call this function in kernel mode, use Cng.lib, which is part of the Driver Development Kit (DDK). For more information, see WDK and Developer Tools.

Windows Server 2008 and Windows Vista:  To call this function in kernel mode, use Ksecdd.lib.


Minimum supported client

Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]