os/security/crypto/weakcryptospi/source/bigint/windowslider.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003-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 <bigint.h>
sl@0
    20
#include "windowslider.h"
sl@0
    21
#include "../common/inlines.h"
sl@0
    22
sl@0
    23
TWindowSlider::TWindowSlider(const TInteger& aExp, TUint aWindowSize)
sl@0
    24
	: iExp(aExp), iSize(aWindowSize)
sl@0
    25
	{
sl@0
    26
	if(iSize == 0)
sl@0
    27
		{
sl@0
    28
		TUint expLen = iExp.BitCount();
sl@0
    29
		//These numbers are more or less arbitrary and can be tuned for empirical
sl@0
    30
		//performance results if desired.  It's a trade off between amount of
sl@0
    31
		//precomputation (more if larger iSize) and number of iterations
sl@0
    32
		//(more if smaller iSize).  The current defaults were obtained
sl@0
    33
		//from crypto++
sl@0
    34
		if( expLen <= 17 )
sl@0
    35
			iSize = 1;
sl@0
    36
		else if( expLen <= 24 )
sl@0
    37
			iSize = 2;
sl@0
    38
		else if( expLen <= 70 )
sl@0
    39
			iSize = 3;
sl@0
    40
		else if( expLen <= 197 )
sl@0
    41
			iSize = 4;
sl@0
    42
		else if( expLen <= 539 )
sl@0
    43
			iSize = 5;
sl@0
    44
		else if( expLen <= 1434 )
sl@0
    45
			iSize = 6;
sl@0
    46
		else 
sl@0
    47
			iSize = 7;
sl@0
    48
		}
sl@0
    49
	assert(iSize>=1 && iSize<=7);
sl@0
    50
	}
sl@0
    51
sl@0
    52
void TWindowSlider::FindNextWindow(TUint aBegin)
sl@0
    53
	{
sl@0
    54
	assert(iExp.Bit(aBegin)); //initial bit must be 1
sl@0
    55
	TInt end = aBegin;
sl@0
    56
	TUint temp = 0;
sl@0
    57
	iValue = 0;
sl@0
    58
	TUint j = 0;
sl@0
    59
	for(TInt i=aBegin; i>=0 && j<iSize; i--, j++)
sl@0
    60
		{
sl@0
    61
		TUint saveMask = WORD_BITS - j - 1;
sl@0
    62
		temp |= iExp.Bit(i) << saveMask;
sl@0
    63
		if( temp & (1 << saveMask) )
sl@0
    64
			{
sl@0
    65
			end = i;
sl@0
    66
			iValue |= temp; //last valid substring
sl@0
    67
			}
sl@0
    68
		}
sl@0
    69
sl@0
    70
	iLength = aBegin - end + 1;
sl@0
    71
	iValue >>= (WORD_BITS - iLength);
sl@0
    72
	}
sl@0
    73