]>
git.saurik.com Git - apple/security.git/blob - AppleCSP/CryptKitCSP/cryptkitcsp.cpp
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // cryptkitcsp - top C++ implementation layer for CryptKit
23 #ifdef CRYPTKIT_CSP_ENABLE
25 #include "cryptkitcsp.h"
26 #include "FEESignatureObject.h" /* raw signer */
27 #include <AppleCSP/SignatureContext.h>
29 #include "FEEAsymmetricContext.h"
30 #include <Security/cssmapple.h>
31 #include <CryptKit/falloc.h>
32 #include <CryptKit/feeFunctions.h>
33 #include <MiscCSPAlgs/SHA1_MD5_Object.h>
35 CssmAllocator
*CryptKitFactory::normAllocator
;
36 CssmAllocator
*CryptKitFactory::privAllocator
;
39 * CryptKit-style memory allocator callbacks
41 static void *ckMalloc(unsigned size
)
43 return CryptKitFactory::privAllocator
->malloc(size
);
45 static void ckFree(void *data
)
47 CryptKitFactory::privAllocator
->free(data
);
49 static void *ckRealloc(void *oldPtr
, unsigned newSize
)
51 return CryptKitFactory::privAllocator
->realloc(oldPtr
, newSize
);
55 // Manage the CryptKit algorithm factory
58 CryptKitFactory::CryptKitFactory(CssmAllocator
*normAlloc
, CssmAllocator
*privAlloc
)
60 setNormAllocator(normAlloc
);
61 setPrivAllocator(privAlloc
);
62 /* once-per-address space */
64 fallocRegister(ckMalloc
, ckFree
, ckRealloc
);
67 CryptKitFactory::~CryptKitFactory()
72 bool CryptKitFactory::setup(
73 AppleCSPSession
&session
,
74 CSPFullPluginSession::CSPContext
* &cspCtx
,
75 const Context
&context
)
77 switch(context
.type()) {
78 case CSSM_ALGCLASS_SIGNATURE
:
79 switch(context
.algorithm()) {
80 case CSSM_ALGID_FEE_MD5
:
82 cspCtx
= new SignatureContext(session
,
84 *(new FEERawSigner(feeRandCallback
,
90 case CSSM_ALGID_FEE_SHA1
:
92 cspCtx
= new SignatureContext(session
,
94 *(new FEERawSigner(feeRandCallback
,
100 case CSSM_ALGID_SHA1WithECDSA
:
102 cspCtx
= new SignatureContext(session
,
104 *(new FEEECDSASigner(feeRandCallback
,
115 case CSSM_ALGCLASS_KEYGEN
:
116 switch(context
.algorithm()) {
119 cspCtx
= new CryptKit::FEEKeyPairGenContext(session
, context
);
127 case CSSM_ALGCLASS_ASYMMETRIC
:
128 switch(context
.algorithm()) {
129 case CSSM_ALGID_FEEDEXP
:
131 cspCtx
= new CryptKit::FEEDExpContext(session
);
134 case CSSM_ALGID_FEED
:
136 cspCtx
= new CryptKit::FEEDContext(session
);
144 /* more here - symmetric, etc. */
148 /* not implemented here */
152 #endif /* CRYPTKIT_CSP_ENABLE */