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