Update contrib.
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 <streamcipher.h>
33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
34 /** The size of the substitution box (i.e. lookup table) in bytes. */
35 const TInt KSBoxSize = 256;
38 /** Maximum ARC4 key size in bytes. */
39 const TInt KMaxARC4KeyBytes = 256; //2048 bits
41 /** Number of bytes to discard by default from an ARC4 key stream. */
42 const TUint KDefaultDiscardBytes = 768;
45 * Implements an RC4-compatible stream cipher that outputs a pseudorandom stream
46 * of bits, having been initialised with a key.
49 class CARC4 : public CStreamCipher
53 * Constructs an instance of a CARC4 object, and initialises it with a key and
54 * (optionally) the number of initial bytes to discard. Defaults to 256.
56 * The number of dropped bytes <b>must</b> be agreed with the other
57 * party, with which information is to be exchanged, prior to encipherment.
59 * @note Several papers have been published indicating that there are weaknesses
60 * in the first bytes of an ARC4 byte stream. A search for "ARC4
61 * discard" should find these papers. Recommended practice is to drop the first
62 * KDefaultDiscardBytes bytes of the key stream.
64 * @param aKey The key to use. aKey must be less than or equal to
65 * KRC4MaxKeySizeBytes.
66 * @param aDiscardBytes The number of bytes to drop from the beginning of the key
68 * @return A pointer to the new CARC4 object.
70 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
71 * cipher strength restrictions of the crypto library.
72 * See TCrypto::IsSymmetricWeakEnoughL()
74 IMPORT_C static CARC4* NewL(const TDesC8& aKey,
75 TUint aDiscardBytes = KDefaultDiscardBytes);
78 * Constructs an instance of a CARC4 object, and initialises it with a key and
79 * (optionally) the number of initial bytes to discard. Defaults to 256.
81 * The number of dropped bytes <b>must</b> be agreed with the other
82 * party, with which information is to be exchanged, prior to encipherment.
86 * @param aKey The key to use. aKey must be less than or equal to
87 * KRC4MaxKeySizeBytes.
88 * @param aDiscardBytes The number of bytes to drop from the beginning of the key
90 * @return A pointer to the new CARC4 object.
92 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
93 * cipher strength restrictions of the crypto library.
94 * See TCrypto::IsSymmetricWeakEnoughL()
96 IMPORT_C static CARC4* NewLC(const TDesC8& aKey,
97 TUint aDiscardBytes = KDefaultDiscardBytes);
99 virtual void Reset(void);
100 virtual TInt KeySize(void) const;
103 * Performs an ARC4 encryption or decryption on supplied data.
105 * @note ARC4 encryption and decryption are symmetrical.
107 * @param aData On input, data to be transformed;
108 * on return, transformed data.
110 virtual void DoProcess(TDes8& aData);
111 /** @internalComponent */