#ifdef CRYPTKIT_CSP_ENABLE
#include "cryptkitcsp.h"
#include "FEESignatureObject.h"
#include <AppleCSP/SignatureContext.h>
#include "FEEKeys.h"
#include "FEEAsymmetricContext.h"
#include <Security/cssmapple.h>
#include <CryptKit/falloc.h>
#include <CryptKit/feeFunctions.h>
#include <MiscCSPAlgs/SHA1_MD5_Object.h>
#include <Security/digestobject.h>
CssmAllocator *CryptKitFactory::normAllocator;
CssmAllocator *CryptKitFactory::privAllocator;
static void *ckMalloc(unsigned size)
{
return CryptKitFactory::privAllocator->malloc(size);
}
static void ckFree(void *data)
{
CryptKitFactory::privAllocator->free(data);
}
static void *ckRealloc(void *oldPtr, unsigned newSize)
{
return CryptKitFactory::privAllocator->realloc(oldPtr, newSize);
}
CryptKitFactory::CryptKitFactory(CssmAllocator *normAlloc, CssmAllocator *privAlloc)
{
setNormAllocator(normAlloc);
setPrivAllocator(privAlloc);
initCryptKit();
fallocRegister(ckMalloc, ckFree, ckRealloc);
}
CryptKitFactory::~CryptKitFactory()
{
terminateCryptKit();
}
bool CryptKitFactory::setup(
AppleCSPSession &session,
CSPFullPluginSession::CSPContext * &cspCtx,
const Context &context)
{
switch(context.type()) {
case CSSM_ALGCLASS_SIGNATURE:
switch(context.algorithm()) {
case CSSM_ALGID_FEE_MD5:
if(cspCtx == NULL) {
cspCtx = new SignatureContext(session,
*(new MD5Object()),
*(new FEERawSigner(feeRandCallback,
&session,
session,
*privAllocator)));
}
return true;
case CSSM_ALGID_FEE_SHA1:
if(cspCtx == NULL) {
cspCtx = new SignatureContext(session,
*(new SHA1Object()),
*(new FEERawSigner(feeRandCallback,
&session,
session,
*privAllocator)));
}
return true;
case CSSM_ALGID_SHA1WithECDSA:
if(cspCtx == NULL) {
cspCtx = new SignatureContext(session,
*(new SHA1Object()),
*(new FEEECDSASigner(feeRandCallback,
&session,
session,
*privAllocator)));
}
return true;
case CSSM_ALGID_FEE:
if(cspCtx == NULL) {
cspCtx = new SignatureContext(session,
*(new NullDigest()),
*(new FEERawSigner(feeRandCallback,
&session,
session,
*privAllocator)));
}
return true;
case CSSM_ALGID_ECDSA:
if(cspCtx == NULL) {
cspCtx = new SignatureContext(session,
*(new NullDigest()),
*(new FEEECDSASigner(feeRandCallback,
&session,
session,
*privAllocator)));
}
return true;
default:
break;
}
break;
case CSSM_ALGCLASS_KEYGEN:
switch(context.algorithm()) {
case CSSM_ALGID_FEE:
if(cspCtx == NULL) {
cspCtx = new CryptKit::FEEKeyPairGenContext(session, context);
}
return true;
default:
break;
}
break;
case CSSM_ALGCLASS_ASYMMETRIC:
switch(context.algorithm()) {
case CSSM_ALGID_FEEDEXP:
if(cspCtx == NULL) {
cspCtx = new CryptKit::FEEDExpContext(session);
}
return true;
case CSSM_ALGID_FEED:
if(cspCtx == NULL) {
cspCtx = new CryptKit::FEEDContext(session);
}
return true;
default:
break;
}
break;
default:
break;
}
return false;
}
#endif