author | andy simpson <andrews@symbian.org> |
Mon, 25 Oct 2010 16:13:35 +0100 | |
branch | RCL_3 |
changeset 107 | c3d26e45acc2 |
parent 49 | 2f10d260163b |
permissions | -rw-r--r-- |
17 | 1 |
/* |
49
2f10d260163b
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
2 |
* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
17 | 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 "3desshim.h" |
|
20 |
||
49
2f10d260163b
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
21 |
#include <cryptospi/cryptosymmetriccipherapi.h> |
17 | 22 |
#include <cryptospi/cryptospidef.h> |
23 |
#include <cryptospi/plugincharacteristics.h> |
|
49
2f10d260163b
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
24 |
#include <cryptospi/keys.h> |
17 | 25 |
#include <cryptostrength.h> |
26 |
#include "../common/inlines.h" |
|
27 |
||
28 |
using namespace CryptoSpi; |
|
29 |
||
30 |
// C3DESEncryptorShim //////////////////////////////////////////////////////// |
|
31 |
C3DESEncryptorShim* C3DESEncryptorShim::NewL(const TDesC8& aKey) |
|
32 |
{ |
|
33 |
C3DESEncryptorShim* self = C3DESEncryptorShim::NewLC(aKey); |
|
34 |
CleanupStack::Pop(self); |
|
35 |
return self; |
|
36 |
} |
|
37 |
||
38 |
C3DESEncryptorShim* C3DESEncryptorShim::NewLC(const TDesC8& aKey) |
|
39 |
{ |
|
40 |
C3DESEncryptorShim* self = new (ELeave) C3DESEncryptorShim(); |
|
41 |
CleanupStack::PushL(self); |
|
42 |
self->ConstructL(aKey); |
|
43 |
// DES only used 7 bits out of every key byte |
|
44 |
TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size()); |
|
45 |
return self; |
|
46 |
} |
|
47 |
||
48 |
C3DESEncryptorShim::C3DESEncryptorShim() |
|
49 |
{ |
|
50 |
} |
|
51 |
||
52 |
C3DESEncryptorShim::~C3DESEncryptorShim() |
|
53 |
{ |
|
54 |
delete iSymmetricCipherImpl; |
|
55 |
delete iKey; |
|
56 |
} |
|
57 |
||
58 |
void C3DESEncryptorShim::ConstructL(const TDesC8& aKey) |
|
59 |
{ |
|
60 |
TKeyProperty keyProperty = {K3DesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; |
|
61 |
CCryptoParams* keyParam =CCryptoParams::NewLC(); |
|
62 |
keyParam->AddL(aKey, KSymmetricKeyParameterUid); |
|
63 |
iKey=CKey::NewL(keyProperty, *keyParam); |
|
64 |
CleanupStack::PopAndDestroy(keyParam); |
|
65 |
||
66 |
CSymmetricCipherFactory::CreateSymmetricCipherL( |
|
67 |
iSymmetricCipherImpl, |
|
68 |
K3DesUid, |
|
69 |
*iKey, |
|
70 |
KCryptoModeEncryptUid, |
|
71 |
KOperationModeECBUid, |
|
72 |
KPaddingModeNoneUid, |
|
73 |
NULL); |
|
74 |
} |
|
75 |
||
76 |
TInt C3DESEncryptorShim::BlockSize() const |
|
77 |
{ |
|
78 |
// SPI returns block size in BITS |
|
79 |
return iSymmetricCipherImpl->BlockSize() >> 3; |
|
80 |
} |
|
81 |
||
82 |
TInt C3DESEncryptorShim::KeySize() const |
|
83 |
{ |
|
84 |
return iSymmetricCipherImpl->KeySize(); |
|
85 |
} |
|
86 |
||
87 |
void C3DESEncryptorShim::Transform(TDes8& aBlock) |
|
88 |
{ |
|
89 |
iOutputBlock.Zero(); |
|
90 |
TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) |
|
91 |
aBlock = iOutputBlock; |
|
92 |
} |
|
93 |
||
94 |
void C3DESEncryptorShim::Reset() |
|
95 |
{ |
|
96 |
iSymmetricCipherImpl->Reset(); |
|
97 |
} |
|
98 |
||
99 |
TInt C3DESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) |
|
100 |
{ |
|
101 |
TInt ret(KErrExtensionNotSupported); |
|
102 |
||
103 |
if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) |
|
104 |
{ |
|
105 |
a0=iSymmetricCipherImpl; |
|
106 |
ret=KErrNone; |
|
107 |
} |
|
108 |
return ret; |
|
109 |
} |
|
110 |
||
111 |
// C3DESDecryptorShim //////////////////////////////////////////////////////// |
|
112 |
C3DESDecryptorShim* C3DESDecryptorShim::NewL(const TDesC8& aKey) |
|
113 |
{ |
|
114 |
C3DESDecryptorShim* self = C3DESDecryptorShim::NewLC(aKey); |
|
115 |
CleanupStack::Pop(self); |
|
116 |
return self; |
|
117 |
} |
|
118 |
||
119 |
||
120 |
C3DESDecryptorShim* C3DESDecryptorShim::NewLC(const TDesC8& aKey) |
|
121 |
{ |
|
122 |
C3DESDecryptorShim* self = new (ELeave) C3DESDecryptorShim(); |
|
123 |
CleanupStack::PushL(self); |
|
124 |
self->ConstructL(aKey); |
|
125 |
// DES only used 7 bits out of every key byte |
|
126 |
TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size()); |
|
127 |
return self; |
|
128 |
} |
|
129 |
||
130 |
C3DESDecryptorShim::C3DESDecryptorShim() |
|
131 |
{ |
|
132 |
} |
|
133 |
||
134 |
C3DESDecryptorShim::~C3DESDecryptorShim() |
|
135 |
{ |
|
136 |
delete iSymmetricCipherImpl; |
|
137 |
delete iKey; |
|
138 |
} |
|
139 |
||
140 |
||
141 |
void C3DESDecryptorShim::ConstructL(const TDesC8& aKey) |
|
142 |
{ |
|
143 |
TKeyProperty keyProperty = {K3DesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; |
|
144 |
CCryptoParams* keyParam =CCryptoParams::NewLC(); |
|
145 |
keyParam->AddL(aKey, KSymmetricKeyParameterUid); |
|
146 |
iKey=CKey::NewL(keyProperty, *keyParam); |
|
147 |
CleanupStack::PopAndDestroy(keyParam); |
|
148 |
CSymmetricCipherFactory::CreateSymmetricCipherL( |
|
149 |
iSymmetricCipherImpl, |
|
150 |
K3DesUid, |
|
151 |
*iKey, |
|
152 |
KCryptoModeDecryptUid, |
|
153 |
KOperationModeECBUid, |
|
154 |
KPaddingModeNoneUid, |
|
155 |
NULL); |
|
156 |
} |
|
157 |
||
158 |
TInt C3DESDecryptorShim::BlockSize() const |
|
159 |
{ |
|
160 |
// SPI returns block size in BITS |
|
161 |
return BitsToBytes(iSymmetricCipherImpl->BlockSize()); |
|
162 |
} |
|
163 |
||
164 |
TInt C3DESDecryptorShim::KeySize() const |
|
165 |
{ |
|
166 |
return iSymmetricCipherImpl->KeySize(); |
|
167 |
} |
|
168 |
||
169 |
void C3DESDecryptorShim::Transform(TDes8& aBlock) |
|
170 |
{ |
|
171 |
iOutputBlock.Zero(); |
|
172 |
TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) |
|
173 |
aBlock = iOutputBlock; |
|
174 |
} |
|
175 |
||
176 |
void C3DESDecryptorShim::Reset() |
|
177 |
{ |
|
178 |
iSymmetricCipherImpl->Reset(); |
|
179 |
} |
|
180 |
||
181 |
TInt C3DESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) |
|
182 |
{ |
|
183 |
TInt ret(KErrExtensionNotSupported); |
|
184 |
||
185 |
if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) |
|
186 |
{ |
|
187 |
a0=iSymmetricCipherImpl; |
|
188 |
ret=KErrNone; |
|
189 |
} |
|
190 |
return ret; |
|
191 |
} |