Commit 9dd84053 authored by Nils Larsch's avatar Nils Larsch
Browse files

ecc api cleanup; summary:

- hide the EC_KEY structure definition in ec_lcl.c + add
  some functions to use/access the EC_KEY fields
- change the way how method specific data (ecdsa/ecdh) is
  attached to a EC_KEY
- add ECDSA_sign_ex and ECDSA_do_sign_ex functions with
  additional parameters for pre-computed values
- rebuild libeay.num from 0.9.7
parent 46a64376
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 * Written by Nils Larsch for the OpenSSL project.
 */
/* ====================================================================
 * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
 * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
@@ -89,6 +89,7 @@ int MAIN(int argc, char **argv)
#endif
	int 	ret = 1;
	EC_KEY 	*eckey = NULL;
	const EC_GROUP *group;
	int 	i, badops = 0;
	const EVP_CIPHER *enc = NULL;
	BIO 	*in = NULL, *out = NULL;
@@ -328,14 +329,13 @@ bad:
			}
		}

	group = EC_KEY_get0_group(eckey);

	if (new_form)
		{
		EC_GROUP_set_point_conversion_form(eckey->group, form);
		eckey->conv_form = form;
		}
		EC_KEY_set_conv_form(eckey, form);

	if (new_asn1_flag)
		EC_GROUP_set_asn1_flag(eckey->group, asn1_flag);
		EC_KEY_set_asn1_flag(eckey, asn1_flag);

	if (text) 
		if (!EC_KEY_print(out, eckey, 0))
@@ -352,7 +352,7 @@ bad:
	if (outformat == FORMAT_ASN1) 
		{
		if (param_out)
			i = i2d_ECPKParameters_bio(out, eckey->group);
			i = i2d_ECPKParameters_bio(out, group);
		else if (pubin || pubout) 
			i = i2d_EC_PUBKEY_bio(out, eckey);
		else 
@@ -361,7 +361,7 @@ bad:
	else if (outformat == FORMAT_PEM) 
		{
		if (param_out)
			i = PEM_write_bio_ECPKParameters(out, eckey->group);
			i = PEM_write_bio_ECPKParameters(out, group);
		else if (pubin || pubout)
			i = PEM_write_bio_EC_PUBKEY(out, eckey);
		else 
+3 −5
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 * Written by Nils Larsch for the OpenSSL project.
 */
/* ====================================================================
 * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
 * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
@@ -647,11 +647,11 @@ bad:

		assert(need_rand);

		eckey->group = group;
		if (EC_KEY_set_group(eckey, group) == 0)
			goto end;
		
		if (!EC_KEY_generate_key(eckey))
			{
			eckey->group = NULL;
			EC_KEY_free(eckey);
			goto end;
			}
@@ -664,11 +664,9 @@ bad:
			{
			BIO_printf(bio_err, "bad output format specified "
				"for outfile\n");
			eckey->group = NULL;
			EC_KEY_free(eckey);
			goto end;
			}
		eckey->group = NULL;
		EC_KEY_free(eckey);
		}

+12 −7
Original line number Diff line number Diff line
@@ -344,6 +344,7 @@ int MAIN(int argc, char **argv)
				{
				X509 *xtmp=NULL;
				EVP_PKEY *dtmp;
				EC_GROUP *group;

				pkey_type=TYPE_EC;
				p+=3;
@@ -354,9 +355,9 @@ int MAIN(int argc, char **argv)
					}
				if ((ec_params = EC_KEY_new()) == NULL)
					goto end;
				if ((ec_params->group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL)) == NULL)
				group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL);
				if (group == NULL)
					{
					if (ec_params)
					EC_KEY_free(ec_params);
					ERR_clear_error();
					(void)BIO_reset(in);
@@ -369,7 +370,7 @@ int MAIN(int argc, char **argv)
					if ((dtmp=X509_get_pubkey(xtmp))==NULL)
						goto end;
					if (dtmp->type == EVP_PKEY_EC)
						ec_params = ECParameters_dup(dtmp->pkey.eckey);
						ec_params = EC_KEY_dup(dtmp->pkey.ec);
					EVP_PKEY_free(dtmp);
					X509_free(xtmp);
					if (ec_params == NULL)
@@ -378,12 +379,16 @@ int MAIN(int argc, char **argv)
						goto end;
						}
					}
				else
					{
					if (EC_KEY_set_group(ec_params, group) == 0)
						goto end;
					EC_GROUP_free(group);
					}

				BIO_free(in);
				in=NULL;
				
				newkey = EC_GROUP_get_degree(ec_params->group);

				newkey = EC_GROUP_get_degree(EC_KEY_get0_group(ec_params));
				}
			else
#endif
+5 −13
Original line number Diff line number Diff line
@@ -981,13 +981,6 @@ bad:
		{
		EC_KEY *ecdh=NULL;

		ecdh = EC_KEY_new();
		if (ecdh == NULL)
			{
			BIO_printf(bio_err,"Could not create ECDH struct.\n");
			goto end;
			}

		if (named_curve)
			{
			int nid = OBJ_sn2nid(named_curve);
@@ -998,9 +991,8 @@ bad:
					named_curve);
				goto end;
				}

			ecdh->group = EC_GROUP_new_by_curve_name(nid);
			if (ecdh->group == NULL)
			ecdh = EC_KEY_new_by_curve_name(nid);
			if (ecdh == NULL)
				{
				BIO_printf(bio_err, "unable to create curve (%s)\n", 
					named_curve);
@@ -1008,15 +1000,15 @@ bad:
				}
			}

		if (ecdh->group != NULL)
		if (ecdh != NULL)
			{
			BIO_printf(bio_s_out,"Setting temp ECDH parameters\n");
			}
		else
			{
			BIO_printf(bio_s_out,"Using default temp ECDH parameters\n");
			ecdh->group=EC_GROUP_new_by_curve_name(NID_sect163r2);
			if (ecdh->group == NULL) 
			ecdh = EC_KEY_new_by_curve_name(NID_sect163r2);
			if (ecdh == NULL) 
				{
				BIO_printf(bio_err, "unable to create curve (sect163r2)\n");
				goto end;
+128 −150
Original line number Diff line number Diff line
@@ -2040,7 +2040,7 @@ int MAIN(int argc, char **argv)
		int ret;

		if (!ecdsa_doit[j]) continue; /* Ignore Curve */ 
		ecdsa[j] = EC_KEY_new();
		ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
		if (ecdsa[j] == NULL) 
			{
			BIO_printf(bio_err,"ECDSA failure.\n");
@@ -2049,18 +2049,8 @@ int MAIN(int argc, char **argv)
			} 
		else 
			{
			ecdsa[j]->group = EC_GROUP_new_by_curve_name(test_curves[j]);
			/* Could not obtain group information */
			if (ecdsa[j]->group == NULL) 
				{
				BIO_printf(bio_err,"ECDSA failure.Could not obtain group information\n");
				ERR_print_errors(bio_err);
				rsa_count=1;
				} 
			else 
				{
#if 1
				EC_GROUP_precompute_mult(ecdsa[j]->group, NULL);
			EC_KEY_precompute_mult(ecdsa[j], NULL);
#endif
			/* Perform ECDSA signature test */
			EC_KEY_generate_key(ecdsa[j]);
@@ -2145,7 +2135,6 @@ int MAIN(int argc, char **argv)
				}
			}
		}
		}
	if (rnd_fake) RAND_cleanup();
#endif

@@ -2158,8 +2147,8 @@ int MAIN(int argc, char **argv)
	for (j=0; j<EC_NUM; j++)
		{
		if (!ecdh_doit[j]) continue;
		ecdh_a[j] = EC_KEY_new();
		ecdh_b[j] = EC_KEY_new();
		ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
		ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
		if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
			{
			BIO_printf(bio_err,"ECDH failure.\n");
@@ -2168,17 +2157,6 @@ int MAIN(int argc, char **argv)
			}
		else
			{
			ecdh_a[j]->group = EC_GROUP_new_by_curve_name(test_curves[j]);
			if (ecdh_a[j]->group == NULL)
				{
				BIO_printf(bio_err,"ECDH failure.\n");
				ERR_print_errors(bio_err);
				rsa_count=1;
				}
			else
				{
				ecdh_b[j]->group = EC_GROUP_dup(ecdh_a[j]->group);

			/* generate two ECDH key pairs */
			if (!EC_KEY_generate_key(ecdh_a[j]) ||
				!EC_KEY_generate_key(ecdh_b[j]))
@@ -2194,7 +2172,7 @@ int MAIN(int argc, char **argv)
				 */
				int field_size, outlen;
				void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
					field_size = EC_GROUP_get_degree(ecdh_a[j]->group);
				field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
				if (field_size <= 24 * 8)
					{
					outlen = KDF1_SHA1_len;
@@ -2206,10 +2184,10 @@ int MAIN(int argc, char **argv)
					kdf = NULL;
					}
				secret_size_a = ECDH_compute_key(secret_a, outlen,
						ecdh_b[j]->pub_key,
					EC_KEY_get0_public_key(ecdh_b[j]),
					ecdh_a[j], kdf);
				secret_size_b = ECDH_compute_key(secret_b, outlen,
						ecdh_a[j]->pub_key,
					EC_KEY_get0_public_key(ecdh_a[j]),
					ecdh_b[j], kdf);
				if (secret_size_a != secret_size_b) 
					ecdh_checks = 0;
@@ -2240,7 +2218,7 @@ int MAIN(int argc, char **argv)
				for (count=0,run=1; COND(ecdh_c[j][0]); count++)
					{
					ECDH_compute_key(secret_a, outlen,
						ecdh_b[j]->pub_key,
					EC_KEY_get0_public_key(ecdh_b[j]),
					ecdh_a[j], kdf);
					}
				d=Time_F(STOP);
@@ -2250,7 +2228,7 @@ int MAIN(int argc, char **argv)
				rsa_count=count;
				}
			}
			}


		if (rsa_count <= 1)
			{
Loading