~ubuntu-branches/ubuntu/precise/gnutls28/precise

« back to all changes in this revision

Viewing changes to lib/gnutls_pubkey.c

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-09-20 19:37:06 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20110920193706-a9phjijvddzg3nkl
Tags: 3.0.3-1
* New upstream version. (Includes a fix for #640639)
* Bump shlibs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <x509/common.h>
35
35
#include <x509_b64.h>
36
36
#include <abstract_int.h>
 
37
#include <gnutls_ecc.h>
37
38
 
38
39
#define PK_PEM_HEADER "PUBLIC KEY"
39
40
 
299
300
                                          &obj->pubkey[1],
300
301
                                          &obj->pubkey[2], &obj->pubkey[3]);
301
302
      break;
 
303
    case GNUTLS_PK_ECC:
 
304
      ret = gnutls_pubkey_import_ecc_x962 (key, &obj->pubkey[0],
 
305
                                          &obj->pubkey[1]);
 
306
      break;
302
307
    default:
303
308
      gnutls_assert ();
304
309
      return GNUTLS_E_UNIMPLEMENTED_FEATURE;
753
758
}
754
759
 
755
760
/**
 
761
 * gnutls_pubkey_get_pk_ecc_x962:
 
762
 * @key: Holds the public key
 
763
 * @parameters: DER encoding of an ANSI X9.62 parameters
 
764
 * @ecpoint: DER encoding of ANSI X9.62 ECPoint
 
765
 *
 
766
 * This function will export the ECC public key's parameters found in
 
767
 * the given certificate.  The new parameters will be allocated using
 
768
 * gnutls_malloc() and will be stored in the appropriate datum.
 
769
 *
 
770
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
 
771
 *
 
772
 * Since: 3.0.0
 
773
 **/
 
774
int gnutls_pubkey_get_pk_ecc_x962 (gnutls_pubkey_t key, gnutls_datum_t* parameters,
 
775
                                   gnutls_datum_t * ecpoint)
 
776
{
 
777
  int ret;
 
778
 
 
779
  if (key == NULL || key->pk_algorithm != GNUTLS_PK_ECC)
 
780
    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
 
781
 
 
782
  ret = _gnutls_x509_write_ecc_pubkey(&key->params, ecpoint);
 
783
  if (ret < 0)
 
784
    return gnutls_assert_val(ret);
 
785
    
 
786
  ret = _gnutls_x509_write_ecc_params(&key->params, parameters);
 
787
  if (ret < 0)
 
788
    {
 
789
      _gnutls_free_datum(ecpoint);
 
790
      return gnutls_assert_val(ret);
 
791
    }
 
792
  
 
793
  return 0;
 
794
}
 
795
 
 
796
/**
756
797
 * gnutls_pubkey_import:
757
798
 * @key: The structure to store the parsed public key. 
758
799
 * @data: The DER or PEM encoded certificate. 
1060
1101
}
1061
1102
 
1062
1103
/**
 
1104
 * gnutls_pubkey_import_ecc_raw:
 
1105
 * @key: The structure to store the parsed key
 
1106
 * @curve: holds the curve
 
1107
 * @x: holds the x
 
1108
 * @y: holds the y
 
1109
 *
 
1110
 * This function will convert the given elliptic curve parameters to a
 
1111
 * #gnutls_pubkey_t.  The output will be stored in @key.
 
1112
 *
 
1113
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
 
1114
 *   negative error value.
 
1115
 *
 
1116
 * Since: 3.0.0
 
1117
 **/
 
1118
int
 
1119
gnutls_pubkey_import_ecc_raw (gnutls_pubkey_t key,
 
1120
                              gnutls_ecc_curve_t curve,
 
1121
                              const gnutls_datum_t * x,
 
1122
                              const gnutls_datum_t * y)
 
1123
{
 
1124
  int ret;
 
1125
 
 
1126
  if (key == NULL)
 
1127
    {
 
1128
      gnutls_assert ();
 
1129
      return GNUTLS_E_INVALID_REQUEST;
 
1130
    }
 
1131
 
 
1132
  key->params.flags = curve;
 
1133
 
 
1134
  ret = _gnutls_ecc_curve_fill_params(curve, &key->params);
 
1135
  if (ret < 0)
 
1136
    return gnutls_assert_val(ret);
 
1137
 
 
1138
  if (_gnutls_mpi_scan_nz (&key->params.params[5], x->data, x->size))
 
1139
    {
 
1140
      gnutls_assert ();
 
1141
      ret = GNUTLS_E_MPI_SCAN_FAILED;
 
1142
      goto cleanup;
 
1143
    }
 
1144
  key->params.params_nr++;
 
1145
 
 
1146
  if (_gnutls_mpi_scan_nz (&key->params.params[6], y->data, y->size))
 
1147
    {
 
1148
      gnutls_assert ();
 
1149
      ret = GNUTLS_E_MPI_SCAN_FAILED;
 
1150
      goto cleanup;
 
1151
    }
 
1152
  key->params.params_nr++;
 
1153
  key->pk_algorithm = GNUTLS_PK_ECC;
 
1154
 
 
1155
  return 0;
 
1156
 
 
1157
cleanup:
 
1158
  gnutls_pk_params_release(&key->params);
 
1159
  return ret;
 
1160
}
 
1161
 
 
1162
/**
 
1163
 * gnutls_pubkey_import_ecc_x962:
 
1164
 * @key: The structure to store the parsed key
 
1165
 * @parameters: DER encoding of an ANSI X9.62 parameters
 
1166
 * @ecpoint: DER encoding of ANSI X9.62 ECPoint
 
1167
 *
 
1168
 * This function will convert the given elliptic curve parameters to a
 
1169
 * #gnutls_pubkey_t.  The output will be stored in @key.
 
1170
 *
 
1171
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
 
1172
 *   negative error value.
 
1173
 *
 
1174
 * Since: 3.0.0
 
1175
 **/
 
1176
int
 
1177
gnutls_pubkey_import_ecc_x962 (gnutls_pubkey_t key,
 
1178
                               const gnutls_datum_t * parameters,
 
1179
                               const gnutls_datum_t * ecpoint)
 
1180
{
 
1181
  int ret;
 
1182
 
 
1183
  if (key == NULL)
 
1184
    {
 
1185
      gnutls_assert ();
 
1186
      return GNUTLS_E_INVALID_REQUEST;
 
1187
    }
 
1188
 
 
1189
  key->params.params_nr = 0;
 
1190
 
 
1191
  ret = _gnutls_x509_read_ecc_params(parameters->data, parameters->size,
 
1192
                                     &key->params);
 
1193
  if (ret < 0)
 
1194
    {
 
1195
      gnutls_assert ();
 
1196
      goto cleanup;
 
1197
    }
 
1198
 
 
1199
  ret = _gnutls_ecc_ansi_x963_import(ecpoint->data, ecpoint->size,
 
1200
         &key->params.params[5], &key->params.params[6]);
 
1201
  if (ret < 0)
 
1202
    {
 
1203
      gnutls_assert ();
 
1204
      goto cleanup;
 
1205
    }
 
1206
  key->params.params_nr+=2;
 
1207
  key->pk_algorithm = GNUTLS_PK_ECC;
 
1208
 
 
1209
  return 0;
 
1210
 
 
1211
cleanup:
 
1212
  gnutls_pk_params_release(&key->params);
 
1213
  return ret;
 
1214
}
 
1215
 
 
1216
/**
1063
1217
 * gnutls_pubkey_import_dsa_raw:
1064
1218
 * @key: The structure to store the parsed key
1065
1219
 * @p: holds the p