]>
git.saurik.com Git - apple/security.git/blob - AppleCSP/BSafeCSP/algmaker.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.
18 #ifdef BSAFE_CSP_ENABLE
22 // algmaker - algorithm factory for BSafe 4
24 #include "bsafecspi.h"
26 #include "AppleCSPSession.h"
29 // BSafe's Chooser table.
30 // These are references to all *BSafe algorithms* we use (and thus must link in)
32 const B_ALGORITHM_METHOD
* const BSafe::bsChooser
[] = {
67 &AM_RSA_STRONG_KEY_GEN
,
69 &AM_RSA_CRT_ENCRYPT_BLIND
,
70 &AM_RSA_CRT_DECRYPT_BLIND
,
82 // random number generation
87 (B_ALGORITHM_METHOD
*)NULL_PTR
95 class Maker0
: public BSafe::MakerBase
{
97 Ctx
*make(AppleCSPSession
&session
, const Context
&context
) const
98 { return new Ctx(session
, context
); }
101 template <class Ctx
, class Arg
>
102 class Maker1
: public BSafe::MakerBase
{
105 Maker1(Arg a
) : arg(a
) { }
106 Ctx
*make(AppleCSPSession
&session
, const Context
&context
) const
107 { return new Ctx(session
, context
, arg
); }
110 template <class Ctx
, class Arg1
, class Arg2
>
111 class Maker2
: public BSafe::MakerBase
{
112 Arg1 arg1
; Arg2 arg2
;
114 Maker2(Arg1 a1
, Arg2 a2
) : arg1(a1
), arg2(a2
) { }
115 Ctx
*make(AppleCSPSession
&session
, const Context
&context
) const
116 { return new Ctx(session
, context
, arg1
, arg2
); }
119 template <class Ctx
, class Arg1
, class Arg2
, class Arg3
>
120 class Maker3
: public BSafe::MakerBase
{
121 Arg1 arg1
; Arg2 arg2
; Arg3 arg3
;
123 Maker3(Arg1 a1
, Arg2 a2
, Arg3 a3
) :
124 arg1(a1
), arg2(a2
), arg3(a3
) { }
125 Ctx
*make(AppleCSPSession
&session
, const Context
&context
) const
126 { return new Ctx(session
, context
, arg1
, arg2
, arg3
); }
130 bug_const
BSafe::MakerTable
BSafe::algorithms
[] = {
131 // signing algorithms
132 // constructor args: BSafe algorithm, signature size
134 CSSM_ALGID_SHA1WithDSA
,
135 CSSM_ALGCLASS_SIGNATURE
,
136 new Maker2
<SigningContext
, B_INFO_TYPE
, size_t>
137 (AI_DSAWithSHA1
, 48) // max size of 48 bytes
140 CSSM_ALGID_SHA1WithRSA
,
141 CSSM_ALGCLASS_SIGNATURE
,
142 new Maker2
<SigningContext
, B_INFO_TYPE
, size_t>
143 (AI_SHA1WithRSAEncryption
, 0) // size = RSA key size
147 CSSM_ALGID_MD5WithRSA
,
148 CSSM_ALGCLASS_SIGNATURE
,
149 new Maker2
<SigningContext
, B_INFO_TYPE
, size_t>
150 (AI_MD5WithRSAEncryption
, 0) // size = RSA key size
154 CSSM_ALGID_MD2WithRSA
,
155 CSSM_ALGCLASS_SIGNATURE
,
156 new Maker2
<SigningContext
, B_INFO_TYPE
, size_t>
157 (AI_MD2WithRSAEncryption
, 0) // size = RSA key size
161 // constructor args: BSafe algorithm, signature size
165 new Maker2
<MacContext
, B_INFO_TYPE
, size_t>
169 // symmetric key generation
170 // constructor args: min/max key size in bits, mustBeByteSized
173 CSSM_ALGCLASS_KEYGEN
,
174 new Maker3
<SymmetricKeyGenContext
, uint32
, uint32
, bool>
179 CSSM_ALGCLASS_KEYGEN
,
180 new Maker3
<SymmetricKeyGenContext
, uint32
, uint32
, bool>
185 CSSM_ALGCLASS_KEYGEN
,
186 new Maker3
<SymmetricKeyGenContext
, uint32
, uint32
, bool>
191 CSSM_ALGCLASS_KEYGEN
,
192 new Maker3
<SymmetricKeyGenContext
, uint32
, uint32
, bool>
197 CSSM_ALGCLASS_KEYGEN
,
198 new Maker3
<SymmetricKeyGenContext
, uint32
, uint32
, bool>
202 CSSM_ALGID_3DES_3KEY
,
203 CSSM_ALGCLASS_KEYGEN
,
204 new Maker3
<SymmetricKeyGenContext
, uint32
, uint32
, bool>
209 CSSM_ALGCLASS_KEYGEN
,
210 new Maker3
<SymmetricKeyGenContext
, uint32
, uint32
, bool>
214 // symmetric encryption algorithms
215 // constructor arg: block size (1 ==> stream cipher)
218 CSSM_ALGCLASS_SYMMETRIC
,
219 new Maker1
<BlockCipherContext
, size_t>(8)
223 CSSM_ALGCLASS_SYMMETRIC
,
224 new Maker1
<BlockCipherContext
, size_t>(8)
227 CSSM_ALGID_3DES_3KEY_EDE
,
228 CSSM_ALGCLASS_SYMMETRIC
,
229 new Maker1
<BlockCipherContext
, size_t>(8)
233 CSSM_ALGCLASS_SYMMETRIC
,
234 new Maker1
<BlockCipherContext
, size_t>(8)
238 CSSM_ALGCLASS_SYMMETRIC
,
239 new Maker1
<BlockCipherContext
, size_t>(1)
243 CSSM_ALGCLASS_SYMMETRIC
,
244 new Maker1
<BlockCipherContext
, size_t>(8)
247 // asymmetric encryption algorithms
250 CSSM_ALGCLASS_ASYMMETRIC
,
251 new Maker0
<PublicKeyCipherContext
>()
255 CSSM_ALGCLASS_ASYMMETRIC
,
256 new Maker0
<PublicKeyCipherContext
>()
259 // key pair generate algorithms
262 CSSM_ALGCLASS_KEYGEN
,
263 new Maker0
<BSafeKeyPairGenContext
>()
267 CSSM_ALGCLASS_KEYGEN
,
268 new Maker0
<BSafeKeyPairGenContext
>()
271 // pseudo-random number generators
273 CSSM_ALGID_MD5Random
,
274 CSSM_ALGCLASS_RANDOMGEN
,
275 new Maker1
<RandomContext
, B_INFO_TYPE
>(AI_MD5Random
)
278 CSSM_ALGID_SHARandom
,
279 CSSM_ALGCLASS_RANDOMGEN
,
280 new Maker1
<RandomContext
, B_INFO_TYPE
>(AI_SHA1Random
)
284 const unsigned int BSafe::algorithmCount
= sizeof(algorithms
) / sizeof(algorithms
[0]);
288 // BSafeFactory hookup
290 void BSafeFactory::setNormAllocator(CssmAllocator
*alloc
)
292 BSafe::setNormAllocator(alloc
);
294 void BSafeFactory::setPrivAllocator(CssmAllocator
*alloc
)
296 BSafe::setPrivAllocator(alloc
);
299 bool BSafeFactory::setup(
300 AppleCSPSession
&session
,
301 CSPFullPluginSession::CSPContext
* &cspCtx
,
302 const Context
&context
)
304 return BSafe::setup(session
, cspCtx
, context
);
312 AppleCSPSession
&session
,
313 CSPFullPluginSession::CSPContext
* &cspCtx
,
314 const Context
&context
)
316 for (const BSafe::MakerTable
*alg
= algorithms
;
317 alg
< algorithms
+ algorithmCount
;
319 if ((alg
->algorithmId
== context
.algorithm()) &&
320 (alg
->algClass
== context
.type())) {
326 cspCtx
= alg
->maker
->make(session
, context
);
333 #endif /* BSAFE_CSP_ENABLE */