Prepare exptest for bn opaquify

Reviewed-by: Tim Hudson <tjh@openssl.org>
This commit is contained in:
Matt Caswell 2014-11-24 10:36:27 +00:00
parent 85bcf27ccc
commit 7a5233118c

View File

@ -73,37 +73,42 @@ static const char rnd_seed[] = "string to make the random number generator think
/* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success. */ /* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success. */
static int test_exp_mod_zero() { static int test_exp_mod_zero() {
BIGNUM a, p, m; BIGNUM *a = NULL, *p = NULL, *m = NULL;
BIGNUM r; BIGNUM *r = NULL;
BN_CTX *ctx = BN_CTX_new(); BN_CTX *ctx = BN_CTX_new();
int ret = 1; int ret = 1;
BN_init(&m); m = BN_new();
BN_one(&m); if(!m) goto err;
BN_one(m);
BN_init(&a); a = BN_new();
BN_one(&a); if(!a) goto err;
BN_one(a);
BN_init(&p); p = BN_new();
BN_zero(&p); if(!p) goto err;
BN_zero(p);
BN_init(&r); r = BN_new();
BN_mod_exp(&r, &a, &p, &m, ctx); if(!r) goto err;
BN_mod_exp(r, a, p, m, ctx);
BN_CTX_free(ctx); BN_CTX_free(ctx);
if (BN_is_zero(&r)) if (BN_is_zero(r))
ret = 0; ret = 0;
else else
{ {
printf("1**0 mod 1 = "); printf("1**0 mod 1 = ");
BN_print_fp(stdout, &r); BN_print_fp(stdout, r);
printf(", should be 0\n"); printf(", should be 0\n");
} }
BN_free(&r); err:
BN_free(&a); BN_free(r);
BN_free(&p); BN_free(a);
BN_free(&m); BN_free(p);
BN_free(m);
return ret; return ret;
} }