【问题标题】:openssl elliptic curves:EC_POINT_add return erroropenssl 椭圆曲线:EC_POINT_add 返回错误
【发布时间】:2016-03-24 13:18:02
【问题描述】:

我正在尝试使用 c 中的 Pollard rho 攻击来解决椭圆曲线离散对数问题。由于目标椭圆曲线是在二进制字段 F2^113 上定义的,因此我需要在我的程序中进行大量的 EC_POINT_add 操作。不幸的是,EC_POINT_add 总是返回 0 并且程序在大约 7x(10^7) 循环后停止。这是我的测试代码,我很困惑为什么 EC_POINT_add 总是返回 0 并且程序在大约 7x(10^7) 循环后停止。我真的需要你的帮助,因为这个问题让我整个星期都感到困惑。谢谢!

/*X1 is a elliptic point, Tx,Ty,BL,c1,d1,c[i],d[i] and R[i] are BIGNUM* */
while(1) {

    if(1 != EC_POINT_get_affine_coordinates_GF2m(curve,X1,Tx,Ty,ctx)) return 0;

    BN_mod(Tx,Tx,BL,ctx);
    i = atoi(BN_bn2dec(Tx));

    if(1 != EC_POINT_add(curve,X1,X1,R[i],ctx)) {
            printf("\nb\n");
            return 0;
    }

    BN_mod_add(c1,c1,c[i],order,ctx);
    BN_mod_add(d1,d1,d[i],order,ctx);

    k++;
    printf("%d ",k);
}

【问题讨论】:

  • 我认为可能是堆栈溢出,但我不知道如何处理。

标签: openssl elliptic-curve


【解决方案1】:

现在,我要回答我自己的问题,因为最后我在我的代码中找到了调试。我测试了所有潜在的错误,最后发现函数'BN_bn2dec()'的返回字符串必须被'OPENSSL_free()'释放,否则在大约2 * 10 ^ 8个循环后会导致分段错误(核心转储) .以下是文档的解释:

    BN_bn2hex() and BN_bn2dec() return printable strings containing the
    hexadecimal and decimal encoding of a respectively. For negative
    numbers, the string is prefaced with a leading '-'. The string must be
    freed later using OPENSSL_free().

我使用 GDB 调试器来定位错误。 GDB 确实是一个非常有用的代码调试工具。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 2013-11-14
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多