|
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 * RC2 implementation |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 @file |
|
26 @internalTechnology |
|
27 */ |
|
28 |
|
29 #ifndef __RC2_H__ |
|
30 #define __RC2_H__ |
|
31 |
|
32 #include "blocktransformation.h" |
|
33 |
|
34 /** The expanded key length of an RC2 key.*/ |
|
35 const TUint KRC2ExpandedKeyLen = 64; |
|
36 |
|
37 /** SSL Effective Key Length Compatibility.*/ |
|
38 const TUint KSSLCompatibilityBits = 1024; |
|
39 |
|
40 /** OpenSSL PKCS8 Effective Key Length Compatibility.*/ |
|
41 const TUint KPkcs8CompatibilityBits = 128; |
|
42 |
|
43 /** The maximum size in bytes for a RC2 key.*/ |
|
44 const TUint KRC2MaxKeySizeBytes = 128; // Max key size in this implementation = 128 bytes |
|
45 |
|
46 /** PKCS12 PBE Effective Key Length Compatibility.*/ |
|
47 const TUint KPkcs12CompatibilityBits = 40; |
|
48 |
|
49 /** |
|
50 * Abstract base class for RC2 encipherment. |
|
51 * |
|
52 * @publishedPartner |
|
53 * @released |
|
54 */ |
|
55 class CRC2 : public CBlockTransformation |
|
56 { |
|
57 public: |
|
58 virtual void Reset(); |
|
59 virtual TInt BlockSize() const; |
|
60 virtual TInt KeySize() const; |
|
61 protected: |
|
62 /** @internalAll */ |
|
63 CRC2(void); |
|
64 virtual void SetKey(const TDesC8& aKey, TInt aEffectiveKeyLenBits); |
|
65 protected: |
|
66 /** |
|
67 * The expanded key buffer. |
|
68 * |
|
69 * Each iK[i] is a 16-bit word. |
|
70 */ |
|
71 TUint16 iK[KRC2ExpandedKeyLen]; // 128 bytes |
|
72 /** |
|
73 * The input key |
|
74 * |
|
75 * The key length must fall between 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. |
|
76 */ |
|
77 TBuf8<KRC2MaxKeySizeBytes> iKey; |
|
78 /** The effective key length in bits */ |
|
79 TInt iEffectiveKeyLenBits; |
|
80 }; |
|
81 |
|
82 /** |
|
83 * Concrete class for RC2 encryption. |
|
84 * |
|
85 * @publishedPartner |
|
86 * @released |
|
87 */ |
|
88 class CRC2Encryptor : public CRC2 |
|
89 { |
|
90 public: |
|
91 /** |
|
92 * Creates an instance of this class. |
|
93 * |
|
94 * @param aKey The key to be used for encryption. The key length must fall between |
|
95 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. |
|
96 * @param aEffectiveKeyLenBits Effective key length bits |
|
97 * (defaults KSSLCompatibilityBits = 1024). |
|
98 * |
|
99 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
100 * cipher strength restrictions of the crypto library. |
|
101 * See TCrypto::IsSymmetricWeakEnoughL() |
|
102 */ |
|
103 IMPORT_C static CRC2Encryptor* NewL(const TDesC8& aKey, |
|
104 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); |
|
105 /** |
|
106 * Creates an instance of this class and leaves it on the cleanup stack. |
|
107 * |
|
108 * @param aKey The key to be used for encryption. The key length must fall between |
|
109 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. |
|
110 * @param aEffectiveKeyLenBits Effective key length bits |
|
111 * (defaults KSSLCompatibilityBits = 1024). |
|
112 * |
|
113 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
114 * cipher strength restrictions of the crypto library. |
|
115 * See TCrypto::IsSymmetricWeakEnoughL() |
|
116 */ |
|
117 IMPORT_C static CRC2Encryptor* NewLC(const TDesC8& aKey, |
|
118 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); |
|
119 virtual void Transform(TDes8& aBlock); |
|
120 protected: |
|
121 /** @internalAll */ |
|
122 CRC2Encryptor(void); |
|
123 }; |
|
124 |
|
125 /** |
|
126 * Concrete class for RC2 decryption. |
|
127 * |
|
128 * @publishedPartner |
|
129 * @released |
|
130 */ |
|
131 class CRC2Decryptor : public CRC2 |
|
132 { |
|
133 public: |
|
134 /** |
|
135 * Creates an instance of this class. |
|
136 * |
|
137 * @param aKey The key to be used for decryption. The key length must fall between |
|
138 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. |
|
139 * @param aEffectiveKeyLenBits Effective key length bits |
|
140 * (defaults KSSLCompatibilityBits = 1024). |
|
141 * |
|
142 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
143 * cipher strength restrictions of the crypto library. |
|
144 * See TCrypto::IsSymmetricWeakEnoughL() |
|
145 */ |
|
146 IMPORT_C static CRC2Decryptor* NewL(const TDesC8& aKey, |
|
147 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); |
|
148 |
|
149 /** |
|
150 * Creates an instance of this class and leaves it on the cleanup stack. |
|
151 * |
|
152 * @param aKey The key to be used for decryption. The key length must fall between |
|
153 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive. |
|
154 * @param aEffectiveKeyLenBits Effective key length bits |
|
155 * (defaults KSSLCompatibilityBits = 1024). |
|
156 * |
|
157 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
158 * cipher strength restrictions of the crypto library. |
|
159 * See TCrypto::IsSymmetricWeakEnoughL() |
|
160 */ |
|
161 IMPORT_C static CRC2Decryptor* NewLC(const TDesC8& aKey, |
|
162 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits); |
|
163 virtual void Transform(TDes8& aBlock); |
|
164 protected: |
|
165 /** @internalAll */ |
|
166 CRC2Decryptor(void); |
|
167 |
|
168 }; |
|
169 |
|
170 #endif // __RC2_H__ |