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 __3DESIMPL_H__
|
|
20 |
#define __3DESIMPL_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 "desimpl.h"
|
|
32 |
|
|
33 |
/**
|
|
34 |
Plug-in class for 3DES block cipher
|
|
35 |
*/
|
|
36 |
namespace SoftwareCrypto
|
|
37 |
{
|
|
38 |
using namespace CryptoSpi;
|
|
39 |
|
|
40 |
NONSHARABLE_CLASS(C3DesImpl) : public CDesImpl
|
|
41 |
{
|
|
42 |
public:
|
|
43 |
/**
|
|
44 |
Creates an instance of a 3DES (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 C3DesImpl instance
|
|
50 |
*/
|
|
51 |
static C3DesImpl* NewL(const CKey& aKey,
|
|
52 |
TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
|
|
53 |
|
|
54 |
/**
|
|
55 |
Creates an instance of a 3DES (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 The 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 C3DesImpl instance
|
|
62 |
*/
|
|
63 |
static C3DesImpl* NewLC(const CKey& aKey,
|
|
64 |
TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
|
|
65 |
|
|
66 |
// From CSymmetricCipherImpl
|
|
67 |
TBool IsValidKeyLength(TInt aKeyBytes) const;
|
|
68 |
TInt GetKeyStrength() const;
|
|
69 |
TUid ImplementationUid() const;
|
|
70 |
const CExtendedCharacteristics* GetExtendedCharacteristicsL();
|
|
71 |
|
|
72 |
static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
|
|
73 |
|
|
74 |
/// 3Destructor
|
|
75 |
~C3DesImpl();
|
|
76 |
|
|
77 |
private:
|
|
78 |
/**
|
|
79 |
Constructor
|
|
80 |
@param aOperationMode The mode of operation e.g. CBC
|
|
81 |
@param aCryptoMode Whether to encrypt or decrypt
|
|
82 |
@param aPaddingMode The padding mode to use. None, SSL, PKCS#7
|
|
83 |
*/
|
|
84 |
C3DesImpl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
|
|
85 |
|
|
86 |
/// second phase of construction
|
|
87 |
void ConstructL(const CKey& aKey);
|
|
88 |
|
|
89 |
/**
|
|
90 |
Creates the key schedules iK1, iK2, iK3 from CBlockTransformationImpl::iKey.
|
|
91 |
This should be called from ConstructL and Reset
|
|
92 |
*/
|
|
93 |
void SetKeySchedule();
|
|
94 |
|
|
95 |
// From CSymmetricBlockCipherImpl
|
|
96 |
void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
|
|
97 |
void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);
|
|
98 |
|
|
99 |
private:
|
|
100 |
/// Size of the key schedule in words
|
|
101 |
static const TUint KKeyScheduleSize = 32;
|
|
102 |
|
|
103 |
/// the key schedules
|
|
104 |
TUint32 iK1[KKeyScheduleSize];
|
|
105 |
TUint32 iK2[KKeyScheduleSize];
|
|
106 |
TUint32 iK3[KKeyScheduleSize];
|
|
107 |
|
|
108 |
static const TUint8 K3DesBlockBytes = 8;
|
|
109 |
static const TUint8 K3DesKeyBytes = 24;
|
|
110 |
};
|
|
111 |
}
|
|
112 |
|
|
113 |
#endif // __3DESIMPL_H__
|