sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the
|
sl@0
|
16 |
* Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
|
sl@0
|
17 |
* 3DES implementation
|
sl@0
|
18 |
*
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
/**
|
sl@0
|
23 |
@file
|
sl@0
|
24 |
@publishedPartner
|
sl@0
|
25 |
@released
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
|
sl@0
|
28 |
#ifndef __3DES_H__
|
sl@0
|
29 |
#define __3DES_H__
|
sl@0
|
30 |
|
sl@0
|
31 |
#include "des.h"
|
sl@0
|
32 |
|
sl@0
|
33 |
/**
|
sl@0
|
34 |
* Abstract base class for triple-DES.
|
sl@0
|
35 |
*
|
sl@0
|
36 |
* Implements features common to triple-DES encryption and decryption.
|
sl@0
|
37 |
*
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
class C3DES : public CDES
|
sl@0
|
40 |
{
|
sl@0
|
41 |
public:
|
sl@0
|
42 |
virtual void Transform(TDes8& aBlock);
|
sl@0
|
43 |
virtual void Reset();
|
sl@0
|
44 |
virtual TInt BlockSize() const;
|
sl@0
|
45 |
virtual TInt KeySize() const;
|
sl@0
|
46 |
protected:
|
sl@0
|
47 |
/** @internalAll */
|
sl@0
|
48 |
C3DES();
|
sl@0
|
49 |
virtual void ConstructL(const TDesC8& aKey);
|
sl@0
|
50 |
/**
|
sl@0
|
51 |
* Initialises the three key schedule arrays from the specified key.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* @param aKey The key to be used for encryption. The key length
|
sl@0
|
54 |
* must be K3DESKeySize = 24 bytes.
|
sl@0
|
55 |
*/
|
sl@0
|
56 |
virtual void DoSetKey(const TDesC8& aKey) = 0;
|
sl@0
|
57 |
|
sl@0
|
58 |
protected:
|
sl@0
|
59 |
/** The second key schedule array */
|
sl@0
|
60 |
TUint32 iK2[KDESScheduleSizeInWords]; // = 32
|
sl@0
|
61 |
/** The third key schedule array */
|
sl@0
|
62 |
TUint32 iK3[KDESScheduleSizeInWords];
|
sl@0
|
63 |
};
|
sl@0
|
64 |
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
* Concrete class for triple-DES encryption.
|
sl@0
|
67 |
*
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
class C3DESEncryptor : public C3DES
|
sl@0
|
70 |
{
|
sl@0
|
71 |
public:
|
sl@0
|
72 |
/**
|
sl@0
|
73 |
* Creates an instance of this class.
|
sl@0
|
74 |
*
|
sl@0
|
75 |
* @param aKey The key to be used for encryption. The key length
|
sl@0
|
76 |
* must be K3DESKeySize = 24 bytes.
|
sl@0
|
77 |
* @return A pointer to the new C3DESEncryptor object.
|
sl@0
|
78 |
*
|
sl@0
|
79 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
80 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
81 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
82 |
*/
|
sl@0
|
83 |
IMPORT_C static C3DESEncryptor* NewL(const TDesC8& aKey);
|
sl@0
|
84 |
|
sl@0
|
85 |
/**
|
sl@0
|
86 |
* Creates an instance of this class and leaves it on the cleanup stack.
|
sl@0
|
87 |
*
|
sl@0
|
88 |
* @param aKey The key to be used for encryption. The key length
|
sl@0
|
89 |
* must be K3DESKeySize = 24 bytes.
|
sl@0
|
90 |
* @return A pointer to the new C3DESEncryptor object.
|
sl@0
|
91 |
*
|
sl@0
|
92 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
93 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
94 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
95 |
*/
|
sl@0
|
96 |
IMPORT_C static C3DESEncryptor* NewLC(const TDesC8& aKey);
|
sl@0
|
97 |
protected:
|
sl@0
|
98 |
virtual void DoSetKey(const TDesC8& aKey);
|
sl@0
|
99 |
};
|
sl@0
|
100 |
|
sl@0
|
101 |
/**
|
sl@0
|
102 |
* Concrete class for triple-DES decryption.
|
sl@0
|
103 |
*
|
sl@0
|
104 |
*/
|
sl@0
|
105 |
class C3DESDecryptor : public C3DES
|
sl@0
|
106 |
{
|
sl@0
|
107 |
public:
|
sl@0
|
108 |
/**
|
sl@0
|
109 |
* Creates an instance of this class.
|
sl@0
|
110 |
*
|
sl@0
|
111 |
* @param aKey The key to be used for decryption. The key length
|
sl@0
|
112 |
* must be K3DESKeySize = 24 bytes.
|
sl@0
|
113 |
* @return A pointer to the new C3DESDecryptor object.
|
sl@0
|
114 |
*
|
sl@0
|
115 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
116 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
117 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
118 |
*/
|
sl@0
|
119 |
IMPORT_C static C3DESDecryptor* NewL(const TDesC8& aKey);
|
sl@0
|
120 |
|
sl@0
|
121 |
/**
|
sl@0
|
122 |
* Creates an instance of this class and leaves it on the cleanup stack.
|
sl@0
|
123 |
*
|
sl@0
|
124 |
* @param aKey The key to be used for decryption. The key length
|
sl@0
|
125 |
* must be K3DESKeySize = 24 bytes.
|
sl@0
|
126 |
* @return A pointer to the new C3DESDecryptor object.
|
sl@0
|
127 |
*
|
sl@0
|
128 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
129 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
130 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
131 |
*/
|
sl@0
|
132 |
IMPORT_C static C3DESDecryptor* NewLC(const TDesC8& aKey);
|
sl@0
|
133 |
protected:
|
sl@0
|
134 |
virtual void DoSetKey(const TDesC8& aKey);
|
sl@0
|
135 |
};
|
sl@0
|
136 |
|
sl@0
|
137 |
#endif // __3DES_H__
|