Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GLVMultiplier.java « ec « math « bouncycastle « org « java « main « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 09b83668ada122295842fc435f3d15c10e5d5f94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.bouncycastle.math.ec;

import java.math.BigInteger;

import org.bouncycastle.math.ec.endo.GLVEndomorphism;

public class GLVMultiplier extends AbstractECMultiplier
{
    protected final ECCurve curve;
    protected final GLVEndomorphism glvEndomorphism;

    public GLVMultiplier(ECCurve curve, GLVEndomorphism glvEndomorphism)
    {
        if (curve == null || curve.getOrder() == null)
        {
            throw new IllegalArgumentException("Need curve with known group order");
        }

        this.curve = curve;
        this.glvEndomorphism = glvEndomorphism;
    }

    protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
    {
        if (!curve.equals(p.getCurve()))
        {
            throw new IllegalStateException();
        }

        BigInteger n = p.getCurve().getOrder();
        BigInteger[] ab = glvEndomorphism.decomposeScalar(k.mod(n));
        BigInteger a = ab[0], b = ab[1];

        ECPointMap pointMap = glvEndomorphism.getPointMap();
        if (glvEndomorphism.hasEfficientPointMap())
        {
            return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap, b);
        }

        return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap.map(p), b);
    }
}