diff options
Diffstat (limited to 'lib/x509/privkey.c')
-rw-r--r-- | lib/x509/privkey.c | 496 |
1 files changed, 249 insertions, 247 deletions
diff --git a/lib/x509/privkey.c b/lib/x509/privkey.c index 9636883fdf..7d3caa317e 100644 --- a/lib/x509/privkey.c +++ b/lib/x509/privkey.c @@ -56,7 +56,7 @@ gnutls_x509_privkey_init (gnutls_x509_privkey_t * key) { (*key)->key = ASN1_TYPE_EMPTY; (*key)->pk_algorithm = GNUTLS_PK_UNKNOWN; - return 0; /* success */ + return 0; /* success */ } return GNUTLS_E_MEMORY_ERROR; @@ -108,7 +108,7 @@ gnutls_x509_privkey_cpy (gnutls_x509_privkey_t dst, gnutls_x509_privkey_t src) { dst->params[i] = _gnutls_mpi_copy (src->params[i]); if (dst->params[i] == NULL) - return GNUTLS_E_MEMORY_ERROR; + return GNUTLS_E_MEMORY_ERROR; } dst->params_size = src->params_size; @@ -118,27 +118,27 @@ gnutls_x509_privkey_cpy (gnutls_x509_privkey_t dst, gnutls_x509_privkey_t src) if (!src->crippled) { switch (dst->pk_algorithm) - { - case GNUTLS_PK_DSA: - ret = _gnutls_asn1_encode_dsa (&dst->key, dst->params); - if (ret < 0) - { - gnutls_assert (); - return ret; - } - break; - case GNUTLS_PK_RSA: - ret = _gnutls_asn1_encode_rsa (&dst->key, dst->params); - if (ret < 0) - { - gnutls_assert (); - return ret; - } - break; - default: - gnutls_assert (); - return GNUTLS_E_INVALID_REQUEST; - } + { + case GNUTLS_PK_DSA: + ret = _gnutls_asn1_encode_dsa (&dst->key, dst->params); + if (ret < 0) + { + gnutls_assert (); + return ret; + } + break; + case GNUTLS_PK_RSA: + ret = _gnutls_asn1_encode_rsa (&dst->key, dst->params); + if (ret < 0) + { + gnutls_assert (); + return ret; + } + break; + default: + gnutls_assert (); + return GNUTLS_E_INVALID_REQUEST; + } } return 0; @@ -149,7 +149,7 @@ gnutls_x509_privkey_cpy (gnutls_x509_privkey_t dst, gnutls_x509_privkey_t src) */ ASN1_TYPE _gnutls_privkey_decode_pkcs1_rsa_key (const gnutls_datum_t * raw_key, - gnutls_x509_privkey_t pkey) + gnutls_x509_privkey_t pkey) { int result; ASN1_TYPE pkey_asn; @@ -160,8 +160,8 @@ _gnutls_privkey_decode_pkcs1_rsa_key (const gnutls_datum_t * raw_key, if ((result = asn1_create_element (_gnutls_get_gnutls_asn (), - "GNUTLS.RSAPrivateKey", - &pkey_asn)) != ASN1_SUCCESS) + "GNUTLS.RSAPrivateKey", + &pkey_asn)) != ASN1_SUCCESS) { gnutls_assert (); return NULL; @@ -175,7 +175,7 @@ _gnutls_privkey_decode_pkcs1_rsa_key (const gnutls_datum_t * raw_key, } if ((result = _gnutls_x509_read_int (pkey_asn, "modulus", - &pk_params.params[0])) < 0) + &pk_params.params[0])) < 0) { gnutls_assert (); goto error; @@ -183,7 +183,7 @@ _gnutls_privkey_decode_pkcs1_rsa_key (const gnutls_datum_t * raw_key, if ((result = _gnutls_x509_read_int (pkey_asn, "publicExponent", - &pk_params.params[1])) < 0) + &pk_params.params[1])) < 0) { gnutls_assert (); goto error; @@ -191,42 +191,42 @@ _gnutls_privkey_decode_pkcs1_rsa_key (const gnutls_datum_t * raw_key, if ((result = _gnutls_x509_read_int (pkey_asn, "privateExponent", - &pk_params.params[2])) < 0) + &pk_params.params[2])) < 0) { gnutls_assert (); goto error; } if ((result = _gnutls_x509_read_int (pkey_asn, "prime1", - &pk_params.params[3])) < 0) + &pk_params.params[3])) < 0) { gnutls_assert (); goto error; } if ((result = _gnutls_x509_read_int (pkey_asn, "prime2", - &pk_params.params[4])) < 0) + &pk_params.params[4])) < 0) { gnutls_assert (); goto error; } if ((result = _gnutls_x509_read_int (pkey_asn, "coefficient", - &pk_params.params[5])) < 0) + &pk_params.params[5])) < 0) { gnutls_assert (); goto error; } if ((result = _gnutls_x509_read_int (pkey_asn, "exponent1", - &pk_params.params[6])) < 0) + &pk_params.params[6])) < 0) { gnutls_assert (); goto error; } if ((result = _gnutls_x509_read_int (pkey_asn, "exponent2", - &pk_params.params[7])) < 0) + &pk_params.params[7])) < 0) { gnutls_assert (); goto error; @@ -267,8 +267,8 @@ decode_dsa_key (const gnutls_datum_t * raw_key, gnutls_x509_privkey_t pkey) if ((result = asn1_create_element (_gnutls_get_gnutls_asn (), - "GNUTLS.DSAPrivateKey", - &dsa_asn)) != ASN1_SUCCESS) + "GNUTLS.DSAPrivateKey", + &dsa_asn)) != ASN1_SUCCESS) { gnutls_assert (); return NULL; @@ -306,7 +306,7 @@ decode_dsa_key (const gnutls_datum_t * raw_key, gnutls_x509_privkey_t pkey) } if ((result = _gnutls_x509_read_int (dsa_asn, "priv", - &pkey->params[4])) < 0) + &pkey->params[4])) < 0) { gnutls_assert (); goto error; @@ -348,8 +348,8 @@ error: **/ int gnutls_x509_privkey_import (gnutls_x509_privkey_t key, - const gnutls_datum_t * data, - gnutls_x509_crt_fmt_t format) + const gnutls_datum_t * data, + gnutls_x509_crt_fmt_t format) { int result = 0, need_free = 0; gnutls_datum_t _data; @@ -373,28 +373,28 @@ gnutls_x509_privkey_import (gnutls_x509_privkey_t key, /* Try the first header */ result = - _gnutls_fbase64_decode (PEM_KEY_RSA, data->data, data->size, &out); + _gnutls_fbase64_decode (PEM_KEY_RSA, data->data, data->size, &out); if (result >= 0) - key->pk_algorithm = GNUTLS_PK_RSA; + key->pk_algorithm = GNUTLS_PK_RSA; if (result == GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR) - { - /* try for the second header */ - result = - _gnutls_fbase64_decode (PEM_KEY_DSA, data->data, data->size, - &out); - if (result <= 0) - { - if (result == 0) - result = GNUTLS_E_INTERNAL_ERROR; - gnutls_assert (); - - goto failover; - } - - key->pk_algorithm = GNUTLS_PK_DSA; - } + { + /* try for the second header */ + result = + _gnutls_fbase64_decode (PEM_KEY_DSA, data->data, data->size, + &out); + if (result <= 0) + { + if (result == 0) + result = GNUTLS_E_INTERNAL_ERROR; + gnutls_assert (); + + goto failover; + } + + key->pk_algorithm = GNUTLS_PK_DSA; + } _data.data = out; _data.size = result; @@ -406,13 +406,13 @@ gnutls_x509_privkey_import (gnutls_x509_privkey_t key, { key->key = _gnutls_privkey_decode_pkcs1_rsa_key (&_data, key); if (key->key == NULL) - gnutls_assert (); + gnutls_assert (); } else if (key->pk_algorithm == GNUTLS_PK_DSA) { key->key = decode_dsa_key (&_data, key); if (key->key == NULL) - gnutls_assert (); + gnutls_assert (); } else { @@ -423,12 +423,12 @@ gnutls_x509_privkey_import (gnutls_x509_privkey_t key, key->key = _gnutls_privkey_decode_pkcs1_rsa_key (&_data, key); if (key->key == NULL) - { - key->pk_algorithm = GNUTLS_PK_DSA; - key->key = decode_dsa_key (&_data, key); - if (key->key == NULL) - gnutls_assert (); - } + { + key->pk_algorithm = GNUTLS_PK_DSA; + key->key = decode_dsa_key (&_data, key); + if (key->key == NULL) + gnutls_assert (); + } } if (key->key == NULL) @@ -453,7 +453,7 @@ failover: { _gnutls_debug_log ("Falling back to PKCS #8 key decoding\n"); result = gnutls_x509_privkey_import_pkcs8 (key, data, format, - NULL, GNUTLS_PKCS_PLAIN); + NULL, GNUTLS_PKCS_PLAIN); } #endif @@ -487,15 +487,15 @@ failover: **/ int gnutls_x509_privkey_import_rsa_raw (gnutls_x509_privkey_t key, - const gnutls_datum_t * m, - const gnutls_datum_t * e, - const gnutls_datum_t * d, - const gnutls_datum_t * p, - const gnutls_datum_t * q, - const gnutls_datum_t * u) + const gnutls_datum_t * m, + const gnutls_datum_t * e, + const gnutls_datum_t * d, + const gnutls_datum_t * p, + const gnutls_datum_t * q, + const gnutls_datum_t * u) { return gnutls_x509_privkey_import_rsa_raw2 (key, m, e, d, p, q, u, NULL, - NULL); + NULL); } /** @@ -517,14 +517,14 @@ gnutls_x509_privkey_import_rsa_raw (gnutls_x509_privkey_t key, **/ int gnutls_x509_privkey_import_rsa_raw2 (gnutls_x509_privkey_t key, - const gnutls_datum_t * m, - const gnutls_datum_t * e, - const gnutls_datum_t * d, - const gnutls_datum_t * p, - const gnutls_datum_t * q, - const gnutls_datum_t * u, - const gnutls_datum_t * e1, - const gnutls_datum_t * e2) + const gnutls_datum_t * m, + const gnutls_datum_t * e, + const gnutls_datum_t * d, + const gnutls_datum_t * p, + const gnutls_datum_t * q, + const gnutls_datum_t * u, + const gnutls_datum_t * e1, + const gnutls_datum_t * e2) { int i = 0, ret; size_t siz = 0; @@ -598,20 +598,20 @@ gnutls_x509_privkey_import_rsa_raw2 (gnutls_x509_privkey_t key, { siz = e1->size; if (_gnutls_mpi_scan_nz (&key->params[6], e1->data, siz)) - { - gnutls_assert (); - FREE_RSA_PRIVATE_PARAMS; - return GNUTLS_E_MPI_SCAN_FAILED; - } + { + gnutls_assert (); + FREE_RSA_PRIVATE_PARAMS; + return GNUTLS_E_MPI_SCAN_FAILED; + } key->params_size++; siz = e2->size; if (_gnutls_mpi_scan_nz (&key->params[7], e2->data, siz)) - { - gnutls_assert (); - FREE_RSA_PRIVATE_PARAMS; - return GNUTLS_E_MPI_SCAN_FAILED; - } + { + gnutls_assert (); + FREE_RSA_PRIVATE_PARAMS; + return GNUTLS_E_MPI_SCAN_FAILED; + } key->params_size++; } @@ -640,11 +640,11 @@ gnutls_x509_privkey_import_rsa_raw2 (gnutls_x509_privkey_t key, { ret = _gnutls_asn1_encode_rsa (&key->key, key->params); if (ret < 0) - { - gnutls_assert (); - FREE_RSA_PRIVATE_PARAMS; - return ret; - } + { + gnutls_assert (); + FREE_RSA_PRIVATE_PARAMS; + return ret; + } } key->params_size = RSA_PRIVATE_PARAMS; @@ -672,11 +672,11 @@ gnutls_x509_privkey_import_rsa_raw2 (gnutls_x509_privkey_t key, **/ int gnutls_x509_privkey_import_dsa_raw (gnutls_x509_privkey_t key, - const gnutls_datum_t * p, - const gnutls_datum_t * q, - const gnutls_datum_t * g, - const gnutls_datum_t * y, - const gnutls_datum_t * x) + const gnutls_datum_t * p, + const gnutls_datum_t * q, + const gnutls_datum_t * g, + const gnutls_datum_t * y, + const gnutls_datum_t * x) { int i = 0, ret; size_t siz = 0; @@ -731,11 +731,11 @@ gnutls_x509_privkey_import_dsa_raw (gnutls_x509_privkey_t key, { ret = _gnutls_asn1_encode_dsa (&key->key, key->params); if (ret < 0) - { - gnutls_assert (); - FREE_DSA_PRIVATE_PARAMS; - return ret; - } + { + gnutls_assert (); + FREE_DSA_PRIVATE_PARAMS; + return ret; + } } key->params_size = DSA_PRIVATE_PARAMS; @@ -792,8 +792,8 @@ gnutls_x509_privkey_get_pk_algorithm (gnutls_x509_privkey_t key) **/ int gnutls_x509_privkey_export (gnutls_x509_privkey_t key, - gnutls_x509_crt_fmt_t format, void *output_data, - size_t * output_data_size) + gnutls_x509_crt_fmt_t format, void *output_data, + size_t * output_data_size) { const char *msg; int ret; @@ -812,34 +812,34 @@ gnutls_x509_privkey_export (gnutls_x509_privkey_t key, msg = NULL; if (key->crippled) - { /* encode the parameters on the fly. - */ + { /* encode the parameters on the fly. + */ switch (key->pk_algorithm) - { - case GNUTLS_PK_DSA: - ret = _gnutls_asn1_encode_dsa (&key->key, key->params); - if (ret < 0) - { - gnutls_assert (); - return ret; - } - break; - case GNUTLS_PK_RSA: - ret = _gnutls_asn1_encode_rsa (&key->key, key->params); - if (ret < 0) - { - gnutls_assert (); - return ret; - } - break; - default: - gnutls_assert (); - return GNUTLS_E_INVALID_REQUEST; - } + { + case GNUTLS_PK_DSA: + ret = _gnutls_asn1_encode_dsa (&key->key, key->params); + if (ret < 0) + { + gnutls_assert (); + return ret; + } + break; + case GNUTLS_PK_RSA: + ret = _gnutls_asn1_encode_rsa (&key->key, key->params); + if (ret < 0) + { + gnutls_assert (); + return ret; + } + break; + default: + gnutls_assert (); + return GNUTLS_E_INVALID_REQUEST; + } } return _gnutls_x509_export_int (key->key, format, msg, - output_data, output_data_size); + output_data, output_data_size); } /** @@ -860,12 +860,12 @@ gnutls_x509_privkey_sec_param (gnutls_x509_privkey_t key) switch (key->pk_algorithm) { case GNUTLS_PK_RSA: - ret = gnutls_pk_bits_to_sec_param (GNUTLS_PK_RSA, _gnutls_mpi_get_nbits (key->params[0] /*m */ - )); + ret = gnutls_pk_bits_to_sec_param (GNUTLS_PK_RSA, _gnutls_mpi_get_nbits (key->params[0] /*m */ + )); break; case GNUTLS_PK_DSA: - ret = gnutls_pk_bits_to_sec_param (GNUTLS_PK_DSA, _gnutls_mpi_get_nbits (key->params[0] /*p */ - )); + ret = gnutls_pk_bits_to_sec_param (GNUTLS_PK_DSA, _gnutls_mpi_get_nbits (key->params[0] /*p */ + )); break; default: ret = GNUTLS_SEC_PARAM_UNKNOWN; @@ -893,13 +893,13 @@ gnutls_x509_privkey_sec_param (gnutls_x509_privkey_t key) **/ int gnutls_x509_privkey_export_rsa_raw (gnutls_x509_privkey_t key, - 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) { return gnutls_x509_privkey_export_rsa_raw2 (key, m, e, d, p, q, u, NULL, - NULL); + NULL); } /** @@ -923,10 +923,10 @@ gnutls_x509_privkey_export_rsa_raw (gnutls_x509_privkey_t key, **/ int gnutls_x509_privkey_export_rsa_raw2 (gnutls_x509_privkey_t key, - 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 * e1, gnutls_datum_t * e2) + 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 * e1, gnutls_datum_t * e2) { int ret; gnutls_pk_params_st pk_params; @@ -1008,10 +1008,10 @@ gnutls_x509_privkey_export_rsa_raw2 (gnutls_x509_privkey_t key, { ret = _gnutls_mpi_dprint_lz (key->params[6], e1); if (ret < 0) - { - gnutls_assert (); - goto error; - } + { + gnutls_assert (); + goto error; + } } /* E2 */ @@ -1019,10 +1019,10 @@ gnutls_x509_privkey_export_rsa_raw2 (gnutls_x509_privkey_t key, { ret = _gnutls_mpi_dprint_lz (key->params[7], e2); if (ret < 0) - { - gnutls_assert (); - goto error; - } + { + gnutls_assert (); + goto error; + } } gnutls_pk_params_release (&pk_params); @@ -1058,9 +1058,9 @@ error: **/ int gnutls_x509_privkey_export_dsa_raw (gnutls_x509_privkey_t key, - 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 ret; @@ -1241,7 +1241,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) /* Write PRIME */ if ((result = asn1_write_value (*c2, "modulus", - m.data, m.size)) != ASN1_SUCCESS) + m.data, m.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1249,7 +1249,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "publicExponent", - e.data, e.size)) != ASN1_SUCCESS) + e.data, e.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1257,7 +1257,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "privateExponent", - d.data, d.size)) != ASN1_SUCCESS) + d.data, d.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1265,7 +1265,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "prime1", - p.data, p.size)) != ASN1_SUCCESS) + p.data, p.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1273,7 +1273,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "prime2", - q.data, q.size)) != ASN1_SUCCESS) + q.data, q.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1281,7 +1281,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "coefficient", - u.data, u.size)) != ASN1_SUCCESS) + u.data, u.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1290,7 +1290,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "exponent1", - exp1.data, exp1.size)) != ASN1_SUCCESS) + exp1.data, exp1.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1298,7 +1298,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "exponent2", - exp2.data, exp2.size)) != ASN1_SUCCESS) + exp2.data, exp2.size)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1306,7 +1306,7 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "otherPrimeInfos", - NULL, 0)) != ASN1_SUCCESS) + NULL, 0)) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1437,7 +1437,7 @@ _gnutls_asn1_encode_dsa (ASN1_TYPE * c2, bigint_t * params) } if ((result = asn1_write_value (*c2, "priv", - x_data, size[4])) != ASN1_SUCCESS) + x_data, size[4])) != ASN1_SUCCESS) { gnutls_assert (); result = _gnutls_asn2err (result); @@ -1480,8 +1480,8 @@ cleanup: **/ int gnutls_x509_privkey_generate (gnutls_x509_privkey_t key, - gnutls_pk_algorithm_t algo, unsigned int bits, - unsigned int flags) + gnutls_pk_algorithm_t algo, unsigned int bits, + unsigned int flags) { int ret; unsigned int params_len = MAX_PRIV_PARAMS_SIZE; @@ -1498,26 +1498,26 @@ gnutls_x509_privkey_generate (gnutls_x509_privkey_t key, case GNUTLS_PK_DSA: ret = _gnutls_dsa_generate_params (key->params, ¶ms_len, bits); if (params_len != DSA_PRIVATE_PARAMS) - { - gnutls_assert (); - ret = GNUTLS_E_INTERNAL_ERROR; - } + { + gnutls_assert (); + ret = GNUTLS_E_INTERNAL_ERROR; + } if (ret < 0) - { - gnutls_assert (); - return ret; - } + { + gnutls_assert (); + return ret; + } if (!key->crippled) - { - ret = _gnutls_asn1_encode_dsa (&key->key, key->params); - if (ret < 0) - { - gnutls_assert (); - goto cleanup; - } - } + { + ret = _gnutls_asn1_encode_dsa (&key->key, key->params); + if (ret < 0) + { + gnutls_assert (); + goto cleanup; + } + } key->params_size = params_len; key->pk_algorithm = GNUTLS_PK_DSA; @@ -1525,25 +1525,25 @@ gnutls_x509_privkey_generate (gnutls_x509_privkey_t key, case GNUTLS_PK_RSA: ret = _gnutls_rsa_generate_params (key->params, ¶ms_len, bits); if (params_len != RSA_PRIVATE_PARAMS) - { - gnutls_assert (); - ret = GNUTLS_E_INTERNAL_ERROR; - } + { + gnutls_assert (); + ret = GNUTLS_E_INTERNAL_ERROR; + } if (ret < 0) - { - gnutls_assert (); - return ret; - } + { + gnutls_assert (); + return ret; + } if (!key->crippled) - { - ret = _gnutls_asn1_encode_rsa (&key->key, key->params); - if (ret < 0) - { - gnutls_assert (); - goto cleanup; - } - } + { + ret = _gnutls_asn1_encode_rsa (&key->key, key->params); + if (ret < 0) + { + gnutls_assert (); + goto cleanup; + } + } key->params_size = params_len; key->pk_algorithm = GNUTLS_PK_RSA; @@ -1587,9 +1587,9 @@ cleanup: **/ int gnutls_x509_privkey_get_key_id (gnutls_x509_privkey_t key, - unsigned int flags, - unsigned char *output_data, - size_t * output_data_size) + unsigned int flags, + unsigned char *output_data, + size_t * output_data_size) { int result; digest_hd_st hd; @@ -1611,23 +1611,23 @@ gnutls_x509_privkey_get_key_id (gnutls_x509_privkey_t key, if (key->pk_algorithm == GNUTLS_PK_RSA) { result = - _gnutls_x509_write_rsa_params (key->params, key->params_size, &der); + _gnutls_x509_write_rsa_params (key->params, key->params_size, &der); if (result < 0) - { - gnutls_assert (); - goto cleanup; - } + { + gnutls_assert (); + goto cleanup; + } } else if (key->pk_algorithm == GNUTLS_PK_DSA) { result = - _gnutls_x509_write_dsa_public_key (key->params, - key->params_size, &der); + _gnutls_x509_write_dsa_public_key (key->params, + key->params_size, &der); if (result < 0) - { - gnutls_assert (); - goto cleanup; - } + { + gnutls_assert (); + goto cleanup; + } } else return GNUTLS_E_INTERNAL_ERROR; @@ -1681,22 +1681,24 @@ cleanup: **/ int gnutls_x509_privkey_sign_data2 (gnutls_x509_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(signer->pk_algorithm, hash, signer->params, data, &digest); + ret = + pk_hash_data (signer->pk_algorithm, hash, signer->params, data, &digest); if (ret < 0) { - gnutls_assert(); + gnutls_assert (); return ret; } - ret = gnutls_x509_privkey_sign_hash2(signer, hash, flags, &digest, signature); + ret = + gnutls_x509_privkey_sign_hash2 (signer, hash, flags, &digest, signature); if (ret < 0) { gnutls_assert (); @@ -1726,8 +1728,8 @@ cleanup: -*/ int gnutls_x509_privkey_sign_hash (gnutls_x509_privkey_t key, - const gnutls_datum_t * hash, - gnutls_datum_t * signature) + const gnutls_datum_t * hash, + gnutls_datum_t * signature) { int result; @@ -1738,7 +1740,7 @@ gnutls_x509_privkey_sign_hash (gnutls_x509_privkey_t key, } result = _gnutls_soft_sign (key->pk_algorithm, key->params, - key->params_size, hash, signature); + key->params_size, hash, signature); if (result < 0) { gnutls_assert (); @@ -1772,22 +1774,22 @@ gnutls_x509_privkey_sign_hash (gnutls_x509_privkey_t key, **/ int gnutls_x509_privkey_sign_hash2 (gnutls_x509_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 (signer->pk_algorithm, hash_algo, &digest); if (ret < 0) @@ -1797,7 +1799,7 @@ gnutls_x509_privkey_sign_hash2 (gnutls_x509_privkey_t signer, } ret = _gnutls_soft_sign (signer->pk_algorithm, signer->params, - signer->params_size, &digest, signature); + signer->params_size, &digest, signature); if (ret < 0) { @@ -1808,7 +1810,7 @@ gnutls_x509_privkey_sign_hash2 (gnutls_x509_privkey_t signer, ret = 0; cleanup: - _gnutls_free_datum(&digest); + _gnutls_free_datum (&digest); return ret; } @@ -1840,10 +1842,10 @@ cleanup: **/ int gnutls_x509_privkey_sign_data (gnutls_x509_privkey_t key, - gnutls_digest_algorithm_t digest, - unsigned int flags, - const gnutls_datum_t * data, - void *signature, size_t * signature_size) + gnutls_digest_algorithm_t digest, + unsigned int flags, + const gnutls_datum_t * data, + void *signature, size_t * signature_size) { int result; gnutls_datum_t sig = { NULL, 0 }; @@ -1892,9 +1894,9 @@ gnutls_x509_privkey_sign_data (gnutls_x509_privkey_t key, **/ int gnutls_x509_privkey_verify_data (gnutls_x509_privkey_t key, - unsigned int flags, - const gnutls_datum_t * data, - const gnutls_datum_t * signature) + unsigned int flags, + const gnutls_datum_t * data, + const gnutls_datum_t * signature) { int result; @@ -1942,18 +1944,18 @@ gnutls_x509_privkey_fix (gnutls_x509_privkey_t key) case GNUTLS_PK_DSA: ret = _gnutls_asn1_encode_dsa (&key->key, key->params); if (ret < 0) - { - gnutls_assert (); - return ret; - } + { + gnutls_assert (); + return ret; + } break; case GNUTLS_PK_RSA: ret = _gnutls_asn1_encode_rsa (&key->key, key->params); if (ret < 0) - { - gnutls_assert (); - return ret; - } + { + gnutls_assert (); + return ret; + } break; default: gnutls_assert (); |