|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "rc2shim.h" |
|
20 |
|
21 #include <cryptospi/cryptoparams.h> |
|
22 #include "cryptosymmetriccipherapi.h" |
|
23 #include <cryptospi/cryptospidef.h> |
|
24 #include <cryptospi/plugincharacteristics.h> |
|
25 #include "keys.h" |
|
26 #include <cryptostrength.h> |
|
27 |
|
28 #include "../common/inlines.h" |
|
29 |
|
30 using namespace CryptoSpi; |
|
31 |
|
32 // CRC2EncryptorShim //////////////////////////////////////////////////////// |
|
33 CRC2EncryptorShim* CRC2EncryptorShim::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) |
|
34 { |
|
35 CRC2EncryptorShim* self = CRC2EncryptorShim::NewLC(aKey, aEffectiveKeyLenBits); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CRC2EncryptorShim* CRC2EncryptorShim::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits) |
|
41 { |
|
42 CRC2EncryptorShim* self = new (ELeave) CRC2EncryptorShim(); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(aKey, aEffectiveKeyLenBits); |
|
45 // weak enough if either aKey or aEffectiveKeyLenBits is weak |
|
46 TInt minKeySize = Min(aEffectiveKeyLenBits, BytesToBits(aKey.Size())); |
|
47 TCrypto::IsSymmetricWeakEnoughL(minKeySize); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CRC2EncryptorShim::CRC2EncryptorShim() |
|
52 { |
|
53 } |
|
54 |
|
55 CRC2EncryptorShim::~CRC2EncryptorShim() |
|
56 { |
|
57 delete iSymmetricCipherImpl; |
|
58 delete iKey; |
|
59 delete iAlgorithmParams; |
|
60 } |
|
61 |
|
62 void CRC2EncryptorShim::ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) |
|
63 { |
|
64 TKeyProperty keyProperty = {KRc2Uid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid}; |
|
65 CCryptoParams* keyParam =CCryptoParams::NewLC(); |
|
66 keyParam->AddL(aKey, KSymmetricKeyParameterUid); |
|
67 iKey=CKey::NewL(keyProperty, *keyParam); |
|
68 CleanupStack::PopAndDestroy(keyParam); |
|
69 |
|
70 iAlgorithmParams = CCryptoParams::NewL(); |
|
71 iAlgorithmParams->AddL(aEffectiveKeyLenBits, KRC2EffectiveKeyLenBits); |
|
72 |
|
73 CSymmetricCipherFactory::CreateSymmetricCipherL( |
|
74 iSymmetricCipherImpl, |
|
75 KRc2Uid, |
|
76 *iKey, |
|
77 KCryptoModeEncryptUid, |
|
78 KOperationModeECBUid, |
|
79 KPaddingModeNoneUid, |
|
80 iAlgorithmParams); |
|
81 } |
|
82 |
|
83 TInt CRC2EncryptorShim::BlockSize() const |
|
84 { |
|
85 // SPI returns block size in BITS |
|
86 return BitsToBytes(iSymmetricCipherImpl->BlockSize()); |
|
87 } |
|
88 |
|
89 TInt CRC2EncryptorShim::KeySize() const |
|
90 { |
|
91 return iSymmetricCipherImpl->KeySize(); |
|
92 } |
|
93 |
|
94 void CRC2EncryptorShim::Transform(TDes8& aBlock) |
|
95 { |
|
96 iOutputBlock.Zero(); |
|
97 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) |
|
98 aBlock = iOutputBlock; |
|
99 } |
|
100 |
|
101 void CRC2EncryptorShim::Reset() |
|
102 { |
|
103 iSymmetricCipherImpl->Reset(); |
|
104 } |
|
105 |
|
106 TInt CRC2EncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) |
|
107 { |
|
108 TInt ret(KErrExtensionNotSupported); |
|
109 |
|
110 if (KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) |
|
111 { |
|
112 a0=iSymmetricCipherImpl; |
|
113 ret=KErrNone; |
|
114 } |
|
115 return ret; |
|
116 } |
|
117 |
|
118 // CRC2DecryptorShim //////////////////////////////////////////////////////// |
|
119 CRC2DecryptorShim* CRC2DecryptorShim::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) |
|
120 { |
|
121 CRC2DecryptorShim* self = CRC2DecryptorShim::NewLC(aKey, aEffectiveKeyLenBits); |
|
122 CleanupStack::Pop(self); |
|
123 return self; |
|
124 } |
|
125 |
|
126 |
|
127 CRC2DecryptorShim* CRC2DecryptorShim::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits) |
|
128 { |
|
129 CRC2DecryptorShim* self = new (ELeave) CRC2DecryptorShim(); |
|
130 CleanupStack::PushL(self); |
|
131 self->ConstructL(aKey, aEffectiveKeyLenBits); |
|
132 // weak enough if either aKey or aEffectiveKeyLenBits is weak |
|
133 TInt minKeySize = Min(aEffectiveKeyLenBits, BytesToBits(aKey.Size())); |
|
134 TCrypto::IsSymmetricWeakEnoughL(minKeySize); |
|
135 return self; |
|
136 } |
|
137 |
|
138 CRC2DecryptorShim::CRC2DecryptorShim() |
|
139 { |
|
140 } |
|
141 |
|
142 CRC2DecryptorShim::~CRC2DecryptorShim() |
|
143 { |
|
144 delete iSymmetricCipherImpl; |
|
145 delete iKey; |
|
146 delete iAlgorithmParams; |
|
147 } |
|
148 |
|
149 |
|
150 void CRC2DecryptorShim::ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) |
|
151 { |
|
152 TKeyProperty keyProperty = {KRc2Uid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid}; |
|
153 CCryptoParams* keyParam =CCryptoParams::NewLC(); |
|
154 keyParam->AddL(aKey, KSymmetricKeyParameterUid); |
|
155 iKey=CKey::NewL(keyProperty, *keyParam); |
|
156 CleanupStack::PopAndDestroy(keyParam); |
|
157 |
|
158 iAlgorithmParams = CCryptoParams::NewL(); |
|
159 iAlgorithmParams->AddL(aEffectiveKeyLenBits, KRC2EffectiveKeyLenBits); |
|
160 |
|
161 CSymmetricCipherFactory::CreateSymmetricCipherL( |
|
162 iSymmetricCipherImpl, |
|
163 KRc2Uid, |
|
164 *iKey, |
|
165 KCryptoModeDecryptUid, |
|
166 KOperationModeECBUid, |
|
167 KPaddingModeNoneUid, |
|
168 iAlgorithmParams); |
|
169 } |
|
170 |
|
171 TInt CRC2DecryptorShim::BlockSize() const |
|
172 { |
|
173 // SPI returns block size in BITS |
|
174 return BitsToBytes(iSymmetricCipherImpl->BlockSize()); |
|
175 } |
|
176 |
|
177 TInt CRC2DecryptorShim::KeySize() const |
|
178 { |
|
179 return iSymmetricCipherImpl->KeySize(); |
|
180 } |
|
181 |
|
182 void CRC2DecryptorShim::Transform(TDes8& aBlock) |
|
183 { |
|
184 iOutputBlock.Zero(); |
|
185 TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) |
|
186 aBlock = iOutputBlock; |
|
187 } |
|
188 |
|
189 void CRC2DecryptorShim::Reset() |
|
190 { |
|
191 iSymmetricCipherImpl->Reset(); |
|
192 } |
|
193 |
|
194 TInt CRC2DecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) |
|
195 { |
|
196 TInt ret(KErrExtensionNotSupported); |
|
197 |
|
198 if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) |
|
199 { |
|
200 a0=iSymmetricCipherImpl; |
|
201 ret=KErrNone; |
|
202 } |
|
203 return ret; |
|
204 } |