diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-16 17:30:42 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-16 17:30:42 +0100 |
commit | 6eb6bbfe8e504a611145f454f4045e8f49fd5e44 (patch) | |
tree | baba850cc86ee2d9d61de89da1cdfe408ad8694a /lib/openpgp | |
parent | bdcfdac13179eccee6294402f2654fece149f82b (diff) | |
download | gnutls-6eb6bbfe8e504a611145f454f4045e8f49fd5e44.tar.gz |
Indented code. Use same indentation but with -nut to avoid usage of tabs. In several editors tabs can be configured not to be 8 spaces and this produces artifacts with the current indentation that is a mixture of tabs and spaces.
Diffstat (limited to 'lib/openpgp')
-rw-r--r-- | lib/openpgp/compat.c | 14 | ||||
-rw-r--r-- | lib/openpgp/extras.c | 98 | ||||
-rw-r--r-- | lib/openpgp/gnutls_openpgp.c | 205 | ||||
-rw-r--r-- | lib/openpgp/gnutls_openpgp.h | 30 | ||||
-rw-r--r-- | lib/openpgp/openpgp_int.h | 20 | ||||
-rw-r--r-- | lib/openpgp/output.c | 290 | ||||
-rw-r--r-- | lib/openpgp/pgp.c | 398 | ||||
-rw-r--r-- | lib/openpgp/pgpverify.c | 16 | ||||
-rw-r--r-- | lib/openpgp/privkey.c | 231 |
9 files changed, 653 insertions, 649 deletions
diff --git a/lib/openpgp/compat.c b/lib/openpgp/compat.c index 50cbbd2e8d..75ef9450c4 100644 --- a/lib/openpgp/compat.c +++ b/lib/openpgp/compat.c @@ -47,8 +47,8 @@ -*/ int _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t cred, - const gnutls_datum_t * cert_list, - int cert_list_length, unsigned int *status) + const gnutls_datum_t * cert_list, + int cert_list_length, unsigned int *status) { int ret = 0; gnutls_openpgp_crt_t key = NULL; @@ -79,10 +79,10 @@ _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t cred, { ret = gnutls_openpgp_crt_verify_ring (key, cred->keyring, 0, &verify); if (ret < 0) - { - gnutls_assert (); - goto leave; - } + { + gnutls_assert (); + goto leave; + } } /* Now try the self signature. */ @@ -118,7 +118,7 @@ leave: -*/ int _gnutls_openpgp_fingerprint (const gnutls_datum_t * cert, - unsigned char *fpr, size_t * fprlen) + unsigned char *fpr, size_t * fprlen) { gnutls_openpgp_crt_t key; int ret; diff --git a/lib/openpgp/extras.c b/lib/openpgp/extras.c index 9e0aec9d32..8ae4bbe0a9 100644 --- a/lib/openpgp/extras.c +++ b/lib/openpgp/extras.c @@ -51,7 +51,7 @@ gnutls_openpgp_keyring_init (gnutls_openpgp_keyring_t * keyring) *keyring = gnutls_calloc (1, sizeof (gnutls_openpgp_keyring_int)); if (*keyring) - return 0; /* success */ + return 0; /* success */ return GNUTLS_E_MEMORY_ERROR; } @@ -90,8 +90,8 @@ gnutls_openpgp_keyring_deinit (gnutls_openpgp_keyring_t keyring) **/ int gnutls_openpgp_keyring_check_id (gnutls_openpgp_keyring_t ring, - const gnutls_openpgp_keyid_t keyid, - unsigned int flags) + const gnutls_openpgp_keyid_t keyid, + unsigned int flags) { cdk_pkt_pubkey_t pk; uint32_t id[2]; @@ -123,8 +123,8 @@ gnutls_openpgp_keyring_check_id (gnutls_openpgp_keyring_t ring, **/ int gnutls_openpgp_keyring_import (gnutls_openpgp_keyring_t keyring, - const gnutls_datum_t * data, - gnutls_openpgp_crt_fmt_t format) + const gnutls_datum_t * data, + gnutls_openpgp_crt_fmt_t format) { cdk_error_t err; cdk_stream_t input = NULL; @@ -138,7 +138,7 @@ gnutls_openpgp_keyring_import (gnutls_openpgp_keyring_t keyring, } _gnutls_debug_log ("PGP: keyring import format '%s'\n", - format == GNUTLS_OPENPGP_FMT_RAW ? "raw" : "base64"); + format == GNUTLS_OPENPGP_FMT_RAW ? "raw" : "base64"); /* Create a new stream from the given data, decode it, and import * the raw database. This to avoid using opencdk streams which are @@ -150,45 +150,45 @@ gnutls_openpgp_keyring_import (gnutls_openpgp_keyring_t keyring, err = cdk_stream_tmp_from_mem (data->data, data->size, &input); if (!err) - err = cdk_stream_set_armor_flag (input, 0); + err = cdk_stream_set_armor_flag (input, 0); if (err) - { - gnutls_assert (); - err = _gnutls_map_cdk_rc (err); - goto error; - } + { + gnutls_assert (); + err = _gnutls_map_cdk_rc (err); + goto error; + } raw_len = cdk_stream_get_length (input); if (raw_len == 0) - { - gnutls_assert (); - err = GNUTLS_E_BASE64_DECODING_ERROR; - goto error; - } + { + gnutls_assert (); + err = GNUTLS_E_BASE64_DECODING_ERROR; + goto error; + } raw_data = gnutls_malloc (raw_len); if (raw_data == NULL) - { - gnutls_assert (); - err = GNUTLS_E_MEMORY_ERROR; - goto error; - } + { + gnutls_assert (); + err = GNUTLS_E_MEMORY_ERROR; + goto error; + } do - { - err = - cdk_stream_read (input, raw_data + written, raw_len - written); + { + err = + cdk_stream_read (input, raw_data + written, raw_len - written); - if (err > 0) - written += err; - } + if (err > 0) + written += err; + } while (written < raw_len && err != EOF && err > 0); raw_len = written; } else - { /* RAW */ + { /* RAW */ raw_len = data->size; raw_data = data->data; } @@ -237,14 +237,14 @@ gnutls_openpgp_keyring_get_crt_count (gnutls_openpgp_keyring_t ring) { err = cdk_keydb_search (st, ring->db, &knode); if (err != CDK_Error_No_Key && err != CDK_Success) - { - gnutls_assert (); - cdk_keydb_search_release (st); - return _gnutls_map_cdk_rc (err); - } + { + gnutls_assert (); + cdk_keydb_search_release (st); + return _gnutls_map_cdk_rc (err); + } if (knode_is_pkey (knode)) - ret++; + ret++; cdk_kbnode_release (knode); @@ -270,7 +270,7 @@ gnutls_openpgp_keyring_get_crt_count (gnutls_openpgp_keyring_t ring) **/ int gnutls_openpgp_keyring_get_crt (gnutls_openpgp_keyring_t ring, - unsigned int idx, gnutls_openpgp_crt_t * cert) + unsigned int idx, gnutls_openpgp_crt_t * cert) { cdk_kbnode_t knode; cdk_error_t err; @@ -289,23 +289,23 @@ gnutls_openpgp_keyring_get_crt (gnutls_openpgp_keyring_t ring, { err = cdk_keydb_search (st, ring->db, &knode); if (err != CDK_EOF && err != CDK_Success) - { - gnutls_assert (); - cdk_keydb_search_release (st); - return _gnutls_map_cdk_rc (err); - } + { + gnutls_assert (); + cdk_keydb_search_release (st); + return _gnutls_map_cdk_rc (err); + } if (idx == count && err == CDK_Success) - { - ret = gnutls_openpgp_crt_init (cert); - if (ret == 0) - (*cert)->knode = knode; - cdk_keydb_search_release (st); - return ret; - } + { + ret = gnutls_openpgp_crt_init (cert); + if (ret == 0) + (*cert)->knode = knode; + cdk_keydb_search_release (st); + return ret; + } if (knode_is_pkey (knode)) - count++; + count++; cdk_kbnode_release (knode); diff --git a/lib/openpgp/gnutls_openpgp.c b/lib/openpgp/gnutls_openpgp.c index 0bf640d893..5d14668706 100644 --- a/lib/openpgp/gnutls_openpgp.c +++ b/lib/openpgp/gnutls_openpgp.c @@ -77,8 +77,8 @@ _gnutls_map_cdk_rc (int rc) -*/ int _gnutls_openpgp_raw_crt_to_gcert (gnutls_cert * gcert, - const gnutls_datum_t * raw, - const gnutls_openpgp_keyid_t keyid) + const gnutls_datum_t * raw, + const gnutls_openpgp_keyid_t keyid) { gnutls_openpgp_crt_t pcrt; int ret; @@ -102,11 +102,11 @@ _gnutls_openpgp_raw_crt_to_gcert (gnutls_cert * gcert, { ret = gnutls_openpgp_crt_set_preferred_key_id (pcrt, keyid); if (ret < 0) - { - gnutls_assert (); - gnutls_openpgp_crt_deinit (pcrt); - return ret; - } + { + gnutls_assert (); + gnutls_openpgp_crt_deinit (pcrt); + return ret; + } } ret = _gnutls_openpgp_crt_to_gcert (gcert, pcrt); @@ -133,8 +133,8 @@ _gnutls_openpgp_raw_crt_to_gcert (gnutls_cert * gcert, **/ int gnutls_certificate_set_openpgp_key (gnutls_certificate_credentials_t res, - gnutls_openpgp_crt_t crt, - gnutls_openpgp_privkey_t pkey) + gnutls_openpgp_crt_t crt, + gnutls_openpgp_privkey_t pkey) { int ret; gnutls_privkey_t privkey; @@ -150,7 +150,7 @@ gnutls_certificate_set_openpgp_key (gnutls_certificate_credentials_t res, ret = gnutls_privkey_import_openpgp (privkey, pkey, - GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE); + GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE); if (ret < 0) { gnutls_privkey_deinit (privkey); @@ -207,8 +207,8 @@ gnutls_certificate_set_openpgp_key (gnutls_certificate_credentials_t res, -*/ int gnutls_openpgp_get_key (gnutls_datum_t * key, - gnutls_openpgp_keyring_t keyring, key_attr_t by, - opaque * pattern) + gnutls_openpgp_keyring_t keyring, key_attr_t by, + opaque * pattern) { cdk_kbnode_t knode = NULL; unsigned long keyid[2]; @@ -284,12 +284,12 @@ leave: **/ int gnutls_certificate_set_openpgp_key_mem (gnutls_certificate_credentials_t res, - const gnutls_datum_t * cert, - const gnutls_datum_t * key, - gnutls_openpgp_crt_fmt_t format) + const gnutls_datum_t * cert, + const gnutls_datum_t * key, + gnutls_openpgp_crt_fmt_t format) { return gnutls_certificate_set_openpgp_key_mem2 (res, cert, key, - NULL, format); + NULL, format); } /** @@ -308,12 +308,12 @@ gnutls_certificate_set_openpgp_key_mem (gnutls_certificate_credentials_t res, **/ int gnutls_certificate_set_openpgp_key_file (gnutls_certificate_credentials_t res, - const char *certfile, - const char *keyfile, - gnutls_openpgp_crt_fmt_t format) + const char *certfile, + const char *keyfile, + gnutls_openpgp_crt_fmt_t format) { return gnutls_certificate_set_openpgp_key_file2 (res, certfile, - keyfile, NULL, format); + keyfile, NULL, format); } static int @@ -324,7 +324,7 @@ get_keyid (gnutls_openpgp_keyid_t keyid, const char *str) if (strlen (str) != 16) { _gnutls_debug_log - ("The OpenPGP subkey ID has to be 16 hexadecimal characters.\n"); + ("The OpenPGP subkey ID has to be 16 hexadecimal characters.\n"); return GNUTLS_E_INVALID_REQUEST; } @@ -360,10 +360,10 @@ get_keyid (gnutls_openpgp_keyid_t keyid, const char *str) **/ int gnutls_certificate_set_openpgp_key_mem2 (gnutls_certificate_credentials_t res, - const gnutls_datum_t * cert, - const gnutls_datum_t * key, - const char *subkey_id, - gnutls_openpgp_crt_fmt_t format) + const gnutls_datum_t * cert, + const gnutls_datum_t * key, + const char *subkey_id, + gnutls_openpgp_crt_fmt_t format) { gnutls_openpgp_privkey_t pkey; gnutls_openpgp_crt_t crt; @@ -405,27 +405,27 @@ gnutls_certificate_set_openpgp_key_mem2 (gnutls_certificate_credentials_t res, if (subkey_id != NULL) { if (strcasecmp (subkey_id, "auto") == 0) - ret = gnutls_openpgp_crt_get_auth_subkey (crt, keyid, 1); + ret = gnutls_openpgp_crt_get_auth_subkey (crt, keyid, 1); else - ret = get_keyid (keyid, subkey_id); + ret = get_keyid (keyid, subkey_id); if (ret < 0) - gnutls_assert (); + gnutls_assert (); if (ret >= 0) - { - ret = gnutls_openpgp_crt_set_preferred_key_id (crt, keyid); - if (ret >= 0) - ret = gnutls_openpgp_privkey_set_preferred_key_id (pkey, keyid); - } + { + ret = gnutls_openpgp_crt_set_preferred_key_id (crt, keyid); + if (ret >= 0) + ret = gnutls_openpgp_privkey_set_preferred_key_id (pkey, keyid); + } if (ret < 0) - { - gnutls_assert (); - gnutls_openpgp_privkey_deinit (pkey); - gnutls_openpgp_crt_deinit (crt); - return ret; - } + { + gnutls_assert (); + gnutls_openpgp_privkey_deinit (pkey); + gnutls_openpgp_crt_deinit (crt); + return ret; + } } ret = gnutls_certificate_set_openpgp_key (res, crt, pkey); @@ -457,10 +457,10 @@ gnutls_certificate_set_openpgp_key_mem2 (gnutls_certificate_credentials_t res, **/ int gnutls_certificate_set_openpgp_key_file2 (gnutls_certificate_credentials_t - res, const char *certfile, - const char *keyfile, - const char *subkey_id, - gnutls_openpgp_crt_fmt_t format) + res, const char *certfile, + const char *keyfile, + const char *subkey_id, + gnutls_openpgp_crt_fmt_t format) { struct stat statbuf; gnutls_datum_t key, cert; @@ -498,7 +498,7 @@ gnutls_certificate_set_openpgp_key_file2 (gnutls_certificate_credentials_t rc = gnutls_certificate_set_openpgp_key_mem2 (res, &cert, &key, subkey_id, - format); + format); free (cert.data); free (key.data); @@ -537,10 +537,10 @@ gnutls_openpgp_count_key_names (const gnutls_datum_t * cert) { p = cdk_kbnode_walk (knode, &ctx, 0); if (!p) - break; + break; pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype == CDK_PKT_USER_ID) - nuids++; + nuids++; } cdk_kbnode_release (knode); @@ -563,8 +563,8 @@ gnutls_openpgp_count_key_names (const gnutls_datum_t * cert) **/ int gnutls_certificate_set_openpgp_keyring_file (gnutls_certificate_credentials_t - c, const char *file, - gnutls_openpgp_crt_fmt_t format) + c, const char *file, + gnutls_openpgp_crt_fmt_t format) { gnutls_datum_t ring; size_t size; @@ -586,7 +586,7 @@ gnutls_certificate_set_openpgp_keyring_file (gnutls_certificate_credentials_t rc = gnutls_certificate_set_openpgp_keyring_mem (c, ring.data, ring.size, - format); + format); free (ring.data); @@ -610,9 +610,9 @@ gnutls_certificate_set_openpgp_keyring_file (gnutls_certificate_credentials_t **/ int gnutls_certificate_set_openpgp_keyring_mem (gnutls_certificate_credentials_t - c, const opaque * data, - size_t dlen, - gnutls_openpgp_crt_fmt_t format) + c, const opaque * data, + size_t dlen, + gnutls_openpgp_crt_fmt_t format) { gnutls_datum_t ddata; int rc; @@ -657,8 +657,8 @@ gnutls_certificate_set_openpgp_keyring_mem (gnutls_certificate_credentials_t -*/ int _gnutls_openpgp_request_key (gnutls_session_t session, gnutls_datum_t * ret, - const gnutls_certificate_credentials_t cred, - opaque * key_fpr, int key_fpr_size) + const gnutls_certificate_credentials_t cred, + opaque * key_fpr, int key_fpr_size) { int rc = 0; @@ -669,11 +669,11 @@ _gnutls_openpgp_request_key (gnutls_session_t session, gnutls_datum_t * ret, } if (key_fpr_size != 16 && key_fpr_size != 20) - return GNUTLS_E_HASH_FAILED; /* only MD5 and SHA1 are supported */ + return GNUTLS_E_HASH_FAILED; /* only MD5 and SHA1 are supported */ rc = gnutls_openpgp_get_key (ret, cred->keyring, KEY_ATTR_FPR, key_fpr); - if (rc >= 0) /* key was found */ + if (rc >= 0) /* key was found */ { rc = 0; goto error; @@ -685,14 +685,14 @@ _gnutls_openpgp_request_key (gnutls_session_t session, gnutls_datum_t * ret, if (session->internals.openpgp_recv_key_func != NULL) { rc = session->internals.openpgp_recv_key_func (session, - key_fpr, - key_fpr_size, ret); + key_fpr, + key_fpr_size, ret); if (rc < 0) - { - gnutls_assert (); - rc = GNUTLS_E_OPENPGP_GETKEY_FAILED; - goto error; - } + { + gnutls_assert (); + rc = GNUTLS_E_OPENPGP_GETKEY_FAILED; + goto error; + } } error: @@ -712,7 +712,7 @@ error: **/ void gnutls_openpgp_set_recv_key_function (gnutls_session_t session, - gnutls_openpgp_recv_key_func func) + gnutls_openpgp_recv_key_func func) { session->internals.openpgp_recv_key_func = func; } @@ -729,7 +729,7 @@ _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, gnutls_openpgp_crt_t cert) memset (gcert, 0, sizeof (gnutls_cert)); gcert->cert_type = GNUTLS_CRT_OPENPGP; - gcert->sign_algo = GNUTLS_SIGN_UNKNOWN; /* N/A here */ + gcert->sign_algo = GNUTLS_SIGN_UNKNOWN; /* N/A here */ gcert->version = gnutls_openpgp_crt_get_version (cert); gcert->params_size = MAX_PUBLIC_PARAMS_SIZE; @@ -742,21 +742,21 @@ _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, gnutls_openpgp_crt_t cert) uint32_t kid32[2]; _gnutls_debug_log - ("Importing Openpgp cert and using openpgp sub key: %s\n", - _gnutls_bin2hex (keyid, sizeof (keyid), err_buf, sizeof (err_buf), - NULL)); + ("Importing Openpgp cert and using openpgp sub key: %s\n", + _gnutls_bin2hex (keyid, sizeof (keyid), err_buf, sizeof (err_buf), + NULL)); KEYID_IMPORT (kid32, keyid); idx = gnutls_openpgp_crt_get_subkey_idx (cert, keyid); if (idx < 0) - { - gnutls_assert (); - return idx; - } + { + gnutls_assert (); + return idx; + } gcert->subject_pk_algorithm = - gnutls_openpgp_crt_get_subkey_pk_algorithm (cert, idx, NULL); + gnutls_openpgp_crt_get_subkey_pk_algorithm (cert, idx, NULL); gnutls_openpgp_crt_get_subkey_usage (cert, idx, &gcert->key_usage); gcert->use_subkey = 1; @@ -764,20 +764,20 @@ _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, gnutls_openpgp_crt_t cert) memcpy (gcert->subkey_id, keyid, sizeof (keyid)); ret = - _gnutls_openpgp_crt_get_mpis (cert, kid32, gcert->params, - &gcert->params_size); + _gnutls_openpgp_crt_get_mpis (cert, kid32, gcert->params, + &gcert->params_size); } else { _gnutls_debug_log - ("Importing Openpgp cert and using main openpgp key\n"); + ("Importing Openpgp cert and using main openpgp key\n"); gcert->subject_pk_algorithm = - gnutls_openpgp_crt_get_pk_algorithm (cert, NULL); + gnutls_openpgp_crt_get_pk_algorithm (cert, NULL); gnutls_openpgp_crt_get_key_usage (cert, &gcert->key_usage); ret = - _gnutls_openpgp_crt_get_mpis (cert, NULL, gcert->params, - &gcert->params_size); + _gnutls_openpgp_crt_get_mpis (cert, NULL, gcert->params, + &gcert->params_size); gcert->use_subkey = 0; } @@ -787,7 +787,7 @@ _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, gnutls_openpgp_crt_t cert) return ret; } - { /* copy the raw certificate */ + { /* copy the raw certificate */ #define SMALL_RAW 512 opaque *raw; size_t raw_size = SMALL_RAW; @@ -798,38 +798,38 @@ _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, gnutls_openpgp_crt_t cert) raw = gnutls_malloc (raw_size); if (raw == NULL) { - gnutls_assert (); - return GNUTLS_E_MEMORY_ERROR; + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; } ret = gnutls_openpgp_crt_export (cert, GNUTLS_OPENPGP_FMT_RAW, raw, - &raw_size); + &raw_size); if (ret < 0 && ret != GNUTLS_E_SHORT_MEMORY_BUFFER) { - gnutls_assert (); - gnutls_free (raw); - return ret; + gnutls_assert (); + gnutls_free (raw); + return ret; } if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) { - raw = gnutls_realloc (raw, raw_size); - if (raw == NULL) - { - gnutls_assert (); - return GNUTLS_E_MEMORY_ERROR; - } - - ret = - gnutls_openpgp_crt_export (cert, GNUTLS_OPENPGP_FMT_RAW, raw, - &raw_size); - if (ret < 0) - { - gnutls_assert (); - gnutls_free (raw); - return ret; - } + raw = gnutls_realloc (raw, raw_size); + if (raw == NULL) + { + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; + } + + ret = + gnutls_openpgp_crt_export (cert, GNUTLS_OPENPGP_FMT_RAW, raw, + &raw_size); + if (ret < 0) + { + gnutls_assert (); + gnutls_free (raw); + return ret; + } } gcert->raw.data = raw; @@ -839,4 +839,3 @@ _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, gnutls_openpgp_crt_t cert) return 0; } - diff --git a/lib/openpgp/gnutls_openpgp.h b/lib/openpgp/gnutls_openpgp.h index c89b867f1c..f30b563f53 100644 --- a/lib/openpgp/gnutls_openpgp.h +++ b/lib/openpgp/gnutls_openpgp.h @@ -21,38 +21,38 @@ typedef enum int gnutls_openpgp_count_key_names (const gnutls_datum_t * cert); int gnutls_openpgp_get_key (gnutls_datum_t * key, - gnutls_openpgp_keyring_t keyring, - key_attr_t by, opaque * pattern); + gnutls_openpgp_keyring_t keyring, + key_attr_t by, opaque * pattern); /* internal */ int _gnutls_openpgp_raw_crt_to_gcert (gnutls_cert * cert, - const gnutls_datum_t * raw, - const gnutls_openpgp_keyid_t); + const gnutls_datum_t * raw, + const gnutls_openpgp_keyid_t); int _gnutls_openpgp_raw_privkey_to_gkey (gnutls_privkey_t * pkey, - const gnutls_datum_t * raw_key); + const gnutls_datum_t * raw_key); int _gnutls_openpgp_request_key (gnutls_session_t, - gnutls_datum_t * ret, - const gnutls_certificate_credentials_t cred, - opaque * key_fpr, int key_fpr_size); + gnutls_datum_t * ret, + const gnutls_certificate_credentials_t cred, + opaque * key_fpr, int key_fpr_size); int _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t, - const gnutls_datum_t * cert_list, - int cert_list_length, unsigned int *status); + const gnutls_datum_t * cert_list, + int cert_list_length, unsigned int *status); int _gnutls_openpgp_fingerprint (const gnutls_datum_t * cert, - unsigned char *fpr, size_t * fprlen); + unsigned char *fpr, size_t * fprlen); time_t _gnutls_openpgp_get_raw_key_creation_time (const gnutls_datum_t * - cert); + cert); time_t _gnutls_openpgp_get_raw_key_expiration_time (const gnutls_datum_t * - cert); + cert); int _gnutls_openpgp_privkey_sign_hash (gnutls_openpgp_privkey_t key, - const gnutls_datum_t * hash, - gnutls_datum_t * signature); + const gnutls_datum_t * hash, + gnutls_datum_t * signature); #endif /*GNUTLS_OPENPGP_LOCAL_H */ diff --git a/lib/openpgp/openpgp_int.h b/lib/openpgp/openpgp_int.h index 235bcfd482..bf0a970352 100644 --- a/lib/openpgp/openpgp_int.h +++ b/lib/openpgp/openpgp_int.h @@ -39,12 +39,12 @@ typedef struct gnutls_openpgp_keyring_int int _gnutls_map_cdk_rc (int rc); int _gnutls_openpgp_export (cdk_kbnode_t node, - gnutls_openpgp_crt_fmt_t format, - void *output_data, size_t * output_data_size, - int private); + gnutls_openpgp_crt_fmt_t format, + void *output_data, size_t * output_data_size, + int private); int _gnutls_openpgp_crt_to_gcert (gnutls_cert * gcert, - gnutls_openpgp_crt_t cert); + gnutls_openpgp_crt_t cert); cdk_packet_t _gnutls_get_valid_subkey (cdk_kbnode_t knode, int key_type); @@ -52,21 +52,21 @@ unsigned int _gnutls_get_pgp_key_usage (unsigned int pgp_usage); int _gnutls_openpgp_crt_get_mpis (gnutls_openpgp_crt_t cert, uint32_t keyid[2], - bigint_t * params, int *params_size); + bigint_t * params, int *params_size); int _gnutls_openpgp_privkey_get_mpis (gnutls_openpgp_privkey_t pkey, - uint32_t keyid[2], bigint_t * params, - int *params_size); + uint32_t keyid[2], bigint_t * params, + int *params_size); cdk_packet_t _gnutls_openpgp_find_key (cdk_kbnode_t knode, uint32_t keyid[2], - unsigned int priv); + unsigned int priv); int _gnutls_read_pgp_mpi (cdk_packet_t pkt, unsigned int priv, size_t idx, - bigint_t * m); + bigint_t * m); int _gnutls_openpgp_find_subkey_idx (cdk_kbnode_t knode, uint32_t keyid[2], - unsigned int priv); + unsigned int priv); int _gnutls_openpgp_get_algo (int cdk_algo); diff --git a/lib/openpgp/output.c b/lib/openpgp/output.c index eaa1902d68..b832253fb7 100644 --- a/lib/openpgp/output.c +++ b/lib/openpgp/output.c @@ -38,7 +38,7 @@ static void hexdump (gnutls_buffer_st * str, const char *data, size_t len, - const char *spc) + const char *spc) { size_t j; @@ -47,15 +47,15 @@ hexdump (gnutls_buffer_st * str, const char *data, size_t len, for (j = 0; j < len; j++) { if (((j + 1) % 16) == 0) - { - addf (str, "%.2x\n", (unsigned char) data[j]); - if (spc && j != (len - 1)) - adds (str, spc); - } + { + addf (str, "%.2x\n", (unsigned char) data[j]); + if (spc && j != (len - 1)) + adds (str, spc); + } else if (j == (len - 1)) - addf (str, "%.2x", (unsigned char) data[j]); + addf (str, "%.2x", (unsigned char) data[j]); else - addf (str, "%.2x:", (unsigned char) data[j]); + addf (str, "%.2x:", (unsigned char) data[j]); } if ((j % 16) != 0) adds (str, "\n"); @@ -71,13 +71,13 @@ hexprint (gnutls_buffer_st * str, const char *data, size_t len) else { for (j = 0; j < len; j++) - addf (str, "%.2x", (unsigned char) data[j]); + addf (str, "%.2x", (unsigned char) data[j]); } } static void print_key_usage (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, - unsigned int idx) + unsigned int idx) { unsigned int key_usage; int err; @@ -204,16 +204,16 @@ print_key_times (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, int idx) if (tim == 0) { - adds (str, _("\t\tExpiration: Never\n")); + adds (str, _("\t\tExpiration: Never\n")); } else { - if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); - else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%ld)\n", (unsigned long) tim); - else - addf (str, _("\t\tExpiration: %s\n"), s); + if (gmtime_r (&tim, &t) == NULL) + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); + else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); + else + addf (str, _("\t\tExpiration: %s\n"), s); } } } @@ -235,77 +235,77 @@ print_key_info (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, int idx) { const char *name = gnutls_pk_algorithm_get_name (err); if (name == NULL) - name = _("unknown"); + name = _("unknown"); addf (str, _("\tPublic Key Algorithm: %s\n"), name); addf (str, _("\tKey Security Level: %s\n"), - gnutls_sec_param_get_name (gnutls_pk_bits_to_sec_param - (err, bits))); + gnutls_sec_param_get_name (gnutls_pk_bits_to_sec_param + (err, bits))); switch (err) - { - case GNUTLS_PK_RSA: - { - gnutls_datum_t m, e; - - if (idx == -1) - err = gnutls_openpgp_crt_get_pk_rsa_raw (cert, &m, &e); - else - err = - gnutls_openpgp_crt_get_subkey_pk_rsa_raw (cert, idx, &m, &e); - - if (err < 0) - addf (str, "error: get_pk_rsa_raw: %s\n", - gnutls_strerror (err)); - else - { - addf (str, _("\t\tModulus (bits %d):\n"), bits); - hexdump (str, m.data, m.size, "\t\t\t"); - adds (str, _("\t\tExponent:\n")); - hexdump (str, e.data, e.size, "\t\t\t"); - - gnutls_free (m.data); - gnutls_free (e.data); - } - - } - break; - - case GNUTLS_PK_DSA: - { - gnutls_datum_t p, q, g, y; - - if (idx == -1) - err = gnutls_openpgp_crt_get_pk_dsa_raw (cert, &p, &q, &g, &y); - else - err = - gnutls_openpgp_crt_get_subkey_pk_dsa_raw (cert, idx, &p, &q, - &g, &y); - if (err < 0) - addf (str, "error: get_pk_dsa_raw: %s\n", - gnutls_strerror (err)); - else - { - addf (str, _("\t\tPublic key (bits %d):\n"), bits); - hexdump (str, y.data, y.size, "\t\t\t"); - adds (str, _("\t\tP:\n")); - hexdump (str, p.data, p.size, "\t\t\t"); - adds (str, _("\t\tQ:\n")); - hexdump (str, q.data, q.size, "\t\t\t"); - adds (str, _("\t\tG:\n")); - hexdump (str, g.data, g.size, "\t\t\t"); - - gnutls_free (p.data); - gnutls_free (q.data); - gnutls_free (g.data); - gnutls_free (y.data); - } - } - break; - - default: - break; - } + { + case GNUTLS_PK_RSA: + { + gnutls_datum_t m, e; + + if (idx == -1) + err = gnutls_openpgp_crt_get_pk_rsa_raw (cert, &m, &e); + else + err = + gnutls_openpgp_crt_get_subkey_pk_rsa_raw (cert, idx, &m, &e); + + if (err < 0) + addf (str, "error: get_pk_rsa_raw: %s\n", + gnutls_strerror (err)); + else + { + addf (str, _("\t\tModulus (bits %d):\n"), bits); + hexdump (str, m.data, m.size, "\t\t\t"); + adds (str, _("\t\tExponent:\n")); + hexdump (str, e.data, e.size, "\t\t\t"); + + gnutls_free (m.data); + gnutls_free (e.data); + } + + } + break; + + case GNUTLS_PK_DSA: + { + gnutls_datum_t p, q, g, y; + + if (idx == -1) + err = gnutls_openpgp_crt_get_pk_dsa_raw (cert, &p, &q, &g, &y); + else + err = + gnutls_openpgp_crt_get_subkey_pk_dsa_raw (cert, idx, &p, &q, + &g, &y); + if (err < 0) + addf (str, "error: get_pk_dsa_raw: %s\n", + gnutls_strerror (err)); + else + { + addf (str, _("\t\tPublic key (bits %d):\n"), bits); + hexdump (str, y.data, y.size, "\t\t\t"); + adds (str, _("\t\tP:\n")); + hexdump (str, p.data, p.size, "\t\t\t"); + adds (str, _("\t\tQ:\n")); + hexdump (str, q.data, q.size, "\t\t\t"); + adds (str, _("\t\tG:\n")); + hexdump (str, g.data, g.size, "\t\t\t"); + + gnutls_free (p.data); + gnutls_free (q.data); + gnutls_free (g.data); + gnutls_free (y.data); + } + } + break; + + default: + break; + } } } @@ -340,29 +340,29 @@ print_cert (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert) err = gnutls_openpgp_crt_get_name (cert, i, NULL, &dn_size); if (err != GNUTLS_E_SHORT_MEMORY_BUFFER - && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE - && err != GNUTLS_E_OPENPGP_UID_REVOKED) - addf (str, "error: get_name: %s\n", gnutls_strerror (err)); + && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE + && err != GNUTLS_E_OPENPGP_UID_REVOKED) + addf (str, "error: get_name: %s\n", gnutls_strerror (err)); else - { - dn = gnutls_malloc (dn_size); - if (!dn) - addf (str, "error: malloc (%d): %s\n", (int) dn_size, - gnutls_strerror (GNUTLS_E_MEMORY_ERROR)); - else - { - err = gnutls_openpgp_crt_get_name (cert, i, dn, &dn_size); - if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE && - err != GNUTLS_E_OPENPGP_UID_REVOKED) - addf (str, "error: get_name: %s\n", gnutls_strerror (err)); - else if (err >= 0) - addf (str, _("\tName[%d]: %s\n"), i, dn); - else if (err == GNUTLS_E_OPENPGP_UID_REVOKED) - addf (str, _("\tRevoked Name[%d]: %s\n"), i, dn); - - gnutls_free (dn); - } - } + { + dn = gnutls_malloc (dn_size); + if (!dn) + addf (str, "error: malloc (%d): %s\n", (int) dn_size, + gnutls_strerror (GNUTLS_E_MEMORY_ERROR)); + else + { + err = gnutls_openpgp_crt_get_name (cert, i, dn, &dn_size); + if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE && + err != GNUTLS_E_OPENPGP_UID_REVOKED) + addf (str, "error: get_name: %s\n", gnutls_strerror (err)); + else if (err >= 0) + addf (str, _("\tName[%d]: %s\n"), i, dn); + else if (err == GNUTLS_E_OPENPGP_UID_REVOKED) + addf (str, _("\tRevoked Name[%d]: %s\n"), i, dn); + + gnutls_free (dn); + } + } i++; } @@ -403,29 +403,29 @@ print_oneline (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert) err = gnutls_openpgp_crt_get_name (cert, i, NULL, &dn_size); if (err != GNUTLS_E_SHORT_MEMORY_BUFFER - && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE - && err != GNUTLS_E_OPENPGP_UID_REVOKED) - addf (str, "unknown name (%s), ", gnutls_strerror (err)); + && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE + && err != GNUTLS_E_OPENPGP_UID_REVOKED) + addf (str, "unknown name (%s), ", gnutls_strerror (err)); else - { - dn = gnutls_malloc (dn_size); - if (!dn) - addf (str, "unknown name (%s), ", - gnutls_strerror (GNUTLS_E_MEMORY_ERROR)); - else - { - err = gnutls_openpgp_crt_get_name (cert, i, dn, &dn_size); - if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE && - err != GNUTLS_E_OPENPGP_UID_REVOKED) - addf (str, "unknown name (%s), ", gnutls_strerror (err)); - else if (err >= 0) - addf (str, _("name[%d]: %s, "), i, dn); - else if (err == GNUTLS_E_OPENPGP_UID_REVOKED) - addf (str, _("revoked name[%d]: %s, "), i, dn); - - gnutls_free (dn); - } - } + { + dn = gnutls_malloc (dn_size); + if (!dn) + addf (str, "unknown name (%s), ", + gnutls_strerror (GNUTLS_E_MEMORY_ERROR)); + else + { + err = gnutls_openpgp_crt_get_name (cert, i, dn, &dn_size); + if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE && + err != GNUTLS_E_OPENPGP_UID_REVOKED) + addf (str, "unknown name (%s), ", gnutls_strerror (err)); + else if (err >= 0) + addf (str, _("name[%d]: %s, "), i, dn); + else if (err == GNUTLS_E_OPENPGP_UID_REVOKED) + addf (str, _("revoked name[%d]: %s, "), i, dn); + + gnutls_free (dn); + } + } i++; } @@ -441,9 +441,9 @@ print_oneline (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert) addf (str, "error: get_fingerprint: %s\n", gnutls_strerror (err)); else { - adds (str, _("fingerprint: ")); - hexprint (str, fpr, fpr_size); - addf (str, ", "); + adds (str, _("fingerprint: ")); + hexprint (str, fpr, fpr_size); + addf (str, ", "); } } @@ -457,11 +457,11 @@ print_oneline (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert) struct tm t; if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%ld), ", (unsigned long) tim); + addf (str, "error: gmtime_r (%ld), ", (unsigned long) tim); else if (strftime (s, max, "%Y-%m-%d %H:%M:%S UTC", &t) == 0) - addf (str, "error: strftime (%ld), ", (unsigned long) tim); + addf (str, "error: strftime (%ld), ", (unsigned long) tim); else - addf (str, _("created: %s, "), s); + addf (str, _("created: %s, "), s); } tim = gnutls_openpgp_crt_get_expiration_time (cert); @@ -471,16 +471,16 @@ print_oneline (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert) struct tm t; if (tim == 0) - adds (str, _("never expires, ")); + adds (str, _("never expires, ")); else - { - if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%ld), ", (unsigned long) tim); - else if (strftime (s, max, "%Y-%m-%d %H:%M:%S UTC", &t) == 0) - addf (str, "error: strftime (%ld), ", (unsigned long) tim); - else - addf (str, _("expires: %s, "), s); - } + { + if (gmtime_r (&tim, &t) == NULL) + addf (str, "error: gmtime_r (%ld), ", (unsigned long) tim); + else if (strftime (s, max, "%Y-%m-%d %H:%M:%S UTC", &t) == 0) + addf (str, "error: strftime (%ld), ", (unsigned long) tim); + else + addf (str, _("expires: %s, "), s); + } } } @@ -514,8 +514,8 @@ print_oneline (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert) **/ int gnutls_openpgp_crt_print (gnutls_openpgp_crt_t cert, - gnutls_certificate_print_formats_t format, - gnutls_datum_t * out) + gnutls_certificate_print_formats_t format, + gnutls_datum_t * out) { gnutls_buffer_st str; @@ -526,7 +526,7 @@ gnutls_openpgp_crt_print (gnutls_openpgp_crt_t cert, else { _gnutls_buffer_append_str (&str, - _("OpenPGP Certificate Information:\n")); + _("OpenPGP Certificate Information:\n")); print_cert (&str, cert); } diff --git a/lib/openpgp/pgp.c b/lib/openpgp/pgp.c index fb6953b000..4dc8af4cf3 100644 --- a/lib/openpgp/pgp.c +++ b/lib/openpgp/pgp.c @@ -49,7 +49,7 @@ gnutls_openpgp_crt_init (gnutls_openpgp_crt_t * key) *key = gnutls_calloc (1, sizeof (gnutls_openpgp_crt_int)); if (*key) - return 0; /* success */ + return 0; /* success */ return GNUTLS_E_MEMORY_ERROR; } @@ -88,8 +88,8 @@ gnutls_openpgp_crt_deinit (gnutls_openpgp_crt_t key) **/ int gnutls_openpgp_crt_import (gnutls_openpgp_crt_t key, - const gnutls_datum_t * data, - gnutls_openpgp_crt_fmt_t format) + const gnutls_datum_t * data, + gnutls_openpgp_crt_fmt_t format) { cdk_stream_t inp; cdk_packet_t pkt; @@ -105,35 +105,35 @@ gnutls_openpgp_crt_import (gnutls_openpgp_crt_t key, { rc = cdk_kbnode_read_from_mem (&key->knode, data->data, data->size); if (rc) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + { + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; + } } else { rc = cdk_stream_tmp_from_mem (data->data, data->size, &inp); if (rc) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + { + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; + } if (cdk_armor_filter_use (inp)) - rc = cdk_stream_set_armor_flag (inp, 0); + rc = cdk_stream_set_armor_flag (inp, 0); if (!rc) - rc = cdk_keydb_get_keyblock (inp, &key->knode); + rc = cdk_keydb_get_keyblock (inp, &key->knode); cdk_stream_close (inp); if (rc) - { - if (rc == CDK_Inv_Packet) - rc = GNUTLS_E_OPENPGP_GETKEY_FAILED; - else - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + { + if (rc == CDK_Inv_Packet) + rc = GNUTLS_E_OPENPGP_GETKEY_FAILED; + else + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; + } } /* Test if the import was successful. */ @@ -151,9 +151,9 @@ gnutls_openpgp_crt_import (gnutls_openpgp_crt_t key, */ int _gnutls_openpgp_export (cdk_kbnode_t node, - gnutls_openpgp_crt_fmt_t format, - void *output_data, - size_t * output_data_size, int private) + gnutls_openpgp_crt_fmt_t format, + void *output_data, + size_t * output_data_size, int private) { size_t input_data_size = *output_data_size; size_t calc_size; @@ -183,30 +183,30 @@ _gnutls_openpgp_export (cdk_kbnode_t node, /* Calculate the size of the encoded data and check if the provided buffer is large enough. */ rc = cdk_armor_encode_buffer (in, *output_data_size, - NULL, 0, &calc_size, - private ? CDK_ARMOR_SECKEY : - CDK_ARMOR_PUBKEY); + NULL, 0, &calc_size, + private ? CDK_ARMOR_SECKEY : + CDK_ARMOR_PUBKEY); if (rc || calc_size > input_data_size) - { - gnutls_free (in); - *output_data_size = calc_size; - gnutls_assert (); - return GNUTLS_E_SHORT_MEMORY_BUFFER; - } + { + gnutls_free (in); + *output_data_size = calc_size; + gnutls_assert (); + return GNUTLS_E_SHORT_MEMORY_BUFFER; + } rc = cdk_armor_encode_buffer (in, *output_data_size, - output_data, input_data_size, &calc_size, - private ? CDK_ARMOR_SECKEY : - CDK_ARMOR_PUBKEY); + output_data, input_data_size, &calc_size, + private ? CDK_ARMOR_SECKEY : + CDK_ARMOR_PUBKEY); gnutls_free (in); *output_data_size = calc_size; if (rc) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + { + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; + } } return 0; @@ -229,11 +229,11 @@ _gnutls_openpgp_export (cdk_kbnode_t node, **/ int gnutls_openpgp_crt_export (gnutls_openpgp_crt_t key, - gnutls_openpgp_crt_fmt_t format, - void *output_data, size_t * output_data_size) + gnutls_openpgp_crt_fmt_t format, + void *output_data, size_t * output_data_size) { return _gnutls_openpgp_export (key->knode, format, output_data, - output_data_size, 0); + output_data_size, 0); } /** @@ -249,7 +249,7 @@ gnutls_openpgp_crt_export (gnutls_openpgp_crt_t key, **/ int gnutls_openpgp_crt_get_fingerprint (gnutls_openpgp_crt_t key, - void *fpr, size_t * fprlen) + void *fpr, size_t * fprlen) { cdk_packet_t pkt; cdk_pkt_pubkey_t pk = NULL; @@ -296,7 +296,7 @@ _gnutls_openpgp_count_key_names (gnutls_openpgp_crt_t key) { pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype == CDK_PKT_USER_ID) - nuids++; + nuids++; } return nuids; @@ -320,7 +320,7 @@ _gnutls_openpgp_count_key_names (gnutls_openpgp_crt_t key) **/ int gnutls_openpgp_crt_get_name (gnutls_openpgp_crt_t key, - int idx, char *buf, size_t * sizeof_buf) + int idx, char *buf, size_t * sizeof_buf) { cdk_kbnode_t ctx = NULL, p; cdk_packet_t pkt = NULL; @@ -341,11 +341,11 @@ gnutls_openpgp_crt_get_name (gnutls_openpgp_crt_t key, { pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype == CDK_PKT_USER_ID) - { - if (pos == idx) - break; - pos++; - } + { + if (pos == idx) + break; + pos++; + } } if (!pkt) @@ -365,7 +365,7 @@ gnutls_openpgp_crt_get_name (gnutls_openpgp_crt_t key, if (buf) { memcpy (buf, uid->name, uid->len); - buf[uid->len] = '\0'; /* make sure it's a string */ + buf[uid->len] = '\0'; /* make sure it's a string */ } *sizeof_buf = uid->len + 1; @@ -392,7 +392,7 @@ gnutls_openpgp_crt_get_name (gnutls_openpgp_crt_t key, **/ gnutls_pk_algorithm_t gnutls_openpgp_crt_get_pk_algorithm (gnutls_openpgp_crt_t key, - unsigned int *bits) + unsigned int *bits) { cdk_packet_t pkt; int algo; @@ -408,7 +408,7 @@ gnutls_openpgp_crt_get_pk_algorithm (gnutls_openpgp_crt_t key, if (pkt) { if (bits) - *bits = cdk_pk_get_nbits (pkt->pkt.public_key); + *bits = cdk_pk_get_nbits (pkt->pkt.public_key); algo = _gnutls_openpgp_get_algo (pkt->pkt.public_key->pubkey_algo); } @@ -510,7 +510,7 @@ gnutls_openpgp_crt_get_expiration_time (gnutls_openpgp_crt_t key) **/ int gnutls_openpgp_crt_get_key_id (gnutls_openpgp_crt_t key, - gnutls_openpgp_keyid_t keyid) + gnutls_openpgp_keyid_t keyid) { cdk_packet_t pkt; uint32_t kid[2]; @@ -576,7 +576,7 @@ gnutls_openpgp_crt_get_revoked_status (gnutls_openpgp_crt_t key) **/ int gnutls_openpgp_crt_check_hostname (gnutls_openpgp_crt_t key, - const char *hostname) + const char *hostname) { char dnsname[MAX_CN]; size_t dnsnamesize; @@ -590,14 +590,14 @@ gnutls_openpgp_crt_check_hostname (gnutls_openpgp_crt_t key, ret = gnutls_openpgp_crt_get_name (key, i, dnsname, &dnsnamesize); if (ret == 0) - { - /* Length returned by gnutls_openpgp_crt_get_name includes - the terminating zero. */ - dnsnamesize--; + { + /* Length returned by gnutls_openpgp_crt_get_name includes + the terminating zero. */ + dnsnamesize--; - if (_gnutls_hostname_compare (dnsname, dnsnamesize, hostname)) - return 1; - } + if (_gnutls_hostname_compare (dnsname, dnsnamesize, hostname)) + return 1; + } } /* not found a matching name */ @@ -636,7 +636,7 @@ _gnutls_get_pgp_key_usage (unsigned int cdk_usage) */ int gnutls_openpgp_crt_get_key_usage (gnutls_openpgp_crt_t key, - unsigned int *key_usage) + unsigned int *key_usage) { cdk_packet_t pkt; @@ -685,7 +685,7 @@ gnutls_openpgp_crt_get_subkey_count (gnutls_openpgp_crt_t key) { pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) - subkeys++; + subkeys++; } return subkeys; @@ -711,7 +711,7 @@ _get_public_subkey (gnutls_openpgp_crt_t key, unsigned int indx) { pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY && indx == subkeys++) - return pkt; + return pkt; } return NULL; @@ -724,7 +724,7 @@ _get_public_subkey (gnutls_openpgp_crt_t key, unsigned int indx) */ cdk_packet_t _gnutls_openpgp_find_key (cdk_kbnode_t knode, uint32_t keyid[2], - unsigned int priv) + unsigned int priv) { cdk_kbnode_t p, ctx; cdk_packet_t pkt; @@ -736,24 +736,24 @@ _gnutls_openpgp_find_key (cdk_kbnode_t knode, uint32_t keyid[2], pkt = cdk_kbnode_get_packet (p); if ((priv == 0 - && (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY - || pkt->pkttype == CDK_PKT_PUBLIC_KEY)) || (priv != 0 - && (pkt->pkttype == - CDK_PKT_SECRET_SUBKEY - || pkt->pkttype - == - CDK_PKT_SECRET_KEY))) - { - if (priv == 0) - cdk_pk_get_keyid (pkt->pkt.public_key, local_keyid); - else - cdk_pk_get_keyid (pkt->pkt.secret_key->pk, local_keyid); - - if (local_keyid[0] == keyid[0] && local_keyid[1] == keyid[1]) - { - return pkt; - } - } + && (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY + || pkt->pkttype == CDK_PKT_PUBLIC_KEY)) || (priv != 0 + && (pkt->pkttype == + CDK_PKT_SECRET_SUBKEY + || pkt->pkttype + == + CDK_PKT_SECRET_KEY))) + { + if (priv == 0) + cdk_pk_get_keyid (pkt->pkt.public_key, local_keyid); + else + cdk_pk_get_keyid (pkt->pkt.secret_key->pk, local_keyid); + + if (local_keyid[0] == keyid[0] && local_keyid[1] == keyid[1]) + { + return pkt; + } + } } gnutls_assert (); @@ -767,7 +767,7 @@ _gnutls_openpgp_find_key (cdk_kbnode_t knode, uint32_t keyid[2], */ int _gnutls_openpgp_find_subkey_idx (cdk_kbnode_t knode, uint32_t keyid[2], - unsigned int priv) + unsigned int priv) { cdk_kbnode_t p, ctx; cdk_packet_t pkt; @@ -782,21 +782,21 @@ _gnutls_openpgp_find_subkey_idx (cdk_kbnode_t knode, uint32_t keyid[2], pkt = cdk_kbnode_get_packet (p); if ((priv == 0 && (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY)) || - (priv != 0 && (pkt->pkttype == CDK_PKT_SECRET_SUBKEY))) - { - if (priv == 0) - cdk_pk_get_keyid (pkt->pkt.public_key, local_keyid); - else - cdk_pk_get_keyid (pkt->pkt.secret_key->pk, local_keyid); - - _gnutls_hard_log ("Found keyid: %x.%x\n", local_keyid[0], - local_keyid[1]); - if (local_keyid[0] == keyid[0] && local_keyid[1] == keyid[1]) - { - return i; - } - i++; - } + (priv != 0 && (pkt->pkttype == CDK_PKT_SECRET_SUBKEY))) + { + if (priv == 0) + cdk_pk_get_keyid (pkt->pkt.public_key, local_keyid); + else + cdk_pk_get_keyid (pkt->pkt.secret_key->pk, local_keyid); + + _gnutls_hard_log ("Found keyid: %x.%x\n", local_keyid[0], + local_keyid[1]); + if (local_keyid[0] == keyid[0] && local_keyid[1] == keyid[1]) + { + return i; + } + i++; + } } gnutls_assert (); @@ -817,7 +817,7 @@ _gnutls_openpgp_find_subkey_idx (cdk_kbnode_t knode, uint32_t keyid[2], **/ int gnutls_openpgp_crt_get_subkey_revoked_status (gnutls_openpgp_crt_t key, - unsigned int idx) + unsigned int idx) { cdk_packet_t pkt; @@ -856,8 +856,8 @@ gnutls_openpgp_crt_get_subkey_revoked_status (gnutls_openpgp_crt_t key, **/ gnutls_pk_algorithm_t gnutls_openpgp_crt_get_subkey_pk_algorithm (gnutls_openpgp_crt_t key, - unsigned int idx, - unsigned int *bits) + unsigned int idx, + unsigned int *bits) { cdk_packet_t pkt; int algo; @@ -874,7 +874,7 @@ gnutls_openpgp_crt_get_subkey_pk_algorithm (gnutls_openpgp_crt_t key, if (pkt) { if (bits) - *bits = cdk_pk_get_nbits (pkt->pkt.public_key); + *bits = cdk_pk_get_nbits (pkt->pkt.public_key); algo = _gnutls_openpgp_get_algo (pkt->pkt.public_key->pubkey_algo); } @@ -894,7 +894,7 @@ gnutls_openpgp_crt_get_subkey_pk_algorithm (gnutls_openpgp_crt_t key, **/ time_t gnutls_openpgp_crt_get_subkey_creation_time (gnutls_openpgp_crt_t key, - unsigned int idx) + unsigned int idx) { cdk_packet_t pkt; time_t timestamp; @@ -926,7 +926,7 @@ gnutls_openpgp_crt_get_subkey_creation_time (gnutls_openpgp_crt_t key, **/ time_t gnutls_openpgp_crt_get_subkey_expiration_time (gnutls_openpgp_crt_t key, - unsigned int idx) + unsigned int idx) { cdk_packet_t pkt; time_t expiredate; @@ -955,8 +955,8 @@ gnutls_openpgp_crt_get_subkey_expiration_time (gnutls_openpgp_crt_t key, **/ int gnutls_openpgp_crt_get_subkey_id (gnutls_openpgp_crt_t key, - unsigned int idx, - gnutls_openpgp_keyid_t keyid) + unsigned int idx, + gnutls_openpgp_keyid_t keyid) { cdk_packet_t pkt; uint32_t kid[2]; @@ -994,8 +994,8 @@ gnutls_openpgp_crt_get_subkey_id (gnutls_openpgp_crt_t key, **/ int gnutls_openpgp_crt_get_subkey_fingerprint (gnutls_openpgp_crt_t key, - unsigned int idx, - void *fpr, size_t * fprlen) + unsigned int idx, + void *fpr, size_t * fprlen) { cdk_packet_t pkt; cdk_pkt_pubkey_t pk = NULL; @@ -1036,7 +1036,7 @@ gnutls_openpgp_crt_get_subkey_fingerprint (gnutls_openpgp_crt_t key, **/ int gnutls_openpgp_crt_get_subkey_idx (gnutls_openpgp_crt_t key, - const gnutls_openpgp_keyid_t keyid) + const gnutls_openpgp_keyid_t keyid) { int ret; uint32_t kid[2]; @@ -1076,8 +1076,8 @@ gnutls_openpgp_crt_get_subkey_idx (gnutls_openpgp_crt_t key, */ int gnutls_openpgp_crt_get_subkey_usage (gnutls_openpgp_crt_t key, - unsigned int idx, - unsigned int *key_usage) + unsigned int idx, + unsigned int *key_usage) { cdk_packet_t pkt; @@ -1098,7 +1098,7 @@ gnutls_openpgp_crt_get_subkey_usage (gnutls_openpgp_crt_t key, int _gnutls_read_pgp_mpi (cdk_packet_t pkt, unsigned int priv, size_t idx, - bigint_t * m) + bigint_t * m) { size_t buf_size = 512; opaque *buf = gnutls_malloc (buf_size); @@ -1119,47 +1119,47 @@ _gnutls_read_pgp_mpi (cdk_packet_t pkt, unsigned int priv, size_t idx, if (priv == 0) err = cdk_pk_get_mpi (pkt->pkt.public_key, idx, buf, buf_size, &buf_size, - NULL); + NULL); else { if (idx < max_pub_params) - err = - cdk_pk_get_mpi (pkt->pkt.secret_key->pk, idx, buf, buf_size, - &buf_size, NULL); + err = + cdk_pk_get_mpi (pkt->pkt.secret_key->pk, idx, buf, buf_size, + &buf_size, NULL); else - { - err = - cdk_sk_get_mpi (pkt->pkt.secret_key, idx - max_pub_params, buf, - buf_size, &buf_size, NULL); - } + { + err = + cdk_sk_get_mpi (pkt->pkt.secret_key, idx - max_pub_params, buf, + buf_size, &buf_size, NULL); + } } if (err == CDK_Too_Short) { buf = gnutls_realloc_fast (buf, buf_size); if (buf == NULL) - { - gnutls_assert (); - return GNUTLS_E_MEMORY_ERROR; - } + { + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; + } if (priv == 0) - err = - cdk_pk_get_mpi (pkt->pkt.public_key, idx, buf, buf_size, &buf_size, - NULL); + err = + cdk_pk_get_mpi (pkt->pkt.public_key, idx, buf, buf_size, &buf_size, + NULL); else - { - if (idx < max_pub_params) - err = - cdk_pk_get_mpi (pkt->pkt.secret_key->pk, idx, buf, buf_size, - &buf_size, NULL); - else - { - err = - cdk_sk_get_mpi (pkt->pkt.secret_key, idx - max_pub_params, - buf, buf_size, &buf_size, NULL); - } - } + { + if (idx < max_pub_params) + err = + cdk_pk_get_mpi (pkt->pkt.secret_key->pk, idx, buf, buf_size, + &buf_size, NULL); + else + { + err = + cdk_sk_get_mpi (pkt->pkt.secret_key, idx - max_pub_params, + buf, buf_size, &buf_size, NULL); + } + } } if (err != CDK_Success) @@ -1186,8 +1186,8 @@ _gnutls_read_pgp_mpi (cdk_packet_t pkt, unsigned int priv, size_t idx, */ int _gnutls_openpgp_crt_get_mpis (gnutls_openpgp_crt_t cert, - uint32_t * keyid /* [2] */ , - bigint_t * params, int *params_size) + uint32_t * keyid /* [2] */ , + bigint_t * params, int *params_size) { int result, i; int pk_algorithm, local_params; @@ -1231,10 +1231,10 @@ _gnutls_openpgp_crt_get_mpis (gnutls_openpgp_crt_t cert, { result = _gnutls_read_pgp_mpi (pkt, 0, i, ¶ms[i]); if (result < 0) - { - gnutls_assert (); - goto error; - } + { + gnutls_assert (); + goto error; + } } return 0; @@ -1253,7 +1253,7 @@ error: */ static int _get_pk_rsa_raw (gnutls_openpgp_crt_t crt, gnutls_openpgp_keyid_t keyid, - gnutls_datum_t * m, gnutls_datum_t * e) + gnutls_datum_t * m, gnutls_datum_t * e) { int pk_algorithm, ret, i; cdk_packet_t pkt; @@ -1318,8 +1318,8 @@ cleanup: static int _get_pk_dsa_raw (gnutls_openpgp_crt_t crt, gnutls_openpgp_keyid_t keyid, - gnutls_datum_t * p, gnutls_datum_t * q, - gnutls_datum_t * g, gnutls_datum_t * y) + gnutls_datum_t * p, gnutls_datum_t * q, + gnutls_datum_t * g, gnutls_datum_t * y) { int pk_algorithm, ret, i; cdk_packet_t pkt; @@ -1424,7 +1424,7 @@ cleanup: **/ int gnutls_openpgp_crt_get_pk_rsa_raw (gnutls_openpgp_crt_t crt, - gnutls_datum_t * m, gnutls_datum_t * e) + gnutls_datum_t * m, gnutls_datum_t * e) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1457,8 +1457,8 @@ gnutls_openpgp_crt_get_pk_rsa_raw (gnutls_openpgp_crt_t crt, **/ int gnutls_openpgp_crt_get_pk_dsa_raw (gnutls_openpgp_crt_t crt, - gnutls_datum_t * p, gnutls_datum_t * q, - gnutls_datum_t * g, gnutls_datum_t * y) + gnutls_datum_t * p, gnutls_datum_t * q, + gnutls_datum_t * g, gnutls_datum_t * y) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1490,9 +1490,9 @@ gnutls_openpgp_crt_get_pk_dsa_raw (gnutls_openpgp_crt_t crt, **/ int gnutls_openpgp_crt_get_subkey_pk_rsa_raw (gnutls_openpgp_crt_t crt, - unsigned int idx, - gnutls_datum_t * m, - gnutls_datum_t * e) + unsigned int idx, + gnutls_datum_t * m, + gnutls_datum_t * e) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1526,11 +1526,11 @@ gnutls_openpgp_crt_get_subkey_pk_rsa_raw (gnutls_openpgp_crt_t crt, **/ int gnutls_openpgp_crt_get_subkey_pk_dsa_raw (gnutls_openpgp_crt_t crt, - unsigned int idx, - gnutls_datum_t * p, - gnutls_datum_t * q, - gnutls_datum_t * g, - gnutls_datum_t * y) + unsigned int idx, + gnutls_datum_t * p, + gnutls_datum_t * q, + gnutls_datum_t * g, + gnutls_datum_t * y) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1557,7 +1557,7 @@ gnutls_openpgp_crt_get_subkey_pk_dsa_raw (gnutls_openpgp_crt_t crt, **/ int gnutls_openpgp_crt_get_preferred_key_id (gnutls_openpgp_crt_t key, - gnutls_openpgp_keyid_t keyid) + gnutls_openpgp_keyid_t keyid) { if (!key || !keyid || !key->preferred_set) { @@ -1583,7 +1583,7 @@ gnutls_openpgp_crt_get_preferred_key_id (gnutls_openpgp_crt_t key, **/ int gnutls_openpgp_crt_set_preferred_key_id (gnutls_openpgp_crt_t key, - const gnutls_openpgp_keyid_t keyid) + const gnutls_openpgp_keyid_t keyid) { int ret; @@ -1627,8 +1627,8 @@ gnutls_openpgp_crt_set_preferred_key_id (gnutls_openpgp_crt_t key, **/ int gnutls_openpgp_crt_get_auth_subkey (gnutls_openpgp_crt_t crt, - gnutls_openpgp_keyid_t keyid, - unsigned int flag) + gnutls_openpgp_keyid_t keyid, + unsigned int flag) { int ret, subkeys, i; unsigned int usage; @@ -1648,38 +1648,38 @@ gnutls_openpgp_crt_get_auth_subkey (gnutls_openpgp_crt_t crt, { ret = gnutls_openpgp_crt_get_subkey_revoked_status (crt, i); - if (ret != 0) /* it is revoked. ignore it */ - continue; + if (ret != 0) /* it is revoked. ignore it */ + continue; if (keyid_init == 0) - { /* keep the first valid subkey */ - ret = gnutls_openpgp_crt_get_subkey_id (crt, i, keyid); - if (ret < 0) - { - gnutls_assert (); - return ret; - } + { /* keep the first valid subkey */ + ret = gnutls_openpgp_crt_get_subkey_id (crt, i, keyid); + if (ret < 0) + { + gnutls_assert (); + return ret; + } - keyid_init = 1; - } + keyid_init = 1; + } ret = gnutls_openpgp_crt_get_subkey_usage (crt, i, &usage); if (ret < 0) - { - gnutls_assert (); - return ret; - } + { + gnutls_assert (); + return ret; + } if (usage & GNUTLS_KEY_KEY_AGREEMENT) - { - ret = gnutls_openpgp_crt_get_subkey_id (crt, i, keyid); - if (ret < 0) - { - gnutls_assert (); - return ret; - } - return 0; - } + { + ret = gnutls_openpgp_crt_get_subkey_id (crt, i, keyid); + if (ret < 0) + { + gnutls_assert (); + return ret; + } + return 0; + } } if (flag && keyid_init) @@ -1703,15 +1703,15 @@ gnutls_openpgp_crt_get_auth_subkey (gnutls_openpgp_crt_t crt, **/ int gnutls_openpgp_crt_verify_hash (gnutls_openpgp_crt_t crt, unsigned int flags, - const gnutls_datum_t * hash, - const gnutls_datum_t * signature) + const gnutls_datum_t * hash, + const gnutls_datum_t * signature) { int ret; bigint_t params[MAX_PUBLIC_PARAMS_SIZE]; int params_size = MAX_PUBLIC_PARAMS_SIZE; gnutls_pk_algorithm_t pk; uint32_t kid[2]; - + if (crt == NULL || !crt->preferred_set) { gnutls_assert (); @@ -1725,7 +1725,7 @@ gnutls_openpgp_crt_verify_hash (gnutls_openpgp_crt_t crt, unsigned int flags, return ret; } pk = ret; - + KEYID_IMPORT (kid, crt->preferred_keyid); ret = _gnutls_openpgp_crt_get_mpis (crt, kid, params, ¶ms_size); if (ret < 0) @@ -1734,7 +1734,7 @@ gnutls_openpgp_crt_verify_hash (gnutls_openpgp_crt_t crt, unsigned int flags, return ret; } - ret = pubkey_verify_sig( NULL, hash, signature, pk, params, params_size); + ret = pubkey_verify_sig (NULL, hash, signature, pk, params, params_size); if (ret < 0) { gnutls_assert (); diff --git a/lib/openpgp/pgpverify.c b/lib/openpgp/pgpverify.c index 94daf6718b..3a5771b528 100644 --- a/lib/openpgp/pgpverify.c +++ b/lib/openpgp/pgpverify.c @@ -58,8 +58,8 @@ **/ int gnutls_openpgp_crt_verify_ring (gnutls_openpgp_crt_t key, - gnutls_openpgp_keyring_t keyring, - unsigned int flags, unsigned int *verify) + gnutls_openpgp_keyring_t keyring, + unsigned int flags, unsigned int *verify) { gnutls_openpgp_keyid_t id; cdk_error_t rc; @@ -101,15 +101,15 @@ gnutls_openpgp_crt_verify_ring (gnutls_openpgp_crt_t key, { rc = gnutls_openpgp_crt_get_key_id (key, id); if (rc < 0) - { - gnutls_assert (); - return rc; - } + { + gnutls_assert (); + return rc; + } rc = gnutls_openpgp_keyring_check_id (keyring, id, 0); /* If it exists in the keyring don't treat it as unknown. */ if (rc == 0 && *verify & GNUTLS_CERT_SIGNER_NOT_FOUND) - *verify ^= GNUTLS_CERT_SIGNER_NOT_FOUND; + *verify ^= GNUTLS_CERT_SIGNER_NOT_FOUND; } return 0; @@ -132,7 +132,7 @@ gnutls_openpgp_crt_verify_ring (gnutls_openpgp_crt_t key, **/ int gnutls_openpgp_crt_verify_self (gnutls_openpgp_crt_t key, - unsigned int flags, unsigned int *verify) + unsigned int flags, unsigned int *verify) { int status; cdk_error_t rc; diff --git a/lib/openpgp/privkey.c b/lib/openpgp/privkey.c index 29dfe51009..304fc9d574 100644 --- a/lib/openpgp/privkey.c +++ b/lib/openpgp/privkey.c @@ -50,7 +50,7 @@ gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t * key) *key = gnutls_calloc (1, sizeof (gnutls_openpgp_privkey_int)); if (*key) - return 0; /* success */ + return 0; /* success */ return GNUTLS_E_MEMORY_ERROR; } @@ -117,9 +117,9 @@ gnutls_openpgp_privkey_sec_param (gnutls_openpgp_privkey_t key) **/ int gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key, - const gnutls_datum_t * data, - gnutls_openpgp_crt_fmt_t format, - const char *password, unsigned int flags) + const gnutls_datum_t * data, + gnutls_openpgp_crt_fmt_t format, + const char *password, unsigned int flags) { cdk_stream_t inp; cdk_packet_t pkt; @@ -135,43 +135,43 @@ gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key, { rc = cdk_kbnode_read_from_mem (&key->knode, data->data, data->size); if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + { + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; + } } else { rc = cdk_stream_tmp_from_mem (data->data, data->size, &inp); if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + { + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; + } if (cdk_armor_filter_use (inp)) - { - rc = cdk_stream_set_armor_flag (inp, 0); - if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - cdk_stream_close (inp); - gnutls_assert (); - return rc; - } - } + { + rc = cdk_stream_set_armor_flag (inp, 0); + if (rc != 0) + { + rc = _gnutls_map_cdk_rc (rc); + cdk_stream_close (inp); + gnutls_assert (); + return rc; + } + } rc = cdk_keydb_get_keyblock (inp, &key->knode); cdk_stream_close (inp); if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + { + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; + } } /* Test if the import was successful. */ @@ -205,13 +205,13 @@ gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key, **/ int gnutls_openpgp_privkey_export (gnutls_openpgp_privkey_t key, - gnutls_openpgp_crt_fmt_t format, - const char *password, unsigned int flags, - void *output_data, size_t * output_data_size) + gnutls_openpgp_crt_fmt_t format, + const char *password, unsigned int flags, + void *output_data, size_t * output_data_size) { /* FIXME for now we do not export encrypted keys */ return _gnutls_openpgp_export (key->knode, format, output_data, - output_data_size, 1); + output_data_size, 1); } @@ -234,7 +234,7 @@ gnutls_openpgp_privkey_export (gnutls_openpgp_privkey_t key, **/ gnutls_pk_algorithm_t gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key, - unsigned int *bits) + unsigned int *bits) { cdk_packet_t pkt; int algo; @@ -250,7 +250,7 @@ gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key, if (pkt) { if (bits) - *bits = cdk_pk_get_nbits (pkt->pkt.secret_key->pk); + *bits = cdk_pk_get_nbits (pkt->pkt.secret_key->pk); algo = _gnutls_openpgp_get_algo (pkt->pkt.secret_key->pk->pubkey_algo); } @@ -321,7 +321,7 @@ gnutls_openpgp_privkey_get_revoked_status (gnutls_openpgp_privkey_t key) **/ int gnutls_openpgp_privkey_get_fingerprint (gnutls_openpgp_privkey_t key, - void *fpr, size_t * fprlen) + void *fpr, size_t * fprlen) { cdk_packet_t pkt; cdk_pkt_pubkey_t pk = NULL; @@ -365,7 +365,7 @@ gnutls_openpgp_privkey_get_fingerprint (gnutls_openpgp_privkey_t key, **/ int gnutls_openpgp_privkey_get_key_id (gnutls_openpgp_privkey_t key, - gnutls_openpgp_keyid_t keyid) + gnutls_openpgp_keyid_t keyid) { cdk_packet_t pkt; uint32_t kid[2]; @@ -418,7 +418,7 @@ gnutls_openpgp_privkey_get_subkey_count (gnutls_openpgp_privkey_t key) { pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype == CDK_PKT_SECRET_SUBKEY) - subkeys++; + subkeys++; } return subkeys; @@ -438,7 +438,7 @@ _get_secret_subkey (gnutls_openpgp_privkey_t key, unsigned int indx) { pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype == CDK_PKT_SECRET_SUBKEY && indx == subkeys++) - return pkt; + return pkt; } return NULL; @@ -458,7 +458,7 @@ _get_secret_subkey (gnutls_openpgp_privkey_t key, unsigned int indx) **/ int gnutls_openpgp_privkey_get_subkey_revoked_status (gnutls_openpgp_privkey_t - key, unsigned int idx) + key, unsigned int idx) { cdk_packet_t pkt; @@ -497,8 +497,8 @@ gnutls_openpgp_privkey_get_subkey_revoked_status (gnutls_openpgp_privkey_t **/ gnutls_pk_algorithm_t gnutls_openpgp_privkey_get_subkey_pk_algorithm (gnutls_openpgp_privkey_t key, - unsigned int idx, - unsigned int *bits) + unsigned int idx, + unsigned int *bits) { cdk_packet_t pkt; int algo; @@ -515,14 +515,14 @@ gnutls_openpgp_privkey_get_subkey_pk_algorithm (gnutls_openpgp_privkey_t key, if (pkt) { if (bits) - *bits = cdk_pk_get_nbits (pkt->pkt.secret_key->pk); + *bits = cdk_pk_get_nbits (pkt->pkt.secret_key->pk); algo = pkt->pkt.secret_key->pubkey_algo; if (is_RSA (algo)) - algo = GNUTLS_PK_RSA; + algo = GNUTLS_PK_RSA; else if (is_DSA (algo)) - algo = GNUTLS_PK_DSA; + algo = GNUTLS_PK_DSA; else - algo = GNUTLS_E_UNKNOWN_PK_ALGORITHM; + algo = GNUTLS_E_UNKNOWN_PK_ALGORITHM; } return algo; @@ -541,7 +541,7 @@ gnutls_openpgp_privkey_get_subkey_pk_algorithm (gnutls_openpgp_privkey_t key, **/ int gnutls_openpgp_privkey_get_subkey_idx (gnutls_openpgp_privkey_t key, - const gnutls_openpgp_keyid_t keyid) + const gnutls_openpgp_keyid_t keyid) { int ret; uint32_t kid[2]; @@ -576,7 +576,7 @@ gnutls_openpgp_privkey_get_subkey_idx (gnutls_openpgp_privkey_t key, **/ time_t gnutls_openpgp_privkey_get_subkey_creation_time (gnutls_openpgp_privkey_t key, - unsigned int idx) + unsigned int idx) { cdk_packet_t pkt; time_t timestamp; @@ -607,7 +607,7 @@ gnutls_openpgp_privkey_get_subkey_creation_time (gnutls_openpgp_privkey_t key, **/ time_t gnutls_openpgp_privkey_get_subkey_expiration_time (gnutls_openpgp_privkey_t - key, unsigned int idx) + key, unsigned int idx) { cdk_packet_t pkt; time_t expiredate; @@ -638,8 +638,8 @@ gnutls_openpgp_privkey_get_subkey_expiration_time (gnutls_openpgp_privkey_t **/ int gnutls_openpgp_privkey_get_subkey_id (gnutls_openpgp_privkey_t key, - unsigned int idx, - gnutls_openpgp_keyid_t keyid) + unsigned int idx, + gnutls_openpgp_keyid_t keyid) { cdk_packet_t pkt; uint32_t kid[2]; @@ -677,8 +677,8 @@ gnutls_openpgp_privkey_get_subkey_id (gnutls_openpgp_privkey_t key, **/ int gnutls_openpgp_privkey_get_subkey_fingerprint (gnutls_openpgp_privkey_t key, - unsigned int idx, - void *fpr, size_t * fprlen) + unsigned int idx, + void *fpr, size_t * fprlen) { cdk_packet_t pkt; cdk_pkt_pubkey_t pk = NULL; @@ -711,8 +711,8 @@ gnutls_openpgp_privkey_get_subkey_fingerprint (gnutls_openpgp_privkey_t key, */ int _gnutls_openpgp_privkey_get_mpis (gnutls_openpgp_privkey_t pkey, - uint32_t * keyid /*[2] */ , - bigint_t * params, int *params_size) + uint32_t * keyid /*[2] */ , + bigint_t * params, int *params_size) { int result, i; int pk_algorithm; @@ -754,10 +754,10 @@ _gnutls_openpgp_privkey_get_mpis (gnutls_openpgp_privkey_t pkey, { result = _gnutls_read_pgp_mpi (pkt, 1, i, &pk_params.params[i]); if (result < 0) - { - gnutls_assert (); - goto error; - } + { + gnutls_assert (); + goto error; + } } /* fixup will generate exp1 and exp2 that are not * available here. @@ -795,9 +795,9 @@ error: */ static int _get_sk_rsa_raw (gnutls_openpgp_privkey_t pkey, gnutls_openpgp_keyid_t keyid, - gnutls_datum_t * m, gnutls_datum_t * e, - gnutls_datum_t * d, gnutls_datum_t * p, - gnutls_datum_t * q, gnutls_datum_t * u) + gnutls_datum_t * m, gnutls_datum_t * e, + gnutls_datum_t * d, gnutls_datum_t * p, + gnutls_datum_t * q, gnutls_datum_t * u) { int pk_algorithm, ret, i; cdk_packet_t pkt; @@ -905,8 +905,8 @@ cleanup: static int _get_sk_dsa_raw (gnutls_openpgp_privkey_t pkey, gnutls_openpgp_keyid_t keyid, - gnutls_datum_t * p, gnutls_datum_t * q, - gnutls_datum_t * g, gnutls_datum_t * y, gnutls_datum_t * x) + gnutls_datum_t * p, gnutls_datum_t * q, + gnutls_datum_t * g, gnutls_datum_t * y, gnutls_datum_t * x) { int pk_algorithm, ret, i; cdk_packet_t pkt; @@ -1027,9 +1027,9 @@ cleanup: **/ int gnutls_openpgp_privkey_export_rsa_raw (gnutls_openpgp_privkey_t pkey, - gnutls_datum_t * m, gnutls_datum_t * e, - gnutls_datum_t * d, gnutls_datum_t * p, - gnutls_datum_t * q, gnutls_datum_t * u) + gnutls_datum_t * m, gnutls_datum_t * e, + gnutls_datum_t * d, gnutls_datum_t * p, + gnutls_datum_t * q, gnutls_datum_t * u) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1063,9 +1063,9 @@ gnutls_openpgp_privkey_export_rsa_raw (gnutls_openpgp_privkey_t pkey, **/ int gnutls_openpgp_privkey_export_dsa_raw (gnutls_openpgp_privkey_t pkey, - gnutls_datum_t * p, gnutls_datum_t * q, - gnutls_datum_t * g, gnutls_datum_t * y, - gnutls_datum_t * x) + gnutls_datum_t * p, gnutls_datum_t * q, + gnutls_datum_t * g, gnutls_datum_t * y, + gnutls_datum_t * x) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1101,13 +1101,13 @@ gnutls_openpgp_privkey_export_dsa_raw (gnutls_openpgp_privkey_t pkey, **/ int gnutls_openpgp_privkey_export_subkey_rsa_raw (gnutls_openpgp_privkey_t pkey, - unsigned int idx, - gnutls_datum_t * m, - gnutls_datum_t * e, - gnutls_datum_t * d, - gnutls_datum_t * p, - gnutls_datum_t * q, - gnutls_datum_t * u) + unsigned int idx, + gnutls_datum_t * m, + gnutls_datum_t * e, + gnutls_datum_t * d, + gnutls_datum_t * p, + gnutls_datum_t * q, + gnutls_datum_t * u) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1142,12 +1142,12 @@ gnutls_openpgp_privkey_export_subkey_rsa_raw (gnutls_openpgp_privkey_t pkey, **/ int gnutls_openpgp_privkey_export_subkey_dsa_raw (gnutls_openpgp_privkey_t pkey, - unsigned int idx, - gnutls_datum_t * p, - gnutls_datum_t * q, - gnutls_datum_t * g, - gnutls_datum_t * y, - gnutls_datum_t * x) + unsigned int idx, + gnutls_datum_t * p, + gnutls_datum_t * q, + gnutls_datum_t * g, + gnutls_datum_t * y, + gnutls_datum_t * x) { gnutls_openpgp_keyid_t keyid; int ret; @@ -1174,7 +1174,7 @@ gnutls_openpgp_privkey_export_subkey_dsa_raw (gnutls_openpgp_privkey_t pkey, **/ int gnutls_openpgp_privkey_get_preferred_key_id (gnutls_openpgp_privkey_t key, - gnutls_openpgp_keyid_t keyid) + gnutls_openpgp_keyid_t keyid) { if (!key || !keyid || !key->preferred_set) { @@ -1199,8 +1199,8 @@ gnutls_openpgp_privkey_get_preferred_key_id (gnutls_openpgp_privkey_t key, **/ int gnutls_openpgp_privkey_set_preferred_key_id (gnutls_openpgp_privkey_t key, - const gnutls_openpgp_keyid_t - keyid) + const gnutls_openpgp_keyid_t + keyid) { int ret; @@ -1240,8 +1240,8 @@ gnutls_openpgp_privkey_set_preferred_key_id (gnutls_openpgp_privkey_t key, -*/ int _gnutls_openpgp_privkey_sign_hash (gnutls_openpgp_privkey_t key, - const gnutls_datum_t * hash, - gnutls_datum_t * signature) + const gnutls_datum_t * hash, + gnutls_datum_t * signature) { int result, i; bigint_t params[MAX_PRIV_PARAMS_SIZE]; @@ -1265,15 +1265,15 @@ _gnutls_openpgp_privkey_sign_hash (gnutls_openpgp_privkey_t key, idx = gnutls_openpgp_privkey_get_subkey_idx (key, keyid); pk_algorithm = - gnutls_openpgp_privkey_get_subkey_pk_algorithm (key, idx, NULL); + gnutls_openpgp_privkey_get_subkey_pk_algorithm (key, idx, NULL); result = - _gnutls_openpgp_privkey_get_mpis (key, kid, params, ¶ms_size); + _gnutls_openpgp_privkey_get_mpis (key, kid, params, ¶ms_size); } else { pk_algorithm = gnutls_openpgp_privkey_get_pk_algorithm (key, NULL); result = _gnutls_openpgp_privkey_get_mpis (key, NULL, - params, ¶ms_size); + params, ¶ms_size); } if (result < 0) @@ -1315,25 +1315,26 @@ _gnutls_openpgp_privkey_sign_hash (gnutls_openpgp_privkey_t key, **/ int gnutls_openpgp_privkey_sign_hash2 (gnutls_openpgp_privkey_t signer, - gnutls_digest_algorithm_t hash_algo, - unsigned int flags, - const gnutls_datum_t * hash_data, - gnutls_datum_t * signature) + gnutls_digest_algorithm_t hash_algo, + unsigned int flags, + const gnutls_datum_t * hash_data, + gnutls_datum_t * signature) { int ret; gnutls_datum_t digest; - digest.data = gnutls_malloc(hash_data->size); + digest.data = gnutls_malloc (hash_data->size); if (digest.data == NULL) { - gnutls_assert(); + gnutls_assert (); return GNUTLS_E_MEMORY_ERROR; } digest.size = hash_data->size; - memcpy(digest.data, hash_data->data, digest.size); + memcpy (digest.data, hash_data->data, digest.size); - ret = pk_prepare_hash (gnutls_openpgp_privkey_get_pk_algorithm (signer, NULL), - hash_algo, &digest); + ret = + pk_prepare_hash (gnutls_openpgp_privkey_get_pk_algorithm (signer, NULL), + hash_algo, &digest); if (ret < 0) { gnutls_assert (); @@ -1350,7 +1351,7 @@ gnutls_openpgp_privkey_sign_hash2 (gnutls_openpgp_privkey_t signer, ret = 0; cleanup: - _gnutls_free_datum(&digest); + _gnutls_free_datum (&digest); return ret; } @@ -1378,22 +1379,26 @@ cleanup: **/ int gnutls_openpgp_privkey_sign_data2 (gnutls_openpgp_privkey_t signer, - gnutls_digest_algorithm_t hash, - unsigned int flags, - const gnutls_datum_t * data, - gnutls_datum_t * signature) + gnutls_digest_algorithm_t hash, + unsigned int flags, + const gnutls_datum_t * data, + gnutls_datum_t * signature) { int ret; gnutls_datum_t digest; - ret = pk_hash_data(gnutls_openpgp_privkey_get_pk_algorithm(signer,NULL), hash, NULL, data, &digest); + ret = + pk_hash_data (gnutls_openpgp_privkey_get_pk_algorithm (signer, NULL), + hash, NULL, data, &digest); if (ret < 0) { - gnutls_assert(); + gnutls_assert (); return ret; } - ret = gnutls_openpgp_privkey_sign_hash2(signer, hash, flags, &digest, signature); + ret = + gnutls_openpgp_privkey_sign_hash2 (signer, hash, flags, &digest, + signature); if (ret < 0) { gnutls_assert (); @@ -1423,9 +1428,9 @@ cleanup: **/ int gnutls_openpgp_privkey_decrypt_data (gnutls_openpgp_privkey_t key, - unsigned int flags, - const gnutls_datum_t * ciphertext, - gnutls_datum_t * plaintext) + unsigned int flags, + const gnutls_datum_t * ciphertext, + gnutls_datum_t * plaintext) { int result, i; bigint_t params[MAX_PUBLIC_PARAMS_SIZE]; @@ -1446,12 +1451,12 @@ gnutls_openpgp_privkey_decrypt_data (gnutls_openpgp_privkey_t key, KEYID_IMPORT (kid, keyid); result = _gnutls_openpgp_privkey_get_mpis (key, kid, - params, ¶ms_size); + params, ¶ms_size); } else { result = _gnutls_openpgp_privkey_get_mpis (key, NULL, - params, ¶ms_size); + params, ¶ms_size); } if (result < 0) |