os/security/crypto/weakcryptospi/source/bigint/windowslider.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/source/bigint/windowslider.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,73 @@
     1.4 +/*
     1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <bigint.h>
    1.23 +#include "windowslider.h"
    1.24 +#include "../common/inlines.h"
    1.25 +
    1.26 +TWindowSlider::TWindowSlider(const TInteger& aExp, TUint aWindowSize)
    1.27 +	: iExp(aExp), iSize(aWindowSize)
    1.28 +	{
    1.29 +	if(iSize == 0)
    1.30 +		{
    1.31 +		TUint expLen = iExp.BitCount();
    1.32 +		//These numbers are more or less arbitrary and can be tuned for empirical
    1.33 +		//performance results if desired.  It's a trade off between amount of
    1.34 +		//precomputation (more if larger iSize) and number of iterations
    1.35 +		//(more if smaller iSize).  The current defaults were obtained
    1.36 +		//from crypto++
    1.37 +		if( expLen <= 17 )
    1.38 +			iSize = 1;
    1.39 +		else if( expLen <= 24 )
    1.40 +			iSize = 2;
    1.41 +		else if( expLen <= 70 )
    1.42 +			iSize = 3;
    1.43 +		else if( expLen <= 197 )
    1.44 +			iSize = 4;
    1.45 +		else if( expLen <= 539 )
    1.46 +			iSize = 5;
    1.47 +		else if( expLen <= 1434 )
    1.48 +			iSize = 6;
    1.49 +		else 
    1.50 +			iSize = 7;
    1.51 +		}
    1.52 +	assert(iSize>=1 && iSize<=7);
    1.53 +	}
    1.54 +
    1.55 +void TWindowSlider::FindNextWindow(TUint aBegin)
    1.56 +	{
    1.57 +	assert(iExp.Bit(aBegin)); //initial bit must be 1
    1.58 +	TInt end = aBegin;
    1.59 +	TUint temp = 0;
    1.60 +	iValue = 0;
    1.61 +	TUint j = 0;
    1.62 +	for(TInt i=aBegin; i>=0 && j<iSize; i--, j++)
    1.63 +		{
    1.64 +		TUint saveMask = WORD_BITS - j - 1;
    1.65 +		temp |= iExp.Bit(i) << saveMask;
    1.66 +		if( temp & (1 << saveMask) )
    1.67 +			{
    1.68 +			end = i;
    1.69 +			iValue |= temp; //last valid substring
    1.70 +			}
    1.71 +		}
    1.72 +
    1.73 +	iLength = aBegin - end + 1;
    1.74 +	iValue >>= (WORD_BITS - iLength);
    1.75 +	}
    1.76 +