os/security/crypto/weakcryptospi/source/symmetric/des.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <des.h>
sl@0
    20
#include "desshim.h"
sl@0
    21
sl@0
    22
const TInt KDESBlockBytes = 8;
sl@0
    23
const TInt KDESKeyBytes = 8;
sl@0
    24
sl@0
    25
CDES::~CDES()
sl@0
    26
	{
sl@0
    27
	}
sl@0
    28
sl@0
    29
CDES::CDES()
sl@0
    30
	{
sl@0
    31
	}
sl@0
    32
sl@0
    33
typedef TUint8 TKeyDES[KDESKeyBytes];
sl@0
    34
const TInt KKnownWeakKeysCount = 16;
sl@0
    35
sl@0
    36
const TKeyDES weak_keys[KKnownWeakKeysCount] =
sl@0
    37
	{
sl@0
    38
	/* weak keys */
sl@0
    39
	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
sl@0
    40
	{0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
sl@0
    41
	{0x1E,0x1E,0x1E,0x1E,0x0E,0x0E,0x0E,0x0E},
sl@0
    42
	{0xE0,0xE0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0},
sl@0
    43
	{0x00,0xFE,0x00,0xFE,0x00,0xFE,0x00,0xFE},
sl@0
    44
	{0xFE,0x00,0xFE,0x00,0xFE,0x00,0xFE,0x00},
sl@0
    45
	{0x1E,0xE0,0x1E,0xE0,0x0E,0xF0,0x0E,0xF0},
sl@0
    46
	{0xE0,0x1E,0xE0,0x1E,0xF0,0x0E,0xF0,0x0E},
sl@0
    47
	{0x00,0xE0,0x00,0xE0,0x00,0xF0,0x00,0xF0},
sl@0
    48
	{0xE0,0x00,0xE0,0x00,0xF0,0x00,0xF0,0x00},
sl@0
    49
	{0x1E,0xFE,0x1E,0xFE,0x0E,0xFE,0x0E,0xFE},
sl@0
    50
	{0xFE,0x1E,0xFE,0x1E,0xFE,0x0E,0xFE,0x0E},
sl@0
    51
	{0x00,0x1E,0x00,0x1E,0x00,0x0E,0x00,0x0E},
sl@0
    52
	{0x1E,0x00,0x1E,0x00,0x0E,0x00,0x0E,0x00},
sl@0
    53
	{0xE0,0xFE,0xE0,0xFE,0xF0,0xFE,0xF0,0xFE},
sl@0
    54
	{0xFE,0xE0,0xFE,0xE0,0xFE,0xF0,0xFE,0xF0}
sl@0
    55
	};
sl@0
    56
	
sl@0
    57
EXPORT_C TBool CDES::IsWeakKey(const TDesC8& aKey)
sl@0
    58
	{
sl@0
    59
	TKeyDES key;
sl@0
    60
	TInt index = 0;
sl@0
    61
	//Reset parity bits
sl@0
    62
	for(; index < KDESKeyBytes; index++)
sl@0
    63
		{
sl@0
    64
		key[index] = aKey[index] & 0xFE;
sl@0
    65
		}
sl@0
    66
		
sl@0
    67
	TBool weak = EFalse;	
sl@0
    68
	//Compare key with potential weak keys without parity	
sl@0
    69
	for (index=0; index < KKnownWeakKeysCount; index++)
sl@0
    70
		{
sl@0
    71
		if (Mem::Compare(weak_keys[index], KDESKeyBytes, &key[0], KDESKeyBytes)==0)
sl@0
    72
			{
sl@0
    73
			weak = ETrue;
sl@0
    74
			break;
sl@0
    75
			}
sl@0
    76
		}
sl@0
    77
	return weak;
sl@0
    78
	}
sl@0
    79
sl@0
    80
/* CDESEncryptor */
sl@0
    81
EXPORT_C CDESEncryptor* CDESEncryptor::NewL(const TDesC8& aKey, TBool /*aCheckWeakKey*/)
sl@0
    82
	{
sl@0
    83
	return CDESEncryptorShim::NewL(aKey);
sl@0
    84
	}
sl@0
    85
sl@0
    86
EXPORT_C CDESEncryptor* CDESEncryptor::NewLC(const TDesC8& aKey, TBool /*aCheckWeakKey*/)
sl@0
    87
	{
sl@0
    88
	return CDESEncryptorShim::NewLC(aKey);
sl@0
    89
	}
sl@0
    90
sl@0
    91
CDESEncryptor::CDESEncryptor()
sl@0
    92
	{
sl@0
    93
	}
sl@0
    94
sl@0
    95
/* CDESDecryptor */
sl@0
    96
EXPORT_C CDESDecryptor* CDESDecryptor::NewL(const TDesC8& aKey, TBool /*aCheckWeakKey*/)
sl@0
    97
	{
sl@0
    98
	return CDESDecryptorShim::NewL(aKey);
sl@0
    99
	}
sl@0
   100
sl@0
   101
EXPORT_C CDESDecryptor* CDESDecryptor::NewLC(const TDesC8& aKey, TBool /*aCheckWeakKey*/)
sl@0
   102
	{
sl@0
   103
	return CDESDecryptorShim::NewLC(aKey);
sl@0
   104
	}
sl@0
   105
sl@0
   106
CDESDecryptor::CDESDecryptor()
sl@0
   107
	{	
sl@0
   108
	}
sl@0
   109
	
sl@0
   110
// All these methods have been replaced by the shim
sl@0
   111
#ifdef _BullseyeCoverage
sl@0
   112
#pragma suppress_warnings on
sl@0
   113
#pragma BullseyeCoverage off
sl@0
   114
#pragma suppress_warnings off
sl@0
   115
#endif
sl@0
   116
sl@0
   117
void CDES::Transform(TDes8& /*aBlock*/)
sl@0
   118
	{
sl@0
   119
	// Method replaced by shim 
sl@0
   120
	ASSERT(EFalse);	
sl@0
   121
	}
sl@0
   122
sl@0
   123
TInt CDES::BlockSize() const
sl@0
   124
	{
sl@0
   125
	// Method replaced by shim 
sl@0
   126
	ASSERT(EFalse);			
sl@0
   127
	return KDESBlockBytes;
sl@0
   128
	}
sl@0
   129
sl@0
   130
TInt CDES::KeySize() const
sl@0
   131
	{
sl@0
   132
	// Method replaced by shim 
sl@0
   133
	ASSERT(EFalse);			
sl@0
   134
	return KDESKeyBytes;
sl@0
   135
	}
sl@0
   136
	
sl@0
   137
void CDES::Reset()
sl@0
   138
	{
sl@0
   139
	// Method replaced by shim 
sl@0
   140
	ASSERT(EFalse);			
sl@0
   141
	}	
sl@0
   142
	
sl@0
   143
void CDES::SetKey(const TDesC8& /*aKey*/, TUint32* /*aKeyBuffer*/)
sl@0
   144
	{
sl@0
   145
	// Method replaced by shim 
sl@0
   146
	ASSERT(EFalse);				
sl@0
   147
	}
sl@0
   148
	
sl@0
   149
void CDES::ConstructL(const TDesC8& /*aKey*/, TBool /*aCheckWeakKey*/)
sl@0
   150
	{
sl@0
   151
	// Method replaced by shim 
sl@0
   152
	ASSERT(EFalse);			
sl@0
   153
	}
sl@0
   154
sl@0
   155
void CDESDecryptor::SetKey(const TDesC8& /*aKey*/, TUint32* /*aKeyBuffer*/)
sl@0
   156
	{
sl@0
   157
	// Method replaced by shim 
sl@0
   158
	ASSERT(EFalse);	
sl@0
   159
	}