summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorKinichiro Inoguchi <inoguchi@cvs.openbsd.org>2017-02-23 14:14:38 +0000
committerKinichiro Inoguchi <inoguchi@cvs.openbsd.org>2017-02-23 14:14:38 +0000
commit752791f421bedfa4637cff8ab0f4307fbf6d712e (patch)
tree3754473c58dd0cd4b66a0662cc64397321a01c2b /regress/lib
parentc18474c98dc873b7c022c594d1fa24513faedb26 (diff)
Check return value of every BN_* functions in bntest
- add macro CHECK_GOTO - unify function return code to rc - add err: label for error goto ok bcook@
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libcrypto/bn/general/bntest.c819
1 files changed, 426 insertions, 393 deletions
diff --git a/regress/lib/libcrypto/bn/general/bntest.c b/regress/lib/libcrypto/bn/general/bntest.c
index 89186dd582c..5faa653022a 100644
--- a/regress/lib/libcrypto/bn/general/bntest.c
+++ b/regress/lib/libcrypto/bn/general/bntest.c
@@ -136,6 +136,17 @@ static unsigned char lst[] =
"\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9"
"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0";
+#define PRINT_ERROR printf("Error in %s [%s:%d]\n", __func__, __FILE__, \
+ __LINE__)
+
+#define CHECK_GOTO(a) do { \
+ if (!(a)) { \
+ PRINT_ERROR; \
+ rc = 0; \
+ goto err; \
+ } \
+} while (0)
+
static void
message(BIO *out, char *m)
{
@@ -369,32 +380,33 @@ test_add(BIO *bp)
BN_init(&b);
BN_init(&c);
- BN_bntest_rand(&a, 512, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&a, 512, 0, 0));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(&b, 450 + i, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&b, 450 + i, 0, 0));
a.neg = rand_neg();
b.neg = rand_neg();
- BN_add(&c, &a, &b);
+ CHECK_GOTO(BN_add(&c, &a, &b));
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " + ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " - ");
}
- BN_print(bp, &c);
+ CHECK_GOTO(BN_print(bp, &c));
BIO_puts(bp, "\n");
}
a.neg = !a.neg;
b.neg = !b.neg;
- BN_add(&c, &c, &b);
- BN_add(&c, &c, &a);
+ CHECK_GOTO(BN_add(&c, &c, &b));
+ CHECK_GOTO(BN_add(&c, &c, &a));
if (!BN_is_zero(&c)) {
fprintf(stderr, "Add test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(&a);
BN_free(&b);
BN_free(&c);
@@ -414,37 +426,38 @@ test_sub(BIO *bp)
for (i = 0; i < num0 + num1; i++) {
if (i < num1) {
- BN_bntest_rand(&a, 512, 0, 0);
- BN_copy(&b, &a);
+ CHECK_GOTO(BN_bntest_rand(&a, 512, 0, 0));
+ CHECK_GOTO(BN_copy(&b, &a));
if (BN_set_bit(&a, i) == 0) {
rc = 0;
break;
}
- BN_add_word(&b, i);
+ CHECK_GOTO(BN_add_word(&b, i));
} else {
- BN_bntest_rand(&b, 400 + i - num1, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&b, 400 + i - num1, 0, 0));
a.neg = rand_neg();
b.neg = rand_neg();
}
- BN_sub(&c, &a, &b);
+ CHECK_GOTO(BN_sub(&c, &a, &b));
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " - ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " - ");
}
- BN_print(bp, &c);
+ CHECK_GOTO(BN_print(bp, &c));
BIO_puts(bp, "\n");
}
- BN_add(&c, &c, &b);
- BN_sub(&c, &c, &a);
+ CHECK_GOTO(BN_add(&c, &c, &b));
+ CHECK_GOTO(BN_sub(&c, &c, &a));
if (!BN_is_zero(&c)) {
fprintf(stderr, "Subtract test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(&a);
BN_free(&b);
BN_free(&c);
@@ -464,8 +477,8 @@ test_div(BIO *bp, BN_CTX *ctx)
BN_init(&d);
BN_init(&e);
- BN_one(&a);
- BN_zero(&b);
+ CHECK_GOTO(BN_one(&a));
+ CHECK_GOTO(BN_zero(&b));
if (BN_div(&d, &c, &a, &b, ctx)) {
fprintf(stderr, "Division by zero succeeded!\n");
@@ -474,43 +487,44 @@ test_div(BIO *bp, BN_CTX *ctx)
for (i = 0; i < num0 + num1; i++) {
if (i < num1) {
- BN_bntest_rand(&a, 400, 0, 0);
- BN_copy(&b, &a);
- BN_lshift(&a, &a, i);
- BN_add_word(&a, i);
+ CHECK_GOTO(BN_bntest_rand(&a, 400, 0, 0));
+ CHECK_GOTO(BN_copy(&b, &a));
+ CHECK_GOTO(BN_lshift(&a, &a, i));
+ CHECK_GOTO(BN_add_word(&a, i));
} else
- BN_bntest_rand(&b, 50 + 3 * (i - num1), 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&b, 50 + 3 * (i - num1), 0, 0));
a.neg = rand_neg();
b.neg = rand_neg();
- BN_div(&d, &c, &a, &b, ctx);
+ CHECK_GOTO(BN_div(&d, &c, &a, &b, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " / ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " - ");
}
- BN_print(bp, &d);
+ CHECK_GOTO(BN_print(bp, &d));
BIO_puts(bp, "\n");
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " % ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " - ");
}
- BN_print(bp, &c);
+ CHECK_GOTO(BN_print(bp, &c));
BIO_puts(bp, "\n");
}
- BN_mul(&e, &d, &b, ctx);
- BN_add(&d, &e, &c);
- BN_sub(&d, &d, &a);
+ CHECK_GOTO(BN_mul(&e, &d, &b, ctx));
+ CHECK_GOTO(BN_add(&d, &e, &c));
+ CHECK_GOTO(BN_sub(&d, &d, &a));
if (!BN_is_zero(&d)) {
fprintf(stderr, "Division test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(&a);
BN_free(&b);
BN_free(&c);
@@ -578,16 +592,16 @@ test_div_word(BIO *bp)
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " / ");
print_word(bp, s);
BIO_puts(bp, " - ");
}
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, "\n");
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " % ");
print_word(bp, s);
BIO_puts(bp, " - ");
@@ -595,15 +609,16 @@ test_div_word(BIO *bp)
print_word(bp, r);
BIO_puts(bp, "\n");
}
- BN_mul_word(&b, s);
- BN_add_word(&b, r);
- BN_sub(&b, &a, &b);
+ CHECK_GOTO(BN_mul_word(&b, s));
+ CHECK_GOTO(BN_add_word(&b, r));
+ CHECK_GOTO(BN_sub(&b, &a, &b));
if (!BN_is_zero(&b)) {
fprintf(stderr, "Division (word) test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(&a);
BN_free(&b);
return (rc);
@@ -626,49 +641,50 @@ test_div_recp(BIO *bp, BN_CTX *ctx)
for (i = 0; i < num0 + num1; i++) {
if (i < num1) {
- BN_bntest_rand(&a, 400, 0, 0);
- BN_copy(&b, &a);
- BN_lshift(&a, &a, i);
- BN_add_word(&a, i);
+ CHECK_GOTO(BN_bntest_rand(&a, 400, 0, 0));
+ CHECK_GOTO(BN_copy(&b, &a));
+ CHECK_GOTO(BN_lshift(&a, &a, i));
+ CHECK_GOTO(BN_add_word(&a, i));
} else
- BN_bntest_rand(&b, 50 + 3 * (i - num1), 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&b, 50 + 3 * (i - num1), 0, 0));
a.neg = rand_neg();
b.neg = rand_neg();
- BN_RECP_CTX_set(&recp, &b, ctx);
- BN_div_recp(&d, &c, &a, &recp, ctx);
+ CHECK_GOTO(BN_RECP_CTX_set(&recp, &b, ctx));
+ CHECK_GOTO(BN_div_recp(&d, &c, &a, &recp, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " / ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " - ");
}
- BN_print(bp, &d);
+ CHECK_GOTO(BN_print(bp, &d));
BIO_puts(bp, "\n");
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " % ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " - ");
}
- BN_print(bp, &c);
+ CHECK_GOTO(BN_print(bp, &c));
BIO_puts(bp, "\n");
}
- BN_mul(&e, &d, &b, ctx);
- BN_add(&d, &e, &c);
- BN_sub(&d, &d, &a);
+ CHECK_GOTO(BN_mul(&e, &d, &b, ctx));
+ CHECK_GOTO(BN_add(&d, &e, &c));
+ CHECK_GOTO(BN_sub(&d, &d, &a));
if (!BN_is_zero(&d)) {
fprintf(stderr, "Reciprocal division test failed!\n");
fprintf(stderr, "a=");
- BN_print_fp(stderr, &a);
+ CHECK_GOTO(BN_print_fp(stderr, &a));
fprintf(stderr, "\nb=");
- BN_print_fp(stderr, &b);
+ CHECK_GOTO(BN_print_fp(stderr, &b));
fprintf(stderr, "\n");
rc = 0;
break;
}
}
+err:
BN_free(&a);
BN_free(&b);
BN_free(&c);
@@ -698,31 +714,32 @@ test_mul(BIO *bp)
for (i = 0; i < num0 + num1; i++) {
if (i <= num1) {
- BN_bntest_rand(&a, 100, 0, 0);
- BN_bntest_rand(&b, 100, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&a, 100, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(&b, 100, 0, 0));
} else
- BN_bntest_rand(&b, i - num1, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&b, i - num1, 0, 0));
a.neg = rand_neg();
b.neg = rand_neg();
- BN_mul(&c, &a, &b, ctx);
+ CHECK_GOTO(BN_mul(&c, &a, &b, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " * ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " - ");
}
- BN_print(bp, &c);
+ CHECK_GOTO(BN_print(bp, &c));
BIO_puts(bp, "\n");
}
- BN_div(&d, &e, &c, &a, ctx);
- BN_sub(&d, &d, &b);
+ CHECK_GOTO(BN_div(&d, &e, &c, &a, ctx));
+ CHECK_GOTO(BN_sub(&d, &d, &b));
if (!BN_is_zero(&d) || !BN_is_zero(&e)) {
fprintf(stderr, "Multiplication test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(&a);
BN_free(&b);
BN_free(&c);
@@ -736,7 +753,7 @@ int
test_sqr(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *c, *d, *e;
- int i, ret = 0;
+ int i, rc = 0;
a = BN_new();
c = BN_new();
@@ -744,21 +761,21 @@ test_sqr(BIO *bp, BN_CTX *ctx)
e = BN_new();
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 40 + i * 10, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 40 + i * 10, 0, 0));
a->neg = rand_neg();
- BN_sqr(c, a, ctx);
+ CHECK_GOTO(BN_sqr(c, a, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * ");
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " - ");
}
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, "\n");
}
- BN_div(d, e, c, a, ctx);
- BN_sub(d, d, a);
+ CHECK_GOTO(BN_div(d, e, c, a, ctx));
+ CHECK_GOTO(BN_sub(d, d, a));
if (!BN_is_zero(d) || !BN_is_zero(e)) {
fprintf(stderr, "Square test failed!\n");
goto err;
@@ -771,18 +788,18 @@ test_sqr(BIO *bp, BN_CTX *ctx)
fprintf(stderr, "BN_hex2bn failed\n");
goto err;
}
- BN_sqr(c, a, ctx);
+ CHECK_GOTO(BN_sqr(c, a, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * ");
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " - ");
}
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, "\n");
}
- BN_mul(d, a, a, ctx);
+ CHECK_GOTO(BN_mul(d, a, a, ctx));
if (BN_cmp(c, d)) {
fprintf(stderr,
"Square test failed: BN_sqr and BN_mul produce "
@@ -796,30 +813,30 @@ test_sqr(BIO *bp, BN_CTX *ctx)
fprintf(stderr, "BN_hex2bn failed\n");
goto err;
}
- BN_sqr(c, a, ctx);
+ CHECK_GOTO(BN_sqr(c, a, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * ");
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " - ");
}
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, "\n");
}
- BN_mul(d, a, a, ctx);
+ CHECK_GOTO(BN_mul(d, a, a, ctx));
if (BN_cmp(c, d)) {
fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "
"different results!\n");
goto err;
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(c);
BN_free(d);
BN_free(e);
- return ret;
+ return rc;
}
int
@@ -843,56 +860,57 @@ test_mont(BIO *bp, BN_CTX *ctx)
BN_init(&B);
BN_init(&n);
- BN_zero(&n);
+ CHECK_GOTO(BN_zero(&n));
if (BN_MONT_CTX_set(mont, &n, ctx)) {
fprintf(stderr, "BN_MONT_CTX_set succeeded for zero modulus!\n");
return (0);
}
- BN_set_word(&n, 16);
+ CHECK_GOTO(BN_set_word(&n, 16));
if (BN_MONT_CTX_set(mont, &n, ctx)) {
fprintf(stderr, "BN_MONT_CTX_set succeeded for even modulus!\n");
return (0);
}
- BN_bntest_rand(&a, 100, 0, 0);
- BN_bntest_rand(&b, 100, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(&a, 100, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(&b, 100, 0, 0));
for (i = 0; i < num2; i++) {
int bits = (200 * (i + 1)) / num2;
if (bits == 0)
continue;
- BN_bntest_rand(&n, bits, 0, 1);
- (void)BN_MONT_CTX_set(mont, &n, ctx);
+ CHECK_GOTO(BN_bntest_rand(&n, bits, 0, 1));
+ CHECK_GOTO(BN_MONT_CTX_set(mont, &n, ctx));
- BN_nnmod(&a, &a, &n, ctx);
- BN_nnmod(&b, &b, &n, ctx);
+ CHECK_GOTO(BN_nnmod(&a, &a, &n, ctx));
+ CHECK_GOTO(BN_nnmod(&b, &b, &n, ctx));
- BN_to_montgomery(&A, &a, mont, ctx);
- BN_to_montgomery(&B, &b, mont, ctx);
+ CHECK_GOTO(BN_to_montgomery(&A, &a, mont, ctx));
+ CHECK_GOTO(BN_to_montgomery(&B, &b, mont, ctx));
- BN_mod_mul_montgomery(&c, &A, &B, mont, ctx);
- BN_from_montgomery(&A, &c, mont, ctx);
+ CHECK_GOTO(BN_mod_mul_montgomery(&c, &A, &B, mont, ctx));
+ CHECK_GOTO(BN_from_montgomery(&A, &c, mont, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " * ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " % ");
- BN_print(bp, &(mont->N));
+ CHECK_GOTO(BN_print(bp, &(mont->N)));
BIO_puts(bp, " - ");
}
- BN_print(bp, &A);
+ CHECK_GOTO(BN_print(bp, &A));
BIO_puts(bp, "\n");
}
- BN_mod_mul(&d, &a, &b, &n, ctx);
- BN_sub(&d, &d, &A);
+ CHECK_GOTO(BN_mod_mul(&d, &a, &b, &n, ctx));
+ CHECK_GOTO(BN_sub(&d, &d, &A));
if (!BN_is_zero(&d)) {
fprintf(stderr, "Montgomery multiplication test failed!\n");
rc = 0;
break;
}
}
+err:
BN_MONT_CTX_free(mont);
BN_free(&a);
BN_free(&b);
@@ -917,30 +935,31 @@ test_mod(BIO *bp, BN_CTX *ctx)
d = BN_new();
e = BN_new();
- BN_bntest_rand(a, 1024, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(b, 450 + i * 10, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(b, 450 + i * 10, 0, 0));
a->neg = rand_neg();
b->neg = rand_neg();
- BN_mod(c, a, b, ctx);
+ CHECK_GOTO(BN_mod(c, a, b, ctx));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " % ");
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, " - ");
}
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, "\n");
}
- BN_div(d, e, a, b, ctx);
- BN_sub(e, e, c);
+ CHECK_GOTO(BN_div(d, e, a, b, ctx));
+ CHECK_GOTO(BN_sub(e, e, c));
if (!BN_is_zero(e)) {
fprintf(stderr, "Modulo test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(a);
BN_free(b);
BN_free(c);
@@ -962,19 +981,19 @@ test_mod_mul(BIO *bp, BN_CTX *ctx)
d = BN_new();
e = BN_new();
- BN_one(a);
- BN_one(b);
- BN_zero(c);
+ CHECK_GOTO(BN_one(a));
+ CHECK_GOTO(BN_one(b));
+ CHECK_GOTO(BN_zero(c));
if (BN_mod_mul(e, a, b, c, ctx)) {
fprintf(stderr, "BN_mod_mul with zero modulus succeeded!\n");
return (0);
}
for (j = 0; j < 3; j++) {
- BN_bntest_rand(c, 1024, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(c, 1024, 0, 0));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 475 + i * 10, 0, 0);
- BN_bntest_rand(b, 425 + i * 11, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 475 + i * 10, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(b, 425 + i * 11, 0, 0));
a->neg = rand_neg();
b->neg = rand_neg();
if (!BN_mod_mul(e, a, b, c, ctx)) {
@@ -987,11 +1006,11 @@ test_mod_mul(BIO *bp, BN_CTX *ctx)
}
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * ");
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, " % ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
if ((a->neg ^ b->neg) && !BN_is_zero(e)) {
/* If (a*b) % c is negative, c must be added
* in order to obtain the normalized remainder
@@ -999,25 +1018,25 @@ test_mod_mul(BIO *bp, BN_CTX *ctx)
* BN_mod_mul could generate negative results)
*/
BIO_puts(bp, " + ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
}
BIO_puts(bp, " - ");
}
- BN_print(bp, e);
+ CHECK_GOTO(BN_print(bp, e));
BIO_puts(bp, "\n");
}
- BN_mul(d, a, b, ctx);
- BN_sub(d, d, e);
- BN_div(a, b, d, c, ctx);
+ CHECK_GOTO(BN_mul(d, a, b, ctx));
+ CHECK_GOTO(BN_sub(d, d, e));
+ CHECK_GOTO(BN_div(a, b, d, c, ctx));
if (!BN_is_zero(b)) {
fprintf(stderr, "Modulo multiply test failed!\n");
ERR_print_errors_fp(stderr);
rc = 0;
- goto done;
+ goto err;
}
}
}
-done:
+err:
BN_free(a);
BN_free(b);
BN_free(c);
@@ -1039,9 +1058,9 @@ test_mod_exp(BIO *bp, BN_CTX *ctx)
d = BN_new();
e = BN_new();
- BN_one(a);
- BN_one(b);
- BN_zero(c);
+ CHECK_GOTO(BN_one(a));
+ CHECK_GOTO(BN_one(b));
+ CHECK_GOTO(BN_zero(c));
if (BN_mod_exp(d, a, b, c, ctx)) {
fprintf(stderr, "BN_mod_exp with zero modulus succeeded!\n");
return (0);
@@ -1055,10 +1074,10 @@ test_mod_exp(BIO *bp, BN_CTX *ctx)
return (0);
}
- BN_bntest_rand(c, 30, 0, 1); /* must be odd for montgomery */
+ CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */
for (i = 0; i < num2; i++) {
- BN_bntest_rand(a, 20 + i * 5, 0, 0);
- BN_bntest_rand(b, 2 + i, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0));
if (!BN_mod_exp(d, a, b, c, ctx)) {
rc = 0;
@@ -1067,19 +1086,19 @@ test_mod_exp(BIO *bp, BN_CTX *ctx)
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " ^ ");
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, " % ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " - ");
}
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, "\n");
}
- BN_exp(e, a, b, ctx);
- BN_sub(e, e, d);
- BN_div(a, b, e, c, ctx);
+ CHECK_GOTO(BN_exp(e, a, b, ctx));
+ CHECK_GOTO(BN_sub(e, e, d));
+ CHECK_GOTO(BN_div(a, b, e, c, ctx));
if (!BN_is_zero(b)) {
fprintf(stderr, "Modulo exponentiation test failed!\n");
rc = 0;
@@ -1087,10 +1106,10 @@ test_mod_exp(BIO *bp, BN_CTX *ctx)
}
}
- BN_bntest_rand(c, 30, 0, 1); /* must be odd for montgomery */
+ CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */
for (i = 0; i < num2; i++) {
- BN_bntest_rand(a, 20 + i * 5, 0, 0);
- BN_bntest_rand(b, 2 + i, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0));
if (!BN_mod_exp_ct(d, a, b, c, ctx)) {
rc = 0;
@@ -1099,19 +1118,19 @@ test_mod_exp(BIO *bp, BN_CTX *ctx)
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " ^ ");
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, " % ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " - ");
}
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, "\n");
}
- BN_exp(e, a, b, ctx);
- BN_sub(e, e, d);
- BN_div(a, b, e, c, ctx);
+ CHECK_GOTO(BN_exp(e, a, b, ctx));
+ CHECK_GOTO(BN_sub(e, e, d));
+ CHECK_GOTO(BN_div(a, b, e, c, ctx));
if (!BN_is_zero(b)) {
fprintf(stderr, "Modulo exponentiation test failed!\n");
rc = 0;
@@ -1119,10 +1138,10 @@ test_mod_exp(BIO *bp, BN_CTX *ctx)
}
}
- BN_bntest_rand(c, 30, 0, 1); /* must be odd for montgomery */
+ CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */
for (i = 0; i < num2; i++) {
- BN_bntest_rand(a, 20 + i * 5, 0, 0);
- BN_bntest_rand(b, 2 + i, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0));
if (!BN_mod_exp_nonct(d, a, b, c, ctx)) {
rc = 0;
@@ -1131,25 +1150,26 @@ test_mod_exp(BIO *bp, BN_CTX *ctx)
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " ^ ");
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, " % ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " - ");
}
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, "\n");
}
- BN_exp(e, a, b, ctx);
- BN_sub(e, e, d);
- BN_div(a, b, e, c, ctx);
+ CHECK_GOTO(BN_exp(e, a, b, ctx));
+ CHECK_GOTO(BN_sub(e, e, d));
+ CHECK_GOTO(BN_div(a, b, e, c, ctx));
if (!BN_is_zero(b)) {
fprintf(stderr, "Modulo exponentiation test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(a);
BN_free(b);
BN_free(c);
@@ -1171,9 +1191,9 @@ test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx)
d = BN_new();
e = BN_new();
- BN_one(a);
- BN_one(b);
- BN_zero(c);
+ CHECK_GOTO(BN_one(a));
+ CHECK_GOTO(BN_one(b));
+ CHECK_GOTO(BN_zero(c));
if (BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) {
fprintf(stderr, "BN_mod_exp_mont_consttime with zero modulus "
"succeeded\n");
@@ -1181,7 +1201,7 @@ test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx)
goto err;
}
- BN_set_word(c, 16);
+ CHECK_GOTO(BN_set_word(c, 16));
if (BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) {
fprintf(stderr, "BN_mod_exp_mont_consttime with even modulus "
"succeeded\n");
@@ -1189,10 +1209,10 @@ test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx)
goto err;
}
- BN_bntest_rand(c, 30, 0, 1); /* must be odd for montgomery */
+ CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */
for (i = 0; i < num2; i++) {
- BN_bntest_rand(a, 20 + i * 5, 0, 0);
- BN_bntest_rand(b, 2 + i, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0));
if (!BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) {
rc = 0;
@@ -1201,19 +1221,19 @@ test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx)
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " ^ ");
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, " % ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " - ");
}
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, "\n");
}
- BN_exp(e, a, b, ctx);
- BN_sub(e, e, d);
- BN_div(a, b, e, c, ctx);
+ CHECK_GOTO(BN_exp(e, a, b, ctx));
+ CHECK_GOTO(BN_sub(e, e, d));
+ CHECK_GOTO(BN_div(a, b, e, c, ctx));
if (!BN_is_zero(b)) {
fprintf(stderr, "Modulo exponentiation test failed!\n");
rc = 0;
@@ -1237,7 +1257,7 @@ int
test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *p, *m, *d, *e, *b, *n, *c;
- int rc = 1;
+ int len, rc = 1;
BN_MONT_CTX *mont;
a = BN_new();
@@ -1249,12 +1269,12 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
n = BN_new();
c = BN_new();
- mont = BN_MONT_CTX_new();
+ CHECK_GOTO(mont = BN_MONT_CTX_new());
- BN_bntest_rand(m, 1024, 0, 1); /* must be odd for montgomery */
+ CHECK_GOTO(BN_bntest_rand(m, 1024, 0, 1)); /* must be odd for montgomery */
/* Zero exponent */
- BN_bntest_rand(a, 1024, 0, 0);
- BN_zero(p);
+ CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0));
+ CHECK_GOTO(BN_zero(p));
if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) {
rc = 0;
goto err;
@@ -1265,24 +1285,27 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
goto err;
}
/* Regression test for carry bug in mulx4x_mont */
- BN_hex2bn(&a,
+ len = BN_hex2bn(&a,
"7878787878787878787878787878787878787878787878787878787878787878"
"7878787878787878787878787878787878787878787878787878787878787878"
"7878787878787878787878787878787878787878787878787878787878787878"
"7878787878787878787878787878787878787878787878787878787878787878");
- BN_hex2bn(&b,
+ CHECK_GOTO(len);
+ len = BN_hex2bn(&b,
"095D72C08C097BA488C5E439C655A192EAFB6380073D8C2664668EDDB4060744"
"E16E57FB4EDB9AE10A0CEFCDC28A894F689A128379DB279D48A2E20849D68593"
"9B7803BCF46CEBF5C533FB0DD35B080593DE5472E3FE5DB951B8BFF9B4CB8F03"
"9CC638A5EE8CDD703719F8000E6A9F63BEED5F2FCD52FF293EA05A251BB4AB81");
- BN_hex2bn(&n,
+ CHECK_GOTO(len);
+ len = BN_hex2bn(&n,
"D78AF684E71DB0C39CFF4E64FB9DB567132CB9C50CC98009FEB820B26F2DED9B"
"91B9B5E2B83AE0AE4EB4E0523CA726BFBE969B89FD754F674CE99118C3F2D1C5"
"D81FDC7C54E02B60262B241D53C040E99E45826ECA37A804668E690E1AFC1CA4"
"2C9A15D84D4954425F0B7642FC0BD9D7B24E2618D2DCC9B729D944BADACFDDAF");
- BN_MONT_CTX_set(mont, n, ctx);
- BN_mod_mul_montgomery(c, a, b, mont, ctx);
- BN_mod_mul_montgomery(d, b, a, mont, ctx);
+ CHECK_GOTO(len);
+ CHECK_GOTO(BN_MONT_CTX_set(mont, n, ctx));
+ CHECK_GOTO(BN_mod_mul_montgomery(c, a, b, mont, ctx));
+ CHECK_GOTO(BN_mod_mul_montgomery(d, b, a, mont, ctx));
if (BN_cmp(c, d)) {
fprintf(stderr, "Montgomery multiplication test failed:"
" a*b != b*a.\n");
@@ -1290,7 +1313,7 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
goto err;
}
/* Regression test for carry bug in sqr[x]8x_mont */
- BN_hex2bn(&n,
+ len = BN_hex2bn(&n,
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
@@ -1307,7 +1330,8 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
"0000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000FFFFFFFFFFFFFF");
- BN_hex2bn(&a,
+ CHECK_GOTO(len);
+ len = BN_hex2bn(&a,
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
@@ -1324,10 +1348,12 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
"0000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000"
"000000000000000000000000000000000000000000FFFFFFFFFFFFFF00000000");
- b = BN_dup(a);
- BN_MONT_CTX_set(mont, n, ctx);
- BN_mod_mul_montgomery(c, a, a, mont, ctx);
- BN_mod_mul_montgomery(d, a, b, mont, ctx);
+ CHECK_GOTO(len);
+ BN_free(b);
+ CHECK_GOTO(b = BN_dup(a));
+ CHECK_GOTO(BN_MONT_CTX_set(mont, n, ctx));
+ CHECK_GOTO(BN_mod_mul_montgomery(c, a, a, mont, ctx));
+ CHECK_GOTO(BN_mod_mul_montgomery(d, a, b, mont, ctx));
if (BN_cmp(c, d)) {
fprintf(stderr, "Montgomery multiplication test failed:"
" a**2 != a*a.\n");
@@ -1335,8 +1361,8 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
goto err;
}
/* Zero input */
- BN_bntest_rand(p, 1024, 0, 0);
- BN_zero(a);
+ CHECK_GOTO(BN_bntest_rand(p, 1024, 0, 0));
+ CHECK_GOTO(BN_zero(a));
if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) {
rc = 0;
goto err;
@@ -1351,8 +1377,8 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
* than the modulus m, in order to test the const time precomputation
* scattering/gathering.
*/
- BN_one(a);
- BN_MONT_CTX_set(mont, m, ctx);
+ CHECK_GOTO(BN_one(a));
+ CHECK_GOTO(BN_MONT_CTX_set(mont, m, ctx));
if (!BN_from_montgomery(e, a, mont, ctx)) {
rc = 0;
goto err;
@@ -1371,7 +1397,7 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
goto err;
}
/* Finally, some regular test vectors. */
- BN_bntest_rand(e, 1024, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(e, 1024, 0, 0));
if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) {
rc = 0;
goto err;
@@ -1409,11 +1435,11 @@ test_exp(BIO *bp, BN_CTX *ctx)
d = BN_new();
e = BN_new();
one = BN_new();
- BN_one(one);
+ CHECK_GOTO(BN_one(one));
for (i = 0; i < num2; i++) {
- BN_bntest_rand(a, 20 + i * 5, 0, 0);
- BN_bntest_rand(b, 2 + i, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0));
if (BN_exp(d, a, b, ctx) <= 0) {
rc = 0;
@@ -1422,24 +1448,25 @@ test_exp(BIO *bp, BN_CTX *ctx)
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " ^ ");
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, " - ");
}
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, "\n");
}
- BN_one(e);
+ CHECK_GOTO(BN_one(e));
for (; !BN_is_zero(b); BN_sub(b, b, one))
- BN_mul(e, e, a, ctx);
- BN_sub(e, e, d);
+ CHECK_GOTO(BN_mul(e, e, a, ctx));
+ CHECK_GOTO(BN_sub(e, e, d));
if (!BN_is_zero(e)) {
fprintf(stderr, "Exponentiation test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(a);
BN_free(b);
BN_free(d);
@@ -1453,27 +1480,27 @@ int
test_gf2m_add(BIO *bp)
{
BIGNUM a, b, c;
- int i, ret = 0;
+ int i, rc = 0;
BN_init(&a);
BN_init(&b);
BN_init(&c);
for (i = 0; i < num0; i++) {
- BN_rand(&a, 512, 0, 0);
- BN_copy(&b, BN_value_one());
+ CHECK_GOTO(BN_rand(&a, 512, 0, 0));
+ CHECK_GOTO(BN_copy(&b, BN_value_one()));
a.neg = rand_neg();
b.neg = rand_neg();
- BN_GF2m_add(&c, &a, &b);
+ CHECK_GOTO(BN_GF2m_add(&c, &a, &b));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, &a);
+ CHECK_GOTO(BN_print(bp, &a));
BIO_puts(bp, " ^ ");
- BN_print(bp, &b);
+ CHECK_GOTO(BN_print(bp, &b));
BIO_puts(bp, " = ");
}
- BN_print(bp, &c);
+ CHECK_GOTO(BN_print(bp, &c));
BIO_puts(bp, "\n");
}
#endif
@@ -1483,26 +1510,26 @@ test_gf2m_add(BIO *bp)
fprintf(stderr, "GF(2^m) addition test (a) failed!\n");
goto err;
}
- BN_GF2m_add(&c, &c, &c);
+ CHECK_GOTO(BN_GF2m_add(&c, &c, &c));
/* Test that c + c = 0. */
if (!BN_is_zero(&c)) {
fprintf(stderr, "GF(2^m) addition test (b) failed!\n");
goto err;
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(&a);
BN_free(&b);
BN_free(&c);
- return ret;
+ return rc;
}
int
test_gf2m_mod(BIO *bp)
{
BIGNUM *a, *b[2], *c, *d, *e;
- int i, j, ret = 0;
+ int i, j, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1513,27 +1540,27 @@ test_gf2m_mod(BIO *bp)
d = BN_new();
e = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 1024, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0));
for (j = 0; j < 2; j++) {
- BN_GF2m_mod(c, a, b[j]);
+ CHECK_GOTO(BN_GF2m_mod(c, a, b[j]));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, " - ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, "\n");
}
}
#endif
- BN_GF2m_add(d, a, c);
- BN_GF2m_mod(e, d, b[j]);
+ CHECK_GOTO(BN_GF2m_add(d, a, c));
+ CHECK_GOTO(BN_GF2m_mod(e, d, b[j]));
/* Test that a + (a mod p) mod p == 0. */
if (!BN_is_zero(e)) {
fprintf(stderr, "GF(2^m) modulo test failed!\n");
@@ -1541,7 +1568,7 @@ test_gf2m_mod(BIO *bp)
}
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
@@ -1549,14 +1576,14 @@ err:
BN_free(c);
BN_free(d);
BN_free(e);
- return ret;
+ return rc;
}
int
test_gf2m_mod_mul(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b[2], *c, *d, *e, *f, *g, *h;
- int i, j, ret = 0;
+ int i, j, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1570,34 +1597,34 @@ test_gf2m_mod_mul(BIO *bp, BN_CTX *ctx)
g = BN_new();
h = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 1024, 0, 0);
- BN_bntest_rand(c, 1024, 0, 0);
- BN_bntest_rand(d, 1024, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(c, 1024, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(d, 1024, 0, 0));
for (j = 0; j < 2; j++) {
- BN_GF2m_mod_mul(e, a, c, b[j], ctx);
+ CHECK_GOTO(BN_GF2m_mod_mul(e, a, c, b[j], ctx));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, " - ");
- BN_print(bp, e);
+ CHECK_GOTO(BN_print(bp, e));
BIO_puts(bp, "\n");
}
}
#endif
- BN_GF2m_add(f, a, d);
- BN_GF2m_mod_mul(g, f, c, b[j], ctx);
- BN_GF2m_mod_mul(h, d, c, b[j], ctx);
- BN_GF2m_add(f, e, g);
- BN_GF2m_add(f, f, h);
+ CHECK_GOTO(BN_GF2m_add(f, a, d));
+ CHECK_GOTO(BN_GF2m_mod_mul(g, f, c, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_mod_mul(h, d, c, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_add(f, e, g));
+ CHECK_GOTO(BN_GF2m_add(f, f, h));
/* Test that (a+d)*c = a*c + d*c. */
if (!BN_is_zero(f)) {
fprintf(stderr, "GF(2^m) modular multiplication test failed!\n");
@@ -1605,7 +1632,7 @@ test_gf2m_mod_mul(BIO *bp, BN_CTX *ctx)
}
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
@@ -1616,14 +1643,14 @@ err:
BN_free(f);
BN_free(g);
BN_free(h);
- return ret;
+ return rc;
}
int
test_gf2m_mod_sqr(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b[2], *c, *d;
- int i, j, ret = 0;
+ int i, j, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1633,30 +1660,30 @@ test_gf2m_mod_sqr(BIO *bp, BN_CTX *ctx)
c = BN_new();
d = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 1024, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0));
for (j = 0; j < 2; j++) {
- BN_GF2m_mod_sqr(c, a, b[j], ctx);
- BN_copy(d, a);
- BN_GF2m_mod_mul(d, a, d, b[j], ctx);
+ CHECK_GOTO(BN_GF2m_mod_sqr(c, a, b[j], ctx));
+ CHECK_GOTO(BN_copy(d, a));
+ CHECK_GOTO(BN_GF2m_mod_mul(d, a, d, b[j], ctx));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " ^ 2 % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, " = ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, "; a * a = ");
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, "\n");
}
}
#endif
- BN_GF2m_add(d, c, d);
+ CHECK_GOTO(BN_GF2m_add(d, c, d));
/* Test that a*a = a^2. */
if (!BN_is_zero(d)) {
fprintf(stderr, "GF(2^m) modular squaring test failed!\n");
@@ -1664,21 +1691,21 @@ test_gf2m_mod_sqr(BIO *bp, BN_CTX *ctx)
}
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
- return ret;
+ return rc;
}
int
test_gf2m_mod_inv(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b[2], *c, *d;
- int i, j, ret = 0;
+ int i, j, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1688,22 +1715,22 @@ test_gf2m_mod_inv(BIO *bp, BN_CTX *ctx)
c = BN_new();
d = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 512, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0));
for (j = 0; j < 2; j++) {
- BN_GF2m_mod_inv(c, a, b[j], ctx);
- BN_GF2m_mod_mul(d, a, c, b[j], ctx);
+ CHECK_GOTO(BN_GF2m_mod_inv(c, a, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_mod_mul(d, a, c, b[j], ctx));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " - 1 % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, "\n");
}
}
@@ -1715,21 +1742,21 @@ test_gf2m_mod_inv(BIO *bp, BN_CTX *ctx)
}
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
- return ret;
+ return rc;
}
int
test_gf2m_mod_div(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b[2], *c, *d, *e, *f;
- int i, j, ret = 0;
+ int i, j, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1741,26 +1768,26 @@ test_gf2m_mod_div(BIO *bp, BN_CTX *ctx)
e = BN_new();
f = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 512, 0, 0);
- BN_bntest_rand(c, 512, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(c, 512, 0, 0));
for (j = 0; j < 2; j++) {
- BN_GF2m_mod_div(d, a, c, b[j], ctx);
- BN_GF2m_mod_mul(e, d, c, b[j], ctx);
- BN_GF2m_mod_div(f, a, e, b[j], ctx);
+ CHECK_GOTO(BN_GF2m_mod_div(d, a, c, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_mod_mul(e, d, c, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_mod_div(f, a, e, b[j], ctx));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " = ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " * ");
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, " % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, "\n");
}
}
@@ -1772,7 +1799,7 @@ test_gf2m_mod_div(BIO *bp, BN_CTX *ctx)
}
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
@@ -1781,14 +1808,14 @@ err:
BN_free(d);
BN_free(e);
BN_free(f);
- return ret;
+ return rc;
}
int
test_gf2m_mod_exp(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b[2], *c, *d, *e, *f;
- int i, j, ret = 0;
+ int i, j, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1800,38 +1827,38 @@ test_gf2m_mod_exp(BIO *bp, BN_CTX *ctx)
e = BN_new();
f = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 512, 0, 0);
- BN_bntest_rand(c, 512, 0, 0);
- BN_bntest_rand(d, 512, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(c, 512, 0, 0));
+ CHECK_GOTO(BN_bntest_rand(d, 512, 0, 0));
for (j = 0; j < 2; j++) {
- BN_GF2m_mod_exp(e, a, c, b[j], ctx);
- BN_GF2m_mod_exp(f, a, d, b[j], ctx);
- BN_GF2m_mod_mul(e, e, f, b[j], ctx);
- BN_add(f, c, d);
- BN_GF2m_mod_exp(f, a, f, b[j], ctx);
+ CHECK_GOTO(BN_GF2m_mod_exp(e, a, c, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_mod_exp(f, a, d, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_mod_mul(e, e, f, b[j], ctx));
+ CHECK_GOTO(BN_add(f, c, d));
+ CHECK_GOTO(BN_GF2m_mod_exp(f, a, f, b[j], ctx));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " ^ (");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " + ");
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, ") = ");
- BN_print(bp, e);
+ CHECK_GOTO(BN_print(bp, e));
BIO_puts(bp, "; - ");
- BN_print(bp, f);
+ CHECK_GOTO(BN_print(bp, f));
BIO_puts(bp, " % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, "\n");
}
}
#endif
- BN_GF2m_add(f, e, f);
+ CHECK_GOTO(BN_GF2m_add(f, e, f));
/* Test that a^(c+d)=a^c*a^d. */
if (!BN_is_zero(f)) {
fprintf(stderr, "GF(2^m) modular exponentiation test failed!\n");
@@ -1839,7 +1866,7 @@ test_gf2m_mod_exp(BIO *bp, BN_CTX *ctx)
}
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
@@ -1848,14 +1875,14 @@ err:
BN_free(d);
BN_free(e);
BN_free(f);
- return ret;
+ return rc;
}
int
test_gf2m_mod_sqrt(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b[2], *c, *d, *e, *f;
- int i, j, ret = 0;
+ int i, j, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1867,26 +1894,26 @@ test_gf2m_mod_sqrt(BIO *bp, BN_CTX *ctx)
e = BN_new();
f = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 512, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0));
for (j = 0; j < 2; j++) {
- BN_GF2m_mod(c, a, b[j]);
- BN_GF2m_mod_sqrt(d, a, b[j], ctx);
- BN_GF2m_mod_sqr(e, d, b[j], ctx);
+ CHECK_GOTO(BN_GF2m_mod(c, a, b[j]));
+ CHECK_GOTO(BN_GF2m_mod_sqrt(d, a, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_mod_sqr(e, d, b[j], ctx));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, d);
+ CHECK_GOTO(BN_print(bp, d));
BIO_puts(bp, " ^ 2 - ");
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, "\n");
}
}
#endif
- BN_GF2m_add(f, c, e);
+ CHECK_GOTO(BN_GF2m_add(f, c, e));
/* Test that d^2 = a, where d = sqrt(a). */
if (!BN_is_zero(f)) {
fprintf(stderr, "GF(2^m) modular square root test failed!\n");
@@ -1894,7 +1921,7 @@ test_gf2m_mod_sqrt(BIO *bp, BN_CTX *ctx)
}
}
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
@@ -1903,14 +1930,14 @@ err:
BN_free(d);
BN_free(e);
BN_free(f);
- return ret;
+ return rc;
}
int
test_gf2m_mod_solve_quad(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b[2], *c, *d, *e;
- int i, j, s = 0, t, ret = 0;
+ int i, j, s = 0, t, rc = 0;
int p0[] = { 163, 7, 6, 3, 0, -1 };
int p1[] = { 193, 15, 0, -1 };
@@ -1921,31 +1948,31 @@ test_gf2m_mod_solve_quad(BIO *bp, BN_CTX *ctx)
d = BN_new();
e = BN_new();
- BN_GF2m_arr2poly(p0, b[0]);
- BN_GF2m_arr2poly(p1, b[1]);
+ CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0]));
+ CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1]));
for (i = 0; i < num0; i++) {
- BN_bntest_rand(a, 512, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0));
for (j = 0; j < 2; j++) {
t = BN_GF2m_mod_solve_quad(c, a, b[j], ctx);
if (t) {
s++;
- BN_GF2m_mod_sqr(d, c, b[j], ctx);
- BN_GF2m_add(d, c, d);
- BN_GF2m_mod(e, a, b[j]);
+ CHECK_GOTO(BN_GF2m_mod_sqr(d, c, b[j], ctx));
+ CHECK_GOTO(BN_GF2m_add(d, c, d));
+ CHECK_GOTO(BN_GF2m_mod(e, a, b[j]));
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL) {
if (!results) {
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " is root of z^2 + z = ");
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, "\n");
}
}
#endif
- BN_GF2m_add(e, e, d);
+ CHECK_GOTO(BN_GF2m_add(e, e, d));
/* Test that solution of quadratic c satisfies c^2 + c = a. */
if (!BN_is_zero(e)) {
fprintf(stderr, "GF(2^m) modular solve quadratic test failed!\n");
@@ -1957,9 +1984,9 @@ test_gf2m_mod_solve_quad(BIO *bp, BN_CTX *ctx)
if (bp != NULL) {
if (!results) {
BIO_puts(bp, "There are no roots of z^2 + z = ");
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " % ");
- BN_print(bp, b[j]);
+ CHECK_GOTO(BN_print(bp, b[j]));
BIO_puts(bp, "\n");
}
}
@@ -1972,7 +1999,7 @@ test_gf2m_mod_solve_quad(BIO *bp, BN_CTX *ctx)
fprintf(stderr, "this is very unlikely and probably indicates an error.\n");
goto err;
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b[0]);
@@ -1980,7 +2007,7 @@ err:
BN_free(c);
BN_free(d);
BN_free(e);
- return ret;
+ return rc;
}
#endif
static int
@@ -2008,7 +2035,7 @@ test_kron(BIO *bp, BN_CTX *ctx)
BIGNUM *a, *b, *r, *t;
int i;
int legendre, kronecker;
- int ret = 0;
+ int rc = 0;
a = BN_new();
b = BN_new();
@@ -2077,9 +2104,9 @@ test_kron(BIO *bp, BN_CTX *ctx)
if (legendre != kronecker) {
fprintf(stderr, "legendre != kronecker; a = ");
- BN_print_fp(stderr, a);
+ CHECK_GOTO(BN_print_fp(stderr, a));
fprintf(stderr, ", b = ");
- BN_print_fp(stderr, b);
+ CHECK_GOTO(BN_print_fp(stderr, b));
fprintf(stderr, "\n");
goto err;
}
@@ -2090,13 +2117,13 @@ test_kron(BIO *bp, BN_CTX *ctx)
putc('\n', stderr);
fflush(stderr);
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(b);
BN_free(r);
BN_free(t);
- return ret;
+ return rc;
}
int
@@ -2105,7 +2132,7 @@ test_sqrt(BIO *bp, BN_CTX *ctx)
BN_GENCB cb;
BIGNUM *a, *p, *r;
int i, j;
- int ret = 0;
+ int rc = 0;
a = BN_new();
p = BN_new();
@@ -2166,11 +2193,11 @@ test_sqrt(BIO *bp, BN_CTX *ctx)
if (BN_cmp(a, r) != 0) {
fprintf(stderr, "BN_mod_sqrt failed: a = ");
- BN_print_fp(stderr, a);
+ CHECK_GOTO(BN_print_fp(stderr, a));
fprintf(stderr, ", r = ");
- BN_print_fp(stderr, r);
+ CHECK_GOTO(BN_print_fp(stderr, r));
fprintf(stderr, ", p = ");
- BN_print_fp(stderr, p);
+ CHECK_GOTO(BN_print_fp(stderr, p));
fprintf(stderr, "\n");
goto err;
}
@@ -2182,63 +2209,64 @@ test_sqrt(BIO *bp, BN_CTX *ctx)
putc('\n', stderr);
fflush(stderr);
}
- ret = 1;
+ rc = 1;
err:
BN_free(a);
BN_free(p);
BN_free(r);
- return ret;
+ return rc;
}
int
test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_)
{
- BIGNUM *a, *b, *c, *d;
+ BIGNUM *a = NULL, *b, *c, *d;
int i;
int rc = 1;
b = BN_new();
c = BN_new();
d = BN_new();
- BN_one(c);
+ CHECK_GOTO(BN_one(c));
if (a_)
a = a_;
else {
a = BN_new();
- BN_bntest_rand(a, 200, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0));
a->neg = rand_neg();
}
for (i = 0; i < num0; i++) {
- (void)BN_lshift(b, a, i + 1);
- BN_add(c, c, c);
+ CHECK_GOTO(BN_lshift(b, a, i + 1));
+ CHECK_GOTO(BN_add(c, c, c));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " - ");
}
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, "\n");
}
- BN_mul(d, a, c, ctx);
- BN_sub(d, d, b);
+ CHECK_GOTO(BN_mul(d, a, c, ctx));
+ CHECK_GOTO(BN_sub(d, d, b));
if (!BN_is_zero(d)) {
fprintf(stderr, "Left shift test failed!\n");
fprintf(stderr, "a=");
- BN_print_fp(stderr, a);
+ CHECK_GOTO(BN_print_fp(stderr, a));
fprintf(stderr, "\nb=");
- BN_print_fp(stderr, b);
+ CHECK_GOTO(BN_print_fp(stderr, b));
fprintf(stderr, "\nc=");
- BN_print_fp(stderr, c);
+ CHECK_GOTO(BN_print_fp(stderr, c));
fprintf(stderr, "\nd=");
- BN_print_fp(stderr, d);
+ CHECK_GOTO(BN_print_fp(stderr, d));
fprintf(stderr, "\n");
rc = 0;
break;
}
}
+err:
BN_free(a);
BN_free(b);
BN_free(c);
@@ -2257,29 +2285,30 @@ test_lshift1(BIO *bp)
b = BN_new();
c = BN_new();
- BN_bntest_rand(a, 200, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0));
a->neg = rand_neg();
for (i = 0; i < num0; i++) {
- (void)BN_lshift1(b, a);
+ CHECK_GOTO(BN_lshift1(b, a));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " * 2");
BIO_puts(bp, " - ");
}
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, "\n");
}
- BN_add(c, a, a);
- BN_sub(a, b, c);
+ CHECK_GOTO(BN_add(c, a, a));
+ CHECK_GOTO(BN_sub(a, b, c));
if (!BN_is_zero(a)) {
fprintf(stderr, "Left shift one test failed!\n");
rc = 0;
break;
}
- BN_copy(a, b);
+ CHECK_GOTO(BN_copy(a, b));
}
+err:
BN_free(a);
BN_free(b);
BN_free(c);
@@ -2298,31 +2327,32 @@ test_rshift(BIO *bp, BN_CTX *ctx)
c = BN_new();
d = BN_new();
e = BN_new();
- BN_one(c);
+ CHECK_GOTO(BN_one(c));
- BN_bntest_rand(a, 200, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0));
a->neg = rand_neg();
for (i = 0; i < num0; i++) {
- (void)BN_rshift(b, a, i + 1);
- BN_add(c, c, c);
+ CHECK_GOTO(BN_rshift(b, a, i + 1));
+ CHECK_GOTO(BN_add(c, c, c));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " / ");
- BN_print(bp, c);
+ CHECK_GOTO(BN_print(bp, c));
BIO_puts(bp, " - ");
}
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, "\n");
}
- BN_div(d, e, a, c, ctx);
- BN_sub(d, d, b);
+ CHECK_GOTO(BN_div(d, e, a, c, ctx));
+ CHECK_GOTO(BN_sub(d, d, b));
if (!BN_is_zero(d)) {
fprintf(stderr, "Right shift test failed!\n");
rc = 0;
break;
}
}
+err:
BN_free(a);
BN_free(b);
BN_free(c);
@@ -2342,28 +2372,29 @@ test_rshift1(BIO *bp)
b = BN_new();
c = BN_new();
- BN_bntest_rand(a, 200, 0, 0);
+ CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0));
a->neg = rand_neg();
for (i = 0; i < num0; i++) {
- (void)BN_rshift1(b, a);
+ CHECK_GOTO(BN_rshift1(b, a));
if (bp != NULL) {
if (!results) {
- BN_print(bp, a);
+ CHECK_GOTO(BN_print(bp, a));
BIO_puts(bp, " / 2");
BIO_puts(bp, " - ");
}
- BN_print(bp, b);
+ CHECK_GOTO(BN_print(bp, b));
BIO_puts(bp, "\n");
}
- BN_sub(c, a, b);
- BN_sub(c, c, b);
+ CHECK_GOTO(BN_sub(c, a, b));
+ CHECK_GOTO(BN_sub(c, c, b));
if (!BN_is_zero(c) && !BN_abs_is_word(c, 1)) {
fprintf(stderr, "Right shift one test failed!\n");
rc = 0;
break;
}
- BN_copy(a, b);
+ CHECK_GOTO(BN_copy(a, b));
}
+err:
BN_free(a);
BN_free(b);
BN_free(c);
@@ -2382,17 +2413,17 @@ rand_neg(void)
int
test_mod_exp_sizes(BIO *bp, BN_CTX *ctx)
{
- BN_MONT_CTX *mont_ctx;
+ BN_MONT_CTX *mont_ctx = NULL;
BIGNUM *p, *x, *y, *r, *r2;
int size;
- int ok = 0;
+ int rc = 0;
BN_CTX_start(ctx);
- p = BN_CTX_get(ctx);
- x = BN_CTX_get(ctx);
- y = BN_CTX_get(ctx);
- r = BN_CTX_get(ctx);
- r2 = BN_CTX_get(ctx);
+ CHECK_GOTO(p = BN_CTX_get(ctx));
+ CHECK_GOTO(x = BN_CTX_get(ctx));
+ CHECK_GOTO(y = BN_CTX_get(ctx));
+ CHECK_GOTO(r = BN_CTX_get(ctx));
+ CHECK_GOTO(r2 = BN_CTX_get(ctx));
mont_ctx = BN_MONT_CTX_new();
if (r2 == NULL || mont_ctx == NULL)
@@ -2410,8 +2441,10 @@ test_mod_exp_sizes(BIO *bp, BN_CTX *ctx)
goto err;
if (BN_cmp(r, r2) != 0) {
- char *r_str = BN_bn2hex(r);
- char *r2_str = BN_bn2hex(r2);
+ char *r_str = NULL;
+ char *r2_str = NULL;
+ CHECK_GOTO(r_str = BN_bn2hex(r));
+ CHECK_GOTO(r2_str = BN_bn2hex(r2));
printf("Incorrect answer at size %d: %s vs %s\n",
size, r_str, r2_str);
@@ -2421,10 +2454,10 @@ test_mod_exp_sizes(BIO *bp, BN_CTX *ctx)
}
}
- ok = 1;
+ rc = 1;
err:
BN_MONT_CTX_free(mont_ctx);
BN_CTX_end(ctx);
- return ok;
+ return rc;
}