2016-03-24 64 views
0

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

/*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); 
} 
+0

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

回答

0

现在,我将回答我自己的问题,因为我已经在代码中找到了调试代码。我测试了所有潜在的错误,最后发现函数'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是一个非常有用的工具来调试代码。