2016-03-24 63 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是一個非常有用的工具來調試代碼。