|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * plugin entry implementation |
|
16 * plugin entry implementation |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include "pluginentry.h" |
|
26 #include "keypair.h" |
|
27 #include "pluginconfig.h" |
|
28 #include "md2impl.h" |
|
29 #include "md5impl.h" |
|
30 #include "md4impl.h" |
|
31 #include "sha1impl.h" |
|
32 #include "hmacimpl.h" |
|
33 #include "keys.h" |
|
34 #include "3desimpl.h" |
|
35 #include "desimpl.h" |
|
36 #include "rc2impl.h" |
|
37 #include "arc4impl.h" |
|
38 #include "randomimpl.h" |
|
39 #include "rijndaelimpl.h" |
|
40 #include "randomimpl.h" |
|
41 #include "rsaimpl.h" |
|
42 #include "dhimpl.h" |
|
43 #include "dhkeypairgenimpl.h" |
|
44 #include "rsakeypairgenimpl.h" |
|
45 #include "dsakeypairgenimpl.h" |
|
46 #include "dsasignerimpl.h" |
|
47 #include "dsaverifyimpl.h" |
|
48 #include "rsasignerimpl.h" |
|
49 #include "rsaverifyimpl.h" |
|
50 #include <cryptospi/cryptospidef.h> |
|
51 |
|
52 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
53 #include "macimpl.h" |
|
54 #endif |
|
55 |
|
56 |
|
57 using namespace SoftwareCrypto; |
|
58 |
|
59 EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins) |
|
60 { |
|
61 const TCharacteristics** ptr(0); |
|
62 switch (aInterface.iUid) |
|
63 { |
|
64 case KHashInterface: |
|
65 { |
|
66 aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); |
|
67 ptr = (const TCharacteristics**) &KHashCharacteristics[0]; |
|
68 } |
|
69 break; |
|
70 |
|
71 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
72 |
|
73 case KMacInterface: |
|
74 { |
|
75 aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*); |
|
76 ptr = (const TCharacteristics**) &KMacCharacteristics[0]; |
|
77 } |
|
78 break; |
|
79 |
|
80 #endif |
|
81 |
|
82 case KRandomInterface: |
|
83 { |
|
84 aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*); |
|
85 ptr= (const TCharacteristics**) &KRandomCharacteristics[0]; |
|
86 } |
|
87 break; |
|
88 |
|
89 case KSymmetricCipherInterface: |
|
90 { |
|
91 aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*); |
|
92 ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0]; |
|
93 } |
|
94 break; |
|
95 |
|
96 case KAsymmetricCipherInterface: |
|
97 { |
|
98 aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*); |
|
99 ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0]; |
|
100 } |
|
101 break; |
|
102 |
|
103 case KSignerInterface: |
|
104 { |
|
105 aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); |
|
106 ptr = (const TCharacteristics**) &KSignerCharacteristics[0]; |
|
107 } |
|
108 break; |
|
109 |
|
110 case KVerifierInterface: |
|
111 { |
|
112 aNumPlugins=sizeof(KVerifierCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); |
|
113 ptr = (const TCharacteristics**) &KVerifierCharacteristics[0]; |
|
114 } |
|
115 break; |
|
116 |
|
117 case KKeyAgreementInterface: |
|
118 { |
|
119 aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*); |
|
120 ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0]; |
|
121 } |
|
122 break; |
|
123 |
|
124 case KKeypairGeneratorInterface: |
|
125 { |
|
126 aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*); |
|
127 ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0]; |
|
128 } |
|
129 break; |
|
130 |
|
131 case KKeyGeneratorInterface: |
|
132 break; |
|
133 |
|
134 default:; |
|
135 } |
|
136 |
|
137 return ptr; |
|
138 } |
|
139 |
|
140 EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt) |
|
141 { |
|
142 switch (aImplementationUid.iUid) |
|
143 { |
|
144 |
|
145 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
146 case KCryptoPluginMacHashMd2: |
|
147 #endif |
|
148 |
|
149 case KCryptoPluginMd2: |
|
150 aExt = CMD2Impl::CreateExtendedCharacteristicsL(); |
|
151 break; |
|
152 |
|
153 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
154 case KCryptoPluginMacHashMd5: |
|
155 #endif |
|
156 |
|
157 case KCryptoPluginMd5: |
|
158 aExt = CMD5Impl::CreateExtendedCharacteristicsL(); |
|
159 break; |
|
160 |
|
161 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
162 case KCryptoPluginMacHashSha1: |
|
163 #endif |
|
164 |
|
165 case KCryptoPluginSha1: |
|
166 aExt = CSHA1Impl::CreateExtendedCharacteristicsL(); |
|
167 break; |
|
168 |
|
169 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
170 case KCryptoPluginMacHashMd4: |
|
171 #endif |
|
172 |
|
173 case KCryptoPluginMd4: |
|
174 aExt = CMD4Impl::CreateExtendedCharacteristicsL(); |
|
175 break; |
|
176 case KCryptoPluginRandom: |
|
177 aExt = CRandomImpl::CreateExtendedCharacteristicsL(); |
|
178 break; |
|
179 case KCryptoPluginDes: |
|
180 aExt = CDesImpl::CreateExtendedCharacteristicsL(); |
|
181 break; |
|
182 case KCryptoPlugin3Des: |
|
183 aExt = C3DesImpl::CreateExtendedCharacteristicsL(); |
|
184 break; |
|
185 case KCryptoPluginRc2: |
|
186 aExt = CRc2Impl::CreateExtendedCharacteristicsL(); |
|
187 break; |
|
188 case KCryptoPluginArc4: |
|
189 aExt = CArc4Impl::CreateExtendedCharacteristicsL(); |
|
190 break; |
|
191 |
|
192 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
193 case KCryptoPluginMacAesXcbcMac96: |
|
194 case KCryptoPluginMacAesXcbcPrf128: |
|
195 #endif |
|
196 |
|
197 case KCryptoPluginAes: |
|
198 aExt = CRijndaelImpl::CreateExtendedCharacteristicsL(); |
|
199 break; |
|
200 case KCryptoPluginRsaCipher: |
|
201 aExt = CRSAImpl::CreateExtendedCharacteristicsL(); |
|
202 break; |
|
203 case KCryptoPluginRsaSigner: |
|
204 aExt = CRSASignerImpl::CreateExtendedCharacteristicsL(); |
|
205 break; |
|
206 case KCryptoPluginDsaSigner: |
|
207 aExt = CDSASignerImpl::CreateExtendedCharacteristicsL(); |
|
208 break; |
|
209 case KCryptoPluginRsaVerifier: |
|
210 aExt = CRSAVerifierImpl::CreateExtendedCharacteristicsL(); |
|
211 break; |
|
212 case KCryptoPluginDsaVerifier: |
|
213 aExt = CDSAVerifierImpl::CreateExtendedCharacteristicsL(); |
|
214 break; |
|
215 case KCryptoPluginDhKeyAgreement: |
|
216 aExt = CDHImpl::CreateExtendedCharacteristicsL(); |
|
217 break; |
|
218 case KCryptoPluginDhKeyPairGen: |
|
219 aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL(); |
|
220 break; |
|
221 case KCryptoPluginRsaKeyPairGen: |
|
222 aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); |
|
223 break; |
|
224 case KCryptoPluginDsaKeyPairGen: |
|
225 aExt = CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); |
|
226 break; |
|
227 default: |
|
228 User::Leave(KErrNotSupported); |
|
229 } |
|
230 } |
|
231 |
|
232 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin, |
|
233 TUid aImplementationId, |
|
234 const CKey& aKey, |
|
235 TUid aCryptoMode, |
|
236 TUid aPaddingMode, |
|
237 const CCryptoParams* /*aAlgorithmParams*/) |
|
238 { |
|
239 switch (aImplementationId.iUid) |
|
240 { |
|
241 case KCryptoPluginRsaCipher: |
|
242 { |
|
243 aPlugin = CRSAImpl::NewL(aKey, aCryptoMode, aPaddingMode); |
|
244 } |
|
245 break; |
|
246 |
|
247 default: |
|
248 User::Leave(KErrNotFound); |
|
249 } |
|
250 } |
|
251 |
|
252 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin, |
|
253 TUid aImplementationId, |
|
254 const CKey& aKey, |
|
255 TUid aPaddingMode, |
|
256 const CCryptoParams* /*aAlgorithmParams*/) |
|
257 { |
|
258 switch (aImplementationId.iUid) |
|
259 { |
|
260 case KCryptoPluginRsaSigner: |
|
261 { |
|
262 aPlugin = CRSASignerImpl::NewL(aKey, aPaddingMode); |
|
263 } |
|
264 break; |
|
265 |
|
266 case KCryptoPluginDsaSigner: |
|
267 { |
|
268 aPlugin = CDSASignerImpl::NewL(aKey); |
|
269 } |
|
270 break; |
|
271 |
|
272 default: |
|
273 User::Leave(KErrNotFound); |
|
274 } |
|
275 } |
|
276 |
|
277 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& aPlugin, |
|
278 TUid aImplementationId, |
|
279 const CKey& aKey, |
|
280 TUid aPaddingMode, |
|
281 const CCryptoParams* /*aAlgorithmParams*/) |
|
282 { |
|
283 switch (aImplementationId.iUid) |
|
284 { |
|
285 case KCryptoPluginRsaVerifier: |
|
286 aPlugin = CRSAVerifierImpl::NewL(aKey, aPaddingMode); |
|
287 break; |
|
288 |
|
289 case KCryptoPluginDsaVerifier: |
|
290 { |
|
291 aPlugin = CDSAVerifierImpl::NewL(aKey); |
|
292 } |
|
293 break; |
|
294 |
|
295 default: |
|
296 User::Leave(KErrNotFound); |
|
297 } |
|
298 } |
|
299 |
|
300 EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin, |
|
301 TUid aImplementationId, |
|
302 TUid aOperationMode, |
|
303 const CKey* aKey, |
|
304 const CCryptoParams* /*aAlgorithmParams*/) |
|
305 { |
|
306 aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey); |
|
307 } |
|
308 |
|
309 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
310 |
|
311 EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin, |
|
312 TUid aImplementationId, |
|
313 const CCryptoParams* /*aAlgorithmParams*/) |
|
314 { |
|
315 aPlugin=CSoftwareHash::NewL(aImplementationId); |
|
316 } |
|
317 |
|
318 EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin, |
|
319 const TUid aImplementationId, |
|
320 const CKey& aKey, |
|
321 const CCryptoParams* aAlgorithmParams) |
|
322 { |
|
323 aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams); |
|
324 } |
|
325 |
|
326 #endif |
|
327 |
|
328 EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin, |
|
329 TUid aImplementationId, |
|
330 const CKey& aPrivateKey, |
|
331 const CCryptoParams* aAlgorithmParams) |
|
332 { |
|
333 // create requested key agreement implementation in this plugin |
|
334 switch (aImplementationId.iUid) |
|
335 { |
|
336 case KCryptoPluginDhKeyAgreement: |
|
337 { |
|
338 aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams); |
|
339 } |
|
340 break; |
|
341 |
|
342 default: |
|
343 User::Leave(KErrNotFound); |
|
344 } |
|
345 } |
|
346 |
|
347 EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin, |
|
348 TUid aImplementationId, |
|
349 const CCryptoParams* /*aAlgorithmParams*/) |
|
350 { |
|
351 // create requested key pair generator implementation in this plugin |
|
352 switch (aImplementationId.iUid) |
|
353 { |
|
354 case KCryptoPluginDhKeyPairGen: |
|
355 { |
|
356 aPlugin = CDHKeyPairGenImpl::NewL(); |
|
357 } |
|
358 break; |
|
359 |
|
360 case KCryptoPluginRsaKeyPairGen: |
|
361 { |
|
362 aPlugin = CRSAKeyPairGenImpl::NewL(); |
|
363 } |
|
364 break; |
|
365 |
|
366 case KCryptoPluginDsaKeyPairGen: |
|
367 { |
|
368 aPlugin = CDSAKeyPairGenImpl::NewL(); |
|
369 } |
|
370 break; |
|
371 |
|
372 default: |
|
373 User::Leave(KErrNotFound); |
|
374 } |
|
375 } |
|
376 |
|
377 EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin, |
|
378 TUid /*aImplementationId*/, |
|
379 const CCryptoParams* /*aAlgorithmParams*/) |
|
380 { |
|
381 aPlugin=CRandomImpl::NewL(); |
|
382 } |
|
383 |
|
384 EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin, |
|
385 TUid aImplementationId, |
|
386 const CKey& aKey, |
|
387 TUid aCryptoMode, |
|
388 TUid aOperationMode, |
|
389 TUid aPadding, |
|
390 const CCryptoParams* aAlgorithmParams) |
|
391 { |
|
392 switch (aImplementationId.iUid) |
|
393 { |
|
394 case KCryptoPluginAes: |
|
395 { |
|
396 aPlugin=CRijndaelImpl::NewL( |
|
397 aKey, aCryptoMode, aOperationMode, aPadding); |
|
398 } |
|
399 break; |
|
400 case KCryptoPluginDes: |
|
401 { |
|
402 aPlugin=CDesImpl::NewL( |
|
403 aKey, aCryptoMode, aOperationMode, aPadding); |
|
404 } |
|
405 break; |
|
406 case KCryptoPlugin3Des: |
|
407 { |
|
408 aPlugin=C3DesImpl::NewL( |
|
409 aKey, aCryptoMode, aOperationMode, aPadding); |
|
410 } |
|
411 break; |
|
412 case KCryptoPluginRc2: |
|
413 { |
|
414 TInt effectiveKeyLenBits(CRc2Impl::KDefaultEffectiveKeyLenBits); |
|
415 |
|
416 if (aAlgorithmParams && aAlgorithmParams->IsPresent(KRC2EffectiveKeyLenBits)) |
|
417 { |
|
418 effectiveKeyLenBits = aAlgorithmParams->GetTIntL(KRC2EffectiveKeyLenBits); |
|
419 if (effectiveKeyLenBits < 0) |
|
420 { |
|
421 User::Leave(KErrArgument); |
|
422 } |
|
423 } |
|
424 aPlugin=CRc2Impl::NewL( |
|
425 aKey, aCryptoMode, aOperationMode, aPadding, effectiveKeyLenBits); |
|
426 } |
|
427 break; |
|
428 |
|
429 case KCryptoPluginArc4: |
|
430 { |
|
431 TInt discardBytes(CArc4Impl::KDefaultDiscardBytes); |
|
432 if (aAlgorithmParams && aAlgorithmParams->IsPresent(KARC4DiscardBytes)) |
|
433 { |
|
434 discardBytes = aAlgorithmParams->GetTIntL(KARC4DiscardBytes); |
|
435 if (discardBytes < 0) |
|
436 { |
|
437 User::Leave(KErrArgument); |
|
438 } |
|
439 } |
|
440 aPlugin=CArc4Impl::NewL(aKey, discardBytes); |
|
441 } |
|
442 break; |
|
443 |
|
444 default: |
|
445 User::Leave(KErrNotFound); |
|
446 } |
|
447 } |
|
448 |