os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/des.inl
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) 2003-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 #ifndef __DES_INL__
    20 #define __DES_INL__
    21 
    22 inline void IPerm(TUint32& left, TUint32& right)
    23 	{
    24 	TUint32 work;
    25 
    26 	right = rotlFixed(right, 4U);
    27 	work = (left ^ right) & 0xf0f0f0f0;
    28 	left ^= work;
    29 	right = rotrFixed(right^work, 20U);
    30 	work = (left ^ right) & 0xffff0000;
    31 	left ^= work;
    32 	right = rotrFixed(right^work, 18U);
    33 	work = (left ^ right) & 0x33333333;
    34 	left ^= work;
    35 	right = rotrFixed(right^work, 6U);
    36 	work = (left ^ right) & 0x00ff00ff;
    37 	left ^= work;
    38 	right = rotlFixed(right^work, 9U);
    39 	work = (left ^ right) & 0xaaaaaaaa;
    40 	left = rotlFixed(left^work, 1U);
    41 	right ^= work;
    42 	}
    43 
    44 inline void FPerm(TUint32& left, TUint32& right)
    45 	{
    46 	TUint32 work;
    47 
    48 	right = rotrFixed(right, 1U);
    49 	work = (left ^ right) & 0xaaaaaaaa;
    50 	right ^= work;
    51 	left = rotrFixed(left^work, 9U);
    52 	work = (left ^ right) & 0x00ff00ff;
    53 	right ^= work;
    54 	left = rotlFixed(left^work, 6U);
    55 	work = (left ^ right) & 0x33333333;
    56 	right ^= work;
    57 	left = rotlFixed(left^work, 18U);
    58 	work = (left ^ right) & 0xffff0000;
    59 	right ^= work;
    60 	left = rotlFixed(left^work, 20U);
    61 	work = (left ^ right) & 0xf0f0f0f0;
    62 	right ^= work;
    63 	left = rotrFixed(left^work, 4U);
    64 	}
    65 
    66 inline void ReverseKeySchedule(TUint32* aKey)
    67 	{
    68 	TInt i = 0;
    69 	for (; i<16; i+=2)
    70 		{
    71 		TClassSwap((*(aKey+i)), (*(aKey+(32-2-i))));
    72 		TClassSwap((*(aKey+i+1)), (*(aKey+(32-1-i))));
    73 		}
    74 	}
    75 
    76 #endif //__DES_INL__