]>
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>
34 #include <Security/digestobject.h>
36 CssmAllocator
*CryptKitFactory::normAllocator
;
37 CssmAllocator
*CryptKitFactory::privAllocator
;
40 * CryptKit-style memory allocator callbacks
42 static void *ckMalloc(unsigned size
)
44 return CryptKitFactory::privAllocator
->malloc(size
);
46 static void ckFree(void *data
)
48 CryptKitFactory::privAllocator
->free(data
);
50 static void *ckRealloc(void *oldPtr
, unsigned newSize
)
52 return CryptKitFactory::privAllocator
->realloc(oldPtr
, newSize
);
56 // Manage the CryptKit algorithm factory
59 CryptKitFactory::CryptKitFactory(CssmAllocator
*normAlloc
, CssmAllocator
*privAlloc
)
61 setNormAllocator(normAlloc
);
62 setPrivAllocator(privAlloc
);
63 /* once-per-address space */
65 fallocRegister(ckMalloc
, ckFree
, ckRealloc
);
68 CryptKitFactory::~CryptKitFactory()
73 bool CryptKitFactory::setup(
74 AppleCSPSession
&session
,
75 CSPFullPluginSession::CSPContext
* &cspCtx
,
76 const Context
&context
)
78 switch(context
.type()) {
79 case CSSM_ALGCLASS_SIGNATURE
:
80 switch(context
.algorithm()) {
81 case CSSM_ALGID_FEE_MD5
:
83 cspCtx
= new SignatureContext(session
,
85 *(new FEERawSigner(feeRandCallback
,
91 case CSSM_ALGID_FEE_SHA1
:
93 cspCtx
= new SignatureContext(session
,
95 *(new FEERawSigner(feeRandCallback
,
101 case CSSM_ALGID_SHA1WithECDSA
:
103 cspCtx
= new SignatureContext(session
,
105 *(new FEEECDSASigner(feeRandCallback
,
113 cspCtx
= new SignatureContext(session
,
115 *(new FEERawSigner(feeRandCallback
,
121 case CSSM_ALGID_ECDSA
:
123 cspCtx
= new SignatureContext(session
,
125 *(new FEEECDSASigner(feeRandCallback
,
136 case CSSM_ALGCLASS_KEYGEN
:
137 switch(context
.algorithm()) {
140 cspCtx
= new CryptKit::FEEKeyPairGenContext(session
, context
);
148 case CSSM_ALGCLASS_ASYMMETRIC
:
149 switch(context
.algorithm()) {
150 case CSSM_ALGID_FEEDEXP
:
152 cspCtx
= new CryptKit::FEEDExpContext(session
);
155 case CSSM_ALGID_FEED
:
157 cspCtx
= new CryptKit::FEEDContext(session
);
165 /* more here - symmetric, etc. */
169 /* not implemented here */
173 #endif /* CRYPTKIT_CSP_ENABLE */