diff options
author | Stef Walter <stefw@redhat.com> | 2014-04-17 07:14:00 +0200 |
---|---|---|
committer | Stef Walter <stefw@redhat.com> | 2014-04-19 22:29:49 +0200 |
commit | 13f3cd21cbc78aaa4b2f70d4614937db7a86a145 (patch) | |
tree | 559daa4c73cdb5a445df0cbf743246f1ee084b6f /gcr/gcr-subject-public-key.c | |
parent | 6e8e755f040d799c84f807f196cd6155bd693f78 (diff) | |
download | gcr-13f3cd21cbc78aaa4b2f70d4614937db7a86a145.tar.gz |
gcr: Move key size code to gcr-subject-public-key.c
Refactor things to key size calculation code is in one place
Diffstat (limited to 'gcr/gcr-subject-public-key.c')
-rw-r--r-- | gcr/gcr-subject-public-key.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gcr/gcr-subject-public-key.c b/gcr/gcr-subject-public-key.c index 5b7dc28..359307c 100644 --- a/gcr/gcr-subject-public-key.c +++ b/gcr/gcr-subject-public-key.c @@ -786,6 +786,24 @@ calculate_rsa_key_size (GBytes *data) } static guint +attributes_rsa_key_size (GckAttributes *attrs) +{ + const GckAttribute *attr; + gulong bits; + + attr = gck_attributes_find (attrs, CKA_MODULUS); + + /* Calculate the bit length, and remove the complement */ + if (attr != NULL) + return (attr->length / 2) * 2 * 8; + + if (gck_attributes_find_ulong (attrs, CKA_MODULUS_BITS, &bits)) + return (gint)bits; + + return 0; +} + +static guint calculate_dsa_params_size (GNode *params) { GNode *asn; @@ -808,6 +826,24 @@ calculate_dsa_params_size (GNode *params) return key_size; } +static guint +attributes_dsa_key_size (GckAttributes *attrs) +{ + const GckAttribute *attr; + gulong bits; + + attr = gck_attributes_find (attrs, CKA_PRIME); + + /* Calculate the bit length, and remove the complement */ + if (attr != NULL) + return (attr->length / 2) * 2 * 8; + + if (gck_attributes_find_ulong (attrs, CKA_PRIME_BITS, &bits)) + return (gint)bits; + + return 0; +} + guint _gcr_subject_public_key_calculate_size (GNode *subject_public_key) { @@ -840,3 +876,22 @@ _gcr_subject_public_key_calculate_size (GNode *subject_public_key) return key_size; } + +guint +_gcr_subject_public_key_attributes_size (GckAttributes *attrs) +{ + gulong key_type; + + if (!gck_attributes_find_ulong (attrs, CKA_KEY_TYPE, &key_type)) + return 0; + + switch (key_type) { + case CKK_RSA: + return attributes_rsa_key_size (attrs); + case CKK_DSA: + return attributes_dsa_key_size (attrs); + default: + g_message ("unsupported key algorithm: %lu", key_type); + return 0; + } +} |