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.
17 * DES encryptor and decryptor implementation
28 #ifndef __DATAENCRYPTIONSTANDARD_H__
29 #define __DATAENCRYPTIONSTANDARD_H__
31 #include <blocktransformation.h>
32 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
33 #include <securityerr.h>
36 /** The size of the key schedule array (in 32-bit words).
39 const TUint KDESScheduleSizeInWords = 32;
42 * Abstract base class for DES, implementing features common between DES encryption and
43 * decryption. From CBlockTransformation
46 class CDES : public CBlockTransformation
49 virtual void Transform(TDes8& aBlock);
50 virtual TInt BlockSize() const;
51 virtual TInt KeySize() const;
56 Indicates whether a supplied key is weak. If the key is one of the weak keys
57 defined by the crypto library (e.g. {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01})
59 @param aKey The Key to be checked. The key length must be
60 KDESKeySize = 8 bytes.
61 @return Whether the key is weak (ETrue or EFalse)
63 IMPORT_C static TBool IsWeakKey(const TDesC8& aKey);
69 void DoTransform(TUint32& l, TUint32& r, const TUint32* aKey);
70 virtual void SetKey(const TDesC8& aKey, TUint32* aKeyBuffer);
71 virtual void ConstructL(const TDesC8& aKey, TBool aCheckWeakKey);
76 * Also used as the first key in triple-DES
78 TUint32 iK1[KDESScheduleSizeInWords]; // = 32
82 * The key length must be KDESKeySize = 8 bytes.
88 * Concrete class for DES encryption.
91 class CDESEncryptor : public CDES
95 * Creates an instance of this class.
97 * @param aKey The key to be used for encryption. The key length must be
98 * KDESKeySize = 8 bytes.
99 * @param aCheckWeakKey Boolean determining whether to check the key against
100 * a set of known weak key values. Defaults to ETrue.
101 * @return A pointer to the new CDESEncryptor object.
103 * @leave KErrWeakKey If the key is a weak one, the function leaves having
104 * previously cleaned up any previously allocated memory.
105 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
106 * cipher strength restrictions of the crypto library.
107 * See TCrypto::IsSymmetricWeakEnoughL()
109 IMPORT_C static CDESEncryptor* NewL(const TDesC8& aKey, TBool aCheckWeakKey = ETrue);
112 * Creates an instance of this class and leaves it on the cleanup stack.
114 * @param aKey The key to be used for encryption. The key length must be
115 * KDESKeySize = 8 bytes.
116 * @param aCheckWeakKey Boolean determining whether to check the resultant key against
117 * a set of known weak key values. Defaults to ETrue.
118 * @return A pointer to the new CDESEncryptor object.
120 * @leave KErrWeakKey If the key is a weak one, the function leaves having
121 * previously cleaned up any previously allocated memory.
122 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
123 * cipher strength restrictions of the crypto library.
124 * See TCrypto::IsSymmetricWeakEnoughL()
126 IMPORT_C static CDESEncryptor* NewLC(const TDesC8& aKey, TBool aCheckWeakKey = ETrue);
128 /** @internalComponent */
133 * Concrete class for DES decryption.
136 class CDESDecryptor : public CDES
140 * Creates an instance of this class.
142 * @param aKey The key to be used for decryption. The key length must be
143 * KDESKeySize = 8 bytes.
144 * @param aCheckWeakKey Boolean determining whether to check the resultant key against
145 * a set of known weak key values. Defaults to ETrue.
146 * @return A pointer to the new CDESDecryptor object.
148 * @leave KErrWeakKey If the key is a weak one, the function leaves having
149 * previously cleaned up any previously allocated memory.
150 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
151 * cipher strength restrictions of the crypto library.
152 * See TCrypto::IsSymmetricWeakEnoughL()
154 IMPORT_C static CDESDecryptor* NewL(const TDesC8& aKey, TBool aCheckWeakKey = ETrue);
157 * Creates an instance of this class and leaves it on the cleanup stack.
159 * @param aKey The key to be used for decryption. The key length must be
160 * KDESKeySize = 8 bytes.
161 * @param aCheckWeakKey Boolean determining whether to check the resultant key against
162 * a set of known weak key values. Defaults to ETrue.
163 * @return A pointer to the new CDESDecryptor object.
165 * @leave KErrWeakKey If the key is a weak one, the function leaves having
166 * previously cleaned up any previously allocated memory.
167 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the
168 * cipher strength restrictions of the crypto library.
169 * See TCrypto::IsSymmetricWeakEnoughL()
171 IMPORT_C static CDESDecryptor* NewLC(const TDesC8& aKey, TBool aCheckWeakKey = ETrue);
172 protected: // From CDES
173 virtual void SetKey(const TDesC8& aKey, TUint32* aKeyBuffer);
174 /** @internalComponent */
178 #endif // __DATAENCRYPTIONSTANDARD_H__