aboutsummaryrefslogtreecommitdiff
path: root/src/dh.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-09-08 19:58:59 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-09-08 19:58:59 +0200
commit77e71ae3b5568ba43c0017a878dc780b3fe0c169 (patch)
treeac50ea90e82f3f6a741a08bab54be44b66ae0173 /src/dh.c
parent81017b0fc2a45d83e045b234b9c66f26323fdab2 (diff)
downloadlibssh-77e71ae3b5568ba43c0017a878dc780b3fe0c169.tar.gz
libssh-77e71ae3b5568ba43c0017a878dc780b3fe0c169.tar.xz
libssh-77e71ae3b5568ba43c0017a878dc780b3fe0c169.zip
dh: Use ssh_string_new() in make_bignum_string().
Diffstat (limited to 'src/dh.c')
-rw-r--r--src/dh.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/dh.c b/src/dh.c
index b449c26d..36e77d6f 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -346,8 +346,11 @@ ssh_string make_bignum_string(bignum num) {
unsigned int len = bignum_num_bytes(num);
unsigned int bits = bignum_num_bits(num);
- /* Remember if the fist bit is set, it is considered as a
- * negative number. So 0's must be appended */
+ 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++;
}
@@ -355,12 +358,13 @@ ssh_string make_bignum_string(bignum num) {
#ifdef DEBUG_CRYPTO
fprintf(stderr, "%d bits, %d bytes, %d padding\n", bits, len, pad);
#endif /* DEBUG_CRYPTO */
-/* TODO: fix that crap !! */
- ptr = malloc(sizeof(struct ssh_string_struct) + len + pad);
+
+ ptr = ssh_string_new(len + pad);
if (ptr == NULL) {
return NULL;
}
- ptr->size = htonl(len + pad);
+
+ /* We have a negative number so we need a leading zero */
if (pad) {
ptr->data[0] = 0;
}