mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
curve25519: Add ssh_curve25519_create_k to allow code re-use.
Signed-off-by: Simon Josefsson <simon@josefsson.org> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
083a4781d8
commit
4bd8d8d362
@@ -51,6 +51,7 @@ typedef unsigned char ssh_curve25519_pubkey[CURVE25519_PUBKEY_SIZE];
|
|||||||
typedef unsigned char ssh_curve25519_privkey[CURVE25519_PRIVKEY_SIZE];
|
typedef unsigned char ssh_curve25519_privkey[CURVE25519_PRIVKEY_SIZE];
|
||||||
|
|
||||||
int ssh_curve25519_init(ssh_session session);
|
int ssh_curve25519_init(ssh_session session);
|
||||||
|
int ssh_curve25519_create_k(ssh_session session, ssh_curve25519_pubkey k);
|
||||||
|
|
||||||
int ssh_client_curve25519_init(ssh_session session);
|
int ssh_client_curve25519_init(ssh_session session);
|
||||||
void ssh_client_curve25519_remove_callbacks(ssh_session session);
|
void ssh_client_curve25519_remove_callbacks(ssh_session session);
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ static struct ssh_packet_callbacks_struct ssh_curve25519_client_callbacks = {
|
|||||||
.user = NULL
|
.user = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int ssh_curve25519_init(ssh_session session)
|
||||||
ssh_curve25519_init(ssh_session session)
|
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
#ifdef HAVE_LIBCRYPTO
|
#ifdef HAVE_LIBCRYPTO
|
||||||
@@ -165,14 +164,12 @@ void ssh_client_curve25519_remove_callbacks(ssh_session session)
|
|||||||
ssh_packet_remove_callbacks(session, &ssh_curve25519_client_callbacks);
|
ssh_packet_remove_callbacks(session, &ssh_curve25519_client_callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssh_curve25519_build_k(ssh_session session)
|
int ssh_curve25519_create_k(ssh_session session, ssh_curve25519_pubkey k)
|
||||||
{
|
{
|
||||||
ssh_curve25519_pubkey k;
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBCRYPTO
|
#ifdef HAVE_LIBCRYPTO
|
||||||
EVP_PKEY_CTX *pctx = NULL;
|
EVP_PKEY_CTX *pctx = NULL;
|
||||||
EVP_PKEY *pkey = NULL, *pubkey = NULL;
|
EVP_PKEY *pkey = NULL, *pubkey = NULL;
|
||||||
size_t shared_key_len = sizeof(k);
|
size_t shared_key_len = CURVE25519_PUBKEY_SIZE;
|
||||||
int rc, ret = SSH_ERROR;
|
int rc, ret = SSH_ERROR;
|
||||||
|
|
||||||
pkey = session->next_crypto->curve25519_privkey;
|
pkey = session->next_crypto->curve25519_privkey;
|
||||||
@@ -247,16 +244,34 @@ out:
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_LIBCRYPTO */
|
#endif /* HAVE_LIBCRYPTO */
|
||||||
|
|
||||||
|
#ifdef DEBUG_CRYPTO
|
||||||
|
ssh_log_hexdump("Session server cookie",
|
||||||
|
session->next_crypto->server_kex.cookie,
|
||||||
|
16);
|
||||||
|
ssh_log_hexdump("Session client cookie",
|
||||||
|
session->next_crypto->client_kex.cookie,
|
||||||
|
16);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ssh_curve25519_build_k(ssh_session session)
|
||||||
|
{
|
||||||
|
ssh_curve25519_pubkey k;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = ssh_curve25519_create_k(session, k);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
bignum_bin2bn(k, CURVE25519_PUBKEY_SIZE, &session->next_crypto->shared_secret);
|
bignum_bin2bn(k, CURVE25519_PUBKEY_SIZE, &session->next_crypto->shared_secret);
|
||||||
if (session->next_crypto->shared_secret == NULL) {
|
if (session->next_crypto->shared_secret == NULL) {
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_CRYPTO
|
#ifdef DEBUG_CRYPTO
|
||||||
ssh_log_hexdump("Session server cookie",
|
|
||||||
session->next_crypto->server_kex.cookie, 16);
|
|
||||||
ssh_log_hexdump("Session client cookie",
|
|
||||||
session->next_crypto->client_kex.cookie, 16);
|
|
||||||
ssh_print_bignum("Shared secret key", session->next_crypto->shared_secret);
|
ssh_print_bignum("Shared secret key", session->next_crypto->shared_secret);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user