// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.math.ec;

import org.bouncycastle.util.Integers;
import java.math.BigInteger;

public class WNafL2RMultiplier extends AbstractECMultiplier
{
    @Override
    protected ECPoint multiplyPositive(final ECPoint ecPoint, final BigInteger bigInteger) {
        final WNafPreCompInfo precompute = WNafUtil.precompute(ecPoint, WNafUtil.getWindowSize(bigInteger.bitLength()), true);
        final ECPoint[] preComp = precompute.getPreComp();
        final ECPoint[] preCompNeg = precompute.getPreCompNeg();
        final int width = precompute.getWidth();
        final int[] generateCompactWindowNaf = WNafUtil.generateCompactWindowNaf(width, bigInteger);
        ECPoint ecPoint2 = ecPoint.getCurve().getInfinity();
        int i = generateCompactWindowNaf.length;
        if (i > 1) {
            final int n = generateCompactWindowNaf[--i];
            final int a = n >> 16;
            int n2 = n & 0xFFFF;
            final int abs = Math.abs(a);
            final ECPoint[] array = (a < 0) ? preCompNeg : preComp;
            ECPoint add;
            if (abs << 2 < 1 << width) {
                final int n3 = 32 - Integers.numberOfLeadingZeros(abs);
                final int n4 = width - n3;
                add = array[(1 << width - 1) - 1 >>> 1].add(array[((abs ^ 1 << n3 - 1) << n4) + 1 >>> 1]);
                n2 -= n4;
            }
            else {
                add = array[abs >>> 1];
            }
            ecPoint2 = add.timesPow2(n2);
        }
        while (i > 0) {
            final int n5 = generateCompactWindowNaf[--i];
            final int a2 = n5 >> 16;
            ecPoint2 = ecPoint2.twicePlus(((a2 < 0) ? preCompNeg : preComp)[Math.abs(a2) >>> 1]).timesPow2(n5 & 0xFFFF);
        }
        return ecPoint2;
    }
}
