From: Nikos Mavrogiannopoulos Date: Sat, 15 Sep 2012 09:15:07 +0000 (+0200) Subject: Added gnutls_x509_privkey_get_pk_algorithm2(). Certtool prints the number of bits... X-Git-Tag: gnutls_3_1_2~71 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=155bb9fac75701776f277f9b3de317243f576312;p=thirdparty%2Fgnutls.git Added gnutls_x509_privkey_get_pk_algorithm2(). Certtool prints the number of bits in a private key. --- diff --git a/lib/includes/gnutls/x509.h b/lib/includes/gnutls/x509.h index 3c86c34168..6c06cd04b2 100644 --- a/lib/includes/gnutls/x509.h +++ b/lib/includes/gnutls/x509.h @@ -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, diff --git a/lib/libgnutls.map b/lib/libgnutls.map index 0bac5774f2..032ee644cb 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -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 { diff --git a/lib/x509/privkey.c b/lib/x509/privkey.c index 98095aa5a0..a88e332665 100644 --- a/lib/x509/privkey.c +++ b/lib/x509/privkey.c @@ -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 diff --git a/src/certtool.c b/src/certtool.c index 4e027edcf6..1040bdcf05 100644 --- a/src/certtool.c +++ b/src/certtool.c @@ -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);