Commit bed0449f authored by jvoisin's avatar jvoisin Committed by Ian Goldberg

Fix: use gcrypt secure memory allocation

Fixes #5
Acked-by: NikitaBorisov's avatarNikita Borisov <me+otr.im@nikita.ca>
Acked-by: default avatarDavid Goulet <dgoulet@ev0ke.net>
Signed-off-by: jvoisin's avatarJulien Voisin <julien.voisin@dustri.org>
parent 3172d79b
......@@ -138,7 +138,7 @@ gcry_error_t otrl_dh_session(DH_sesskeys *sess, const DH_keypair *kp,
}
/* Calculate the shared secret MPI */
gab = gcry_mpi_new(DH1536_MOD_LEN_BITS);
gab = gcry_mpi_snew(DH1536_MOD_LEN_BITS);
gcry_mpi_powm(gab, y, kp->priv, DH1536_MODULUS);
/* Output it in the right format */
......@@ -256,7 +256,7 @@ gcry_error_t otrl_dh_compute_v2_auth_keys(const DH_keypair *our_dh,
}
/* Calculate the shared secret MPI */
s = gcry_mpi_new(DH1536_MOD_LEN_BITS);
s = gcry_mpi_snew(DH1536_MOD_LEN_BITS);
gcry_mpi_powm(s, their_pub, our_dh->priv, DH1536_MODULUS);
/* Output it in the right format */
......@@ -381,7 +381,7 @@ gcry_error_t otrl_dh_compute_v1_session_id(const DH_keypair *our_dh,
}
/* Calculate the shared secret MPI */
s = gcry_mpi_new(DH1536_MOD_LEN_BITS);
s = gcry_mpi_snew(DH1536_MOD_LEN_BITS);
gcry_mpi_powm(s, their_pub, our_dh->priv, DH1536_MODULUS);
/* Output it in the right format */
......
......@@ -133,7 +133,7 @@ void otrl_sm_state_new(OtrlSMState *smst)
void otrl_sm_state_init(OtrlSMState *smst)
{
otrl_sm_state_free(smst);
smst->secret = gcry_mpi_new(SM_MOD_LEN_BITS);
smst->secret = gcry_mpi_snew(SM_MOD_LEN_BITS);
smst->x2 = NULL;
smst->x3 = NULL;
smst->g1 = gcry_mpi_copy(SM_GENERATOR);
......@@ -431,7 +431,7 @@ static gcry_error_t otrl_sm_proof_know_log(gcry_mpi_t *c, gcry_mpi_t *d,
const gcry_mpi_t g, const gcry_mpi_t x, int version)
{
gcry_mpi_t r = randomExponent();
gcry_mpi_t temp = gcry_mpi_new(SM_MOD_LEN_BITS);
gcry_mpi_t temp = gcry_mpi_snew(SM_MOD_LEN_BITS);
gcry_mpi_powm(temp, g, r, SM_MODULUS);
otrl_sm_hash(c, version, temp, NULL);
gcry_mpi_mulm(temp, x, *c, SM_ORDER);
......
......@@ -53,9 +53,9 @@ void sesskeys_gen(unsigned char sessionid[20], unsigned char sendenc[16],
(const unsigned char *)DH1536_MODULUS_S, 0, NULL);
gcry_mpi_scan(&generator, GCRYMPI_FMT_HEX,
(const unsigned char *)DH1536_GENERATOR_S, 0, NULL);
*our_yp = gcry_mpi_new(DH1536_MOD_LEN_BITS);
*our_yp = gcry_mpi_snew(DH1536_MOD_LEN_BITS);
gcry_mpi_powm(*our_yp, generator, our_x, modulus);
secretv = gcry_mpi_new(DH1536_MOD_LEN_BITS);
secretv = gcry_mpi_snew(DH1536_MOD_LEN_BITS);
gcry_mpi_powm(secretv, their_y, our_x, modulus);
gcry_mpi_release(generator);
gcry_mpi_release(modulus);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment