int dh_generate_f(ssh_session session) { #ifdef HAVE_LIBCRYPTO bignum_CTX ctx = bignum_ctx_new(); if (ctx == NULL) { return -1; } #endif session->next_crypto->f = bignum_new(); if (session->next_crypto->f == NULL) { #ifdef HAVE_LIBCRYPTO bignum_ctx_free(ctx); #endif return -1; } #ifdef HAVE_LIBGCRYPT bignum_mod_exp(session->next_crypto->f, g, session->next_crypto->y, select_p(session->next_crypto->kex_type)); #elif defined HAVE_LIBCRYPTO bignum_mod_exp(session->next_crypto->f, g, session->next_crypto->y, select_p(session->next_crypto->kex_type), ctx); #endif #ifdef DEBUG_CRYPTO ssh_print_bignum("f", session->next_crypto->f); #endif #ifdef HAVE_LIBCRYPTO bignum_ctx_free(ctx); #endif return 0; }
/* used by server */ int dh_generate_e(ssh_session session) { #ifdef HAVE_LIBCRYPTO bignum_CTX ctx = bignum_ctx_new(); if (ctx == NULL) { return -1; } #endif session->next_crypto->e = bignum_new(); if (session->next_crypto->e == NULL) { #ifdef HAVE_LIBCRYPTO bignum_ctx_free(ctx); #endif return -1; } #ifdef HAVE_LIBGCRYPT bignum_mod_exp(session->next_crypto->e, g, session->next_crypto->x, p); #elif defined HAVE_LIBCRYPTO bignum_mod_exp(session->next_crypto->e, g, session->next_crypto->x, p, ctx); #endif #ifdef DEBUG_CRYPTO ssh_print_bignum("e", session->next_crypto->e); #endif #ifdef HAVE_LIBCRYPTO bignum_ctx_free(ctx); #endif return 0; }
int dh_build_k(ssh_session session) { #ifdef HAVE_LIBCRYPTO bignum_CTX ctx = bignum_ctx_new(); if (ctx == NULL) { return -1; } #endif session->next_crypto->k = bignum_new(); if (session->next_crypto->k == NULL) { #ifdef HAVE_LIBCRYPTO bignum_ctx_free(ctx); #endif return -1; } /* the server and clients don't use the same numbers */ #ifdef HAVE_LIBGCRYPT if(session->client) { bignum_mod_exp(session->next_crypto->k, session->next_crypto->f, session->next_crypto->x, select_p(session->next_crypto->kex_type)); } else { bignum_mod_exp(session->next_crypto->k, session->next_crypto->e, session->next_crypto->y, select_p(session->next_crypto->kex_type)); } #elif defined HAVE_LIBCRYPTO if (session->client) { bignum_mod_exp(session->next_crypto->k, session->next_crypto->f, session->next_crypto->x, select_p(session->next_crypto->kex_type), ctx); } else { bignum_mod_exp(session->next_crypto->k, session->next_crypto->e, session->next_crypto->y, select_p(session->next_crypto->kex_type), ctx); } #endif #ifdef DEBUG_CRYPTO ssh_print_hexa("Session server cookie", session->next_crypto->server_kex.cookie, 16); ssh_print_hexa("Session client cookie", session->next_crypto->client_kex.cookie, 16); ssh_print_bignum("Shared secret key", session->next_crypto->k); #endif #ifdef HAVE_LIBCRYPTO bignum_ctx_free(ctx); #endif return 0; }