Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@chromium.org>2015-04-21 03:41:36 +0300
committerAdam Langley <agl@google.com>2015-05-05 01:41:10 +0300
commit8bac8c48ec875341e32889113e8a110dc3fc9803 (patch)
tree8c4d49cca7bf54806f7d4a0b574e8d160c250da6 /crypto/bn/bn_test.cc
parent68de407b5fc746c0fa82706dd897288d01c32930 (diff)
Test negatives for BN_div.
Change-Id: I8ebe58724e8b81a7f21762eff51f0ffd141ab08b Reviewed-on: https://boringssl-review.googlesource.com/4485 Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/bn/bn_test.cc')
-rw-r--r--crypto/bn/bn_test.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc
index 43fd7752..ab147d15 100644
--- a/crypto/bn/bn_test.cc
+++ b/crypto/bn/bn_test.cc
@@ -452,6 +452,33 @@ static bool test_div(FILE *fp, BN_CTX *ctx) {
return false;
}
}
+
+ // Test that BN_div never gives negative zero in the quotient.
+ if (!BN_set_word(a.get(), 1) ||
+ !BN_set_word(b.get(), 2)) {
+ return false;
+ }
+ BN_set_negative(a.get(), 1);
+ if (!BN_div(d.get(), c.get(), a.get(), b.get(), ctx)) {
+ return false;
+ }
+ if (!BN_is_zero(d.get()) || BN_is_negative(d.get())) {
+ fprintf(stderr, "Division test failed!\n");
+ return false;
+ }
+
+ // Test that BN_div never gives negative zero in the remainder.
+ if (!BN_set_word(b.get(), 1)) {
+ return false;
+ }
+ if (!BN_div(d.get(), c.get(), a.get(), b.get(), ctx)) {
+ return false;
+ }
+ if (!BN_is_zero(c.get()) || BN_is_negative(c.get())) {
+ fprintf(stderr, "Division test failed!\n");
+ return false;
+ }
+
return true;
}