OpenSSL: Use EC_POINT_clear_free instead of EC_POINT_free
This changes OpenSSL calls to explicitly clear the EC_POINT memory allocations when freeing them. This adds an extra layer of security by avoiding leaving potentially private keys into local memory after they are not needed anymore. While some of these variables are not really private (e.g., they are sent in clear anyway), the extra cost of clearing them is not significant and it is simpler to just clear these explicitly rather than review each possible code path to confirm where this does not help. Signed-off-by: Florent Daigniere <nextgens@freenetproject.org>
This commit is contained in:
parent
3248071dc3
commit
26c10f797c
4 changed files with 13 additions and 13 deletions
|
@ -1157,13 +1157,13 @@ struct crypto_ec_point * crypto_ec_point_from_bin(struct crypto_ec *e,
|
||||||
if (x == NULL || y == NULL || elem == NULL) {
|
if (x == NULL || y == NULL || elem == NULL) {
|
||||||
BN_clear_free(x);
|
BN_clear_free(x);
|
||||||
BN_clear_free(y);
|
BN_clear_free(y);
|
||||||
EC_POINT_free(elem);
|
EC_POINT_clear_free(elem);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EC_POINT_set_affine_coordinates_GFp(e->group, elem, x, y,
|
if (!EC_POINT_set_affine_coordinates_GFp(e->group, elem, x, y,
|
||||||
e->bnctx)) {
|
e->bnctx)) {
|
||||||
EC_POINT_free(elem);
|
EC_POINT_clear_free(elem);
|
||||||
elem = NULL;
|
elem = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -263,7 +263,7 @@ int compute_password_element(EAP_PWD_group *grp, u16 num,
|
||||||
fail:
|
fail:
|
||||||
EC_GROUP_free(grp->group);
|
EC_GROUP_free(grp->group);
|
||||||
grp->group = NULL;
|
grp->group = NULL;
|
||||||
EC_POINT_free(grp->pwe);
|
EC_POINT_clear_free(grp->pwe);
|
||||||
grp->pwe = NULL;
|
grp->pwe = NULL;
|
||||||
BN_clear_free(grp->order);
|
BN_clear_free(grp->order);
|
||||||
grp->order = NULL;
|
grp->order = NULL;
|
||||||
|
|
|
@ -153,14 +153,14 @@ static void eap_pwd_deinit(struct eap_sm *sm, void *priv)
|
||||||
BN_clear_free(data->my_scalar);
|
BN_clear_free(data->my_scalar);
|
||||||
BN_clear_free(data->k);
|
BN_clear_free(data->k);
|
||||||
BN_CTX_free(data->bnctx);
|
BN_CTX_free(data->bnctx);
|
||||||
EC_POINT_free(data->my_element);
|
EC_POINT_clear_free(data->my_element);
|
||||||
EC_POINT_free(data->server_element);
|
EC_POINT_clear_free(data->server_element);
|
||||||
os_free(data->id_peer);
|
os_free(data->id_peer);
|
||||||
os_free(data->id_server);
|
os_free(data->id_server);
|
||||||
bin_clear_free(data->password, data->password_len);
|
bin_clear_free(data->password, data->password_len);
|
||||||
if (data->grp) {
|
if (data->grp) {
|
||||||
EC_GROUP_free(data->grp->group);
|
EC_GROUP_free(data->grp->group);
|
||||||
EC_POINT_free(data->grp->pwe);
|
EC_POINT_clear_free(data->grp->pwe);
|
||||||
BN_clear_free(data->grp->order);
|
BN_clear_free(data->grp->order);
|
||||||
BN_clear_free(data->grp->prime);
|
BN_clear_free(data->grp->prime);
|
||||||
os_free(data->grp);
|
os_free(data->grp);
|
||||||
|
@ -474,8 +474,8 @@ fin:
|
||||||
BN_clear_free(x);
|
BN_clear_free(x);
|
||||||
BN_clear_free(y);
|
BN_clear_free(y);
|
||||||
BN_clear_free(cofactor);
|
BN_clear_free(cofactor);
|
||||||
EC_POINT_free(K);
|
EC_POINT_clear_free(K);
|
||||||
EC_POINT_free(point);
|
EC_POINT_clear_free(point);
|
||||||
if (data->outbuf == NULL)
|
if (data->outbuf == NULL)
|
||||||
eap_pwd_state(data, FAILURE);
|
eap_pwd_state(data, FAILURE);
|
||||||
else
|
else
|
||||||
|
|
|
@ -140,14 +140,14 @@ static void eap_pwd_reset(struct eap_sm *sm, void *priv)
|
||||||
BN_clear_free(data->my_scalar);
|
BN_clear_free(data->my_scalar);
|
||||||
BN_clear_free(data->k);
|
BN_clear_free(data->k);
|
||||||
BN_CTX_free(data->bnctx);
|
BN_CTX_free(data->bnctx);
|
||||||
EC_POINT_free(data->my_element);
|
EC_POINT_clear_free(data->my_element);
|
||||||
EC_POINT_free(data->peer_element);
|
EC_POINT_clear_free(data->peer_element);
|
||||||
os_free(data->id_peer);
|
os_free(data->id_peer);
|
||||||
os_free(data->id_server);
|
os_free(data->id_server);
|
||||||
bin_clear_free(data->password, data->password_len);
|
bin_clear_free(data->password, data->password_len);
|
||||||
if (data->grp) {
|
if (data->grp) {
|
||||||
EC_GROUP_free(data->grp->group);
|
EC_GROUP_free(data->grp->group);
|
||||||
EC_POINT_free(data->grp->pwe);
|
EC_POINT_clear_free(data->grp->pwe);
|
||||||
BN_clear_free(data->grp->order);
|
BN_clear_free(data->grp->order);
|
||||||
BN_clear_free(data->grp->prime);
|
BN_clear_free(data->grp->prime);
|
||||||
os_free(data->grp);
|
os_free(data->grp);
|
||||||
|
@ -724,8 +724,8 @@ eap_pwd_process_commit_resp(struct eap_sm *sm, struct eap_pwd_data *data,
|
||||||
res = 1;
|
res = 1;
|
||||||
|
|
||||||
fin:
|
fin:
|
||||||
EC_POINT_free(K);
|
EC_POINT_clear_free(K);
|
||||||
EC_POINT_free(point);
|
EC_POINT_clear_free(point);
|
||||||
BN_clear_free(cofactor);
|
BN_clear_free(cofactor);
|
||||||
BN_clear_free(x);
|
BN_clear_free(x);
|
||||||
BN_clear_free(y);
|
BN_clear_free(y);
|
||||||
|
|
Loading…
Reference in a new issue