|
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 * symmetric cipher abstract interface |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @publishedPartner |
|
23 @released |
|
24 */ |
|
25 |
|
26 #ifndef __CRYPTOAPI_SYMMETRICCIPHER_H__ |
|
27 #define __CRYPTOAPI_SYMMETRICCIPHER_H__ |
|
28 |
|
29 #include <cryptospi/cryptoplugin.h> |
|
30 |
|
31 namespace CryptoSpi |
|
32 { |
|
33 class CKey; |
|
34 /** |
|
35 The Symmetric Cipher Base definition. Intended to allow plug-ins |
|
36 to implement extensible symmetric cipher functionality, and to work with all |
|
37 known existing symmetric algorithms, e.g. DES, 3DES, ADES, RC2, ARC4 etc |
|
38 */ |
|
39 class MSymmetricCipherBase : public MPlugin |
|
40 { |
|
41 public: |
|
42 |
|
43 /** |
|
44 Set the key of this cipher. Reset() is called to reinitialise the cipher. |
|
45 @param aKey The symmetric key. |
|
46 */ |
|
47 virtual void SetKeyL(const CKey& aKey) = 0; |
|
48 |
|
49 /** |
|
50 Set the operation mode of this cipher |
|
51 @param aOperationMode The operation mode e.g. CBC, ECB etc |
|
52 */ |
|
53 virtual void SetOperationModeL(TUid aOperationMode) = 0; |
|
54 |
|
55 /** |
|
56 Set the crypto mode of this cipher. Reset() is called to reinitialise the cipher. |
|
57 @param aCryptoMode The crypto mode e.g encryption, decryption |
|
58 */ |
|
59 virtual void SetCryptoModeL(TUid aCryptoMode) = 0; |
|
60 |
|
61 /** |
|
62 Set padding Mode of this cipher. Reset() is called to reinitialise the cipher. |
|
63 @param aPaddingMode The padding mode e.g. SSLv3, PKCS7 |
|
64 */ |
|
65 virtual void SetPaddingModeL(TUid aPaddingMode) = 0; |
|
66 |
|
67 /** |
|
68 Set the initialization vector of this cipher. Reset() is called to reinitialise the cipher. |
|
69 @param aIv The initialization vector. |
|
70 */ |
|
71 virtual void SetIvL(const TDesC8& aIv) = 0; |
|
72 |
|
73 /** |
|
74 Returns the maximum length that an output buffer would need to be in order to hold the result |
|
75 of the next process operation, given the input length aInputLength and the internal |
|
76 state of the state of the cipher. |
|
77 @param aInputLength The length of the input to process |
|
78 @return The length of the output buffer |
|
79 */ |
|
80 virtual TInt MaxOutputLength(TInt aInputLength) const = 0; |
|
81 |
|
82 /** |
|
83 Returns the maximum length that an output buffer would need to be in order to hold the result |
|
84 of the final processing operation, given the input length aInputLength and the |
|
85 internal state of the cipher. |
|
86 @param aInputLength The length of input to process |
|
87 @return The length of the output buffer |
|
88 */ |
|
89 virtual TInt MaxFinalOutputLength(TInt aInputLength) const = 0; |
|
90 |
|
91 /** |
|
92 Returns the block size in bits. For stream ciphers (e.g. ARC4) the block size |
|
93 is defined to be 8 bits. |
|
94 @return The block size in bits |
|
95 */ |
|
96 virtual TInt BlockSize() const = 0; |
|
97 |
|
98 /** |
|
99 Returns the size of the current key in bits. |
|
100 @return The size of the current key in bits |
|
101 */ |
|
102 virtual TInt KeySize() const = 0; |
|
103 }; |
|
104 |
|
105 |
|
106 class MSymmetricCipher : public MSymmetricCipherBase |
|
107 { |
|
108 public: |
|
109 /** |
|
110 Encrypts or decrypts aInput and appends the result to aOutput. |
|
111 @param aInput The input data to be processed. |
|
112 @param aOutput The resulting processed data appended to aOutput. |
|
113 */ |
|
114 virtual void ProcessL(const TDesC8& aInput, TDes8& aOutput) = 0; |
|
115 |
|
116 /** |
|
117 Pads aInput to be block aligned using the underlying padding system, then |
|
118 encrypts or decrypts the input data, and appends the result to aOutput |
|
119 @param aInput The input buffer to be encrypted or decrypted. |
|
120 @param aOutput The resulting, padded, processed data is appended to aOutput. |
|
121 */ |
|
122 virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) = 0; |
|
123 }; |
|
124 |
|
125 |
|
126 class MAsyncSymmetricCipher : public MSymmetricCipherBase |
|
127 { |
|
128 public: |
|
129 |
|
130 /** |
|
131 Encrypts or decrypts aInput and appends the result to aOutput asynchronously |
|
132 @param aInput The input data to be processed. |
|
133 @param aOutput The resulting processed data appended to aOutput. |
|
134 @param aRequestStatus |
|
135 */ |
|
136 virtual void ProcessL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus) = 0; |
|
137 |
|
138 /** |
|
139 Asynchronously Pads aInput to be block aligned using the underlying padding system, the |
|
140 encrypts or decrypts the input data, and appends the result to aOutput |
|
141 @param aInput The input buffer to be encrypted or decrypted. |
|
142 @param aOutput The resulting, padded, processed data is appended to aOutput. |
|
143 @param aRequestStatus |
|
144 */ |
|
145 virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus) = 0; |
|
146 |
|
147 /** |
|
148 Cancel the outstanding request |
|
149 */ |
|
150 virtual void Cancel() = 0; |
|
151 }; |
|
152 |
|
153 } // namespace CryptoSpi |
|
154 |
|
155 #endif //__CRYPTOAPI_SYMMETRICCIPHER_H__ |