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 |
* RC2 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 __RC2_H__
|
sl@0
|
29 |
#define __RC2_H__
|
sl@0
|
30 |
|
sl@0
|
31 |
#include "blocktransformation.h"
|
sl@0
|
32 |
|
sl@0
|
33 |
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
|
sl@0
|
34 |
|
sl@0
|
35 |
/** OpenSSL PKCS8 Effective Key Length Compatibility.*/
|
sl@0
|
36 |
const TUint KPkcs8CompatibilityBits = 128;
|
sl@0
|
37 |
|
sl@0
|
38 |
/** PKCS12 PBE Effective Key Length Compatibility.*/
|
sl@0
|
39 |
const TUint KPkcs12CompatibilityBits = 40;
|
sl@0
|
40 |
|
sl@0
|
41 |
#endif
|
sl@0
|
42 |
|
sl@0
|
43 |
/** The expanded key length of an RC2 key.*/
|
sl@0
|
44 |
const TUint KRC2ExpandedKeyLen = 64;
|
sl@0
|
45 |
|
sl@0
|
46 |
/** SSL Effective Key Length Compatibility.*/
|
sl@0
|
47 |
const TUint KSSLCompatibilityBits = 1024;
|
sl@0
|
48 |
|
sl@0
|
49 |
/** The maximum size in bytes for a RC2 key.*/
|
sl@0
|
50 |
const TUint KRC2MaxKeySizeBytes = 128; // Max key size in this implementation = 128 bytes
|
sl@0
|
51 |
|
sl@0
|
52 |
/**
|
sl@0
|
53 |
* Abstract base class for RC2 encipherment.
|
sl@0
|
54 |
*
|
sl@0
|
55 |
*/
|
sl@0
|
56 |
class CRC2 : public CBlockTransformation
|
sl@0
|
57 |
{
|
sl@0
|
58 |
public:
|
sl@0
|
59 |
virtual void Reset();
|
sl@0
|
60 |
virtual TInt BlockSize() const;
|
sl@0
|
61 |
virtual TInt KeySize() const;
|
sl@0
|
62 |
protected:
|
sl@0
|
63 |
/** @internalAll */
|
sl@0
|
64 |
CRC2(void);
|
sl@0
|
65 |
virtual void SetKey(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
|
sl@0
|
66 |
protected:
|
sl@0
|
67 |
/**
|
sl@0
|
68 |
* The expanded key buffer.
|
sl@0
|
69 |
*
|
sl@0
|
70 |
* Each iK[i] is a 16-bit word.
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
TUint16 iK[KRC2ExpandedKeyLen]; // 128 bytes
|
sl@0
|
73 |
/**
|
sl@0
|
74 |
* The input key
|
sl@0
|
75 |
*
|
sl@0
|
76 |
* The key length must fall between 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
|
sl@0
|
77 |
*/
|
sl@0
|
78 |
TBuf8<KRC2MaxKeySizeBytes> iKey;
|
sl@0
|
79 |
/** The effective key length in bits */
|
sl@0
|
80 |
TInt iEffectiveKeyLenBits;
|
sl@0
|
81 |
};
|
sl@0
|
82 |
|
sl@0
|
83 |
/**
|
sl@0
|
84 |
* Concrete class for RC2 encryption.
|
sl@0
|
85 |
*
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
class CRC2Encryptor : public CRC2
|
sl@0
|
88 |
{
|
sl@0
|
89 |
public:
|
sl@0
|
90 |
/**
|
sl@0
|
91 |
* Creates an instance of this class.
|
sl@0
|
92 |
*
|
sl@0
|
93 |
* @param aKey The key to be used for encryption. The key length must fall between
|
sl@0
|
94 |
* 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
|
sl@0
|
95 |
* @param aEffectiveKeyLenBits Effective key length bits
|
sl@0
|
96 |
* (defaults KSSLCompatibilityBits = 1024).
|
sl@0
|
97 |
*
|
sl@0
|
98 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
99 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
100 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
101 |
*/
|
sl@0
|
102 |
IMPORT_C static CRC2Encryptor* NewL(const TDesC8& aKey,
|
sl@0
|
103 |
TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
|
sl@0
|
104 |
/**
|
sl@0
|
105 |
* Creates an instance of this class and leaves it on the cleanup stack.
|
sl@0
|
106 |
*
|
sl@0
|
107 |
* @param aKey The key to be used for encryption. The key length must fall between
|
sl@0
|
108 |
* 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
|
sl@0
|
109 |
* @param aEffectiveKeyLenBits Effective key length bits
|
sl@0
|
110 |
* (defaults KSSLCompatibilityBits = 1024).
|
sl@0
|
111 |
*
|
sl@0
|
112 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
113 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
114 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
IMPORT_C static CRC2Encryptor* NewLC(const TDesC8& aKey,
|
sl@0
|
117 |
TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
|
sl@0
|
118 |
virtual void Transform(TDes8& aBlock);
|
sl@0
|
119 |
protected:
|
sl@0
|
120 |
/** @internalAll */
|
sl@0
|
121 |
CRC2Encryptor(void);
|
sl@0
|
122 |
};
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
* Concrete class for RC2 decryption.
|
sl@0
|
126 |
*
|
sl@0
|
127 |
*/
|
sl@0
|
128 |
class CRC2Decryptor : public CRC2
|
sl@0
|
129 |
{
|
sl@0
|
130 |
public:
|
sl@0
|
131 |
/**
|
sl@0
|
132 |
* Creates an instance of this class.
|
sl@0
|
133 |
*
|
sl@0
|
134 |
* @param aKey The key to be used for decryption. The key length must fall between
|
sl@0
|
135 |
* 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
|
sl@0
|
136 |
* @param aEffectiveKeyLenBits Effective key length bits
|
sl@0
|
137 |
* (defaults KSSLCompatibilityBits = 1024).
|
sl@0
|
138 |
*
|
sl@0
|
139 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
140 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
141 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
142 |
*/
|
sl@0
|
143 |
IMPORT_C static CRC2Decryptor* NewL(const TDesC8& aKey,
|
sl@0
|
144 |
TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
|
sl@0
|
145 |
|
sl@0
|
146 |
/**
|
sl@0
|
147 |
* Creates an instance of this class and leaves it on the cleanup stack.
|
sl@0
|
148 |
*
|
sl@0
|
149 |
* @param aKey The key to be used for decryption. The key length must fall between
|
sl@0
|
150 |
* 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
|
sl@0
|
151 |
* @param aEffectiveKeyLenBits Effective key length bits
|
sl@0
|
152 |
* (defaults KSSLCompatibilityBits = 1024).
|
sl@0
|
153 |
*
|
sl@0
|
154 |
* @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
|
sl@0
|
155 |
* cipher strength restrictions of the crypto library.
|
sl@0
|
156 |
* See TCrypto::IsSymmetricWeakEnoughL()
|
sl@0
|
157 |
*/
|
sl@0
|
158 |
IMPORT_C static CRC2Decryptor* NewLC(const TDesC8& aKey,
|
sl@0
|
159 |
TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
|
sl@0
|
160 |
virtual void Transform(TDes8& aBlock);
|
sl@0
|
161 |
protected:
|
sl@0
|
162 |
/** @internalAll */
|
sl@0
|
163 |
CRC2Decryptor(void);
|
sl@0
|
164 |
|
sl@0
|
165 |
};
|
sl@0
|
166 |
|
sl@0
|
167 |
#endif // __RC2_H__
|