Fix alice_priv_free in implementations (#293)

* fix

replaced free by OQS_MEM_secure_free where necessary

* commit

* commit

* removed //free(alice_priv)
This commit is contained in:
Vlad Gheorghiu 2018-06-01 10:26:46 -04:00 committed by Douglas Stebila
parent 068c48ae37
commit 89d290a75f
11 changed files with 19 additions and 11 deletions

4
.gitignore vendored
View File

@ -105,3 +105,7 @@ data/
# Exceptions
!/src/kex_sidh_msr/config.h
!src/sig_picnic/external/config.h.in
# Misc (master branch)
.objs_upstream
*_kem*

View File

@ -66,7 +66,7 @@ int main(void) {
printf("===============================================================\n");
/* Alice's initial message */
int success = OQS_KEX_alice_0(kex, &alice_priv, &alice_msg, &alice_msg_len);
OQS_STATUS success = OQS_KEX_alice_0(kex, &alice_priv, &alice_msg, &alice_msg_len);
if (success != OQS_SUCCESS) {
eprintf("ERROR: OQS_KEX_alice_0 failed!\n");
cleanup(alice_msg, alice_msg_len, alice_key, alice_key_len, bob_msg,

View File

@ -145,7 +145,7 @@ cleanup:
void OQS_KEX_code_mcbits_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
if (alice_priv) {
free(alice_priv);
OQS_MEM_secure_free(alice_priv, CRYPTO_SECRETKEYBYTES);
}
}

View File

@ -20,12 +20,13 @@
#include "recommended.h"
#define MACRIFY(NAME) NAME##_recommended
#include "kex_lwe_frodo_macrify.c"
static size_t alice_priv_key_len = PARAMS_N * PARAMS_NBAR * sizeof(uint16_t);
// undefine macros to avoid any confusion later
#include "recommended.h"
#undef MACRIFY
void OQS_KEX_lwe_frodo_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
free(alice_priv);
OQS_MEM_secure_free(alice_priv, alice_priv_key_len);
}
void OQS_KEX_lwe_frodo_free(OQS_KEX *k) {

View File

@ -222,7 +222,7 @@ cleanup:
void OQS_KEX_ntru_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
if (alice_priv) {
OQS_KEX_ntru_alice_priv *ntru_alice_priv = (OQS_KEX_ntru_alice_priv *) alice_priv;
free(ntru_alice_priv->priv_key);
OQS_MEM_secure_free(ntru_alice_priv->priv_key, ntru_alice_priv->priv_key_len);
}
free(alice_priv);
}

View File

@ -175,7 +175,7 @@ cleanup:
void OQS_KEX_rlwe_bcns15_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
if (alice_priv) {
free(alice_priv);
OQS_MEM_secure_free(alice_priv, 1024 * sizeof(uint32_t));
}
}

View File

@ -155,7 +155,7 @@ cleanup:
void OQS_KEX_rlwe_msrln16_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
if (alice_priv) {
free(alice_priv);
OQS_MEM_secure_free(alice_priv, 1024 * sizeof(uint32_t));
}
}

View File

@ -150,7 +150,7 @@ cleanup:
void OQS_KEX_rlwe_newhope_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
if (alice_priv) {
free(alice_priv);
OQS_MEM_secure_free(alice_priv, sizeof(poly));
}
}

View File

@ -206,7 +206,9 @@ OQS_STATUS OQS_KEX_sidh_iqc_ref_alice_1(OQS_KEX *k, const void *alice_priv,
void OQS_KEX_sidh_iqc_ref_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
if (alice_priv) {
free(alice_priv);
uint32_t prime_size = (mpz_sizeinbase(characteristic, 2) + 7) / 8;
uint32_t private_key_size = 2 * prime_size;
OQS_MEM_secure_free(alice_priv, private_key_size);
}
}

View File

@ -302,9 +302,10 @@ cleanup:
return ret;
}
void OQS_KEX_sidh_msr_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
void OQS_KEX_sidh_msr_alice_priv_free(OQS_KEX *k, void *alice_priv) {
if (alice_priv) {
free(alice_priv);
SIDH_CTX *sidh_ctx = (SIDH_CTX *) k->ctx;
OQS_MEM_secure_free(alice_priv, (sidh_ctx->priv_key_len) * sizeof(uint8_t));
}
}

View File

@ -71,7 +71,7 @@ int main(void) {
}
/* Generates the signature key pair */
int success = OQS_SIG_keygen(s, priv, pub);
OQS_STATUS success = OQS_SIG_keygen(s, priv, pub);
if (success != OQS_SUCCESS) {
eprintf("ERROR: OQS_SIG_keygen failed!\n");
cleanup(msg, msg_len, sig, sig_len, pub, priv, s, rnd);