summaryrefslogtreecommitdiffhomepage
path: root/common-kex.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2005-05-05 03:58:21 +0000
committerMatt Johnston <matt@ucc.asn.au>2005-05-05 03:58:21 +0000
commitcf585ba1dee7a7e1f2fbc90d2251d99b7da66a7e (patch)
tree34034ef46643844cbece5ea3c8926b4db0346200 /common-kex.c
parent298a5717bc479f13276982858e84172c3c29146a (diff)
- refactored random mp_int generation and byte->mp_int code
- added RSA blinding --HG-- extra : convert_revision : 5d5b4657a24a1c8f53c6fc45d5ec29ddb85fb45a
Diffstat (limited to 'common-kex.c')
-rw-r--r--common-kex.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/common-kex.c b/common-kex.c
index a2336c5..8a8aa93 100644
--- a/common-kex.c
+++ b/common-kex.c
@@ -469,18 +469,13 @@ void gen_kexdh_vals(mp_int *dh_pub, mp_int *dh_priv) {
DEF_MP_INT(dh_p);
DEF_MP_INT(dh_q);
DEF_MP_INT(dh_g);
- unsigned char randbuf[DH_P_LEN];
- int dh_q_len;
TRACE(("enter send_msg_kexdh_reply"))
m_mp_init_multi(&dh_g, &dh_p, &dh_q, NULL);
/* read the prime and generator*/
- if (mp_read_unsigned_bin(&dh_p, (unsigned char*)dh_p_val, DH_P_LEN)
- != MP_OKAY) {
- dropbear_exit("Diffie-Hellman error");
- }
+ bytes_to_mp(&dh_p, (unsigned char*)dh_p_val, DH_P_LEN);
if (mp_set_int(&dh_g, DH_G_VAL) != MP_OKAY) {
dropbear_exit("Diffie-Hellman error");
@@ -495,16 +490,8 @@ void gen_kexdh_vals(mp_int *dh_pub, mp_int *dh_priv) {
dropbear_exit("Diffie-Hellman error");
}
- dh_q_len = mp_unsigned_bin_size(&dh_q);
-
- /* calculate our random value dh_y */
- do {
- assert((unsigned int)dh_q_len <= sizeof(randbuf));
- genrandom(randbuf, dh_q_len);
- if (mp_read_unsigned_bin(dh_priv, randbuf, dh_q_len) != MP_OKAY) {
- dropbear_exit("Diffie-Hellman error");
- }
- } while (mp_cmp(dh_priv, &dh_q) == MP_GT || mp_cmp_d(dh_priv, 0) != MP_GT);
+ /* Generate a private portion 0 < dh_priv < dh_q */
+ gen_random_mpint(&dh_q, dh_priv);
/* f = g^y mod p */
if (mp_exptmod(&dh_g, dh_priv, &dh_p, dh_pub) != MP_OKAY) {
@@ -526,10 +513,7 @@ void kexdh_comb_key(mp_int *dh_pub_us, mp_int *dh_priv, mp_int *dh_pub_them,
/* read the prime and generator*/
mp_init(&dh_p);
- if (mp_read_unsigned_bin(&dh_p, (unsigned char*)dh_p_val, DH_P_LEN)
- != MP_OKAY) {
- dropbear_exit("Diffie-Hellman error");
- }
+ bytes_to_mp(&dh_p, dh_p_val, DH_P_LEN);
/* Check that dh_pub_them (dh_e or dh_f) is in the range [1, p-1] */
if (mp_cmp(dh_pub_them, &dh_p) != MP_LT