summaryrefslogtreecommitdiffstats
path: root/libssh/dh.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-16 14:55:38 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-16 14:55:38 +0000
commita092a841395f6848a9ef82ec315d0b1cf6afe641 (patch)
tree1a056eea376ba47668fd8b29f042af1d55bebb27 /libssh/dh.c
parentc6eb54c39e4663c8f9ea82e8bf29bfdb3c8d945a (diff)
downloadlibssh-a092a841395f6848a9ef82ec315d0b1cf6afe641.tar.gz
libssh-a092a841395f6848a9ef82ec315d0b1cf6afe641.tar.xz
libssh-a092a841395f6848a9ef82ec315d0b1cf6afe641.zip
Add return value to dh_build_k().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@506 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/dh.c')
-rw-r--r--libssh/dh.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/libssh/dh.c b/libssh/dh.c
index 4f37615f..fd581cb2 100644
--- a/libssh/dh.c
+++ b/libssh/dh.c
@@ -407,34 +407,54 @@ int dh_import_e(SSH_SESSION *session, STRING *e_string) {
return 0;
}
-void dh_build_k(SSH_SESSION *session){
+int dh_build_k(SSH_SESSION *session) {
#ifdef HAVE_LIBCRYPTO
- bignum_CTX ctx=bignum_ctx_new();
+ 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
- session->next_crypto->k=bignum_new();
+ 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,p);
- } else {
- bignum_mod_exp(session->next_crypto->k,session->next_crypto->e,session->next_crypto->y,p);
- }
+ if(session->client) {
+ bignum_mod_exp(session->next_crypto->k, session->next_crypto->f,
+ session->next_crypto->x, p);
+ } else {
+ bignum_mod_exp(session->next_crypto->k, session->next_crypto->e,
+ session->next_crypto->y, p);
+ }
#elif defined HAVE_LIBCRYPTO
- if(session->client){
- bignum_mod_exp(session->next_crypto->k,session->next_crypto->f,session->next_crypto->x,p,ctx);
- } else {
- bignum_mod_exp(session->next_crypto->k,session->next_crypto->e,session->next_crypto->y,p,ctx);
- }
+ if (session->client) {
+ bignum_mod_exp(session->next_crypto->k, session->next_crypto->f,
+ session->next_crypto->x, p, ctx);
+ } else {
+ bignum_mod_exp(session->next_crypto->k, session->next_crypto->e,
+ session->next_crypto->y, p, ctx);
+ }
#endif
+
#ifdef DEBUG_CRYPTO
- ssh_print_hexa("session server cookie",session->server_kex.cookie,16);
- ssh_print_hexa("session client cookie",session->client_kex.cookie,16);
- ssh_print_bignum("shared secret key",session->next_crypto->k);
+ ssh_print_hexa("Session server cookie", session->server_kex.cookie, 16);
+ ssh_print_hexa("Session client cookie", session->client_kex.cookie, 16);
+ ssh_print_bignum("Shared secret key", session->next_crypto->k);
#endif
+
#ifdef HAVE_LIBCRYPTO
- bignum_ctx_free(ctx);
+ bignum_ctx_free(ctx);
#endif
+
+ return 0;
}
+
/*
static void sha_add(STRING *str,SHACTX ctx){
sha1_update(ctx,str,string_len(str)+4);