]>
git.saurik.com Git - apple/security.git/blob - AppleCSP/RSA_DSA/RSA_DSA_csp.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 * RSA_DSA_csp.cpp - Algorithm factory for RSA/DSA
23 #include "RSA_DSA_csp.h"
24 #include "RSA_DSA_signature.h" /* raw signer */
25 #include <MiscCSPAlgs/SHA1_MD5_Object.h> /* raw digest */
26 #include <AppleCSP/SignatureContext.h>
27 #include <Security/digestobject.h>
28 #include "RSA_DSA_keys.h"
29 #include "RSA_asymmetric.h"
30 #include <MiscCSPAlgs/MD2Object.h>
31 #include <Security/cssmapple.h>
33 #define OPENSSL_DSA_ENABLE 1
35 CssmAllocator
*RSA_DSA_Factory::normAllocator
;
36 CssmAllocator
*RSA_DSA_Factory::privAllocator
;
38 /* normally found in crypto.h, which has way too much useless cruft....move these to
39 * a local header.... */
41 extern int CRYPTO_set_mem_functions(
43 void *(*r
)(void *,size_t),
45 int CRYPTO_set_locked_mem_functions(
47 void (*free_func
)(void *));
51 * openssl-style memory allocator callbacks
53 static void *osMalloc(size_t size
)
55 return RSA_DSA_Factory::privAllocator
->malloc(size
);
57 static void osFree(void *data
)
59 RSA_DSA_Factory::privAllocator
->free(data
);
61 static void *osRealloc(void *oldPtr
, size_t newSize
)
63 return RSA_DSA_Factory::privAllocator
->realloc(oldPtr
, newSize
);
66 RSA_DSA_Factory::RSA_DSA_Factory(CssmAllocator
*normAlloc
, CssmAllocator
*privAlloc
)
68 setNormAllocator(normAlloc
);
69 setPrivAllocator(privAlloc
);
70 /* once-per-address space */
71 CRYPTO_set_mem_functions(osMalloc
, osRealloc
, osFree
);
72 CRYPTO_set_locked_mem_functions(osMalloc
, osFree
);
73 /* these should go in a lib somewhere */
74 ERR_load_RSA_strings();
75 ERR_load_BN_strings();
76 ERR_load_DSA_strings();
79 RSA_DSA_Factory::~RSA_DSA_Factory()
81 // TBD terminateCryptKit();
84 bool RSA_DSA_Factory::setup(
85 AppleCSPSession
&session
,
86 CSPFullPluginSession::CSPContext
* &cspCtx
,
87 const Context
&context
)
89 switch(context
.type()) {
90 case CSSM_ALGCLASS_SIGNATURE
:
91 switch(context
.algorithm()) {
92 case CSSM_ALGID_SHA1WithRSA
:
94 cspCtx
= new SignatureContext(session
,
96 *(new RSASigner(*privAllocator
,
101 case CSSM_ALGID_MD5WithRSA
:
103 cspCtx
= new SignatureContext(session
,
105 *(new RSASigner(*privAllocator
,
110 case CSSM_ALGID_MD2WithRSA
:
112 cspCtx
= new SignatureContext(session
,
114 *(new RSASigner(*privAllocator
,
119 #if OPENSSL_DSA_ENABLE
120 case CSSM_ALGID_SHA1WithDSA
:
122 cspCtx
= new SignatureContext(session
,
124 *(new DSASigner(*privAllocator
,
131 cspCtx
= new SignatureContext(session
,
133 *(new DSASigner(*privAllocator
,
135 // set later via setDigestAlgorithm but not used by DSA
142 cspCtx
= new SignatureContext(session
,
144 *(new RSASigner(*privAllocator
,
146 // set later via setDigestAlgorithm
155 case CSSM_ALGCLASS_KEYGEN
:
156 switch(context
.algorithm()) {
159 cspCtx
= new RSAKeyPairGenContext(session
, context
);
162 #if OPENSSL_DSA_ENABLE
165 cspCtx
= new DSAKeyPairGenContext(session
, context
);
174 case CSSM_ALGCLASS_ASYMMETRIC
:
175 switch(context
.algorithm()) {
178 cspCtx
= new RSA_CryptContext(session
);
186 /* more here - symmetric, etc. */
190 /* not implemented here */