First public contribution.
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the
16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
31 #include "blocktransformation.h"
33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
35 /** OpenSSL PKCS8 Effective Key Length Compatibility.*/
36 const TUint KPkcs8CompatibilityBits = 128;
38 /** PKCS12 PBE Effective Key Length Compatibility.*/
39 const TUint KPkcs12CompatibilityBits = 40;
43 /** The expanded key length of an RC2 key.*/
44 const TUint KRC2ExpandedKeyLen = 64;
46 /** SSL Effective Key Length Compatibility.*/
47 const TUint KSSLCompatibilityBits = 1024;
49 /** The maximum size in bytes for a RC2 key.*/
50 const TUint KRC2MaxKeySizeBytes = 128; // Max key size in this implementation = 128 bytes
53 * Abstract base class for RC2 encipherment.
56 class CRC2 : public CBlockTransformation
60 virtual TInt BlockSize() const;
61 virtual TInt KeySize() const;
65 virtual void SetKey(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
68 * The expanded key buffer.
70 * Each iK[i] is a 16-bit word.
72 TUint16 iK[KRC2ExpandedKeyLen]; // 128 bytes
76 * The key length must fall between 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
78 TBuf8<KRC2MaxKeySizeBytes> iKey;
79 /** The effective key length in bits */
80 TInt iEffectiveKeyLenBits;
84 * Concrete class for RC2 encryption.
87 class CRC2Encryptor : public CRC2
91 * Creates an instance of this class.
93 * @param aKey The key to be used for encryption. The key length must fall between
94 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
95 * @param aEffectiveKeyLenBits Effective key length bits
96 * (defaults KSSLCompatibilityBits = 1024).
98 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
99 * cipher strength restrictions of the crypto library.
100 * See TCrypto::IsSymmetricWeakEnoughL()
102 IMPORT_C static CRC2Encryptor* NewL(const TDesC8& aKey,
103 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
105 * Creates an instance of this class and leaves it on the cleanup stack.
107 * @param aKey The key to be used for encryption. The key length must fall between
108 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
109 * @param aEffectiveKeyLenBits Effective key length bits
110 * (defaults KSSLCompatibilityBits = 1024).
112 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
113 * cipher strength restrictions of the crypto library.
114 * See TCrypto::IsSymmetricWeakEnoughL()
116 IMPORT_C static CRC2Encryptor* NewLC(const TDesC8& aKey,
117 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
118 virtual void Transform(TDes8& aBlock);
125 * Concrete class for RC2 decryption.
128 class CRC2Decryptor : public CRC2
132 * Creates an instance of this class.
134 * @param aKey The key to be used for decryption. The key length must fall between
135 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
136 * @param aEffectiveKeyLenBits Effective key length bits
137 * (defaults KSSLCompatibilityBits = 1024).
139 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
140 * cipher strength restrictions of the crypto library.
141 * See TCrypto::IsSymmetricWeakEnoughL()
143 IMPORT_C static CRC2Decryptor* NewL(const TDesC8& aKey,
144 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
147 * Creates an instance of this class and leaves it on the cleanup stack.
149 * @param aKey The key to be used for decryption. The key length must fall between
150 * 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
151 * @param aEffectiveKeyLenBits Effective key length bits
152 * (defaults KSSLCompatibilityBits = 1024).
154 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
155 * cipher strength restrictions of the crypto library.
156 * See TCrypto::IsSymmetricWeakEnoughL()
158 IMPORT_C static CRC2Decryptor* NewLC(const TDesC8& aKey,
159 TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
160 virtual void Transform(TDes8& aBlock);