【问题标题】:Get X-Coordinate of Elliptical Curve using Bouncy Castle使用 Bouncy Castle 获取椭圆曲线的 X 坐标
【发布时间】:2018-11-27 14:03:47
【问题描述】:

我尝试计算椭圆曲线 F2m (m = 163) 的 x 坐标的 Tr(x) 运算。为此,我使用了具有相应类型的“Bouncy Castle”。我的椭圆曲线的迹线等于 0 或 1,我的代码如下:

public int CalculateTrace_Test(byte[] array)
{
    int m = 163;            
    BigInteger two = new BigInteger("2", 10);
    BigInteger x = new BigInteger(array);
    BigInteger xi = x;
    BigInteger temp = x;
    for (int i = 1; i < m; i++)
    {
        var next = xi.ModPow(two.Pow(i), fx);
        temp = temp.Xor(next);
    }

    return temp.IntValue;
}

这里 fx 是由不可约多项式f(x) = x^163+x^7+x^6+x^3 + 1 形成的整数。

所以我的问题是它不起作用,因此我什么都有,但不是 1 或 0。谁能告诉我跟踪的实现有什么问题?

【问题讨论】:

    标签: java cryptography bouncycastle


    【解决方案1】:

    看起来您在 GF(2m) 中正确地进行了场算术运算。支持正确字段算术的类在包org.bouncycastle.math.ec 中。看看ECFieldElement.F2mECCurve.F2m。此外,对于您对应于 SECT163 归约多项式的特定情况,SecT163FieldElement 类可能特别有用。

    这里有一些直接从org.bouncycastle.math.ec.tools.TraceOptimizer 类复制的代码。代码假设有限域具有特征 2。

    private static int calculateTrace(ECFieldElement fe) {
        int m = fe.getFieldSize();
        ECFieldElement tr = fe;
        for (int i = 1; i < m; ++i) {
            fe = fe.square();
            tr = tr.add(fe);
        }
        BigInteger b = tr.toBigInteger();
        if (b.bitLength() > 1) {
            throw new IllegalStateException();
        }
        return b.intValue();
    

    【讨论】:

    • 对不起,“特征2”是什么? F2m ?
    • 没有适合您的维基百科?阅读this
    • 谢谢,我修改了你的代码,因为在 C# 版本“BouncyCastle”中没有这样的类,现在它可以工作了。关于“特征 2”,在您的代码中使用 ECFieldElement,而不是在二进制字段的情况下使用 F2mFieldElement
    • 问题和答案中都没有 C#,所以我不确定该评论是关于什么的。
    • @RotvikKnuzich:如果您对 C# 感兴趣,那么为什么不在您的问题中提及呢?
    猜你喜欢
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多