Remove superfluous crypto/bio dependencies from tests.
Limiting uses of crypto/bio to code that really need to it by avoiding
the use of BIO just to write to stdout/stderr.
Change-Id: I34e0f773161aeec073691e439ac353fb7b1785f3
Reviewed-on: https://boringssl-review.googlesource.com/3930
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc
index caef572..20d15a1 100644
--- a/crypto/bn/bn_test.cc
+++ b/crypto/bn/bn_test.cc
@@ -70,7 +70,6 @@
#include <stdio.h>
#include <string.h>
-#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
@@ -84,30 +83,30 @@
static const int num1 = 50; // additional tests for some functions
static const int num2 = 5; // number of tests for slow functions
-static bool test_add(BIO *bp);
-static bool test_sub(BIO *bp);
-static bool test_lshift1(BIO *bp);
-static bool test_lshift(BIO *bp, BN_CTX *ctx, ScopedBIGNUM a);
-static bool test_rshift1(BIO *bp);
-static bool test_rshift(BIO *bp, BN_CTX *ctx);
-static bool test_sqr(BIO *bp, BN_CTX *ctx);
-static bool test_mul(BIO *bp);
-static bool test_div(BIO *bp, BN_CTX *ctx);
+static bool test_add(FILE *fp);
+static bool test_sub(FILE *fp);
+static bool test_lshift1(FILE *fp);
+static bool test_lshift(FILE *fp, BN_CTX *ctx, ScopedBIGNUM a);
+static bool test_rshift1(FILE *fp);
+static bool test_rshift(FILE *fp, BN_CTX *ctx);
+static bool test_sqr(FILE *fp, BN_CTX *ctx);
+static bool test_mul(FILE *fp);
+static bool test_div(FILE *fp, BN_CTX *ctx);
static int rand_neg();
-static bool test_div_word(BIO *bp);
-static bool test_mont(BIO *bp, BN_CTX *ctx);
-static bool test_mod(BIO *bp, BN_CTX *ctx);
-static bool test_mod_mul(BIO *bp, BN_CTX *ctx);
-static bool test_mod_exp(BIO *bp, BN_CTX *ctx);
-static bool test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx);
-static bool test_exp(BIO *bp, BN_CTX *ctx);
-static bool test_mod_sqrt(BIO *bp, BN_CTX *ctx);
+static bool test_div_word(FILE *fp);
+static bool test_mont(FILE *fp, BN_CTX *ctx);
+static bool test_mod(FILE *fp, BN_CTX *ctx);
+static bool test_mod_mul(FILE *fp, BN_CTX *ctx);
+static bool test_mod_exp(FILE *fp, BN_CTX *ctx);
+static bool test_mod_exp_mont_consttime(FILE *fp, BN_CTX *ctx);
+static bool test_exp(FILE *fp, BN_CTX *ctx);
+static bool test_mod_sqrt(FILE *fp, BN_CTX *ctx);
static bool test_exp_mod_zero(void);
-static bool test_small_prime(BIO *bp, BN_CTX *ctx);
-static bool test_mod_exp_mont5(BIO *bp, BN_CTX *ctx);
-static bool test_sqrt(BIO *bp, BN_CTX *ctx);
-static bool test_bn2bin_padded(BIO *bp, BN_CTX *ctx);
+static bool test_small_prime(FILE *fp, BN_CTX *ctx);
+static bool test_mod_exp_mont5(FILE *fp, BN_CTX *ctx);
+static bool test_sqrt(FILE *fp, BN_CTX *ctx);
+static bool test_bn2bin_padded(FILE *fp, BN_CTX *ctx);
// g_results can be set to true to cause the result of each computation to be
// printed.
@@ -117,15 +116,19 @@
"\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";
-static void message(BIO *out, const char *m) {
- BIO_puts(out, "print \"test ");
- BIO_puts(out, m);
- BIO_puts(out, "\\n\"\n");
+// A wrapper around puts that takes its arguments in the same order as our *_fp
+// functions.
+static void puts_fp(FILE *out, const char *m) {
+ fputs(m, out);
+}
+
+static void message(FILE *out, const char *m) {
+ puts_fp(out, "print \"test ");
+ puts_fp(out, m);
+ puts_fp(out, "\\n\"\n");
}
int main(int argc, char *argv[]) {
- char *outfile = NULL;
-
CRYPTO_library_init();
argc--;
@@ -133,11 +136,6 @@
while (argc >= 1) {
if (strcmp(*argv, "-results") == 0) {
g_results = true;
- } else if (strcmp(*argv, "-out") == 0) {
- if (--argc < 1) {
- break;
- }
- outfile = *(++argv);
}
argc--;
argv++;
@@ -149,161 +147,147 @@
return 1;
}
- ScopedBIO out(BIO_new(BIO_s_file()));
- if (!out) {
- return 1;
- }
-
- if (outfile == NULL) {
- BIO_set_fp(out.get(), stdout, BIO_NOCLOSE);
- } else {
- if (!BIO_write_filename(out.get(), outfile)) {
- perror(outfile);
- return 1;
- }
- }
-
if (!g_results) {
- BIO_puts(out.get(), "obase=16\nibase=16\n");
+ puts_fp(stdout, "obase=16\nibase=16\n");
}
- message(out.get(), "BN_add");
- if (!test_add(out.get())) {
+ message(stdout, "BN_add");
+ if (!test_add(stdout)) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_sub");
- if (!test_sub(out.get())) {
+ message(stdout, "BN_sub");
+ if (!test_sub(stdout)) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_lshift1");
- if (!test_lshift1(out.get())) {
+ message(stdout, "BN_lshift1");
+ if (!test_lshift1(stdout)) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_lshift (fixed)");
+ message(stdout, "BN_lshift (fixed)");
ScopedBIGNUM sample(BN_bin2bn(kSample, sizeof(kSample) - 1, NULL));
if (!sample) {
return 1;
}
- if (!test_lshift(out.get(), ctx.get(), bssl::move(sample))) {
+ if (!test_lshift(stdout, ctx.get(), bssl::move(sample))) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_lshift");
- if (!test_lshift(out.get(), ctx.get(), nullptr)) {
+ message(stdout, "BN_lshift");
+ if (!test_lshift(stdout, ctx.get(), nullptr)) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_rshift1");
- if (!test_rshift1(out.get())) {
+ message(stdout, "BN_rshift1");
+ if (!test_rshift1(stdout)) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_rshift");
- if (!test_rshift(out.get(), ctx.get())) {
+ message(stdout, "BN_rshift");
+ if (!test_rshift(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_sqr");
- if (!test_sqr(out.get(), ctx.get())) {
+ message(stdout, "BN_sqr");
+ if (!test_sqr(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_mul");
- if (!test_mul(out.get())) {
+ message(stdout, "BN_mul");
+ if (!test_mul(stdout)) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_div");
- if (!test_div(out.get(), ctx.get())) {
+ message(stdout, "BN_div");
+ if (!test_div(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_div_word");
- if (!test_div_word(out.get())) {
+ message(stdout, "BN_div_word");
+ if (!test_div_word(stdout)) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_mod");
- if (!test_mod(out.get(), ctx.get())) {
+ message(stdout, "BN_mod");
+ if (!test_mod(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_mod_mul");
- if (!test_mod_mul(out.get(), ctx.get())) {
+ message(stdout, "BN_mod_mul");
+ if (!test_mod_mul(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_mont");
- if (!test_mont(out.get(), ctx.get())) {
+ message(stdout, "BN_mont");
+ if (!test_mont(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_mod_exp");
- if (!test_mod_exp(out.get(), ctx.get())) {
+ message(stdout, "BN_mod_exp");
+ if (!test_mod_exp(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_mod_exp_mont_consttime");
- if (!test_mod_exp_mont_consttime(out.get(), ctx.get()) ||
- !test_mod_exp_mont5(out.get(), ctx.get())) {
+ message(stdout, "BN_mod_exp_mont_consttime");
+ if (!test_mod_exp_mont_consttime(stdout, ctx.get()) ||
+ !test_mod_exp_mont5(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_exp");
- if (!test_exp(out.get(), ctx.get()) ||
+ message(stdout, "BN_exp");
+ if (!test_exp(stdout, ctx.get()) ||
!test_exp_mod_zero()) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_mod_sqrt");
- if (!test_mod_sqrt(out.get(), ctx.get())) {
+ message(stdout, "BN_mod_sqrt");
+ if (!test_mod_sqrt(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "Small prime generation");
- if (!test_small_prime(out.get(), ctx.get())) {
+ message(stdout, "Small prime generation");
+ if (!test_small_prime(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_sqrt");
- if (!test_sqrt(out.get(), ctx.get())) {
+ message(stdout, "BN_sqrt");
+ if (!test_sqrt(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
- message(out.get(), "BN_bn2bin_padded");
- if (!test_bn2bin_padded(out.get(), ctx.get())) {
+ message(stdout, "BN_bn2bin_padded");
+ if (!test_bn2bin_padded(stdout, ctx.get())) {
return 1;
}
- (void)BIO_flush(out.get());
+ fflush(stdout);
printf("PASS\n");
return 0;
}
-static bool test_add(BIO *bp) {
+static bool test_add(FILE *fp) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -320,15 +304,15 @@
if (!BN_add(c.get(), a.get(), b.get())) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " + ");
- BN_print(bp, b.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " + ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
a->neg = !a->neg;
b->neg = !b->neg;
@@ -344,7 +328,7 @@
return true;
}
-static bool test_sub(BIO *bp) {
+static bool test_sub(FILE *fp) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -370,15 +354,15 @@
if (!BN_sub(c.get(), a.get(), b.get())) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " - ");
- BN_print(bp, b.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " - ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
if (!BN_add(c.get(), c.get(), b.get()) ||
!BN_sub(c.get(), c.get(), a.get())) {
@@ -392,7 +376,7 @@
return true;
}
-static bool test_div(BIO *bp, BN_CTX *ctx) {
+static bool test_div(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -418,24 +402,24 @@
if (!BN_div(d.get(), c.get(), a.get(), b.get(), ctx)) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " / ");
- BN_print(bp, b.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " / ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, d.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, d.get());
+ puts_fp(fp, "\n");
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " % ");
- BN_print(bp, b.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " % ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
if (!BN_mul(e.get(), d.get(), b.get(), ctx) ||
!BN_add(d.get(), e.get(), c.get()) ||
@@ -450,7 +434,7 @@
return true;
}
-static bool test_lshift1(BIO *bp) {
+static bool test_lshift1(FILE *fp) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -462,14 +446,14 @@
if (!BN_lshift1(b.get(), a.get())) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * 2");
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * 2");
+ puts_fp(fp, " - ");
}
- BN_print(bp, b.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, "\n");
}
if (!BN_add(c.get(), a.get(), a.get()) ||
!BN_sub(a.get(), b.get(), c.get())) {
@@ -487,7 +471,7 @@
return true;
}
-static bool test_rshift(BIO *bp, BN_CTX *ctx) {
+static bool test_rshift(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -503,15 +487,15 @@
!BN_add(c.get(), c.get(), c.get())) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " / ");
- BN_print(bp, c.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " / ");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, b.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, "\n");
}
if (!BN_div(d.get(), e.get(), a.get(), c.get(), ctx) ||
!BN_sub(d.get(), d.get(), b.get())) {
@@ -525,7 +509,7 @@
return true;
}
-static bool test_rshift1(BIO *bp) {
+static bool test_rshift1(FILE *fp) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -538,14 +522,14 @@
if (!BN_rshift1(b.get(), a.get())) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " / 2");
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " / 2");
+ puts_fp(fp, " - ");
}
- BN_print(bp, b.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, "\n");
}
if (!BN_sub(c.get(), a.get(), b.get()) ||
!BN_sub(c.get(), c.get(), b.get())) {
@@ -562,7 +546,7 @@
return true;
}
-static bool test_lshift(BIO *bp, BN_CTX *ctx, ScopedBIGNUM a) {
+static bool test_lshift(FILE *fp, BN_CTX *ctx, ScopedBIGNUM a) {
if (!a) {
a.reset(BN_new());
if (!a || !BN_rand(a.get(), 200, 0, 0)) {
@@ -583,15 +567,15 @@
!BN_add(c.get(), c.get(), c.get())) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * ");
- BN_print(bp, c.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * ");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, b.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, "\n");
}
if (!BN_mul(d.get(), a.get(), c.get(), ctx) ||
!BN_sub(d.get(), d.get(), b.get())) {
@@ -614,7 +598,7 @@
return true;
}
-static bool test_mul(BIO *bp) {
+static bool test_mul(FILE *fp) {
ScopedBN_CTX ctx(BN_CTX_new());
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
@@ -639,15 +623,15 @@
if (!BN_mul(c.get(), a.get(), b.get(), ctx.get())) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * ");
- BN_print(bp, b.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
if (!BN_div(d.get(), e.get(), c.get(), a.get(), ctx.get()) ||
!BN_sub(d.get(), d.get(), b.get())) {
@@ -661,7 +645,7 @@
return true;
}
-static bool test_sqr(BIO *bp, BN_CTX *ctx) {
+static bool test_sqr(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM c(BN_new());
ScopedBIGNUM d(BN_new());
@@ -678,15 +662,15 @@
if (!BN_sqr(c.get(), a.get(), ctx)) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * ");
- BN_print(bp, a.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
if (!BN_div(d.get(), e.get(), c.get(), a.get(), ctx) ||
!BN_sub(d.get(), d.get(), a.get())) {
@@ -706,15 +690,15 @@
!BN_sqr(c.get(), a.get(), ctx)) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * ");
- BN_print(bp, a.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
if (!BN_mul(d.get(), a.get(), a.get(), ctx)) {
return false;
@@ -734,15 +718,15 @@
!BN_sqr(c.get(), a.get(), ctx)) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * ");
- BN_print(bp, a.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
if (!BN_mul(d.get(), a.get(), a.get(), ctx)) {
return false;
@@ -765,11 +749,11 @@
return sign[(neg++) % 8];
}
-static void print_word(BIO *bp, BN_ULONG w) {
- BIO_printf(bp, BN_HEX_FMT1, w);
+static void print_word(FILE *fp, BN_ULONG w) {
+ fprintf(fp, BN_HEX_FMT1, w);
}
-static bool test_div_word(BIO *bp) {
+static bool test_div_word(FILE *fp) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
if (!a || !b) {
@@ -794,24 +778,24 @@
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " / ");
- print_word(bp, s);
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " / ");
+ print_word(fp, s);
+ puts_fp(fp, " - ");
}
- BN_print(bp, b.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, "\n");
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " % ");
- print_word(bp, s);
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " % ");
+ print_word(fp, s);
+ puts_fp(fp, " - ");
}
- print_word(bp, r);
- BIO_puts(bp, "\n");
+ print_word(fp, r);
+ puts_fp(fp, "\n");
}
if (!BN_mul_word(b.get(), s) ||
!BN_add_word(b.get(), r) ||
@@ -826,7 +810,7 @@
return true;
}
-static bool test_mont(BIO *bp, BN_CTX *ctx) {
+static bool test_mont(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -857,17 +841,17 @@
!BN_from_montgomery(A.get(), c.get(), mont.get(), ctx)) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * ");
- BN_print(bp, b.get());
- BIO_puts(bp, " % ");
- BN_print(bp, &mont->N);
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " % ");
+ BN_print_fp(fp, &mont->N);
+ puts_fp(fp, " - ");
}
- BN_print(bp, A.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, A.get());
+ puts_fp(fp, "\n");
}
if (!BN_mod_mul(d.get(), a.get(), b.get(), n.get(), ctx) ||
!BN_sub(d.get(), d.get(), A.get())) {
@@ -881,7 +865,7 @@
return true;
}
-static bool test_mod(BIO *bp, BN_CTX *ctx) {
+static bool test_mod(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -901,15 +885,15 @@
if (!BN_mod(c.get(), a.get(), b.get(), ctx)) {
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " % ");
- BN_print(bp, b.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " % ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, c.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, "\n");
}
if (!BN_div(d.get(), e.get(), a.get(), b.get(), ctx) ||
!BN_sub(e.get(), e.get(), c.get())) {
@@ -923,7 +907,7 @@
return true;
}
-static bool test_mod_mul(BIO *bp, BN_CTX *ctx) {
+static bool test_mod_mul(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -948,25 +932,25 @@
ERR_print_errors_fp(stderr);
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " * ");
- BN_print(bp, b.get());
- BIO_puts(bp, " % ");
- BN_print(bp, c.get());
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " * ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " % ");
+ BN_print_fp(fp, c.get());
if (a->neg != b->neg && !BN_is_zero(e.get())) {
// If (a*b) % c is negative, c must be added
// in order to obtain the normalized remainder
// (new with OpenSSL 0.9.7, previous versions of
// BN_mod_mul could generate negative results)
- BIO_puts(bp, " + ");
- BN_print(bp, c.get());
+ puts_fp(fp, " + ");
+ BN_print_fp(fp, c.get());
}
- BIO_puts(bp, " - ");
+ puts_fp(fp, " - ");
}
- BN_print(bp, e.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, e.get());
+ puts_fp(fp, "\n");
}
if (!BN_mul(d.get(), a.get(), b.get(), ctx) ||
!BN_sub(d.get(), d.get(), e.get()) ||
@@ -983,7 +967,7 @@
return true;
}
-static bool test_mod_exp(BIO *bp, BN_CTX *ctx) {
+static bool test_mod_exp(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -1000,17 +984,17 @@
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " ^ ");
- BN_print(bp, b.get());
- BIO_puts(bp, " % ");
- BN_print(bp, c.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " ^ ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " % ");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, d.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, d.get());
+ puts_fp(fp, "\n");
}
if (!BN_exp(e.get(), a.get(), b.get(), ctx) ||
!BN_sub(e.get(), e.get(), d.get()) ||
@@ -1025,7 +1009,7 @@
return true;
}
-static bool test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx) {
+static bool test_mod_exp_mont_consttime(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM c(BN_new());
@@ -1043,17 +1027,17 @@
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " ^ ");
- BN_print(bp, b.get());
- BIO_puts(bp, " % ");
- BN_print(bp, c.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " ^ ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " % ");
+ BN_print_fp(fp, c.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, d.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, d.get());
+ puts_fp(fp, "\n");
}
if (!BN_exp(e.get(), a.get(), b.get(), ctx) ||
!BN_sub(e.get(), e.get(), d.get()) ||
@@ -1070,7 +1054,7 @@
// Test constant-time modular exponentiation with 1024-bit inputs,
// which on x86_64 cause a different code branch to be taken.
-static bool test_mod_exp_mont5(BIO *bp, BN_CTX *ctx) {
+static bool test_mod_exp_mont5(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM p(BN_new());
ScopedBIGNUM m(BN_new());
@@ -1135,7 +1119,7 @@
return true;
}
-static bool test_exp(BIO *bp, BN_CTX *ctx) {
+static bool test_exp(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM b(BN_new());
ScopedBIGNUM d(BN_new());
@@ -1151,15 +1135,15 @@
return false;
}
- if (bp != NULL) {
+ if (fp != NULL) {
if (!g_results) {
- BN_print(bp, a.get());
- BIO_puts(bp, " ^ ");
- BN_print(bp, b.get());
- BIO_puts(bp, " - ");
+ BN_print_fp(fp, a.get());
+ puts_fp(fp, " ^ ");
+ BN_print_fp(fp, b.get());
+ puts_fp(fp, " - ");
}
- BN_print(bp, d.get());
- BIO_puts(bp, "\n");
+ BN_print_fp(fp, d.get());
+ puts_fp(fp, "\n");
}
if (!BN_one(e.get())) {
return false;
@@ -1222,7 +1206,7 @@
return 1;
}
-static bool test_mod_sqrt(BIO *bp, BN_CTX *ctx) {
+static bool test_mod_sqrt(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM a(BN_new());
ScopedBIGNUM p(BN_new());
ScopedBIGNUM r(BN_new());
@@ -1292,7 +1276,7 @@
return true;
}
-static bool test_small_prime(BIO *bp, BN_CTX *ctx) {
+static bool test_small_prime(FILE *fp, BN_CTX *ctx) {
static const int kBits = 10;
ScopedBIGNUM r(BN_new());
@@ -1300,15 +1284,15 @@
return false;
}
if (BN_num_bits(r.get()) != kBits) {
- BIO_printf(bp, "Expected %d bit prime, got %d bit number\n", kBits,
- BN_num_bits(r.get()));
+ fprintf(fp, "Expected %d bit prime, got %d bit number\n", kBits,
+ BN_num_bits(r.get()));
return false;
}
return true;
}
-static bool test_sqrt(BIO *bp, BN_CTX *ctx) {
+static bool test_sqrt(FILE *fp, BN_CTX *ctx) {
ScopedBIGNUM n(BN_new());
ScopedBIGNUM nn(BN_new());
ScopedBIGNUM sqrt(BN_new());
@@ -1353,7 +1337,7 @@
return true;
}
-static bool test_bn2bin_padded(BIO *bp, BN_CTX *ctx) {
+static bool test_bn2bin_padded(FILE *fp, BN_CTX *ctx) {
uint8_t zeros[256], out[256], reference[128];
memset(zeros, 0, sizeof(zeros));
diff --git a/crypto/dh/dh_test.c b/crypto/dh/dh_test.c
index 4c22bbb..836b3b2 100644
--- a/crypto/dh/dh_test.c
+++ b/crypto/dh/dh_test.c
@@ -59,7 +59,6 @@
#include <stdio.h>
#include <string.h>
-#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
@@ -80,8 +79,8 @@
} else if (p == 3) {
c = '\n';
}
- BIO_write(arg->arg, &c, 1);
- (void)BIO_flush(arg->arg);
+ fputc(c, arg->arg);
+ fflush(arg->arg);
return 1;
}
@@ -95,17 +94,10 @@
char buf[12];
unsigned char *abuf = NULL, *bbuf = NULL;
int i, alen, blen, aout, bout, ret = 1;
- BIO *out;
CRYPTO_library_init();
- out = BIO_new(BIO_s_file());
- if (out == NULL) {
- return 1;
- }
- BIO_set_fp(out, stdout, BIO_NOCLOSE);
-
- BN_GENCB_set(&_cb, &cb, out);
+ BN_GENCB_set(&_cb, &cb, stdout);
if (((a = DH_new()) == NULL) ||
!DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, &_cb)) {
goto err;
@@ -115,23 +107,23 @@
goto err;
}
if (i & DH_CHECK_P_NOT_PRIME) {
- BIO_puts(out, "p value is not prime\n");
+ puts("p value is not prime\n");
}
if (i & DH_CHECK_P_NOT_SAFE_PRIME) {
- BIO_puts(out, "p value is not a safe prime\n");
+ puts("p value is not a safe prime\n");
}
if (i & DH_CHECK_UNABLE_TO_CHECK_GENERATOR) {
- BIO_puts(out, "unable to check the generator value\n");
+ puts("unable to check the generator value\n");
}
if (i & DH_CHECK_NOT_SUITABLE_GENERATOR) {
- BIO_puts(out, "the g value is not a generator\n");
+ puts("the g value is not a generator\n");
}
- BIO_puts(out, "\np =");
- BN_print(out, a->p);
- BIO_puts(out, "\ng =");
- BN_print(out, a->g);
- BIO_puts(out, "\n");
+ puts("\np =");
+ BN_print_fp(stdout, a->p);
+ puts("\ng =");
+ BN_print_fp(stdout, a->g);
+ puts("\n");
b = DH_new();
if (b == NULL) {
@@ -147,42 +139,42 @@
if (!DH_generate_key(a)) {
goto err;
}
- BIO_puts(out, "pri 1=");
- BN_print(out, a->priv_key);
- BIO_puts(out, "\npub 1=");
- BN_print(out, a->pub_key);
- BIO_puts(out, "\n");
+ puts("pri 1=");
+ BN_print_fp(stdout, a->priv_key);
+ puts("\npub 1=");
+ BN_print_fp(stdout, a->pub_key);
+ puts("\n");
if (!DH_generate_key(b)) {
goto err;
}
- BIO_puts(out, "pri 2=");
- BN_print(out, b->priv_key);
- BIO_puts(out, "\npub 2=");
- BN_print(out, b->pub_key);
- BIO_puts(out, "\n");
+ puts("pri 2=");
+ BN_print_fp(stdout, b->priv_key);
+ puts("\npub 2=");
+ BN_print_fp(stdout, b->pub_key);
+ puts("\n");
alen = DH_size(a);
abuf = (unsigned char *)OPENSSL_malloc(alen);
aout = DH_compute_key(abuf, b->pub_key, a);
- BIO_puts(out, "key1 =");
+ puts("key1 =");
for (i = 0; i < aout; i++) {
sprintf(buf, "%02X", abuf[i]);
- BIO_puts(out, buf);
+ puts(buf);
}
- BIO_puts(out, "\n");
+ puts("\n");
blen = DH_size(b);
bbuf = (unsigned char *)OPENSSL_malloc(blen);
bout = DH_compute_key(bbuf, a->pub_key, b);
- BIO_puts(out, "key2 =");
+ puts("key2 =");
for (i = 0; i < bout; i++) {
sprintf(buf, "%02X", bbuf[i]);
- BIO_puts(out, buf);
+ puts(buf);
}
- BIO_puts(out, "\n");
+ puts("\n");
if ((aout < 4) || (bout != aout) || (memcmp(abuf, bbuf, aout) != 0)) {
fprintf(stderr, "Error in DH routines\n");
ret = 1;
@@ -209,7 +201,6 @@
if (a != NULL) {
DH_free(a);
}
- BIO_free(out);
return ret;
}
diff --git a/crypto/dsa/dsa_test.c b/crypto/dsa/dsa_test.c
index 1273638..83ecf25 100644
--- a/crypto/dsa/dsa_test.c
+++ b/crypto/dsa/dsa_test.c
@@ -61,7 +61,6 @@
#include <string.h>
-#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
@@ -166,9 +165,6 @@
0xdc, 0xd8, 0xc8,
};
-static BIO *bio_err = NULL;
-static BIO *bio_out = NULL;
-
static DSA *get_fips_dsa(void) {
DSA *dsa = DSA_new();
if (!dsa) {
@@ -187,7 +183,7 @@
return dsa;
}
-static int test_generate(void) {
+static int test_generate(FILE *out) {
BN_GENCB cb;
DSA *dsa = NULL;
int counter, ok = 0, i, j;
@@ -196,49 +192,49 @@
uint8_t sig[256];
unsigned int siglen;
- BIO_printf(bio_out, "test generation of DSA parameters\n");
+ fprintf(out, "test generation of DSA parameters\n");
- BN_GENCB_set(&cb, dsa_cb, bio_out);
+ BN_GENCB_set(&cb, dsa_cb, out);
dsa = DSA_new();
if (dsa == NULL ||
!DSA_generate_parameters_ex(dsa, 512, seed, 20, &counter, &h, &cb)) {
goto end;
}
- BIO_printf(bio_out, "seed\n");
+ fprintf(out, "seed\n");
for (i = 0; i < 20; i += 4) {
- BIO_printf(bio_out, "%02X%02X%02X%02X ", seed[i], seed[i + 1], seed[i + 2],
- seed[i + 3]);
+ fprintf(out, "%02X%02X%02X%02X ", seed[i], seed[i + 1], seed[i + 2],
+ seed[i + 3]);
}
- BIO_printf(bio_out, "\ncounter=%d h=%ld\n", counter, h);
+ fprintf(out, "\ncounter=%d h=%ld\n", counter, h);
if (counter != 105) {
- BIO_printf(bio_err, "counter should be 105\n");
+ fprintf(stderr, "counter should be 105\n");
goto end;
}
if (h != 2) {
- BIO_printf(bio_err, "h should be 2\n");
+ fprintf(stderr, "h should be 2\n");
goto end;
}
i = BN_bn2bin(dsa->q, buf);
j = sizeof(fips_q);
if (i != j || memcmp(buf, fips_q, i) != 0) {
- BIO_printf(bio_err, "q value is wrong\n");
+ fprintf(stderr, "q value is wrong\n");
goto end;
}
i = BN_bn2bin(dsa->p, buf);
j = sizeof(fips_p);
if (i != j || memcmp(buf, fips_p, i) != 0) {
- BIO_printf(bio_err, "p value is wrong\n");
+ fprintf(stderr, "p value is wrong\n");
goto end;
}
i = BN_bn2bin(dsa->g, buf);
j = sizeof(fips_g);
if (i != j || memcmp(buf, fips_g, i) != 0) {
- BIO_printf(bio_err, "g value is wrong\n");
+ fprintf(stderr, "g value is wrong\n");
goto end;
}
@@ -247,7 +243,7 @@
if (DSA_verify(0, fips_digest, sizeof(fips_digest), sig, siglen, dsa) == 1) {
ok = 1;
} else {
- BIO_printf(bio_err, "verification failure\n");
+ fprintf(stderr, "verification failure\n");
}
end:
@@ -267,7 +263,7 @@
int ret = DSA_verify(0, fips_digest, sizeof(fips_digest), sig, sig_len, dsa);
if (ret != expect) {
- BIO_printf(bio_err, "DSA_verify returned %d, want %d\n", ret, expect);
+ fprintf(stderr, "DSA_verify returned %d, want %d\n", ret, expect);
goto end;
}
ok = 1;
@@ -285,23 +281,16 @@
int main(int argc, char **argv) {
CRYPTO_library_init();
- bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
- bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
-
- if (!test_generate() ||
+ if (!test_generate(stdout) ||
!test_verify(fips_sig, sizeof(fips_sig), 1) ||
!test_verify(fips_sig_negative, sizeof(fips_sig_negative), -1) ||
!test_verify(fips_sig_extra, sizeof(fips_sig_extra), -1) ||
!test_verify(fips_sig_bad_length, sizeof(fips_sig_bad_length), -1) ||
!test_verify(fips_sig_bad_r, sizeof(fips_sig_bad_r), 0)) {
- BIO_print_errors(bio_err);
- BIO_free(bio_err);
- BIO_free(bio_out);
+ ERR_print_errors_fp(stderr);
return 1;
}
- BIO_free(bio_err);
- BIO_free(bio_out);
printf("PASS\n");
return 0;
}
@@ -326,11 +315,11 @@
c = '\n';
}
- BIO_write(arg->arg, &c, 1);
- (void)BIO_flush(arg->arg);
+ fputc(c, arg->arg);
+ fflush(arg->arg);
if (!ok && p == 0 && num > 1) {
- BIO_printf((BIO *)arg, "error in dsatest\n");
+ fprintf(stderr, "error in dsatest\n");
return 0;
}
diff --git a/crypto/ecdsa/ecdsa_test.c b/crypto/ecdsa/ecdsa_test.c
index d307ab8..9d86576 100644
--- a/crypto/ecdsa/ecdsa_test.c
+++ b/crypto/ecdsa/ecdsa_test.c
@@ -52,7 +52,6 @@
#include <openssl/ecdsa.h>
-#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/ec.h>
@@ -62,7 +61,7 @@
#include <openssl/rand.h>
-int test_builtin(BIO *out) {
+int test_builtin(FILE *out) {
size_t n = 0;
EC_KEY *eckey = NULL, *wrong_eckey = NULL;
EC_GROUP *group;
@@ -78,7 +77,7 @@
/* fill digest values with some random data */
if (!RAND_bytes(digest, 20) || !RAND_bytes(wrong_digest, 20)) {
- BIO_printf(out, "ERROR: unable to get random data\n");
+ fprintf(out, "ERROR: unable to get random data\n");
goto builtin_err;
}
@@ -89,9 +88,8 @@
/* create and verify a ecdsa signature with every availble curve
* (with ) */
- BIO_printf(out,
- "\ntesting ECDSA_sign() and ECDSA_verify() "
- "with some internal curves:\n");
+ fprintf(out, "\ntesting ECDSA_sign() and ECDSA_verify() "
+ "with some internal curves:\n");
static const int kCurveNIDs[] = {NID_secp224r1, NID_X9_62_prime256v1,
NID_secp384r1, NID_secp521r1, NID_undef};
@@ -124,10 +122,10 @@
continue;
}
- BIO_printf(out, "%s: ", OBJ_nid2sn(nid));
+ fprintf(out, "%s: ", OBJ_nid2sn(nid));
/* create key */
if (!EC_KEY_generate_key(eckey)) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
/* create second key */
@@ -144,19 +142,19 @@
}
EC_GROUP_free(group);
if (!EC_KEY_generate_key(wrong_eckey)) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
/* check key */
if (!EC_KEY_check_key(eckey)) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
/* create signature */
sig_len = ECDSA_size(eckey);
signature = OPENSSL_malloc(sig_len);
@@ -164,39 +162,39 @@
goto builtin_err;
}
if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
/* verify signature */
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
/* verify signature with the wrong key */
if (ECDSA_verify(0, digest, 20, signature, sig_len, wrong_eckey) == 1) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
/* wrong digest */
if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len, eckey) == 1) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
/* wrong length */
if (ECDSA_verify(0, digest, 20, signature, sig_len - 1, eckey) == 1) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
/* Modify a single byte of the signature: to ensure we don't
* garble the ASN1 structure, we read the raw signature and
@@ -204,7 +202,7 @@
sig_ptr = signature;
ecdsa_sig = d2i_ECDSA_SIG(NULL, &sig_ptr, sig_len);
if (ecdsa_sig == NULL) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
@@ -213,7 +211,7 @@
s_len = BN_num_bytes(ecdsa_sig->s);
bn_len = BN_num_bytes(order);
if (r_len > bn_len || s_len > bn_len) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
buf_len = 2 * bn_len;
@@ -240,7 +238,7 @@
sig_ptr2 = signature;
sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2);
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
/* Sanity check: undo the modification and verify signature. */
@@ -253,13 +251,13 @@
sig_ptr2 = signature;
sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2);
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) {
- BIO_printf(out, " failed\n");
+ fprintf(out, " failed\n");
goto builtin_err;
}
- BIO_printf(out, ".");
- (void)BIO_flush(out);
+ fprintf(out, ".");
+ fflush(out);
- BIO_printf(out, " ok\n");
+ fprintf(out, " ok\n");
/* cleanup */
/* clean bogus errors */
ERR_clear_error();
@@ -301,14 +299,11 @@
int main(void) {
int ret = 1;
- BIO *out;
CRYPTO_library_init();
ERR_load_crypto_strings();
- out = BIO_new_fp(stdout, BIO_NOCLOSE);
-
- if (!test_builtin(out)) {
+ if (!test_builtin(stdout)) {
goto err;
}
@@ -316,16 +311,12 @@
err:
if (ret) {
- BIO_printf(out, "\nECDSA test failed\n");
+ printf("\nECDSA test failed\n");
} else {
- BIO_printf(out, "\nPASS\n");
+ printf("\nPASS\n");
}
if (ret) {
- BIO_print_errors(out);
- }
-
- if (out != NULL) {
- BIO_free(out);
+ ERR_print_errors_fp(stdout);
}
return ret;