⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ecpoint$fp.java

📁 进行与数字证书相关开发必须的java源码
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   ECPoint.java

package jit.math.ec;

import jit.math.BigInteger;

// Referenced classes of package jit.math.ec:
//            ECPoint, ECFieldElement, ECConstants, ECCurve

public static class Fp extends ECPoint
{

    public byte[] getEncoded()
    {
        byte PC;
        if(getY().toBigInteger().testBit(0))
            PC = 2;
        else
            PC = 3;
        byte X[] = getX().toBigInteger().toByteArray();
        byte PO[] = new byte[X.length + 1];
        PO[0] = PC;
        System.arraycopy(X, 0, PO, 1, X.length);
        return PO;
    }

    public byte[] getEncoded(boolean uncompress)
    {
        if(uncompress)
        {
            byte PC = 4;
            byte X[] = getX().toBigInteger().toByteArray();
            byte Y[] = getY().toBigInteger().toByteArray();
            int xOff = X[0] != 0 ? 0 : 1;
            int yOff = Y[0] != 0 ? 0 : 1;
            byte PO[] = new byte[(((X.length - xOff) + Y.length) - yOff) + 1];
            PO[0] = PC;
            System.arraycopy(X, xOff, PO, 1, X.length - xOff);
            System.arraycopy(Y, yOff, PO, (X.length - xOff) + 1, Y.length - yOff);
            return PO;
        } else
        {
            return getEncoded();
        }
    }

    public ECPoint add(ECPoint b)
    {
        if(getX().toBigInteger().equals(ECConstants.ZERO))
            return b;
        if(b.getX().toBigInteger().equals(ECConstants.ZERO))
        {
            return this;
        } else
        {
            ECFieldElement gamma = b.y.subtract(y).divide(b.x.subtract(x));
            ECFieldElement x3 = gamma.multiply(gamma).subtract(x).subtract(b.x);
            ECFieldElement y3 = gamma.multiply(x.subtract(x3)).subtract(y);
            return new Fp(curve, x3, y3);
        }
    }

    public ECPoint twice()
    {
        if(getX().toBigInteger().equals(ECConstants.ZERO))
        {
            return this;
        } else
        {
            ECFieldElement TWO = curve.fromBigInteger(BigInteger.valueOf(2L));
            ECFieldElement THREE = curve.fromBigInteger(BigInteger.valueOf(3L));
            ECFieldElement gamma = x.multiply(x).multiply(THREE).add(curve.a).divide(y.multiply(TWO));
            ECFieldElement x3 = gamma.multiply(gamma).subtract(x.multiply(TWO));
            ECFieldElement y3 = gamma.multiply(x.subtract(x3)).subtract(y);
            return new Fp(curve, x3, y3);
        }
    }

    public ECPoint subtract(ECPoint p2)
    {
        return add(new Fp(curve, p2.x, p2.y.negate()));
    }

    public ECPoint multiply(BigInteger k)
    {
        BigInteger e = k;
        BigInteger h = e.multiply(BigInteger.valueOf(3L));
        ECPoint R = this;
        for(int i = h.bitLength() - 2; i > 0; i--)
        {
            R = R.twice();
            if(h.testBit(i) && !e.testBit(i))
            {
                R = R.add(this);
                continue;
            }
            if(!h.testBit(i) && e.testBit(i))
                R = R.subtract(this);
        }

        return R;
    }

    public Fp(ECCurve curve, ECFieldElement x, ECFieldElement y)
    {
        super(curve, x, y);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -