]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added gnutls_x509_privkey_get_pk_algorithm2(). Certtool prints the number of bits...
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 15 Sep 2012 09:15:07 +0000 (11:15 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 15 Sep 2012 09:15:07 +0000 (11:15 +0200)
lib/includes/gnutls/x509.h
lib/libgnutls.map
lib/x509/privkey.c
src/certtool.c

index 3c86c34168d8e3c7eebf4e31ec15f65eb8e8a9c9..6c06cd04b272272b7dd9728f303e32d80ddbaa80 100644 (file)
@@ -767,6 +767,7 @@ extern "C"
                                           const gnutls_datum_t * x);
 
   int gnutls_x509_privkey_get_pk_algorithm (gnutls_x509_privkey_t key);
+  int gnutls_x509_privkey_get_pk_algorithm2 (gnutls_x509_privkey_t key, unsigned int *bits);
   int gnutls_x509_privkey_get_key_id (gnutls_x509_privkey_t key,
                                       unsigned int flags,
                                       unsigned char *output_data,
index 0bac5774f2aed3fa1da800aa7f381a5b414678f2..032ee644cb80ce011a0ce99c25eb68b409ea94b3 100644 (file)
@@ -834,6 +834,7 @@ GNUTLS_3_1_0 {
        gnutls_sign_get_pk_algorithm;
        gnutls_sign_get_hash_algorithm;
        gnutls_sign_algorithm_get;
+       gnutls_x509_privkey_get_pk_algorithm2;
 } GNUTLS_3_0_0;
 
 GNUTLS_PRIVATE {
index 98095aa5a0baedbdb0425ec3f6e43809f57bb401..a88e33266505d169cef273a6e5956e042d8dd529 100644 (file)
@@ -984,6 +984,38 @@ gnutls_x509_privkey_get_pk_algorithm (gnutls_x509_privkey_t key)
   return key->pk_algorithm;
 }
 
+/**
+ * gnutls_x509_privkey_get_pk_algorithm2:
+ * @key: should contain a #gnutls_x509_privkey_t structure
+ * @bits: The number of bits in the public key algorithm
+ *
+ * This function will return the public key algorithm of a private
+ * key.
+ *
+ * Returns: a member of the #gnutls_pk_algorithm_t enumeration on
+ *   success, or a negative error code on error.
+ **/
+int
+gnutls_x509_privkey_get_pk_algorithm2 (gnutls_x509_privkey_t key, unsigned int *bits)
+{
+int ret;
+
+  if (key == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_INVALID_REQUEST;
+    }
+
+  if (bits)
+    {
+      ret = pubkey_to_bits(key->pk_algorithm, &key->params);
+      if (ret < 0) ret = 0;
+      *bits = ret;
+    }
+
+  return key->pk_algorithm;
+}
+
 /**
  * gnutls_x509_privkey_export:
  * @key: Holds the key
index 4e027edcf6ac4941dd679201aaa9db7dd43eca94..1040bdcf0507d1bebb173669337aebcbf2563c5a 100644 (file)
@@ -1576,15 +1576,15 @@ const char *cprint;
   /* Public key algorithm
    */
   fprintf (outfile, "Public Key Info:\n");
-  ret = gnutls_x509_privkey_get_pk_algorithm (key);
+  ret = gnutls_x509_privkey_get_pk_algorithm2 (key, &bits);
   fprintf (outfile, "\tPublic Key Algorithm: ");
 
   key_type = ret;
 
   cprint = gnutls_pk_algorithm_get_name (key_type);
   fprintf (outfile, "%s\n", cprint ? cprint : "Unknown");
-  fprintf (outfile, "\tKey Security Level: %s\n\n",
-           gnutls_sec_param_get_name (gnutls_x509_privkey_sec_param (key)));
+  fprintf (outfile, "\tKey Security Level: %s (%u bits)\n\n",
+           gnutls_sec_param_get_name (gnutls_x509_privkey_sec_param (key)), bits);
 
   /* Print the raw public and private keys
    */
@@ -1601,7 +1601,6 @@ const char *cprint;
       else
         {
           print_rsa_pkey (outfile, &m, &e, &d, &p, &q, &u, &exp1, &exp2);
-          bits = m.size * 8;
 
           gnutls_free (m.data);
           gnutls_free (e.data);
@@ -1624,7 +1623,6 @@ const char *cprint;
       else
         {
           print_dsa_pkey (outfile, &x, &y, &p, &q, &g);
-          bits = y.size * 8;
 
           gnutls_free (x.data);
           gnutls_free (y.data);
@@ -1645,7 +1643,6 @@ const char *cprint;
       else
         {
           print_ecc_pkey (outfile, curve, &k, &x, &y);
-          bits = gnutls_ecc_curve_get_size(curve) * 8;
 
           gnutls_free (x.data);
           gnutls_free (y.data);