]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Return proper MPI lengths in bits.
authorSimon Josefsson <simon@josefsson.org>
Wed, 17 Jun 2009 07:20:08 +0000 (09:20 +0200)
committerSimon Josefsson <simon@josefsson.org>
Wed, 17 Jun 2009 07:20:08 +0000 (09:20 +0200)
Reported by Peter Hendrickson <pdh@wiredyne.com> in
<http://thread.gmane.org/gmane.comp.encryption.gpg.gnutls.devel/3607>.

lib/gnutls_ui.c

index 6ad2e4f729f53bd83ee64263a88709cbc1c5fcca..4f96762e40c31c4e1bc81427ef0b1b3c48a29b67 100644 (file)
@@ -288,6 +288,24 @@ gnutls_dh_get_secret_bits (gnutls_session_t session)
     }
 }
 
+static int
+mpi_buf2bits (gnutls_datum_t *mpi_buf)
+{
+  bigint_t mpi;
+  int rc;
+
+  rc = _gnutls_mpi_scan_nz (&mpi, mpi_buf->data, mpi_buf->size);
+  if (rc)
+    {
+      gnutls_assert ();
+      return rc;
+    }
+
+  rc = _gnutls_mpi_get_nbits (mpi);
+  _gnutls_mpi_release (&mpi);
+
+  return rc;
+}
 
 /**
  * gnutls_dh_get_prime_bits - return the bits used in D-H key exchange
@@ -346,8 +364,7 @@ gnutls_dh_get_prime_bits (gnutls_session_t session)
       return GNUTLS_E_INVALID_REQUEST;
     }
 
-  return (dh->prime.size) * 8;
-
+  return mpi_buf2bits (&dh->prime);
 }
 
 /**
@@ -368,7 +385,7 @@ gnutls_rsa_export_get_modulus_bits (gnutls_session_t session)
   if (info == NULL)
     return GNUTLS_E_INTERNAL_ERROR;
 
-  return info->rsa_export.modulus.size * 8;
+  return mpi_buf2bits (&info->rsa_export.modulus);
 }
 
 /**
@@ -426,8 +443,7 @@ gnutls_dh_get_peers_public_bits (gnutls_session_t session)
       return GNUTLS_E_INVALID_REQUEST;
     }
 
-  return dh->public_key.size * 8;
-
+  return mpi_buf2bits (&dh->public_key);
 }
 
 /* CERTIFICATE STUFF */