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,
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
/* 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
*/
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);
else
{
print_dsa_pkey (outfile, &x, &y, &p, &q, &g);
- bits = y.size * 8;
gnutls_free (x.data);
gnutls_free (y.data);
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);