17
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#ifndef __ASYMMETRICCIPHERIMPL_H__
|
|
20 |
#define __ASYMMETRICCIPHERIMPL_H__
|
|
21 |
|
|
22 |
/**
|
|
23 |
@file
|
|
24 |
@internalComponent
|
|
25 |
@released
|
|
26 |
*/
|
|
27 |
|
|
28 |
#include <e32base.h>
|
|
29 |
#include <cryptospi/cryptospidef.h>
|
|
30 |
#include <padding.h>
|
|
31 |
#include "asymmetriccipherplugin.h"
|
|
32 |
#include "keys.h"
|
|
33 |
#include "common/inlines.h"
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Abstract base class for symmetric cipher plug-ins.
|
|
37 |
*/
|
|
38 |
namespace SoftwareCrypto
|
|
39 |
{
|
|
40 |
using namespace CryptoSpi;
|
|
41 |
|
|
42 |
NONSHARABLE_CLASS(CAsymmetricCipherImpl) : public CBase, public MAsymmetricCipher
|
|
43 |
{
|
|
44 |
public:
|
|
45 |
|
|
46 |
// Override MPlugin virtual functions
|
|
47 |
void Close();
|
|
48 |
void Reset(); // Always call reset in super-class if you override this
|
|
49 |
TAny* GetExtension(TUid aExtensionId);
|
|
50 |
void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics);
|
|
51 |
// End of MPlugin
|
|
52 |
|
|
53 |
// Override MAsymmetricCipherBase virtual functions
|
|
54 |
void SetKeyL(const CKey& aKey); // override DoSetKeyL instead
|
|
55 |
void SetCryptoModeL(TUid aCryptoMode); // override DoSetCryptoModeL instead
|
|
56 |
void SetPaddingModeL(TUid aPaddingMode); // override DoSetPaddingModeL instead
|
|
57 |
virtual TInt GetMaximumInputLengthL() const;
|
|
58 |
virtual TInt GetMaximumOutputLengthL() const;
|
|
59 |
// End of MAsymmetricCipherBase
|
|
60 |
|
|
61 |
// Override MAsymmetricCipher virtual functions
|
|
62 |
virtual void ProcessL(const TDesC8& aInput, TDes8& aOutput) = 0;
|
|
63 |
// End of MAsymmetricCipher
|
|
64 |
|
|
65 |
/// Destructor
|
|
66 |
~CAsymmetricCipherImpl();
|
|
67 |
|
|
68 |
protected:
|
|
69 |
/**
|
|
70 |
Constructor
|
|
71 |
@param aCryptoMode Whether to encrypt or decrypt
|
|
72 |
@param aPaddingMode The padding mode
|
|
73 |
*/
|
|
74 |
CAsymmetricCipherImpl(TUid aCryptoMode, TUid aPaddingMode);
|
|
75 |
|
|
76 |
/**
|
|
77 |
Second phase of construction. Always call ConstructL in the super-class
|
|
78 |
if you override this method.
|
|
79 |
|
|
80 |
@param aKey The key to initialise the cipher with.
|
|
81 |
*/
|
|
82 |
virtual void ConstructL(const CKey& aKey);
|
|
83 |
|
|
84 |
/**
|
|
85 |
Implemented by each cipher subclass to determine whether the
|
|
86 |
specified key length is valid for that cipher.
|
|
87 |
This is called by ConstructL and SetKeyL
|
|
88 |
@param aKeyBytes The key length in bytes to verify.
|
|
89 |
@return ETrue if key length is acceptable
|
|
90 |
*/
|
|
91 |
virtual TBool IsValidKeyLengthL(TInt aKeyBytes) const = 0;
|
|
92 |
|
|
93 |
/**
|
|
94 |
Helper function implemented by concrete cipher sub-class that allows
|
|
95 |
GetCharacteristicsL to return the correct characteristics object.
|
|
96 |
@return The implemention uid
|
|
97 |
*/
|
|
98 |
virtual TUid ImplementationUid() const = 0;
|
|
99 |
|
|
100 |
/**
|
|
101 |
Validates and sets the crypto mode (iCryptoMode)
|
|
102 |
@param aCryptoMode The crypto mode
|
|
103 |
*/
|
|
104 |
virtual void DoSetCryptoModeL(TUid aCryptoMode);
|
|
105 |
|
|
106 |
/**
|
|
107 |
Extracts the raw key from aKey and sets iKey and iKeyBytes
|
|
108 |
The key length is also checked to meet export restrictions and
|
|
109 |
to ensure that it is appropriate for the cipher.
|
|
110 |
@param aKey The key
|
|
111 |
*/
|
|
112 |
virtual void DoSetKeyL(const CKey& aKey);
|
|
113 |
|
|
114 |
/**
|
|
115 |
Validates and sets the padding mode (iPaddingMode & iPadding)
|
|
116 |
@param aPadding The desired padding mode
|
|
117 |
*/
|
|
118 |
virtual void DoSetPaddingModeL(TUid aPadding);
|
|
119 |
|
|
120 |
private:
|
|
121 |
|
|
122 |
protected:
|
|
123 |
/// encryption or decryption
|
|
124 |
TUid iCryptoMode;
|
|
125 |
|
|
126 |
/// the current padding scheme
|
|
127 |
TUid iPaddingMode;
|
|
128 |
|
|
129 |
/// the key
|
|
130 |
CKey* iKey;
|
|
131 |
|
|
132 |
/// current padding scheme implementation
|
|
133 |
CPadding* iPadding;
|
|
134 |
};
|
|
135 |
}
|
|
136 |
|
|
137 |
#endif // __ASYMMETRICCIPHERIMPL_H__
|