|
1 /* |
|
2 * Copyright (c) 2000, 2004 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 "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: This file contains the header of CCrAlgInfo class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CR_ALGINFO_H |
|
21 #define CR_ALGINFO_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> // CBase. |
|
25 |
|
26 #include "crdefs.h" // CrDefines. |
|
27 |
|
28 // CONSTANTS |
|
29 const TUint8 KCrMediumDigestLength = 16; |
|
30 const TUint8 KCrLongDigestLength = 20; |
|
31 |
|
32 const TUint8 KDigestInputSize = 64; |
|
33 |
|
34 const TUint8 KCrDESKeyLength= 8; |
|
35 const TUint8 KCrDESIVLength = 8; |
|
36 |
|
37 const TUint8 KCrRCLongKeyLength = 16; |
|
38 const TUint8 KCrRCMediumKeyLength = 8; |
|
39 const TUint8 KCrRCShortKeyLength = 5; |
|
40 const TUint8 KCrRCIVLength = 8; |
|
41 |
|
42 const TUint8 KCrPaddingLength = 8; |
|
43 |
|
44 // MACROS |
|
45 // DATA TYPES |
|
46 |
|
47 // Algorithms. |
|
48 enum TCrAlgorithm |
|
49 { |
|
50 // Message digest algorithms. |
|
51 ECrMD2, |
|
52 ECrMD5, |
|
53 ECrRIPEMD, |
|
54 ECrSHA, |
|
55 ECrSHA1, |
|
56 ECrHMAC, // item is used only with Symbian library |
|
57 ECrHMAC_MD5, // item is used only with NoCry library |
|
58 ECrHMAC_RIPEMD, // item is used only with NoCry library |
|
59 ECrHMAC_SHA1, // item is used only with NoCry library |
|
60 ECrLAST_DIGEST, |
|
61 |
|
62 // Symmetric crypto algorithms. |
|
63 ECrDES, |
|
64 ECrDES2, |
|
65 ECrDES3, |
|
66 ECrDESX, |
|
67 ECrRC2, |
|
68 ECrRC4, |
|
69 ECrRC5, |
|
70 ECrLAST_SYMM_CRYPTO, |
|
71 }; |
|
72 |
|
73 // Mode of the symmetric crypto algorithm. |
|
74 enum TCrSymmMode |
|
75 { |
|
76 ECrCBC, |
|
77 ECrCFB, |
|
78 ECrECB, |
|
79 ECrOFB, |
|
80 }; |
|
81 |
|
82 // CLASS DECLARATION |
|
83 |
|
84 /** |
|
85 * class CCrAlgInfo |
|
86 * CCrAlgInfo contains all information related to symmetric |
|
87 * crypto and digest algorithms. |
|
88 * |
|
89 * @lib crpkcs12.lib |
|
90 * @since Series 60 3.0 |
|
91 */ |
|
92 NONSHARABLE_CLASS( CCrAlgInfo ): public CBase |
|
93 { |
|
94 ///////////////////////////////////////////// |
|
95 // Constructors and destructors. |
|
96 private: |
|
97 CCrAlgInfo(); |
|
98 |
|
99 void ConstructL( |
|
100 const TCrAlgorithm aType, |
|
101 const TInt aLen, |
|
102 const TInt aIVLen = 0, |
|
103 const TDesC8* aKey = NULL, |
|
104 const TDesC8* aIV = NULL, |
|
105 const TBool aEncrypt = ETrue, |
|
106 const TBool aSingleBlock = ETrue, |
|
107 const TCrSymmMode aMode = ECrCBC); |
|
108 |
|
109 public: |
|
110 ~CCrAlgInfo(); |
|
111 |
|
112 /** |
|
113 * Constructors |
|
114 * @param aType Type of the algorithm of this object |
|
115 * @param aKey Key of this object. |
|
116 * @param aIV Initialization vector of this object. |
|
117 * @param aEncrypt Encrypt if true, otherwise decrypt. |
|
118 * @param aSingleBlock Single block mode if true. |
|
119 * @param aMode Algorithm mode. |
|
120 * @return Pointer to the created object. |
|
121 */ |
|
122 static CCrAlgInfo* NewLC( |
|
123 const TCrAlgorithm aType, |
|
124 const TDesC8& aKey, |
|
125 const TDesC8& aIV, |
|
126 const TBool aEncrypt = ETrue, |
|
127 const TBool aSingleBlock = ETrue, |
|
128 const TCrSymmMode aMode = ECrCBC); |
|
129 |
|
130 static CCrAlgInfo* NewLC( |
|
131 const TCrAlgorithm aType); |
|
132 |
|
133 static CCrAlgInfo* NewL( |
|
134 const TCrAlgorithm aType, |
|
135 const TDesC8& aKey, |
|
136 const TDesC8& aIV, |
|
137 const TBool aEncrypt = ETrue, |
|
138 const TBool aSingleBlock = ETrue, |
|
139 const TCrSymmMode aMode = ECrCBC); |
|
140 |
|
141 static CCrAlgInfo* NewL( |
|
142 const TCrAlgorithm aType); |
|
143 |
|
144 private: |
|
145 // Sets parity bits. |
|
146 TCrStatus SetParityBits(TPtr8 aPtrKey); |
|
147 |
|
148 public: // Data |
|
149 // Type of the algorithm. |
|
150 TCrAlgorithm iType; |
|
151 |
|
152 // Pointer to initialized algorithm object. |
|
153 TAny* iAlgorithmObject; |
|
154 |
|
155 // This buffer contains last portion of the |
|
156 // data to encrypt/decrypt which is encrypted/ |
|
157 // decrypted in FinalCryptSymm function. |
|
158 // Relevant only if symmetric crypto algorithm |
|
159 // in question. |
|
160 HBufC8* iLastPortion; |
|
161 |
|
162 // This buffer contains digest if calculating |
|
163 // message digest. Relevant only if digest |
|
164 // algorithm in question. |
|
165 HBufC8* iDigest; |
|
166 |
|
167 // This buffer contains key if en/decryption |
|
168 // in process. Relevant only if crypt |
|
169 // algorithm in question. |
|
170 HBufC8* iKey; |
|
171 |
|
172 // This buffer contains initialization |
|
173 // vector if en/decryption in process. |
|
174 // Relevant only if crypt algorithm in question. |
|
175 HBufC8* iIV; |
|
176 |
|
177 // Is this object for encrypting or decrypting? |
|
178 // Relevant only if symmetric crypto algorithm |
|
179 // in question. |
|
180 TBool iEncrypt; |
|
181 |
|
182 // True if only one block. |
|
183 TBool iSingleBlock; |
|
184 |
|
185 // Block status, first/middle/last. Usage depends on algorithm used. |
|
186 TInt iBlockStatus; |
|
187 |
|
188 // Mode of a symmetric crypto algorithm. Relevant |
|
189 // only if symmetric crypto algorithm in question. |
|
190 TCrSymmMode iMode; |
|
191 |
|
192 // Padding. Relevant only if Symbian symmetric |
|
193 // crypto algorithm in question. |
|
194 TAny* iPadding; |
|
195 |
|
196 }; |
|
197 |
|
198 #endif // CR_ALGINFO_H |
|
199 |
|
200 // End of File |