|
1 /* |
|
2 * Copyright (c) 2002-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 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the |
|
16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted. |
|
17 * 3DES implementation |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 @file |
|
26 @internalAll |
|
27 */ |
|
28 |
|
29 #ifndef __3DES_H__ |
|
30 #define __3DES_H__ |
|
31 |
|
32 #include "des.h" |
|
33 |
|
34 /** |
|
35 * Abstract base class for triple-DES. |
|
36 * |
|
37 * Implements features common to triple-DES encryption and decryption. |
|
38 * |
|
39 * @publishedPartner |
|
40 * @released |
|
41 */ |
|
42 class C3DES : public CDES |
|
43 { |
|
44 public: |
|
45 virtual void Transform(TDes8& aBlock); |
|
46 virtual void Reset(); |
|
47 virtual TInt BlockSize() const; |
|
48 virtual TInt KeySize() const; |
|
49 protected: |
|
50 /** @internalAll */ |
|
51 C3DES(); |
|
52 virtual void ConstructL(const TDesC8& aKey); |
|
53 /** |
|
54 * Initialises the three key schedule arrays from the specified key. |
|
55 * |
|
56 * @param aKey The key to be used for encryption. The key length |
|
57 * must be K3DESKeySize = 24 bytes. |
|
58 */ |
|
59 virtual void DoSetKey(const TDesC8& aKey) = 0; |
|
60 |
|
61 protected: |
|
62 /** The second key schedule array */ |
|
63 TUint32 iK2[KDESScheduleSizeInWords]; // = 32 |
|
64 /** The third key schedule array */ |
|
65 TUint32 iK3[KDESScheduleSizeInWords]; |
|
66 }; |
|
67 |
|
68 /** |
|
69 * Concrete class for triple-DES encryption. |
|
70 * |
|
71 * @publishedPartner |
|
72 * @released |
|
73 */ |
|
74 class C3DESEncryptor : public C3DES |
|
75 { |
|
76 public: |
|
77 /** |
|
78 * Creates an instance of this class. |
|
79 * |
|
80 * @param aKey The key to be used for encryption. The key length |
|
81 * must be K3DESKeySize = 24 bytes. |
|
82 * @return A pointer to the new C3DESEncryptor object. |
|
83 * |
|
84 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
85 * cipher strength restrictions of the crypto library. |
|
86 * See TCrypto::IsSymmetricWeakEnoughL() |
|
87 */ |
|
88 IMPORT_C static C3DESEncryptor* NewL(const TDesC8& aKey); |
|
89 |
|
90 /** |
|
91 * Creates an instance of this class and leaves it on the cleanup stack. |
|
92 * |
|
93 * @param aKey The key to be used for encryption. The key length |
|
94 * must be K3DESKeySize = 24 bytes. |
|
95 * @return A pointer to the new C3DESEncryptor object. |
|
96 * |
|
97 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
98 * cipher strength restrictions of the crypto library. |
|
99 * See TCrypto::IsSymmetricWeakEnoughL() |
|
100 */ |
|
101 IMPORT_C static C3DESEncryptor* NewLC(const TDesC8& aKey); |
|
102 protected: |
|
103 virtual void DoSetKey(const TDesC8& aKey); |
|
104 }; |
|
105 |
|
106 /** |
|
107 * Concrete class for triple-DES decryption. |
|
108 * |
|
109 * @publishedPartner |
|
110 * @released |
|
111 */ |
|
112 class C3DESDecryptor : public C3DES |
|
113 { |
|
114 public: |
|
115 /** |
|
116 * Creates an instance of this class. |
|
117 * |
|
118 * @param aKey The key to be used for decryption. The key length |
|
119 * must be K3DESKeySize = 24 bytes. |
|
120 * @return A pointer to the new C3DESDecryptor object. |
|
121 * |
|
122 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
123 * cipher strength restrictions of the crypto library. |
|
124 * See TCrypto::IsSymmetricWeakEnoughL() |
|
125 */ |
|
126 IMPORT_C static C3DESDecryptor* NewL(const TDesC8& aKey); |
|
127 |
|
128 /** |
|
129 * Creates an instance of this class and leaves it on the cleanup stack. |
|
130 * |
|
131 * @param aKey The key to be used for decryption. The key length |
|
132 * must be K3DESKeySize = 24 bytes. |
|
133 * @return A pointer to the new C3DESDecryptor object. |
|
134 * |
|
135 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
136 * cipher strength restrictions of the crypto library. |
|
137 * See TCrypto::IsSymmetricWeakEnoughL() |
|
138 */ |
|
139 IMPORT_C static C3DESDecryptor* NewLC(const TDesC8& aKey); |
|
140 protected: |
|
141 virtual void DoSetKey(const TDesC8& aKey); |
|
142 }; |
|
143 |
|
144 #endif // __3DES_H__ |