19
|
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 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#ifndef __DESIMPL_H__
|
|
20 |
#define __DESIMPL_H__
|
|
21 |
|
|
22 |
/**
|
|
23 |
@file
|
|
24 |
@internalComponent
|
|
25 |
@released
|
|
26 |
*/
|
|
27 |
|
|
28 |
#include <e32base.h>
|
|
29 |
#include <e32cmn.h>
|
|
30 |
#include "keys.h"
|
|
31 |
#include "symmetriccipherimpl.h"
|
|
32 |
|
|
33 |
/**
|
|
34 |
Plug-in class for DES block cipher
|
|
35 |
*/
|
|
36 |
namespace SoftwareCrypto
|
|
37 |
{
|
|
38 |
using namespace CryptoSpi;
|
|
39 |
|
|
40 |
NONSHARABLE_CLASS(CDesImpl) : public CSymmetricBlockCipherImpl
|
|
41 |
{
|
|
42 |
public:
|
|
43 |
/**
|
|
44 |
Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in.
|
|
45 |
@param aKey The key
|
|
46 |
@param aCryptoMode whether to encrypt or decrypt
|
|
47 |
@param aOperationMode The block cipher mode ECB, CBC, CTR etc
|
|
48 |
@param aPadding The padding scheme to use None, SSLv3, PKCS#7
|
|
49 |
@return A pointer to a CDesImpl instance
|
|
50 |
*/
|
|
51 |
static CDesImpl* NewL(const CKey& aKey,
|
|
52 |
TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
|
|
53 |
|
|
54 |
/**
|
|
55 |
Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in.
|
|
56 |
A pointer to the plug-in instance is placed on the cleanup stack.
|
|
57 |
@param aKey The key
|
|
58 |
@param aCryptoMode Whether to encrypt or decrypt
|
|
59 |
@param aOperationMode T block cipher mode ECB, CBC, CTR etc
|
|
60 |
@param aPadding The padding scheme to use None, SSLv3, PKCS#7
|
|
61 |
@return A pointer to a CDesImpl instance
|
|
62 |
*/
|
|
63 |
static CDesImpl* NewLC(const CKey& aKey,
|
|
64 |
TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
|
|
65 |
|
|
66 |
// From CSymmetricCipherImpl
|
|
67 |
TInt GetKeyStrength() const;
|
|
68 |
TBool IsValidKeyLength(TInt aKeyBytes) const;
|
|
69 |
TUid ImplementationUid() const;
|
|
70 |
const CExtendedCharacteristics* GetExtendedCharacteristicsL();
|
|
71 |
|
|
72 |
static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
|
|
73 |
|
|
74 |
/// Destructor
|
|
75 |
~CDesImpl();
|
|
76 |
protected:
|
|
77 |
/**
|
|
78 |
Constructor
|
|
79 |
@param aBlockBytes The block size in bytes (needed to allow
|
|
80 |
3DES implementation to inherit from this class)
|
|
81 |
@param aOperationMode The mode of operation e.g. CBC
|
|
82 |
@param aCryptoMode Whether to encrypt or decrypt
|
|
83 |
@param aPaddingMode The padding mode to use. None, SSL, PKCS#7
|
|
84 |
*/
|
|
85 |
CDesImpl(TUint8 aBlockBytes, TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
|
|
86 |
|
|
87 |
/**
|
|
88 |
Second phase of construction
|
|
89 |
@param aKey The key object
|
|
90 |
*/
|
|
91 |
void ConstructL(const CKey& aKey);
|
|
92 |
|
|
93 |
// These protected functions are re-used by 3DES
|
|
94 |
/**
|
|
95 |
Transforms a block of data
|
|
96 |
@param l The left half of the block to transform
|
|
97 |
@param r The right half of the block to transform
|
|
98 |
@param aKeySchedule The keyschedule to use for the transformation
|
|
99 |
*/
|
|
100 |
void DoTransform(TUint32& l, TUint32& r, const TUint32* aKeySchedule);
|
|
101 |
|
|
102 |
/**
|
|
103 |
Setup the key schedule for encryption
|
|
104 |
@param aKey The input key
|
|
105 |
@param aKeySchedule A pointer to the key schedule buffer
|
|
106 |
*/
|
|
107 |
void SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
|
|
108 |
|
|
109 |
/**
|
|
110 |
Setup the key schedule for decryption
|
|
111 |
@param aKey The input key
|
|
112 |
@param aKeySchedule A pointer to the key schedule buffer
|
|
113 |
*/
|
|
114 |
void SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
|
|
115 |
|
|
116 |
static const TUint8 KDesBlockBytes = 8;
|
|
117 |
static const TUint8 KDesKeyBytes = 8;
|
|
118 |
|
|
119 |
private:
|
|
120 |
|
|
121 |
/**
|
|
122 |
Creates the key schedule iK from CBlockTransformationImpl::iKey.
|
|
123 |
This should be called from ConstructL and Reset
|
|
124 |
*/
|
|
125 |
void SetKeySchedule();
|
|
126 |
|
|
127 |
// From CSymmetricBlockCipherImpl
|
|
128 |
void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
|
|
129 |
void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);
|
|
130 |
|
|
131 |
private:
|
|
132 |
/// Size of the key schedule in words
|
|
133 |
static const TUint KKeyScheduleSize = 32;
|
|
134 |
|
|
135 |
/// the key schedule
|
|
136 |
TUint32 iK[KKeyScheduleSize];
|
|
137 |
};
|
|
138 |
}
|
|
139 |
|
|
140 |
#endif // __DESIMPL_H__
|