Commit 0260405c authored by Nils Larsch's avatar Nils Larsch
Browse files

fix BN_mod_word and give a more reasonable return value if an error occurred

parent 0537f968
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -69,6 +69,9 @@ BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
#endif
	int i;

	if (w == 0)
		return (BN_ULONG)-1;

	bn_check_top(a);
	w&=BN_MASK2;
	for (i=a->top-1; i>=0; i--)
@@ -94,7 +97,7 @@ BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)

	if (!w)
		/* actually this an error (division by zero) */
		return 0;
		return (BN_ULONG)-1;
	if (a->top == 0)
		return 0;

@@ -102,7 +105,7 @@ BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
	j = BN_BITS2 - BN_num_bits_word(w);
	w <<= j;
	if (!BN_lshift(a, a, j))
		return 0;
		return (BN_ULONG)-1;

	for (i=a->top-1; i>=0; i--)
		{
+7 −3
Original line number Diff line number Diff line
@@ -29,11 +29,11 @@ BN_add_word() adds B<w> to B<a> (C<a+=w>).

BN_sub_word() subtracts B<w> from B<a> (C<a-=w>).

BN_mul_word() multiplies B<a> and B<w> (C<a*=b>).
BN_mul_word() multiplies B<a> and B<w> (C<a*=w>).

BN_div_word() divides B<a> by B<w> (C<a/=w>) and returns the remainder.

BN_mod_word() returns the remainder of B<a> divided by B<w> (C<a%m>).
BN_mod_word() returns the remainder of B<a> divided by B<w> (C<a%w>).

For BN_div_word() and BN_mod_word(), B<w> must not be 0.

@@ -42,7 +42,8 @@ For BN_div_word() and BN_mod_word(), B<w> must not be 0.
BN_add_word(), BN_sub_word() and BN_mul_word() return 1 for success, 0
on error. The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.

BN_mod_word() and BN_div_word() return B<a>%B<w>.
BN_mod_word() and BN_div_word() return B<a>%B<w> on success and
B<(BN_ULONG)-1> if an error occurred.

=head1 SEE ALSO

@@ -54,4 +55,7 @@ BN_add_word() and BN_mod_word() are available in all versions of
SSLeay and OpenSSL. BN_div_word() was added in SSLeay 0.8, and
BN_sub_word() and BN_mul_word() in SSLeay 0.9.0.

Before 0.9.8a the return value for BN_div_word() and BN_mod_word()
in case of an error was 0.

=cut