|
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 #ifndef __3DESIMPL_H__ |
|
20 #define __3DESIMPL_H__ |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent |
|
25 @released |
|
26 */ |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <e32cmn.h> |
|
30 #include "keys.h" |
|
31 #include "desimpl.h" |
|
32 |
|
33 /** |
|
34 Plug-in class for 3DES block cipher |
|
35 */ |
|
36 namespace SoftwareCrypto |
|
37 { |
|
38 NONSHARABLE_CLASS(C3DesImpl) : public CDesImpl |
|
39 { |
|
40 public: |
|
41 |
|
42 /** |
|
43 Creates an instance of a 3DES (Data Encryption Standard) symmetric cipher plug-in. |
|
44 @param aKey The key |
|
45 @param aCryptoMode Whether to encrypt or decrypt |
|
46 @param aOperationMode The block cipher mode ECB, CBC, CTR etc |
|
47 @param aPadding The padding scheme to use None, SSLv3, PKCS#7 |
|
48 @return A pointer to a C3DesImpl instance |
|
49 */ |
|
50 static C3DesImpl* NewL(const CryptoSpi::CKey& aKey, |
|
51 TUid aCryptoMode, TUid aOperationMode, TUid aPadding); |
|
52 |
|
53 /** |
|
54 Creates an instance of a 3DES (Data Encryption Standard) symmetric cipher plug-in. |
|
55 A pointer to the plug-in instance is placed on the cleanup stack. |
|
56 @param aKey The key |
|
57 @param aCryptoMode Whether to encrypt or decrypt |
|
58 @param aOperationMode The block cipher mode ECB, CBC, CTR etc |
|
59 @param aPadding The padding scheme to use None, SSLv3, PKCS#7 |
|
60 @return A pointer to a C3DesImpl instance |
|
61 */ |
|
62 static C3DesImpl* NewLC(const CryptoSpi::CKey& aKey, |
|
63 TUid aCryptoMode, TUid aOperationMode, TUid aPadding); |
|
64 |
|
65 // From CSymmetricCipherImpl |
|
66 TBool IsValidKeyLength(TInt aKeyBytes) const; |
|
67 TInt GetKeyStrength() const; |
|
68 TUid ImplementationUid() const; |
|
69 |
|
70 /// 3Destructor |
|
71 ~C3DesImpl(); |
|
72 |
|
73 private: |
|
74 /** |
|
75 Constructor |
|
76 @param aOperationMode The mode of operation e.g. CBC |
|
77 @param aCryptoMode Whether to encrypt or decrypt |
|
78 @param aPaddingMode The padding mode to use. None, SSL, PKCS#7 |
|
79 */ |
|
80 C3DesImpl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode); |
|
81 |
|
82 /// second phase of construction |
|
83 void ConstructL(const CryptoSpi::CKey& aKey); |
|
84 |
|
85 /** |
|
86 Creates the key schedules iK1, iK2, iK3 from CBlockTransformationImpl::iKey. |
|
87 This should be called from ConstructL and Reset |
|
88 */ |
|
89 void SetKeySchedule(); |
|
90 |
|
91 // From CSymmetricBlockCipherImpl |
|
92 void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks); |
|
93 void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks); |
|
94 |
|
95 private: |
|
96 /// Size of the key schedule in words |
|
97 static const TUint KKeyScheduleSize = 32; |
|
98 |
|
99 /// the key schedules |
|
100 TUint32 iK1[KKeyScheduleSize]; |
|
101 TUint32 iK2[KKeyScheduleSize]; |
|
102 TUint32 iK3[KKeyScheduleSize]; |
|
103 |
|
104 static const TUint8 K3DesBlockBytes = 8; |
|
105 static const TUint8 K3DesKeyBytes = 24; |
|
106 }; |
|
107 } |
|
108 |
|
109 #endif // __3DESIMPL_H__ |