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