X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/bac41a7b9a0a9254fa30f8bb6e6038ab71a483e2..67c7378dcb8de24c86b7fedff90b4b496f2e474c:/AppleCSP/MiscCSPAlgs/miscAlgFactory.cpp diff --git a/AppleCSP/MiscCSPAlgs/miscAlgFactory.cpp b/AppleCSP/MiscCSPAlgs/miscAlgFactory.cpp index 2e7e848b..a02d49b8 100644 --- a/AppleCSP/MiscCSPAlgs/miscAlgFactory.cpp +++ b/AppleCSP/MiscCSPAlgs/miscAlgFactory.cpp @@ -23,6 +23,7 @@ #include "miscAlgFactory.h" #include +#include #include "desContext.h" #include "rc2Context.h" #include "rc4Context.h" @@ -31,15 +32,9 @@ #include "DigestContext.h" #include "SHA1_MD5_Object.h" /* raw digest */ #include "MD2Object.h" +#include "NullCryptor.h" #include -/* - * normally CSSM_ALGID_SHA1HMAC_LEGACY maps to a MacLegacyContext if - * CRYPTKIT_CSP_ENABLE is true. For quick testing, we also map - * CSSM_ALGID_SHA1HMAC to MacLegacyContext. - */ -#define HMAC_BOGUS_ENABLE 0 - /* * These #defines are mainly to facilitate measuring the performance of our own * implementation vs. the ones in BSafe. This factory gets called first; if @@ -83,7 +78,20 @@ bool MiscAlgFactory::setup( switch(alg) { case CSSM_ALGID_AES: if(cspCtx == NULL) { - cspCtx = new AESContext(session); + /* + * Get optional block size to determine correct implementation + */ + uint32 blockSize = context.getInt(CSSM_ATTRIBUTE_BLOCK_SIZE); + if(blockSize == 0) { + blockSize = GLADMAN_BLOCK_SIZE_BYTES; + } + if(GLADMAN_AES_128_ENABLE && + (blockSize == GLADMAN_BLOCK_SIZE_BYTES)) { + cspCtx = new GAESContext(session); + } + else { + cspCtx = new AESContext(session); + } } return true; @@ -132,6 +140,14 @@ bool MiscAlgFactory::setup( return true; #endif + #if NULL_CRYPT_ENABLE + case CSSM_ALGID_NONE: + if(cspCtx == NULL) { + cspCtx = new NullCryptor(session); + } + return true; + #endif /* NULL_CRYPT_ENABLE */ + default: break; // not our symmetric alg } // switch alg for symmetric @@ -233,13 +249,32 @@ bool MiscAlgFactory::setup( case CSSM_ALGID_SHA1HMAC: if(cspCtx == NULL) { cspCtx = new AppleSymmKeyGenerator(session, - HMAC_MIN_KEY_SIZE * 8, + HMAC_SHA_MIN_KEY_SIZE * 8, + HMAC_MAX_KEY_SIZE * 8, + true); // must be byte size + } + return true; + case CSSM_ALGID_MD5HMAC: + if(cspCtx == NULL) { + cspCtx = new AppleSymmKeyGenerator(session, + HMAC_MD5_MIN_KEY_SIZE * 8, HMAC_MAX_KEY_SIZE * 8, true); // must be byte size } return true; #endif + #if NULL_CRYPT_ENABLE + case CSSM_ALGID_NONE: + if(cspCtx == NULL) { + cspCtx = new AppleSymmKeyGenerator(session, + NULL_CRYPT_BLOCK_SIZE * 8, + NULL_CRYPT_BLOCK_SIZE * 8, + true); // must be byte size + } + return true; + #endif /* NULL_CRYPT_ENABLE */ + default: break; // not our keygen alg } // switch alg for keygen @@ -249,20 +284,16 @@ bool MiscAlgFactory::setup( switch(alg) { #if MAF_MAC_ENABLE case CSSM_ALGID_SHA1HMAC: + case CSSM_ALGID_MD5HMAC: if(cspCtx == NULL) { - #if HMAC_BOGUS_ENABLE - /* quick hack for Keychain Access testing */ - cspCtx = new MacLegacyContext(session); - #else - cspCtx = new MacContext(session); - #endif + cspCtx = new MacContext(session, alg); } return true; #endif #if CRYPTKIT_CSP_ENABLE case CSSM_ALGID_SHA1HMAC_LEGACY: if(cspCtx == NULL) { - cspCtx = new MacLegacyContext(session); + cspCtx = new MacLegacyContext(session, alg); } return true; #endif