version 1.3, 2014/01/09 23:20:00 |
version 1.4, 2014/01/12 08:13:13 |
|
|
crypto_scalarmult_curve25519(pub, key, basepoint); |
crypto_scalarmult_curve25519(pub, key, basepoint); |
} |
} |
|
|
BIGNUM * |
void |
kexc25519_shared_key(const u_char key[CURVE25519_SIZE], |
kexc25519_shared_key(const u_char key[CURVE25519_SIZE], |
const u_char pub[CURVE25519_SIZE]) |
const u_char pub[CURVE25519_SIZE], Buffer *out) |
{ |
{ |
u_char shared_key[CURVE25519_SIZE]; |
u_char shared_key[CURVE25519_SIZE]; |
BIGNUM *shared_secret; |
|
|
|
crypto_scalarmult_curve25519(shared_key, key, pub); |
crypto_scalarmult_curve25519(shared_key, key, pub); |
#ifdef DEBUG_KEXECDH |
#ifdef DEBUG_KEXECDH |
dump_digest("shared secret", shared_key, CURVE25519_SIZE); |
dump_digest("shared secret", shared_key, CURVE25519_SIZE); |
#endif |
#endif |
if ((shared_secret = BN_new()) == NULL) |
buffer_clear(out); |
fatal("%s: BN_new failed", __func__); |
buffer_put_bignum2_from_string(out, shared_key, CURVE25519_SIZE); |
if (BN_bin2bn(shared_key, sizeof(shared_key), shared_secret) == NULL) |
|
fatal("%s: BN_bin2bn failed", __func__); |
|
memset(shared_key, 0, CURVE25519_SIZE); /* XXX explicit_bzero() */ |
memset(shared_key, 0, CURVE25519_SIZE); /* XXX explicit_bzero() */ |
return (shared_secret); |
|
} |
} |
|
|
void |
void |
|
|
u_char *serverhostkeyblob, int sbloblen, |
u_char *serverhostkeyblob, int sbloblen, |
const u_char client_dh_pub[CURVE25519_SIZE], |
const u_char client_dh_pub[CURVE25519_SIZE], |
const u_char server_dh_pub[CURVE25519_SIZE], |
const u_char server_dh_pub[CURVE25519_SIZE], |
const BIGNUM *shared_secret, |
const u_char *shared_secret, u_int secretlen, |
u_char **hash, u_int *hashlen) |
u_char **hash, u_int *hashlen) |
{ |
{ |
Buffer b; |
Buffer b; |
|
|
buffer_put_string(&b, serverhostkeyblob, sbloblen); |
buffer_put_string(&b, serverhostkeyblob, sbloblen); |
buffer_put_string(&b, client_dh_pub, CURVE25519_SIZE); |
buffer_put_string(&b, client_dh_pub, CURVE25519_SIZE); |
buffer_put_string(&b, server_dh_pub, CURVE25519_SIZE); |
buffer_put_string(&b, server_dh_pub, CURVE25519_SIZE); |
buffer_put_bignum2(&b, shared_secret); |
buffer_append(&b, shared_secret, secretlen); |
|
|
#ifdef DEBUG_KEX |
#ifdef DEBUG_KEX |
buffer_dump(&b); |
buffer_dump(&b); |