Deleted Added
full compact
ec_asn1.c (267256) ec_asn1.c (273144)
1/* crypto/ec/ec_asn1.c */
2/*
3 * Written by Nils Larsch for the OpenSSL project.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 1169 unchanged lines hidden (view full) ---

1178 }
1179 else
1180 {
1181 ECerr(EC_F_D2I_ECPRIVATEKEY,
1182 EC_R_MISSING_PRIVATE_KEY);
1183 goto err;
1184 }
1185
1/* crypto/ec/ec_asn1.c */
2/*
3 * Written by Nils Larsch for the OpenSSL project.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 1169 unchanged lines hidden (view full) ---

1178 }
1179 else
1180 {
1181 ECerr(EC_F_D2I_ECPRIVATEKEY,
1182 EC_R_MISSING_PRIVATE_KEY);
1183 goto err;
1184 }
1185
1186 if (ret->pub_key)
1187 EC_POINT_clear_free(ret->pub_key);
1188 ret->pub_key = EC_POINT_new(ret->group);
1189 if (ret->pub_key == NULL)
1190 {
1191 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
1192 goto err;
1193 }
1194
1186 if (priv_key->publicKey)
1187 {
1188 const unsigned char *pub_oct;
1195 if (priv_key->publicKey)
1196 {
1197 const unsigned char *pub_oct;
1189 size_t pub_oct_len;
1198 int pub_oct_len;
1190
1199
1191 if (ret->pub_key)
1192 EC_POINT_clear_free(ret->pub_key);
1193 ret->pub_key = EC_POINT_new(ret->group);
1194 if (ret->pub_key == NULL)
1200 pub_oct = M_ASN1_STRING_data(priv_key->publicKey);
1201 pub_oct_len = M_ASN1_STRING_length(priv_key->publicKey);
1202 /* The first byte - point conversion form - must be present. */
1203 if (pub_oct_len <= 0)
1195 {
1204 {
1196 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
1205 ECerr(EC_F_D2I_ECPRIVATEKEY, EC_R_BUFFER_TOO_SMALL);
1197 goto err;
1198 }
1206 goto err;
1207 }
1199 pub_oct = M_ASN1_STRING_data(priv_key->publicKey);
1200 pub_oct_len = M_ASN1_STRING_length(priv_key->publicKey);
1201 /* save the point conversion form */
1208 /* Save the point conversion form. */
1202 ret->conv_form = (point_conversion_form_t)(pub_oct[0] & ~0x01);
1203 if (!EC_POINT_oct2point(ret->group, ret->pub_key,
1209 ret->conv_form = (point_conversion_form_t)(pub_oct[0] & ~0x01);
1210 if (!EC_POINT_oct2point(ret->group, ret->pub_key,
1204 pub_oct, pub_oct_len, NULL))
1211 pub_oct, (size_t)(pub_oct_len), NULL))
1205 {
1206 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
1207 goto err;
1208 }
1209 }
1212 {
1213 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
1214 goto err;
1215 }
1216 }
1217 else
1218 {
1219 if (!EC_POINT_mul(ret->group, ret->pub_key, ret->priv_key, NULL, NULL, NULL))
1220 {
1221 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
1222 goto err;
1223 }
1224 /* Remember the original private-key-only encoding. */
1225 ret->enc_flag |= EC_PKEY_NO_PUBKEY;
1226 }
1210
1211 ok = 1;
1212err:
1213 if (!ok)
1214 {
1215 if (ret)
1216 EC_KEY_free(ret);
1217 ret = NULL;

--- 7 unchanged lines hidden (view full) ---

1225
1226int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
1227 {
1228 int ret=0, ok=0;
1229 unsigned char *buffer=NULL;
1230 size_t buf_len=0, tmp_len;
1231 EC_PRIVATEKEY *priv_key=NULL;
1232
1227
1228 ok = 1;
1229err:
1230 if (!ok)
1231 {
1232 if (ret)
1233 EC_KEY_free(ret);
1234 ret = NULL;

--- 7 unchanged lines hidden (view full) ---

1242
1243int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
1244 {
1245 int ret=0, ok=0;
1246 unsigned char *buffer=NULL;
1247 size_t buf_len=0, tmp_len;
1248 EC_PRIVATEKEY *priv_key=NULL;
1249
1233 if (a == NULL || a->group == NULL || a->priv_key == NULL)
1250 if (a == NULL || a->group == NULL || a->priv_key == NULL ||
1251 (!(a->enc_flag & EC_PKEY_NO_PUBKEY) && a->pub_key == NULL))
1234 {
1235 ECerr(EC_F_I2D_ECPRIVATEKEY,
1236 ERR_R_PASSED_NULL_PARAMETER);
1237 goto err;
1238 }
1239
1240 if ((priv_key = EC_PRIVATEKEY_new()) == NULL)
1241 {

--- 207 unchanged lines hidden ---
1252 {
1253 ECerr(EC_F_I2D_ECPRIVATEKEY,
1254 ERR_R_PASSED_NULL_PARAMETER);
1255 goto err;
1256 }
1257
1258 if ((priv_key = EC_PRIVATEKEY_new()) == NULL)
1259 {

--- 207 unchanged lines hidden ---