miscAlgFactory.cpp [plain text]
#include "miscAlgFactory.h"
#include <AES/aescspi.h>
#include "desContext.h"
#include "rc2Context.h"
#include "rc4Context.h"
#include "rc5Context.h"
#include "MacContext.h"
#include "DigestContext.h"
#include "SHA1_MD5_Object.h"
#include "MD2Object.h"
#include <Security/cssmapple.h>
#define HMAC_BOGUS_ENABLE 0
#ifdef BSAFE_CSP_ENABLE
#define MAF_DES_ENABLE 0
#define MAF_DES3_ENABLE 0
#define MAF_RC2_ENABLE 0
#define MAF_RC4_ENABLE 0
#define MAF_RC5_ENABLE 0
#define MAF_MAC_ENABLE 0
#else
#define MAF_DES_ENABLE 1
#define MAF_DES3_ENABLE 1
#define MAF_RC2_ENABLE 1
#define MAF_RC4_ENABLE 1
#define MAF_RC5_ENABLE 1
#define MAF_MAC_ENABLE 1
#endif
#if (!MAF_DES_ENABLE || !MAF_DES3_ENABLE || !MAF_RC2_ENABLE || !MAF_RC4_ENABLE || \
!MAF_RC5_ENABLE || !MAF_MAC_ENABLE)
#warning Internal DES/RC2/RC4/RC5/Mac implementation disabled!
#endif
bool MiscAlgFactory::setup(
AppleCSPSession &session,
CSPFullPluginSession::CSPContext * &cspCtx,
const Context &context)
{
CSSM_CONTEXT_TYPE ctype = context.type();
CSSM_ALGORITHMS alg = context.algorithm();
switch(ctype) {
case CSSM_ALGCLASS_SYMMETRIC:
switch(alg) {
case CSSM_ALGID_AES:
if(cspCtx == NULL) {
cspCtx = new AESContext(session);
}
return true;
#if MAF_DES_ENABLE
case CSSM_ALGID_DES:
if(cspCtx == NULL) {
cspCtx = new DESContext(session);
}
return true;
#endif
#if MAF_DES3_ENABLE
case CSSM_ALGID_3DES_3KEY_EDE:
if(cspCtx == NULL) {
cspCtx = new DES3Context(session);
}
return true;
#endif
#if MAF_RC2_ENABLE
case CSSM_ALGID_RC2:
if(cspCtx == NULL) {
cspCtx = new RC2Context(session);
}
return true;
#endif
#if MAF_RC4_ENABLE
case CSSM_ALGID_RC4:
if(cspCtx == NULL) {
cspCtx = new RC4Context(session);
}
return true;
#endif
#if MAF_RC5_ENABLE
case CSSM_ALGID_RC5:
if(cspCtx == NULL) {
cspCtx = new RC5Context(session);
}
return true;
#endif
default:
break; } break;
case CSSM_ALGCLASS_DIGEST:
switch(alg) {
case CSSM_ALGID_SHA1:
if(cspCtx == NULL) {
cspCtx = new DigestContext(session,
*(new SHA1Object));
}
return true;
case CSSM_ALGID_MD5:
if(cspCtx == NULL) {
cspCtx = new DigestContext(session,
*(new MD5Object));
}
return true;
case CSSM_ALGID_MD2:
if(cspCtx == NULL) {
cspCtx = new DigestContext(session,
*(new MD2Object));
}
return true;
default:
break; } break;
case CSSM_ALGCLASS_KEYGEN:
switch(alg) {
case CSSM_ALGID_AES:
if(cspCtx == NULL) {
cspCtx = new AESKeyGenContext(session);
}
return true;
#if MAF_DES_ENABLE
case CSSM_ALGID_DES:
if(cspCtx == NULL) {
cspCtx = new AppleSymmKeyGenerator(session,
DES_KEY_SIZE_BITS_EXTERNAL,
DES_KEY_SIZE_BITS_EXTERNAL,
true); }
return true;
#endif
#if MAF_DES3_ENABLE
case CSSM_ALGID_3DES_3KEY_EDE:
if(cspCtx == NULL) {
cspCtx = new AppleSymmKeyGenerator(session,
DES3_KEY_SIZE_BYTES * 8,
DES3_KEY_SIZE_BYTES * 8,
true); }
return true;
#endif
#if MAF_RC2_ENABLE
case CSSM_ALGID_RC2:
if(cspCtx == NULL) {
cspCtx = new AppleSymmKeyGenerator(session,
RC2_MIN_KEY_SIZE_BYTES * 8,
RC2_MAX_KEY_SIZE_BYTES * 8,
true); }
return true;
#endif
#if MAF_RC4_ENABLE
case CSSM_ALGID_RC4:
if(cspCtx == NULL) {
cspCtx = new AppleSymmKeyGenerator(session,
RC4_MIN_KEY_SIZE_BYTES * 8,
RC4_MAX_KEY_SIZE_BYTES * 8,
true); }
return true;
#endif
#if MAF_RC5_ENABLE
case CSSM_ALGID_RC5:
if(cspCtx == NULL) {
cspCtx = new AppleSymmKeyGenerator(session,
RC5_MIN_KEY_SIZE_BYTES * 8,
RC5_MAX_KEY_SIZE_BYTES * 8,
true); }
return true;
#endif
#if MAF_MAC_ENABLE
case CSSM_ALGID_SHA1HMAC:
if(cspCtx == NULL) {
cspCtx = new AppleSymmKeyGenerator(session,
HMAC_MIN_KEY_SIZE * 8,
HMAC_MAX_KEY_SIZE * 8,
true); }
return true;
#endif
default:
break; } break;
case CSSM_ALGCLASS_MAC:
switch(alg) {
#if MAF_MAC_ENABLE
case CSSM_ALGID_SHA1HMAC:
if(cspCtx == NULL) {
#if HMAC_BOGUS_ENABLE
cspCtx = new MacLegacyContext(session);
#else
cspCtx = new MacContext(session);
#endif
}
return true;
#endif
#if CRYPTKIT_CSP_ENABLE
case CSSM_ALGID_SHA1HMAC_LEGACY:
if(cspCtx == NULL) {
cspCtx = new MacLegacyContext(session);
}
return true;
#endif
default:
break;
}
break;
default:
break; }
return false;
}