Information
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.

BCryptCreateHash function

The BCryptCreateHash function is called to create a hash or Message Authentication Code (MAC) object.

Syntax


NTSTATUS WINAPI BCryptCreateHash(
  _Inout_   BCRYPT_ALG_HANDLE hAlgorithm,
  _Out_     BCRYPT_HASH_HANDLE *phHash,
  _Out_     PUCHAR pbHashObject,
  _In_opt_  ULONG cbHashObject,
  _In_opt_  PUCHAR pbSecret,
  _In_      ULONG cbSecret,
  _In_      ULONG dwFlags
);

Parameters

hAlgorithm [in, out]

The handle of an algorithm provider created by using the BCryptOpenAlgorithmProvider function. The algorithm that was specified when the provider was created must support the hash interface.

phHash [out]

A pointer to a BCRYPT_HASH_HANDLE value that receives a handle that represents the hash or MAC object. This handle is used in subsequent hashing or MAC functions, such as the BCryptHashData function. When you have finished using this handle, release it by passing it to the BCryptDestroyHash function.

pbHashObject [out]

A pointer to a buffer that receives the 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 or MAC object for the specified algorithm.

This memory can only be freed after the handle pointed to by the phHash parameter is destroyed.

If the value of this parameter is NULL and the value of the cbHashObject parameter is zero, the memory for the hash object is allocated and freed by this function.

Windows Vista:  This memory management functionality is available beginning with Windows Vista with SP1.

cbHashObject [in, optional]

The size, in bytes, of the pbHashObject buffer.

If the value of this parameter is zero and the value of the pbHashObject parameter is NULL, the memory for the key object is allocated and freed by this function.

Windows Vista:  This memory management functionality is available beginning with Windows Vista with SP1.

pbSecret [in, optional]

A pointer to a buffer that contains the key to use for the hash or MAC. The cbSecret parameter contains the size of this buffer. This key only applies to hash algorithms opened by the BCryptOpenAlgorithmProvider function by using the BCRYPT_ALG_HANDLE_HMAC flag. Otherwise, set this parameter to NULL.

cbSecret [in]

The size, in bytes, of the pbSecret buffer. If no key is used, set this parameter to zero.

dwFlags [in]

Flags that modify the behavior of the function. This can be zero or the following value.

ValueMeaning
BCRYPT_HASH_REUSABLE_FLAG

Creates a reusable hashing object. The object can be used for a new hashing operation immediately after calling BCryptFinishHash. For more information, see Creating a Hash with CNG.

Windows Server 2008 R2, Windows 7, Windows Server 2008, and Windows Vista:  This flag is not supported.

 

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
STATUS_SUCCESS

The function was successful.

STATUS_BUFFER_TOO_SMALL

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

STATUS_INVALID_HANDLE

The algorithm handle in the hAlgorithm parameter is not valid.

STATUS_INVALID_PARAMETER

One or more parameters are not valid.

STATUS_NOT_SUPPORTED

The algorithm provider specified by the hAlgorithm parameter does not support the hash interface.

 

Remarks

Depending on what processor modes a provider supports, BCryptCreateHash 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 hAlgorithm parameter must have been opened by using the BCRYPT_PROV_DISPATCH flag, and any pointers passed to the BCryptCreateHash 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.

Requirements

Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 [desktop apps only]

Header

Bcrypt.h

Library

Bcrypt.lib

DLL

Bcrypt.dll

See also

BCryptDestroyHash

 

 

Community Additions

Show:
© 2014 Microsoft