Share via


CryptSetHashParam (Windows Embedded CE 6.0)

1/6/2010

This function customizes the operations of a hash object. Currently, only a single parameter is defined for this function.

Syntax

BOOL WINAPI CryptSetHashParam( 
  HCRYPTHASH hHash,
  DWORD dwParam, 
  BYTE* pbData, 
  DWORD dwFlags
);

Parameters

  • hHash
    [in] HCRYPTHASH handle to the hash object on which to set parameters.
  • dwParam
    [in] Specifies the parameter value.

    The following table shows the possible values.

    Value Description

    HP_HASHVAL

    Byte array containing a hash value to place directly into the hash object. Before setting this value, the size of the hash value must be determined by reading the HP_HASHSIZE value with the CryptGetHashParam function.

    Some CSPs do not support this capability.

    HP_HMAC_INFO

    HMAC_INFO structure that specifies the underlying hash algorithm and any optional parameters.

    Some cryptographic service provider (CSP) types can add additional values that can be set with this function.

  • pbData
    [in] Pointer to a parameter data buffer. Place the parameter data in this buffer before calling the CryptSetHashParam function. The form of this data varies depending on the parameter number.
  • dwFlags
    [in] Reserved for future use and must be set to zero.

Return Value

TRUE indicates success. FALSE indicates failure. To get extended error information, call the GetLastError function.

The following table shows the common values for the GetLastError function. The error values prefaced by NTE are generated by the particular CSP you are using.

Value Description

ERROR_INVALID_HANDLE

One of the parameters specifies an invalid handle.

ERROR_BUSY

The CSP context is currently being used by another process.

ERROR_INVALID_PARAMETER

One of the parameters contains an invalid value. This is most often an illegal pointer.

NTE_BAD_FLAGS

The dwFlags parameter is nonzero or the pbData buffer contains an invalid value.

NTE_BAD_HASH

The hash object specified by the hHash parameter is invalid.

NTE_BAD_TYPE

The dwParam parameter specifies an unknown parameter.

NTE_BAD_UID

The CSP context that was specified when the hKey key was created cannot be found.

NTE_FAIL

The function failed in some unexpected way.

Remarks

Occasionally, a hash value that has been generated elsewhere must be signed. The following sequence of operations accomplishes the task:

  1. Create a hash object with CryptCreateHash.
  2. Set the dwParam parameter to HP_HASHVAL.
  3. Sign the hash value by using CryptSignHash, thereby obtaining a digital signature block.
  4. Destroy the hash object by using CryptDestroyHash.

Example Code

// EXAMPLE CODE FOR USING CryptSetHashParam
// Set up the variables.
HCRYPTHASH   hHash; // A handle to the hash object on which to set
 // parameters
DWORD dwParam; // dwParam- paramater # can be HP_HMAC_INFO-
 // initialized elsewhere
BYTE pbData[16]; // The parameter data buffer
DWORD dwFlags = 0;// set to zero
BOOL Return;
Return = CryptSetHashParam(hHash, dwParam, pbData, dwFlags);
if (Return) {
 cout<< "function succeeds"<< endl;
}
else {
 cout<< "retrieve error"<< endl;
}

Requirements

Header wincrypt.h
Library coredll.lib
Windows Embedded CE Windows CE 2.10 and later

See Also

Reference

Cryptography Functions
CryptCreateHash
CryptDestroyHash
CryptGetHashParam
CryptSetKeyParam
CryptSignHash
HMAC_INFO