sl@0: /* sl@0: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "desshim.h" sl@0: sl@0: const TInt KDESBlockBytes = 8; sl@0: const TInt KDESKeyBytes = 8; sl@0: sl@0: CDES::~CDES() sl@0: { sl@0: } sl@0: sl@0: CDES::CDES() sl@0: { sl@0: } sl@0: sl@0: typedef TUint8 TKeyDES[KDESKeyBytes]; sl@0: const TInt KKnownWeakKeysCount = 16; sl@0: sl@0: const TKeyDES weak_keys[KKnownWeakKeysCount] = sl@0: { sl@0: /* weak keys */ sl@0: {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, sl@0: {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, sl@0: {0x1E,0x1E,0x1E,0x1E,0x0E,0x0E,0x0E,0x0E}, sl@0: {0xE0,0xE0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0}, sl@0: {0x00,0xFE,0x00,0xFE,0x00,0xFE,0x00,0xFE}, sl@0: {0xFE,0x00,0xFE,0x00,0xFE,0x00,0xFE,0x00}, sl@0: {0x1E,0xE0,0x1E,0xE0,0x0E,0xF0,0x0E,0xF0}, sl@0: {0xE0,0x1E,0xE0,0x1E,0xF0,0x0E,0xF0,0x0E}, sl@0: {0x00,0xE0,0x00,0xE0,0x00,0xF0,0x00,0xF0}, sl@0: {0xE0,0x00,0xE0,0x00,0xF0,0x00,0xF0,0x00}, sl@0: {0x1E,0xFE,0x1E,0xFE,0x0E,0xFE,0x0E,0xFE}, sl@0: {0xFE,0x1E,0xFE,0x1E,0xFE,0x0E,0xFE,0x0E}, sl@0: {0x00,0x1E,0x00,0x1E,0x00,0x0E,0x00,0x0E}, sl@0: {0x1E,0x00,0x1E,0x00,0x0E,0x00,0x0E,0x00}, sl@0: {0xE0,0xFE,0xE0,0xFE,0xF0,0xFE,0xF0,0xFE}, sl@0: {0xFE,0xE0,0xFE,0xE0,0xFE,0xF0,0xFE,0xF0} sl@0: }; sl@0: sl@0: EXPORT_C TBool CDES::IsWeakKey(const TDesC8& aKey) sl@0: { sl@0: TKeyDES key; sl@0: TInt index = 0; sl@0: //Reset parity bits sl@0: for(; index < KDESKeyBytes; index++) sl@0: { sl@0: key[index] = aKey[index] & 0xFE; sl@0: } sl@0: sl@0: TBool weak = EFalse; sl@0: //Compare key with potential weak keys without parity sl@0: for (index=0; index < KKnownWeakKeysCount; index++) sl@0: { sl@0: if (Mem::Compare(weak_keys[index], KDESKeyBytes, &key[0], KDESKeyBytes)==0) sl@0: { sl@0: weak = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: return weak; sl@0: } sl@0: sl@0: /* CDESEncryptor */ sl@0: EXPORT_C CDESEncryptor* CDESEncryptor::NewL(const TDesC8& aKey, TBool /*aCheckWeakKey*/) sl@0: { sl@0: return CDESEncryptorShim::NewL(aKey); sl@0: } sl@0: sl@0: EXPORT_C CDESEncryptor* CDESEncryptor::NewLC(const TDesC8& aKey, TBool /*aCheckWeakKey*/) sl@0: { sl@0: return CDESEncryptorShim::NewLC(aKey); sl@0: } sl@0: sl@0: CDESEncryptor::CDESEncryptor() sl@0: { sl@0: } sl@0: sl@0: /* CDESDecryptor */ sl@0: EXPORT_C CDESDecryptor* CDESDecryptor::NewL(const TDesC8& aKey, TBool /*aCheckWeakKey*/) sl@0: { sl@0: return CDESDecryptorShim::NewL(aKey); sl@0: } sl@0: sl@0: EXPORT_C CDESDecryptor* CDESDecryptor::NewLC(const TDesC8& aKey, TBool /*aCheckWeakKey*/) sl@0: { sl@0: return CDESDecryptorShim::NewLC(aKey); sl@0: } sl@0: sl@0: CDESDecryptor::CDESDecryptor() sl@0: { sl@0: } sl@0: sl@0: // All these methods have been replaced by the shim sl@0: #ifdef _BullseyeCoverage sl@0: #pragma suppress_warnings on sl@0: #pragma BullseyeCoverage off sl@0: #pragma suppress_warnings off sl@0: #endif sl@0: sl@0: void CDES::Transform(TDes8& /*aBlock*/) sl@0: { sl@0: // Method replaced by shim sl@0: ASSERT(EFalse); sl@0: } sl@0: sl@0: TInt CDES::BlockSize() const sl@0: { sl@0: // Method replaced by shim sl@0: ASSERT(EFalse); sl@0: return KDESBlockBytes; sl@0: } sl@0: sl@0: TInt CDES::KeySize() const sl@0: { sl@0: // Method replaced by shim sl@0: ASSERT(EFalse); sl@0: return KDESKeyBytes; sl@0: } sl@0: sl@0: void CDES::Reset() sl@0: { sl@0: // Method replaced by shim sl@0: ASSERT(EFalse); sl@0: } sl@0: sl@0: void CDES::SetKey(const TDesC8& /*aKey*/, TUint32* /*aKeyBuffer*/) sl@0: { sl@0: // Method replaced by shim sl@0: ASSERT(EFalse); sl@0: } sl@0: sl@0: void CDES::ConstructL(const TDesC8& /*aKey*/, TBool /*aCheckWeakKey*/) sl@0: { sl@0: // Method replaced by shim sl@0: ASSERT(EFalse); sl@0: } sl@0: sl@0: void CDESDecryptor::SetKey(const TDesC8& /*aKey*/, TUint32* /*aKeyBuffer*/) sl@0: { sl@0: // Method replaced by shim sl@0: ASSERT(EFalse); sl@0: }