{
BIGNUM *btmp;
int ret = 0;
+
if (b)
btmp = b;
else
error:
- if (!b)
+ if (btmp != b)
BN_free(btmp);
return ret;
if (!save_serial(crlnumberfile, "new", crlnumber, NULL))
goto end;
- if (crlnumber) {
- BN_free(crlnumber);
- crlnumber = NULL;
- }
+ BN_free(crlnumber);
+ crlnumber = NULL;
if (!do_X509_CRL_sign(crl, pkey, dgst, sigopts))
goto end;
app_RAND_write_file(NULL);
ret = 0;
end:
- if (cb != NULL)
- BN_GENCB_free(cb);
+ BN_GENCB_free(cb);
BIO_free(in);
BIO_free_all(out);
DSA_free(dsa);
ret = 0;
end:
- if (ec_p)
- BN_free(ec_p);
- if (ec_a)
- BN_free(ec_a);
- if (ec_b)
- BN_free(ec_b);
- if (ec_gen)
- BN_free(ec_gen);
- if (ec_order)
- BN_free(ec_order);
- if (ec_cofactor)
- BN_free(ec_cofactor);
+ BN_free(ec_p);
+ BN_free(ec_a);
+ BN_free(ec_b);
+ BN_free(ec_gen);
+ BN_free(ec_order);
+ BN_free(ec_cofactor);
if (buffer)
OPENSSL_free(buffer);
BIO_free(in);
ret = 0;
end:
- if (bn)
- BN_free(bn);
- if (cb)
- BN_GENCB_free(cb);
+ BN_free(bn);
+ BN_GENCB_free(cb);
RSA_free(rsa);
BIO_free_all(out);
if (passout)
if (!ret) {
BIO_printf(bio_err, "Could not convert PSK key '%s' to BIGNUM\n",
psk_key);
- if (bn)
- BN_free(bn);
+ BN_free(bn);
return 0;
}
BN_mod_exp(r, g, p, N, bn_ctx) &&
BN_add_word(r, 1) && BN_cmp(r, N) == 0;
- if (r)
- BN_free(r);
- if (p)
- BN_free(p);
- if (bn_ctx)
- BN_CTX_free(bn_ctx);
+ BN_free(r);
+ BN_free(p);
+ BN_CTX_free(bn_ctx);
return ret;
}
if (!ret) {
BIO_printf(bio_err, "Could not convert PSK key '%s' to BIGNUM\n",
psk_key);
- if (bn)
- BN_free(bn);
+ BN_free(bn);
return 0;
}
if (BN_num_bytes(bn) > (int)max_psk_len) {
}
if (tmp != ftmp)
OPENSSL_free(tmp);
- if (bl)
- BN_free(bl);
+ BN_free(bl);
return (len);
err:
if (tmp != ftmp)
OPENSSL_free(tmp);
- if (bl)
- BN_free(bl);
+ BN_free(bl);
return (0);
}
CRYPTO_THREADID_current(&ret->tid);
return (ret);
err:
- if (ret != NULL)
- BN_BLINDING_free(ret);
+ BN_BLINDING_free(ret);
return (NULL);
}
if (r == NULL)
return;
- if (r->A != NULL)
- BN_free(r->A);
- if (r->Ai != NULL)
- BN_free(r->Ai);
- if (r->e != NULL)
- BN_free(r->e);
- if (r->mod != NULL)
- BN_free(r->mod);
+ BN_free(r->A);
+ BN_free(r->Ai);
+ BN_free(r->e);
+ BN_free(r->mod);
OPENSSL_free(r);
}
goto err;
if (e != NULL) {
- if (ret->e != NULL)
- BN_free(ret->e);
+ BN_free(ret->e);
ret->e = BN_dup(e);
}
if (ret->e == NULL)
return ret;
err:
- if (b == NULL && ret != NULL) {
+ if (b == NULL) {
BN_BLINDING_free(ret);
ret = NULL;
}
{
BN_GENCB cb;
BIGNUM *rnd = NULL;
- int found = 0;
BN_GENCB_set_old(&cb, callback, cb_arg);
goto err;
/* we have a prime :-) */
- found = 1;
+ return ret;
err:
- if (!found && (ret == NULL) && (rnd != NULL))
- BN_free(rnd);
- return (found ? rnd : NULL);
+ BN_free(rnd);
+ return NULL;
}
int BN_is_prime(const BIGNUM *a, int checks,
goto err;
ret = 1;
err:
- if ((in_mont == NULL) && (mont != NULL))
+ if (in_mont == NULL)
BN_MONT_CTX_free(mont);
BN_CTX_end(ctx);
bn_check_top(rr);
goto err;
ret = 1;
err:
- if ((in_mont == NULL) && (mont != NULL))
+ if (in_mont == NULL)
BN_MONT_CTX_free(mont);
if (powerbuf != NULL) {
OPENSSL_cleanse(powerbuf, powerbufLen);
}
ret = 1;
err:
- if ((in_mont == NULL) && (mont != NULL))
+ if (in_mont == NULL)
BN_MONT_CTX_free(mont);
BN_CTX_end(ctx);
bn_check_top(rr);
goto err;
ret = 1;
err:
- if ((in_mont == NULL) && (mont != NULL))
+ if (in_mont == NULL)
BN_MONT_CTX_free(mont);
BN_CTX_end(ctx);
bn_check_top(rr);
i = ((n - 1) / BN_BYTES) + 1;
m = ((n - 1) % (BN_BYTES));
if (bn_wexpand(ret, (int)i) == NULL) {
- if (bn)
- BN_free(bn);
+ BN_free(bn);
return NULL;
}
ret->top = i;
ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m));
bn_check_top(r);
- if (abs_m)
- BN_free(abs_m);
+ BN_free(abs_m);
return ret;
}
/* we have a prime :-) */
found = 1;
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
bn_check_top(ret);
return found;
}
if (ctx_passed == NULL)
BN_CTX_free(ctx);
}
- if (mont != NULL)
- BN_MONT_CTX_free(mont);
+ BN_MONT_CTX_free(mont);
return (ret);
}
err:
if (bn_data != NULL)
OPENSSL_free(bn_data);
- if (t != NULL)
- BN_free(t);
+ BN_free(t);
if (!ok && buf) {
OPENSSL_free(buf);
buf = NULL;
end:
if (err) {
- if (ret != NULL && ret != in) {
+ if (ret != in)
BN_clear_free(ret);
- }
ret = NULL;
}
BN_CTX_end(ctx);
return 0;
} else
a = NULL;
- if (*dst)
- BN_free(*dst);
+ BN_free(*dst);
*dst = a;
return 1;
}
ok = 1;
err:
- if (q != NULL)
- BN_free(q);
+ BN_free(q);
return (ok);
}
prk = priv_key;
if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) {
- if (local_prk)
- BN_free(local_prk);
+ BN_free(local_prk);
goto err;
}
- if (local_prk)
- BN_free(local_prk);
+ BN_free(local_prk);
}
dh->pub_key = pub_key;
if (ok != 1)
DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB);
- if ((pub_key != NULL) && (dh->pub_key == NULL))
+ if (pub_key != dh->pub_key)
BN_free(pub_key);
- if ((priv_key != NULL) && (dh->priv_key == NULL))
+ if (priv_key != dh->priv_key)
BN_free(priv_key);
BN_CTX_free(ctx);
return (ok);
static int dh_finish(DH *dh)
{
- if (dh->method_mont_p)
- BN_MONT_CTX_free(dh->method_mont_p);
+ BN_MONT_CTX_free(dh->method_mont_p);
return (1);
}
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data);
- if (r->p != NULL)
- BN_clear_free(r->p);
- if (r->g != NULL)
- BN_clear_free(r->g);
- if (r->q != NULL)
- BN_clear_free(r->q);
- if (r->j != NULL)
- BN_clear_free(r->j);
+ BN_clear_free(r->p);
+ BN_clear_free(r->g);
+ BN_clear_free(r->q);
+ BN_clear_free(r->j);
if (r->seed)
OPENSSL_free(r->seed);
- if (r->counter != NULL)
- BN_clear_free(r->counter);
- if (r->pub_key != NULL)
- BN_clear_free(r->pub_key);
- if (r->priv_key != NULL)
- BN_clear_free(r->priv_key);
+ BN_clear_free(r->counter);
+ BN_clear_free(r->pub_key);
+ BN_clear_free(r->priv_key);
OPENSSL_free(r);
}
if (dctx->use_dsa) {
DSA *dsa_dh;
dsa_dh = dsa_dh_generate(dctx, pcb);
- if (pcb)
- BN_GENCB_free(pcb);
+ BN_GENCB_free(pcb);
if (!dsa_dh)
return 0;
dh = DSA_dup_DH(dsa_dh);
#endif
dh = DH_new();
if (!dh) {
- if (pcb)
- BN_GENCB_free(pcb);
+ BN_GENCB_free(pcb);
return 0;
}
ret = DH_generate_parameters_ex(dh,
dctx->prime_len, dctx->generator, pcb);
- if (pcb)
- BN_GENCB_free(pcb);
+ BN_GENCB_free(pcb);
if (ret)
EVP_PKEY_assign_DH(pkey, dh);
else
if ((a = BN_dup(from->pkey.dsa->p)) == NULL)
return 0;
- if (to->pkey.dsa->p != NULL)
- BN_free(to->pkey.dsa->p);
+ BN_free(to->pkey.dsa->p);
to->pkey.dsa->p = a;
if ((a = BN_dup(from->pkey.dsa->q)) == NULL)
return 0;
- if (to->pkey.dsa->q != NULL)
- BN_free(to->pkey.dsa->q);
+ BN_free(to->pkey.dsa->q);
to->pkey.dsa->q = a;
if ((a = BN_dup(from->pkey.dsa->g)) == NULL)
return 0;
- if (to->pkey.dsa->g != NULL)
- BN_free(to->pkey.dsa->g);
+ BN_free(to->pkey.dsa->g);
to->pkey.dsa->g = a;
return 1;
}
ok = 1;
err:
if (ok) {
- if (ret->p)
- BN_free(ret->p);
- if (ret->q)
- BN_free(ret->q);
- if (ret->g)
- BN_free(ret->g);
+ BN_free(ret->p);
+ BN_free(ret->q);
+ BN_free(ret->g);
ret->p = BN_dup(p);
ret->q = BN_dup(q);
ret->g = BN_dup(g);
if (seed_out)
memcpy(seed_out, seed, qsize);
}
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
- if (mont != NULL)
- BN_MONT_CTX_free(mont);
+ BN_CTX_free(ctx);
+ BN_MONT_CTX_free(mont);
return ok;
}
err:
if (ok == 1) {
if (p != ret->p) {
- if (ret->p)
- BN_free(ret->p);
+ BN_free(ret->p);
ret->p = BN_dup(p);
}
if (q != ret->q) {
- if (ret->q)
- BN_free(ret->q);
+ BN_free(ret->q);
ret->q = BN_dup(q);
}
- if (ret->g)
- BN_free(ret->g);
+ BN_free(ret->g);
ret->g = BN_dup(g);
if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {
ok = -1;
OPENSSL_free(seed);
if (seed_out != seed_tmp)
OPENSSL_free(seed_tmp);
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
- if (mont != NULL)
- BN_MONT_CTX_free(mont);
+ BN_CTX_free(ctx);
+ BN_MONT_CTX_free(mont);
EVP_MD_CTX_cleanup(&mctx);
return ok;
}
rv = 0;
err:
BN_CTX_end(ctx);
- if (mont)
- BN_MONT_CTX_free(mont);
+ BN_MONT_CTX_free(mont);
BN_CTX_free(ctx);
return rv;
prk = priv_key;
if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {
- if (local_prk != NULL)
- BN_free(local_prk);
+ BN_free(local_prk);
goto err;
}
- if (local_prk != NULL)
- BN_free(local_prk);
+ BN_free(local_prk);
}
dsa->priv_key = priv_key;
ok = 1;
err:
- if ((pub_key != NULL) && (dsa->pub_key == NULL))
+ if (pub_key != dsa->pub_key)
BN_free(pub_key);
- if ((priv_key != NULL) && (dsa->priv_key == NULL))
+ if (priv_key != dsa->priv_key)
BN_free(priv_key);
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
return (ok);
}
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
- if (r->p != NULL)
- BN_clear_free(r->p);
- if (r->q != NULL)
- BN_clear_free(r->q);
- if (r->g != NULL)
- BN_clear_free(r->g);
- if (r->pub_key != NULL)
- BN_clear_free(r->pub_key);
- if (r->priv_key != NULL)
- BN_clear_free(r->priv_key);
- if (r->kinv != NULL)
- BN_clear_free(r->kinv);
- if (r->r != NULL)
- BN_clear_free(r->r);
+ BN_clear_free(r->p);
+ BN_clear_free(r->q);
+ BN_clear_free(r->g);
+ BN_clear_free(r->pub_key);
+ BN_clear_free(r->priv_key);
+ BN_clear_free(r->kinv);
+ BN_clear_free(r->r);
OPENSSL_free(r);
}
BN_free(r);
BN_free(s);
}
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
BN_clear_free(m);
BN_clear_free(xr);
- if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
- BN_clear_free(kinv);
+ BN_clear_free(kinv);
return (ret);
}
if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)
goto err;
- if (*kinvp != NULL)
- BN_clear_free(*kinvp);
+ BN_clear_free(*kinvp);
*kinvp = kinv;
kinv = NULL;
- if (*rp != NULL)
- BN_clear_free(*rp);
+ BN_clear_free(*rp);
*rp = r;
ret = 1;
err:
if (!ret) {
DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);
- if (r != NULL)
- BN_clear_free(r);
+ BN_clear_free(r);
}
- if (ctx_in == NULL)
+ if (ctx != ctx_in)
BN_CTX_free(ctx);
BN_clear_free(k);
BN_clear_free(kq);
err:
if (ret < 0)
DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB);
- if (ctx != NULL)
- BN_CTX_free(ctx);
- if (u1)
- BN_free(u1);
- if (u2)
- BN_free(u2);
- if (t1)
- BN_free(t1);
+ BN_CTX_free(ctx);
+ BN_free(u1);
+ BN_free(u2);
+ BN_free(t1);
return (ret);
}
static int dsa_finish(DSA *dsa)
{
- if (dsa->method_mont_p)
- BN_MONT_CTX_free(dsa->method_mont_p);
+ BN_MONT_CTX_free(dsa->method_mont_p);
return (1);
}
pcb = NULL;
dsa = DSA_new();
if (!dsa) {
- if (pcb)
- BN_GENCB_free(pcb);
+ BN_GENCB_free(pcb);
return 0;
}
ret = dsa_builtin_paramgen(dsa, dctx->nbits, dctx->qbits, dctx->pmd,
NULL, 0, NULL, NULL, NULL, pcb);
- if (pcb)
- BN_GENCB_free(pcb);
+ BN_GENCB_free(pcb);
if (ret)
EVP_PKEY_assign_DSA(pkey, dsa);
else
err:
EC_POINT_free(p);
EC_POINT_free(acc);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
err:
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return 0;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
#endif
group->b = BN_new();
if (!group->field || !group->a || !group->b) {
- if (group->field)
- BN_free(group->field);
- if (group->a)
- BN_free(group->a);
- if (group->b)
- BN_free(group->b);
+ BN_free(group->field);
+ BN_free(group->a);
+ BN_free(group->b);
return 0;
}
return 1;
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
point->Z = BN_new();
if (!point->X || !point->Y || !point->Z) {
- if (point->X)
- BN_free(point->X);
- if (point->Y)
- BN_free(point->Y);
- if (point->Z)
- BN_free(point->Z);
+ BN_free(point->X);
+ BN_free(point->Y);
+ BN_free(point->Z);
return 0;
}
return 1;
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
if (!ret)
ECerr(EC_F_DO_EC_KEY_PRINT, reason);
- if (pub_key)
- BN_free(pub_key);
- if (order)
- BN_free(order);
- if (ctx)
- BN_CTX_free(ctx);
+ BN_free(pub_key);
+ BN_free(order);
+ BN_CTX_free(ctx);
if (buffer != NULL)
OPENSSL_free(buffer);
return (ret);
ok = 1;
- err:if (tmp)
- BN_free(tmp);
+ err:
+ BN_free(tmp);
return (ok);
}
ok = 1;
- err:if (buffer_1)
+ err:
+ if (buffer_1)
OPENSSL_free(buffer_1);
if (buffer_2)
OPENSSL_free(buffer_2);
- if (tmp_1)
- BN_free(tmp_1);
- if (tmp_2)
- BN_free(tmp_2);
+ BN_free(tmp_1);
+ BN_free(tmp_2);
return (ok);
}
static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group,
ECPARAMETERS *param)
{
- int ok = 0;
size_t len = 0;
ECPARAMETERS *ret = NULL;
BIGNUM *tmp = NULL;
}
}
- ok = 1;
+ return ret;
- err:if (!ok) {
- if (ret && !param)
- ECPARAMETERS_free(ret);
- ret = NULL;
- }
- if (tmp)
- BN_free(tmp);
+ err:
+ if (!param)
+ ECPARAMETERS_free(ret);
+ BN_free(tmp);
if (buffer)
OPENSSL_free(buffer);
- return (ret);
+ return NULL;
}
ECPKPARAMETERS *ec_asn1_group2pkparameters(const EC_GROUP *group,
/* extract the cofactor (optional) */
if (params->cofactor == NULL) {
- if (b) {
- BN_free(b);
- b = NULL;
- }
+ BN_free(b);
+ b = NULL;
} else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
ret = NULL;
}
- if (p)
- BN_free(p);
- if (a)
- BN_free(a);
- if (b)
- BN_free(b);
+ BN_free(p);
+ BN_free(a);
+ BN_free(b);
EC_POINT_free(point);
return (ret);
}
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
EC_POINT_free(point);
return ret;
}
group = NULL;
}
EC_POINT_free(P);
- if (ctx)
- BN_CTX_free(ctx);
- if (p)
- BN_free(p);
- if (a)
- BN_free(a);
- if (b)
- BN_free(b);
- if (order)
- BN_free(order);
- if (x)
- BN_free(x);
- if (y)
- BN_free(y);
+ BN_CTX_free(ctx);
+ BN_free(p);
+ BN_free(a);
+ BN_free(b);
+ BN_free(order);
+ BN_free(x);
+ BN_free(y);
return group;
}
EC_GROUP_free(r->group);
EC_POINT_free(r->pub_key);
- if (r->priv_key != NULL)
- BN_clear_free(r->priv_key);
+ BN_clear_free(r->priv_key);
EC_EX_DATA_free_all_data(&r->method_data);
ok = 1;
err:
- if (order)
- BN_free(order);
+ BN_free(order);
if (eckey->pub_key == NULL)
EC_POINT_free(pub_key);
- if (priv_key != NULL && eckey->priv_key == NULL)
+ if (eckey->priv_key != priv_key)
BN_free(priv_key);
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
return (ok);
}
}
ok = 1;
err:
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
EC_POINT_free(point);
return (ok);
}
ok = 1;
err:
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
EC_POINT_free(point);
return ok;
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
{
- if (key->priv_key)
- BN_clear_free(key->priv_key);
+ BN_clear_free(key->priv_key);
key->priv_key = BN_dup(priv_key);
return (key->priv_key == NULL) ? 0 : 1;
}
return ret;
err:
- if (ret->order)
- BN_free(ret->order);
- if (ret->cofactor)
- BN_free(ret->cofactor);
+ BN_free(ret->order);
+ BN_free(ret->cofactor);
OPENSSL_free(ret);
return NULL;
}
EC_EX_DATA_free_all_data(&group->extra_data);
- if (group->mont_data)
- BN_MONT_CTX_free(group->mont_data);
+ BN_MONT_CTX_free(group->mont_data);
EC_POINT_free(group->generator);
BN_free(group->order);
EC_EX_DATA_clear_free_all_data(&group->extra_data);
- if (group->mont_data)
- BN_MONT_CTX_free(group->mont_data);
+ BN_MONT_CTX_free(group->mont_data);
EC_POINT_clear_free(group->generator);
BN_clear_free(group->order);
return 0;
} else {
/* src->generator == NULL */
- if (dest->mont_data != NULL) {
- BN_MONT_CTX_free(dest->mont_data);
- dest->mont_data = NULL;
- }
+ BN_MONT_CTX_free(dest->mont_data);
+ dest->mont_data = NULL;
}
if (src->generator != NULL) {
b3 = BN_CTX_get(ctx);
if (!b3) {
BN_CTX_end(ctx);
- if (ctx_new)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx_new);
return -1;
}
!EC_GROUP_get_cofactor(a, a2, ctx) ||
!EC_GROUP_get_cofactor(b, b2, ctx)) {
BN_CTX_end(ctx);
- if (ctx_new)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx_new);
return -1;
}
if (BN_cmp(a1, b1) || BN_cmp(a2, b2))
}
BN_CTX_end(ctx);
- if (ctx_new)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx_new);
return r;
}
BN_CTX *ctx = BN_CTX_new();
int ret = 0;
- if (group->mont_data) {
- BN_MONT_CTX_free(group->mont_data);
- group->mont_data = NULL;
- }
+ BN_MONT_CTX_free(group->mont_data);
+ group->mont_data = NULL;
if (ctx == NULL)
goto err;
err:
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
return ret;
}
ret = 1;
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
EC_POINT_free(tmp);
if (wsize != NULL)
OPENSSL_free(wsize);
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (pre_comp)
ec_pre_comp_free(pre_comp);
if (points) {
err:
if (!ret)
ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
- if (p)
- BN_free(p);
- if (a)
- BN_free(a);
- if (b)
- BN_free(b);
- if (gen)
- BN_free(gen);
- if (order)
- BN_free(order);
- if (cofactor)
- BN_free(cofactor);
- if (ctx)
- BN_CTX_free(ctx);
+ BN_free(p);
+ BN_free(a);
+ BN_free(b);
+ BN_free(gen);
+ BN_free(order);
+ BN_free(cofactor);
+ BN_CTX_free(ctx);
if (buffer != NULL)
OPENSSL_free(buffer);
return (ret);
void ec_GFp_mont_group_finish(EC_GROUP *group)
{
- if (group->field_data1 != NULL) {
- BN_MONT_CTX_free(group->field_data1);
- group->field_data1 = NULL;
- }
- if (group->field_data2 != NULL) {
- BN_free(group->field_data2);
- group->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(group->field_data1);
+ group->field_data1 = NULL;
+ BN_free(group->field_data2);
+ group->field_data2 = NULL;
ec_GFp_simple_group_finish(group);
}
void ec_GFp_mont_group_clear_finish(EC_GROUP *group)
{
- if (group->field_data1 != NULL) {
- BN_MONT_CTX_free(group->field_data1);
- group->field_data1 = NULL;
- }
- if (group->field_data2 != NULL) {
- BN_clear_free(group->field_data2);
- group->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(group->field_data1);
+ group->field_data1 = NULL;
+ BN_clear_free(group->field_data2);
+ group->field_data2 = NULL;
ec_GFp_simple_group_clear_finish(group);
}
int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
{
- if (dest->field_data1 != NULL) {
- BN_MONT_CTX_free(dest->field_data1);
- dest->field_data1 = NULL;
- }
- if (dest->field_data2 != NULL) {
- BN_clear_free(dest->field_data2);
- dest->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(dest->field_data1);
+ dest->field_data1 = NULL;
+ BN_clear_free(dest->field_data2);
+ dest->field_data2 = NULL;
if (!ec_GFp_simple_group_copy(dest, src))
return 0;
return 1;
err:
- if (dest->field_data1 != NULL) {
- BN_MONT_CTX_free(dest->field_data1);
- dest->field_data1 = NULL;
- }
+ BN_MONT_CTX_free(dest->field_data1);
+ dest->field_data1 = NULL;
return 0;
}
BIGNUM *one = NULL;
int ret = 0;
- if (group->field_data1 != NULL) {
- BN_MONT_CTX_free(group->field_data1);
- group->field_data1 = NULL;
- }
- if (group->field_data2 != NULL) {
- BN_free(group->field_data2);
- group->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(group->field_data1);
+ group->field_data1 = NULL;
+ BN_free(group->field_data2);
+ group->field_data2 = NULL;
if (ctx == NULL) {
ctx = new_ctx = BN_CTX_new();
}
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
- if (mont != NULL)
- BN_MONT_CTX_free(mont);
+ BN_CTX_free(new_ctx);
+ BN_MONT_CTX_free(mont);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
ret = 1;
err:
- if (ctx_new)
- BN_CTX_free(ctx_new);
+ BN_CTX_free(ctx_new);
return ret;
}
ret = 1;
err:
- if (ctx_new)
- BN_CTX_free(ctx_new);
+ BN_CTX_free(ctx_new);
return ret;
}
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (secrets != NULL)
OPENSSL_free(secrets);
if (pre_comp != NULL)
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
nistp224_pre_comp_free(pre);
return ret;
}
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (secrets != NULL)
OPENSSL_free(secrets);
if (pre_comp != NULL)
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
nistp256_pre_comp_free(pre);
return ret;
}
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (secrets != NULL)
OPENSSL_free(secrets);
if (pre_comp != NULL)
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
nistp521_pre_comp_free(pre);
return ret;
}
ret = EC_POINT_set_affine_coordinates_GFp(group, out, x, y, ctx);
- if (x)
- BN_free(x);
- if (y)
- BN_free(y);
+ BN_free(x);
+ BN_free(y);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
err:
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return 0;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
ret = 1;
err:
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
point->Z_is_one = 0;
if (!point->X || !point->Y || !point->Z) {
- if (point->X)
- BN_free(point->X);
- if (point->Y)
- BN_free(point->Y);
- if (point->Z)
- BN_free(point->Z);
+ BN_free(point->X);
+ BN_free(point->Y);
+ BN_free(point->Z);
return 0;
}
return 1;
ret = 1;
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
ret = 1;
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
end:
if (ctx) /* otherwise we already called BN_CTX_end */
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
end:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (prod_Z != NULL) {
for (i = 0; i < num; i++) {
if (prod_Z[i] == NULL)
EC_POINT_free(tmp);
if (ctx)
BN_CTX_end(ctx);
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
if (buf)
OPENSSL_free(buf);
return (ret);
}
/* clear old values if necessary */
- if (*rp != NULL)
- BN_clear_free(*rp);
- if (*kinvp != NULL)
- BN_clear_free(*kinvp);
+ BN_clear_free(*rp);
+ BN_clear_free(*kinvp);
/* save the pre-computed values */
*rp = r;
*kinvp = k;
ret = 1;
err:
if (!ret) {
- if (k != NULL)
- BN_clear_free(k);
- if (r != NULL)
- BN_clear_free(r);
+ BN_clear_free(k);
+ BN_clear_free(r);
}
- if (ctx_in == NULL)
+ if (ctx != ctx_in)
BN_CTX_free(ctx);
- if (order != NULL)
- BN_free(order);
+ BN_free(order);
EC_POINT_free(tmp_point);
- if (X)
- BN_clear_free(X);
+ BN_clear_free(X);
return (ret);
}
ECDSA_SIG_free(ret);
ret = NULL;
}
- if (ctx)
- BN_CTX_free(ctx);
- if (m)
- BN_clear_free(m);
- if (tmp)
- BN_clear_free(tmp);
- if (order)
- BN_free(order);
- if (kinv)
- BN_clear_free(kinv);
+ BN_CTX_free(ctx);
+ BN_clear_free(m);
+ BN_clear_free(tmp);
+ BN_free(order);
+ BN_clear_free(kinv);
return ret;
}
}
}
- if (bl)
- BN_free(bl);
+ BN_free(bl);
return n;
err:
- if (bl)
- BN_free(bl);
+ BN_free(bl);
return -1;
}
PEMerr(PEM_F_B2I_DSS, ERR_R_MALLOC_FAILURE);
DSA_free(dsa);
EVP_PKEY_free(ret);
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
return NULL;
}
}
err:
- if (i != NULL)
- BN_free(i);
- if (j != NULL)
- BN_free(j);
- if (k != NULL)
- BN_free(k);
- if (l != NULL)
- BN_free(l);
- if (m != NULL)
- BN_free(m);
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_free(i);
+ BN_free(j);
+ BN_free(k);
+ BN_free(l);
+ BN_free(m);
+ BN_CTX_free(ctx);
return (ret);
}
void RSA_blinding_off(RSA *rsa)
{
- if (rsa->blinding != NULL) {
- BN_BLINDING_free(rsa->blinding);
- rsa->blinding = NULL;
- }
+ BN_BLINDING_free(rsa->blinding);
+ rsa->blinding = NULL;
rsa->flags &= ~RSA_FLAG_BLINDING;
rsa->flags |= RSA_FLAG_NO_BLINDING;
}
CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret));
err:
BN_CTX_end(ctx);
- if (in_ctx == NULL)
+ if (ctx != in_ctx)
BN_CTX_free(ctx);
- if (rsa->e == NULL)
+ if (e != rsa->e)
BN_free(e);
- if (local_n)
- BN_free(local_n);
+ BN_free(local_n);
return ret;
}
return rsa;
}
err:
- if (e)
- BN_free(e);
+ BN_free(e);
RSA_free(rsa);
- if (cb)
- BN_GENCB_free(cb);
+ BN_GENCB_free(cb);
return 0;
}
#endif
r = num;
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
if (!BN_MONT_CTX_set_locked
(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
rsa->_method_mod_n)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
}
if (blinding)
r = num;
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
if (!BN_MONT_CTX_set_locked
(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
rsa->_method_mod_n)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
}
if (blinding)
RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
(&rsa->_method_mod_p, CRYPTO_LOCK_RSA, p, ctx)
|| !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,
CRYPTO_LOCK_RSA, q, ctx)) {
- if (local_p)
- BN_free(local_p);
- if (local_q)
- BN_free(local_q);
+ BN_free(local_p);
+ BN_free(local_q);
goto err;
}
}
- if (local_p)
- BN_free(local_p);
- if (local_q)
- BN_free(local_q);
+ BN_free(local_p);
+ BN_free(local_q);
}
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
d = rsa->d;
if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,
rsa->_method_mod_n)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
}
}
ret = 1;
err:
- if (local_dmp1)
- BN_free(local_dmp1);
- if (local_dmq1)
- BN_free(local_dmq1);
- if (local_c)
- BN_free(local_c);
- if (local_r1)
- BN_free(local_r1);
+ BN_free(local_dmp1);
+ BN_free(local_dmq1);
+ BN_free(local_c);
+ BN_free(local_r1);
BN_CTX_end(ctx);
return (ret);
}
static int RSA_eay_finish(RSA *rsa)
{
- if (rsa->_method_mod_n != NULL)
- BN_MONT_CTX_free(rsa->_method_mod_n);
- if (rsa->_method_mod_p != NULL)
- BN_MONT_CTX_free(rsa->_method_mod_p);
- if (rsa->_method_mod_q != NULL)
- BN_MONT_CTX_free(rsa->_method_mod_q);
+ BN_MONT_CTX_free(rsa->_method_mod_n);
+ BN_MONT_CTX_free(rsa->_method_mod_p);
+ BN_MONT_CTX_free(rsa->_method_mod_q);
return (1);
}
ok = 1;
err:
- if (local_r0)
- BN_free(local_r0);
- if (local_d)
- BN_free(local_d);
- if (local_p)
- BN_free(local_p);
+ BN_free(local_r0);
+ BN_free(local_d);
+ BN_free(local_p);
if (ok == -1) {
RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);
ok = 0;
}
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
return ok;
}
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
- if (r->n != NULL)
- BN_clear_free(r->n);
- if (r->e != NULL)
- BN_clear_free(r->e);
- if (r->d != NULL)
- BN_clear_free(r->d);
- if (r->p != NULL)
- BN_clear_free(r->p);
- if (r->q != NULL)
- BN_clear_free(r->q);
- if (r->dmp1 != NULL)
- BN_clear_free(r->dmp1);
- if (r->dmq1 != NULL)
- BN_clear_free(r->dmq1);
- if (r->iqmp != NULL)
- BN_clear_free(r->iqmp);
- if (r->blinding != NULL)
- BN_BLINDING_free(r->blinding);
- if (r->mt_blinding != NULL)
- BN_BLINDING_free(r->mt_blinding);
+ BN_clear_free(r->n);
+ BN_clear_free(r->e);
+ BN_clear_free(r->d);
+ BN_clear_free(r->p);
+ BN_clear_free(r->q);
+ BN_clear_free(r->dmp1);
+ BN_clear_free(r->dmq1);
+ BN_clear_free(r->iqmp);
+ BN_BLINDING_free(r->blinding);
+ BN_BLINDING_free(r->mt_blinding);
OPENSSL_free_locked(r->bignum_data);
OPENSSL_free(r);
}
{
RSA_PKEY_CTX *rctx = ctx->data;
if (rctx) {
- if (rctx->pub_exp)
- BN_free(rctx->pub_exp);
+ BN_free(rctx->pub_exp);
if (rctx->tbuf)
OPENSSL_free(rctx->tbuf);
if (rctx->oaep_label)
ret = 1;
err:
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
- if (ctx2)
- BN_CTX_free(ctx2);
+ BN_CTX_free(ctx);
+ BN_CTX_free(ctx2);
return ret;
ok = 1;
error:
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
if (ok)
return 1;
BN_CTX *bn_ctx;
BIGNUM *A = NULL;
- if (a == NULL || N == NULL || g == NULL ||
- (bn_ctx = BN_CTX_new()) == NULL)
+ if (a == NULL || N == NULL || g == NULL || (bn_ctx = BN_CTX_new()) == NULL)
return NULL;
if ((A = BN_new()) != NULL && !BN_mod_exp(A, g, a, N, bn_ctx)) {
if ((tmp = BN_new()) == NULL ||
(tmp2 = BN_new()) == NULL ||
- (tmp3 = BN_new()) == NULL || (K = BN_new()) == NULL)
+ (tmp3 = BN_new()) == NULL ||
+ (K = BN_new()) == NULL)
goto err;
if (!BN_mod_exp(tmp, g, x, N, bn_ctx))
return sig;
FAILED:
- if (bn_r)
- BN_free(bn_r);
- if (bn_s)
- BN_free(bn_s);
+ BN_free(bn_r);
+ BN_free(bn_s);
return NULL;
}
return 1;
FAILED:
- if (!dh->priv_key && bn_prv)
+ if (!dh->priv_key)
BN_free(bn_prv);
- if (!dh->pub_key && bn_pub)
+ if (!dh->pub_key)
BN_free(bn_pub);
return 0;
the B<A> and B<Ai> values into the newly created B<BN_BLINDING> object.
BN_BLINDING_free() frees the B<BN_BLINDING> structure.
+If B<b> is NULL, nothing is done.
BN_BLINDING_update() updates the B<BN_BLINDING> parameters by squaring
the B<A> and B<Ai> or, after specific number of uses and if the
If L<BN_CTX_start(3)|BN_CTX_start(3)> has been used on the B<BN_CTX>,
L<BN_CTX_end(3)|BN_CTX_end(3)> must be called before the B<BN_CTX>
may be freed by BN_CTX_free().
+If B<c> is NULL, nothing is done.
=head1 RETURN VALUES
programs should prefer the "new" style, whilst the "old" style is provided
for backwards compatibility purposes.
-A BN_GENCB structure should be created through a call to BN_GENCB_new, and freed
-through a call to BN_GENCB_free.
+A BN_GENCB structure should be created through a call to BN_GENCB_new(),
+and freed through a call to BN_GENCB_free().
For "new" style callbacks a BN_GENCB structure should be initialised with a
call to BN_GENCB_set(), where B<gencb> is a B<BN_GENCB *>, B<callback> is of
BN_MONT_CTX_free() frees the components of the B<BN_MONT_CTX>, and, if
it was created by BN_MONT_CTX_new(), also the structure itself.
+If B<mont> is NULL, nothing is done.
BN_mod_mul_montgomery() computes Mont(I<a>,I<b>):=I<a>*I<b>*R^-1 and places
the result in I<r>.
BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
was created by BN_RECP_CTX_new(), also the structure itself.
+If B<recp> is NULL, nothing is done.
BN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing
1/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an
BN_free() frees the components of the B<BIGNUM>, and if it was created
by BN_new(), also the structure itself. BN_clear_free() additionally
overwrites the data before the memory is returned to the system.
+If B<a> is NULL, nothing is done.
=head1 RETURN VALUES
err:
if (P) EC_POINT_free(P);
if (grp) EC_GROUP_free(grp);
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
return ok;
}
ret = newsig;
err:
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
if (C) EC_POINT_free(C);
- if (md) BN_free(md);
- if (!ret && newsig) {
+ BN_free(md);
+ if (!ret)
DSA_SIG_free(newsig);
- }
return ret;
}
}
err:
if (C) EC_POINT_free(C);
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
- if (md) BN_free(md);
+ BN_CTX_free(ctx);
+ BN_free(md);
return ok;
}
ok = 256;
err:
if (pub_key) EC_POINT_free(pub_key);
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
return ok;
}
dto = DSA_new();
EVP_PKEY_assign(to, EVP_PKEY_base_id(from), dto);
}
-#define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);
- COPYBIGNUM(dto, dfrom, p)
- COPYBIGNUM(dto, dfrom, q)
- COPYBIGNUM(dto, dfrom, g)
-
- if (dto->priv_key)
+ BN_free(dto->p);
+ dto->p = BN_dup(dfrom->p);
+ BN_free(dto->q);
+ dto->q = BN_dup(dfrom->q);
+ BN_free(dto->g);
+ dto->g = BN_dup(dfrom->g);
+
+ if (dto->priv_key)
gost94_compute_public(dto);
return 1;
}
Y = BN_new();
if (!X || !Y) {
GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE);
- if (X)
- BN_free(X);
- if (Y)
- BN_free(Y);
+ BN_free(X);
+ BN_free(Y);
BN_free(order);
return 0;
}
ret = newsig;
err:
BN_free(md);
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
- if (!ret && newsig) {
+ BN_CTX_free(ctx);
+ if (!ret)
DSA_SIG_free(newsig);
- }
return ret;
}
GOSTerr(GOST_F_GOST_DO_VERIFY, GOST_R_SIGNATURE_MISMATCH);
}
err:
- if (md)
- BN_free(md);
- if (ctx) {
+ BN_free(md);
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
- return ok;
+ BN_CTX_free(ctx);
+ return (ok == 0);
}
/*
return 0;
}
#define dump_signature(a,b,c)
- if (dsa->p) {
- BN_free(dsa->p);
- }
+ BN_free(dsa->p);
dsa->p = NULL;
BN_dec2bn(&(dsa->p), params->p);
- if (dsa->q) {
- BN_free(dsa->q);
- }
+ BN_free(dsa->q);
dsa->q = NULL;
BN_dec2bn(&(dsa->q), params->q);
- if (dsa->g) {
- BN_free(dsa->g);
- }
+ BN_free(dsa->g);
dsa->g = NULL;
BN_dec2bn(&(dsa->g), params->a);
return 1;
OPENSSL_free(sw_param.up.crt.dmq1.value);
if (sw_param.up.crt.iqmp.value)
OPENSSL_free(sw_param.up.crt.iqmp.value);
- if (result)
- BN_free(result);
- if (argument)
- BN_free(argument);
+ BN_free(result);
+ BN_free(argument);
if (acquired)
release_context(hac);
return to_return;
err:
if (acquired)
release_context(hac);
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
return to_return;
}
err:
if (acquired)
release_context(hac);
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
return to_return;
}
# endif
}
# endif
-# ifndef OPENSSL_NO_DSA
-# ifdef NOT_USED
-static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
- BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
- BN_CTX *ctx, BN_MONT_CTX *in_mont)
-{
- BIGNUM t;
- int to_return = 0;
-
- BN_init(&t);
- /* let rr = a1 ^ p1 mod m */
- if (!ubsec_mod_exp(rr, a1, p1, m, ctx))
- goto end;
- /* let t = a2 ^ p2 mod m */
- if (!ubsec_mod_exp(&t, a2, p2, m, ctx))
- goto end;
- /* let rr = rr * t mod m */
- if (!BN_mod_mul(rr, rr, &t, m, ctx))
- goto end;
- to_return = 1;
- end:
- BN_free(&t);
- return to_return;
-}
-
-static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
- const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
- BN_MONT_CTX *m_ctx)
-{
- return ubsec_mod_exp(r, a, p, m, ctx);
-}
-# endif
-# endif
-
# ifndef OPENSSL_NO_RSA
/*
err:
if (!to_return) {
- if (r)
- BN_free(r);
- if (s)
- BN_free(s);
+ BN_free(r);
+ BN_free(s);
}
BN_clear_free(&m);
return to_return;
return -1;
s->srp_ctx.N = BN_dup(GN->N);
s->srp_ctx.g = BN_dup(GN->g);
- if (s->srp_ctx.v != NULL) {
- BN_clear_free(s->srp_ctx.v);
- s->srp_ctx.v = NULL;
- }
- if (s->srp_ctx.s != NULL) {
- BN_clear_free(s->srp_ctx.s);
- s->srp_ctx.s = NULL;
- }
+ BN_clear_free(s->srp_ctx.v);
+ s->srp_ctx.v = NULL;
+ BN_clear_free(s->srp_ctx.s);
+ s->srp_ctx.s = NULL;
if (!SRP_create_verifier_BN
(user, pass, &s->srp_ctx.s, &s->srp_ctx.v, GN->N, GN->g))
return -1;
}
ret = 1;
err:
- if (a != NULL)
- BN_free(a);
- if (c != NULL)
- BN_free(c);
- if (d != NULL)
- BN_free(d);
- if (e != NULL)
- BN_free(e);
+ BN_free(a);
+ BN_free(c);
+ BN_free(d);
+ BN_free(e);
return ret;
}
fflush(stderr);
ret = 1;
err:
- if (a != NULL)
- BN_free(a);
- if (b != NULL)
- BN_free(b);
- if (r != NULL)
- BN_free(r);
- if (t != NULL)
- BN_free(t);
+ BN_free(a);
+ BN_free(b);
+ BN_free(r);
+ BN_free(t);
return ret;
}
}
ret = 1;
err:
- if (a != NULL)
- BN_free(a);
- if (p != NULL)
- BN_free(p);
- if (r != NULL)
- BN_free(r);
+ BN_free(a);
+ BN_free(p);
+ BN_free(r);
return ret;
}
OPENSSL_free(bbuf);
DH_free(b);
DH_free(a);
- if (_cb)
- BN_GENCB_free(_cb);
+ BN_GENCB_free(_cb);
BIO_free(out);
# ifdef OPENSSL_SYS_NETWARE
if (ret)
if (!ret)
ERR_print_errors(bio_err);
DSA_free(dsa);
- if (cb != NULL)
- BN_GENCB_free(cb);
+ BN_GENCB_free(cb);
CRYPTO_cleanup_all_ex_data();
ERR_remove_thread_state(NULL);
ERR_free_strings();
OPENSSL_free(abuf);
if (bbuf != NULL)
OPENSSL_free(bbuf);
- if (x_a)
- BN_free(x_a);
- if (y_a)
- BN_free(y_a);
- if (x_b)
- BN_free(x_b);
- if (y_b)
- BN_free(y_b);
+ BN_free(x_a);
+ BN_free(y_a);
+ BN_free(x_b);
+ BN_free(y_b);
EC_KEY_free(b);
EC_KEY_free(a);
return (ret);
goto err;
ok = 1;
err:
- if (priv)
- BN_clear_free(priv);
+ BN_clear_free(priv);
EC_POINT_free(pub);
if (ok)
return k;
err:
ERR_print_errors_fp(stderr);
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
BIO_free(out);
CRYPTO_cleanup_all_ex_data();
ERR_remove_thread_state(NULL);
EC_KEY_free(key);
if (signature)
ECDSA_SIG_free(signature);
- if (r)
- BN_free(r);
- if (s)
- BN_free(s);
+ BN_free(r);
+ BN_free(s);
EVP_MD_CTX_cleanup(&md_ctx);
- if (kinv)
- BN_clear_free(kinv);
- if (rp)
- BN_clear_free(rp);
+ BN_clear_free(kinv);
+ BN_clear_free(rp);
return ret;
}
BN_free(scalar3);
}
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
BN_free(p);
BN_free(a);
BN_free(b);
fprintf(stdout, " ok\n\n");
}
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
BN_free(p);
BN_free(a);
BN_free(b);
end:
printf("\n");
}
- if (bn)
- BN_free(bn);
+ BN_free(bn);
return (rsa_tmp);
}
if (!ret) {
BIO_printf(bio_err, "Could not convert PSK key '%s' to BIGNUM\n",
pskkey);
- if (bn)
- BN_free(bn);
+ BN_free(bn);
return 0;
}
if (BN_num_bytes(bn) > (int)max_psk_len) {