|
|
@@ -1203,6 +1203,37 @@ static bool TestNegativeZero(BN_CTX *ctx) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Test that |BN_rshift| and |BN_rshift1| will not produce a negative zero. |
|
|
|
if (!BN_set_word(a.get(), 1)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
BN_set_negative(a.get(), 1); |
|
|
|
if (!BN_rshift(b.get(), a.get(), 1) || |
|
|
|
!BN_rshift1(c.get(), a.get())) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!BN_is_zero(b.get()) || BN_is_negative(b.get())) { |
|
|
|
fprintf(stderr, "BN_rshift(-1, 1) produced the wrong result.\n"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!BN_is_zero(c.get()) || BN_is_negative(c.get())) { |
|
|
|
fprintf(stderr, "BN_rshift1(-1) produced the wrong result.\n"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Test that |BN_div_word| will not produce a negative zero. |
|
|
|
if (BN_div_word(a.get(), 2) == (BN_ULONG)-1) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!BN_is_zero(a.get()) || BN_is_negative(a.get())) { |
|
|
|
fprintf(stderr, "BN_div_word(-1, 2) produced the wrong result.\n"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|