mirror of
https://github.com/clearml/dropbear
synced 2025-06-16 19:28:49 +00:00
- Rename buf_put_ecc_pubkey_string() to buf_put_ecc_raw_pubkey_string()
- Reindent ecc.c properly --HG-- branch : ecc
This commit is contained in:
parent
a7d1a9cfcb
commit
4f07805d0a
@ -51,7 +51,7 @@ void send_msg_kexdh_init() {
|
|||||||
} else {
|
} else {
|
||||||
#ifdef DROPBEAR_ECDH
|
#ifdef DROPBEAR_ECDH
|
||||||
cli_ses.ecdh_param = gen_kexecdh_param();
|
cli_ses.ecdh_param = gen_kexecdh_param();
|
||||||
buf_put_ecc_pubkey_string(ses.writepayload, &cli_ses.ecdh_param->key);
|
buf_put_ecc_raw_pubkey_string(ses.writepayload, &cli_ses.ecdh_param->key);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
encrypt_packet();
|
encrypt_packet();
|
||||||
|
@ -662,7 +662,7 @@ void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them,
|
|||||||
// public keys from client and server
|
// public keys from client and server
|
||||||
ecc_key *Q_C, *Q_S, *Q_them;
|
ecc_key *Q_C, *Q_S, *Q_them;
|
||||||
|
|
||||||
Q_them = buf_get_ecc_pubkey(pub_them, algo_kex->ecc_curve);
|
Q_them = buf_get_ecc_raw_pubkey(pub_them, algo_kex->ecc_curve);
|
||||||
|
|
||||||
ses.dh_K = dropbear_ecc_shared_secret(Q_them, ¶m->key);
|
ses.dh_K = dropbear_ecc_shared_secret(Q_them, ¶m->key);
|
||||||
|
|
||||||
@ -680,9 +680,9 @@ void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them,
|
|||||||
/* K_S, the host key */
|
/* K_S, the host key */
|
||||||
buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
|
buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
|
||||||
/* Q_C, client's ephemeral public key octet string */
|
/* Q_C, client's ephemeral public key octet string */
|
||||||
buf_put_ecc_pubkey_string(ses.kexhashbuf, Q_C);
|
buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_C);
|
||||||
/* Q_S, server's ephemeral public key octet string */
|
/* Q_S, server's ephemeral public key octet string */
|
||||||
buf_put_ecc_pubkey_string(ses.kexhashbuf, Q_S);
|
buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_S);
|
||||||
/* K, the shared secret */
|
/* K, the shared secret */
|
||||||
buf_putmpint(ses.kexhashbuf, ses.dh_K);
|
buf_putmpint(ses.kexhashbuf, ses.dh_K);
|
||||||
|
|
||||||
|
30
ecc.c
30
ecc.c
@ -40,16 +40,6 @@ static ecc_key * new_ecc_key(void) {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void buf_put_ecc_pubkey_string(buffer *buf, ecc_key *key) {
|
|
||||||
unsigned long len = key->dp->size*2 + 1;
|
|
||||||
buf_putint(buf, len);
|
|
||||||
int err = ecc_ansi_x963_export(key, buf_getwriteptr(buf, len), &len);
|
|
||||||
if (err != CRYPT_OK) {
|
|
||||||
dropbear_exit("ECC error");
|
|
||||||
}
|
|
||||||
buf_incrwritepos(buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copied from libtomcrypt ecc_import.c (version there is static), modified
|
// Copied from libtomcrypt ecc_import.c (version there is static), modified
|
||||||
// for different mp_int pointer without LTC_SOURCE
|
// for different mp_int pointer without LTC_SOURCE
|
||||||
static int ecc_is_point(ecc_key *key)
|
static int ecc_is_point(ecc_key *key)
|
||||||
@ -98,7 +88,7 @@ static int ecc_is_point(ecc_key *key)
|
|||||||
err = CRYPT_OK;
|
err = CRYPT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
mp_clear_multi(prime, b, t1, t2, NULL);
|
mp_clear_multi(prime, b, t1, t2, NULL);
|
||||||
m_free(prime);
|
m_free(prime);
|
||||||
m_free(b);
|
m_free(b);
|
||||||
@ -107,7 +97,19 @@ error:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecc_key * buf_get_ecc_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) {
|
/* For the "ephemeral public key octet string" in ECDH (rfc5656 section 4) */
|
||||||
|
void buf_put_ecc_raw_pubkey_string(buffer *buf, ecc_key *key) {
|
||||||
|
unsigned long len = key->dp->size*2 + 1;
|
||||||
|
buf_putint(buf, len);
|
||||||
|
int err = ecc_ansi_x963_export(key, buf_getwriteptr(buf, len), &len);
|
||||||
|
if (err != CRYPT_OK) {
|
||||||
|
dropbear_exit("ECC error");
|
||||||
|
}
|
||||||
|
buf_incrwritepos(buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* For the "ephemeral public key octet string" in ECDH (rfc5656 section 4) */
|
||||||
|
ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) {
|
||||||
ecc_key *key = NULL;
|
ecc_key *key = NULL;
|
||||||
int ret = DROPBEAR_FAILURE;
|
int ret = DROPBEAR_FAILURE;
|
||||||
const unsigned int size = curve->dp->size;
|
const unsigned int size = curve->dp->size;
|
||||||
@ -151,7 +153,7 @@ ecc_key * buf_get_ecc_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve
|
|||||||
|
|
||||||
ret = DROPBEAR_SUCCESS;
|
ret = DROPBEAR_SUCCESS;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (ret == DROPBEAR_FAILURE) {
|
if (ret == DROPBEAR_FAILURE) {
|
||||||
if (key) {
|
if (key) {
|
||||||
ecc_free(key);
|
ecc_free(key);
|
||||||
@ -198,7 +200,7 @@ mp_int * dropbear_ecc_shared_secret(ecc_key *public_key, ecc_key *private_key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = DROPBEAR_SUCCESS;
|
err = DROPBEAR_SUCCESS;
|
||||||
done:
|
done:
|
||||||
if (err == DROPBEAR_SUCCESS) {
|
if (err == DROPBEAR_SUCCESS) {
|
||||||
shared_secret = m_malloc(sizeof(*shared_secret));
|
shared_secret = m_malloc(sizeof(*shared_secret));
|
||||||
m_mp_init(shared_secret);
|
m_mp_init(shared_secret);
|
||||||
|
4
ecc.h
4
ecc.h
@ -20,8 +20,8 @@ extern const struct dropbear_ecc_curve ecc_curve_nistp521;
|
|||||||
|
|
||||||
// "pubkey" refers to a point, but LTC uses ecc_key structure for both public
|
// "pubkey" refers to a point, but LTC uses ecc_key structure for both public
|
||||||
// and private keys
|
// and private keys
|
||||||
void buf_put_ecc_pubkey_string(buffer *buf, ecc_key *key);
|
void buf_put_ecc_raw_pubkey_string(buffer *buf, ecc_key *key);
|
||||||
ecc_key * buf_get_ecc_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve);
|
ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve);
|
||||||
int buf_get_ecc_privkey_string(buffer *buf, ecc_key *key);
|
int buf_get_ecc_privkey_string(buffer *buf, ecc_key *key);
|
||||||
|
|
||||||
mp_int * dropbear_ecc_shared_secret(ecc_key *pub_key, ecc_key *priv_key);
|
mp_int * dropbear_ecc_shared_secret(ecc_key *pub_key, ecc_key *priv_key);
|
||||||
|
@ -104,7 +104,7 @@ static void send_msg_kexdh_reply(mp_int *dh_e, buffer *ecdh_qs) {
|
|||||||
struct kex_ecdh_param *ecdh_param = gen_kexecdh_param();
|
struct kex_ecdh_param *ecdh_param = gen_kexecdh_param();
|
||||||
kexecdh_comb_key(ecdh_param, ecdh_qs, svr_opts.hostkey);
|
kexecdh_comb_key(ecdh_param, ecdh_qs, svr_opts.hostkey);
|
||||||
|
|
||||||
buf_put_ecc_pubkey_string(ses.writepayload, &ecdh_param->key);
|
buf_put_ecc_raw_pubkey_string(ses.writepayload, &ecdh_param->key);
|
||||||
free_kexecdh_param(ecdh_param);
|
free_kexecdh_param(ecdh_param);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user