#include <Security/macclient.h>
using namespace CssmClient;
void MacContext::activate()
{
if (!mActive)
{
check(CSSM_CSP_CreateMacContext(attachment()->handle(), mAlgorithm,
mKey, &mHandle));
mActive = true;
}
}
void GenerateMac::sign(const CssmData *data, uint32 count, CssmData &mac)
{
unstaged();
check(CSSM_GenerateMac(handle(), data, count, &mac));
}
void GenerateMac::init()
{
check(CSSM_GenerateMacInit(handle()));
mStaged = true;
}
void GenerateMac::sign(const CssmData *data, uint32 count)
{
staged();
check(CSSM_GenerateMacUpdate(handle(), data, count));
}
void GenerateMac::operator () (CssmData &mac)
{
staged();
check(CSSM_GenerateMacFinal(handle(), &mac));
mStaged = false;
}
void VerifyMac::verify(const CssmData *data, uint32 count, const CssmData &mac)
{
unstaged();
check(CSSM_VerifyMac(handle(), data, count, &mac));
}
void VerifyMac::init()
{
check(CSSM_VerifyMacInit(handle()));
mStaged = true;
}
void VerifyMac::verify(const CssmData *data, uint32 count)
{
staged();
check(CSSM_VerifyMacUpdate(handle(), data, count));
}
void VerifyMac::operator () (const CssmData &mac)
{
staged();
check(CSSM_VerifyMacFinal(handle(), &mac));
mStaged = false;
}