CSecureChannelClient::MACInit
The MACInit method acquires a message authentication code (MAC) channel.
Syntax
HRESULT MACInit(HMAC*phMAC);
Parameters
phMAC
[out] Pointer to the MAC handle for the parameter data. The handle is acquired by MACInit to be used for subsequent MACUpdate and MACFinal calls. This datatype is declared in Sac.h installed with the Windows Media Format SDK.
Return Values
The method returns an HRESULT. All the interface methods in Windows Media Device Manager can return any of the following classes of error codes:
- Standard COM error codes
- Windows error codes converted to HRESULT values
- Windows Media Device Manager error codes
For an extenstive list of possible error codes, see Error Codes.
Possible values include, but are not limited to, those in the following table.
Return code | Description |
S_OK | The method succeeded. |
E_INVALIDARG | The phMAC parameter is invalid or is a NULL pointer. |
E_FAIL | An unspecified error occurred. |
Remarks
MACInit begins a message authentication code (MAC) session. For example, MACInit should be called before content is transferred when writing to a storage device to verify the MAC returned by the IMDSPStorage::GetRights call on the service provider.
Example Code
The following example code checks the MAC received by a call to IWMDMStorage::GetRights to verify that the data has not been tampered with.
HRESULT hr;
CSecureChannelClient *pSPClient = NULL;
hr = m_pStorage->GetRights(ppRights, pnRightsCount, abTempMAC);
if (SUCCEEDED(hr))
{
// Verify MAC returned by GetRights on the service provider.
pSPClient->MACInit(&hMAC);
pSPClient->MACUpdate(hMAC, (BYTE*)(*ppRights),
sizeof(WMDMRIGHTS) * (*pnRightsCount));
pSPClient->MACUpdate(hMAC, (BYTE*)(pnRightsCount),
sizeof(*pnRightsCount));
pSPClient->MACFinal(hMAC, abMACVerify);
if (memcmp(abMACVerify, abTempMAC, WMDM_MAC_LENGTH) != 0)
{
hr = WMDM_E_MAC_CHECK_FAILED;
goto exit;
}
}
Requirements
Header: Include scclient.h.
Library: mssachlp.lib
See Also