aboutsummaryrefslogtreecommitdiff
path: root/src/dh.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2014-04-24 09:05:47 +0200
committerAndreas Schneider <asn@cryptomilk.org>2014-08-06 10:07:36 +0200
commit228dc08038a18e8cc165baa4a9348d173549a048 (patch)
tree9e6901081b8d911ace37b942c24a961b81963897 /src/dh.c
parent33cd594f1f36a40882927ccb6b82db8cda651995 (diff)
downloadlibssh-228dc08038a18e8cc165baa4a9348d173549a048.tar.gz
libssh-228dc08038a18e8cc165baa4a9348d173549a048.tar.xz
libssh-228dc08038a18e8cc165baa4a9348d173549a048.zip
bignums: detach bignum-related functions from dh.c.
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src/dh.c')
-rw-r--r--src/dh.c71
1 files changed, 1 insertions, 70 deletions
diff --git a/src/dh.c b/src/dh.c
index c95e5b58..fc14ff60 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -60,6 +60,7 @@
#include "libssh/dh.h"
#include "libssh/ssh2.h"
#include "libssh/pki.h"
+#include "libssh/bignum.h"
/* todo: remove it */
#include "libssh/string.h"
@@ -225,20 +226,6 @@ void ssh_crypto_finalize(void) {
}
}
-/* prints the bignum on stderr */
-void ssh_print_bignum(const char *which, bignum num) {
-#ifdef HAVE_LIBGCRYPT
- unsigned char *hex = NULL;
- bignum_bn2hex(num, &hex);
-#elif defined HAVE_LIBCRYPTO
- char *hex = NULL;
- hex = bignum_bn2hex(num);
-#endif
- fprintf(stderr, "%s value: ", which);
- fprintf(stderr, "%s\n", (hex == NULL) ? "(null)" : (char *) hex);
- SAFE_FREE(hex);
-}
-
int dh_generate_x(ssh_session session) {
session->next_crypto->x = bignum_new();
if (session->next_crypto->x == NULL) {
@@ -351,62 +338,6 @@ int dh_generate_f(ssh_session session) {
return 0;
}
-ssh_string make_bignum_string(bignum num) {
- ssh_string ptr = NULL;
- int pad = 0;
- unsigned int len = bignum_num_bytes(num);
- unsigned int bits = bignum_num_bits(num);
-
- if (len == 0) {
- return NULL;
- }
-
- /* If the first bit is set we have a negative number */
- if (!(bits % 8) && bignum_is_bit_set(num, bits - 1)) {
- pad++;
- }
-
-#ifdef DEBUG_CRYPTO
- fprintf(stderr, "%d bits, %d bytes, %d padding\n", bits, len, pad);
-#endif /* DEBUG_CRYPTO */
-
- ptr = ssh_string_new(len + pad);
- if (ptr == NULL) {
- return NULL;
- }
-
- /* We have a negative number so we need a leading zero */
- if (pad) {
- ptr->data[0] = 0;
- }
-
-#ifdef HAVE_LIBGCRYPT
- bignum_bn2bin(num, len, ptr->data + pad);
-#elif HAVE_LIBCRYPTO
- bignum_bn2bin(num, ptr->data + pad);
-#endif
-
- return ptr;
-}
-
-bignum make_string_bn(ssh_string string){
- bignum bn = NULL;
- unsigned int len = ssh_string_len(string);
-
-#ifdef DEBUG_CRYPTO
- fprintf(stderr, "Importing a %d bits, %d bytes object ...\n",
- len * 8, len);
-#endif /* DEBUG_CRYPTO */
-
-#ifdef HAVE_LIBGCRYPT
- bignum_bin2bn(string->data, len, &bn);
-#elif defined HAVE_LIBCRYPTO
- bn = bignum_bin2bn(string->data, len, NULL);
-#endif
-
- return bn;
-}
-
ssh_string dh_get_e(ssh_session session) {
return make_bignum_string(session->next_crypto->e);
}