|
1 /* |
|
2 * Copyright (c) 2003-2006 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: Class definition of TUtlCrypto. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #if !defined(__UTLCRYPTO_H__) |
|
21 #define __UTLCRYPTO_H__ |
|
22 |
|
23 #include <e32std.h> |
|
24 |
|
25 class CSymmetricCipher; |
|
26 class CDH; |
|
27 class CDHKeyPair; |
|
28 class CMessageDigest; |
|
29 class CDSASignature; |
|
30 class TUtlCrypto; |
|
31 |
|
32 |
|
33 class CUtlSymmetricCipher : public CBase |
|
34 /** |
|
35 * Symmetric cipher |
|
36 * @internalComponent |
|
37 */ |
|
38 { |
|
39 friend class TUtlCrypto; |
|
40 public: |
|
41 IMPORT_C ~CUtlSymmetricCipher(); |
|
42 |
|
43 IMPORT_C void Process(const TDesC8& aInput, TDes8& aOutput); |
|
44 IMPORT_C void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); |
|
45 IMPORT_C TInt MaxOutputLength(TInt aInputTextLength) const; |
|
46 IMPORT_C TInt MaxFinalOutputLength(TInt aInputTextLength) const; |
|
47 IMPORT_C void Reset(); |
|
48 IMPORT_C TInt BlockSize() const; |
|
49 IMPORT_C TInt KeySize() const; |
|
50 private: |
|
51 CUtlSymmetricCipher(); |
|
52 private: |
|
53 CSymmetricCipher* iSymmetricCipher; |
|
54 }; |
|
55 |
|
56 |
|
57 class CUtlMessageDigest : public CBase |
|
58 /** |
|
59 * Message digester |
|
60 * @internalComponent |
|
61 */ |
|
62 { |
|
63 friend class TUtlCrypto; |
|
64 public: |
|
65 IMPORT_C ~CUtlMessageDigest(); |
|
66 |
|
67 IMPORT_C CMessageDigest* ReplicateL(void); |
|
68 IMPORT_C void Update(const TDesC8& aMessage); |
|
69 IMPORT_C TPtrC8 Final(const TDesC8& aMessage); |
|
70 IMPORT_C TPtrC8 Final(void); |
|
71 IMPORT_C CMessageDigest* CopyL(void); |
|
72 IMPORT_C TInt BlockSize(void) const; |
|
73 IMPORT_C TInt HashSize(void) const; |
|
74 IMPORT_C void Reset(void); |
|
75 |
|
76 private: |
|
77 CUtlMessageDigest(); |
|
78 private: |
|
79 CMessageDigest* iMessageDigest; |
|
80 }; |
|
81 |
|
82 |
|
83 class CUtlDiffieHellman : public CBase |
|
84 /** |
|
85 * Diffie-Hellman key exchange |
|
86 * @internalComponent |
|
87 */ |
|
88 { |
|
89 friend class TUtlCrypto; |
|
90 public: |
|
91 IMPORT_C ~CUtlDiffieHellman(); |
|
92 IMPORT_C const HBufC8* GenerateXL(void); |
|
93 IMPORT_C const HBufC8* CompleteKL(const TDesC8& aY); |
|
94 |
|
95 private: |
|
96 CUtlDiffieHellman(); |
|
97 private: |
|
98 CDHKeyPair* iDhKeyPair; |
|
99 CDH* iDhKeyAgreement; |
|
100 TInt iModulusLength; |
|
101 }; |
|
102 |
|
103 |
|
104 class TUtlCrypto |
|
105 /** |
|
106 * Crypto factory |
|
107 * @internalComponent |
|
108 */ |
|
109 { |
|
110 public: |
|
111 enum TUtlSymmetricCipherId |
|
112 { |
|
113 EUtlSymmetricCipherDesCbc, ///< DES |
|
114 EUtlSymmetricCipher3DesCbc, ///< 3DES |
|
115 EUtlSymmetricCipherAesCbc ///< AES |
|
116 }; |
|
117 |
|
118 enum TUtlMessageDigestId |
|
119 { |
|
120 EUtlMessageDigestMd5, ///< MD5 |
|
121 EUtlMessageDigestSha1 ///< SHA1 |
|
122 }; |
|
123 |
|
124 enum TUtlCryptoVersion |
|
125 { |
|
126 EUtlCryptoVersionOld, ///< not Symbian crypto library |
|
127 EUtlCryptoVersionSymbian1 ///< Symbian crypto library |
|
128 }; |
|
129 |
|
130 public: |
|
131 IMPORT_C static CUtlSymmetricCipher* MakeSymmetricEncryptorL(TUtlSymmetricCipherId aCipherId, |
|
132 const TDesC8& aKey, |
|
133 const TDesC8& aIv=KNullDesC8); |
|
134 IMPORT_C static CUtlSymmetricCipher* MakeSymmetricDecryptorL(TUtlSymmetricCipherId aCipherId, |
|
135 const TDesC8& aKey, |
|
136 const TDesC8& aIv=KNullDesC8); |
|
137 |
|
138 IMPORT_C static CUtlMessageDigest* MakeMessageDigesterL(TUtlMessageDigestId aDigestId, |
|
139 const TDesC8& aHmacKey=KNullDesC8); |
|
140 |
|
141 IMPORT_C static CUtlDiffieHellman* MakeDiffieHellmanL(const TDesC8& aN, const TDesC8& aG); |
|
142 |
|
143 IMPORT_C static void RsaPublicKeyEncryptL(const TDesC8& aPublicKeyData, |
|
144 const TDesC8& aPlaintext, |
|
145 HBufC8*& aCiphertext); |
|
146 |
|
147 IMPORT_C static void RsaPublicKeyDecryptL(const TDesC8& aPublicKeyData, |
|
148 const TDesC8& aCiphertext, |
|
149 HBufC8*& aPlaintext); |
|
150 |
|
151 IMPORT_C static TBool DsaVerifySignatureL(const TDesC8& aPublicKeyData, |
|
152 const TDesC8& aDsaParams, |
|
153 const TDesC8& aDsaSignatureR, |
|
154 const TDesC8& aDsaSignatureS, |
|
155 const TDesC8& aHashData); |
|
156 |
|
157 IMPORT_C static TBool IsWeakCryptoLibrary(void); |
|
158 |
|
159 IMPORT_C static TUtlCryptoVersion CryptoVersion(void); |
|
160 }; |
|
161 |
|
162 #endif |