summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBodo Möller <bodo@openssl.org>2002-08-07 10:49:54 +0000
committerBodo Möller <bodo@openssl.org>2002-08-07 10:49:54 +0000
commit14a7cfb32a0347a4bc620ae1b552b21c4c1e270b (patch)
tree13c4bcc3d58ba7db5e598cd668670873b51e8ce3 /apps
parent7a8645d1716d7f84435b0f3d8d2fd122d6f75113 (diff)
use a generic EC_KEY structure (EC keys are not ECDSA specific)
Submitted by: Nils Larsch
Diffstat (limited to 'apps')
-rw-r--r--apps/ecdsa.c40
-rw-r--r--apps/ecparam.c31
-rw-r--r--apps/req.c45
3 files changed, 61 insertions, 55 deletions
diff --git a/apps/ecdsa.c b/apps/ecdsa.c
index 91c8d1d7d7..f54590d61f 100644
--- a/apps/ecdsa.c
+++ b/apps/ecdsa.c
@@ -60,8 +60,8 @@
#include "apps.h"
#include <openssl/bio.h>
#include <openssl/err.h>
-#include <openssl/ecdsa.h>
#include <openssl/evp.h>
+#include <openssl/ecdsa.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
@@ -85,7 +85,7 @@ int MAIN(int argc, char **argv)
{
ENGINE *e = NULL;
int ret = 1;
- ECDSA *ecdsa = NULL;
+ EC_KEY *eckey = NULL;
int i, badops = 0;
const EVP_CIPHER *enc = NULL;
BIO *in = NULL, *out = NULL;
@@ -279,17 +279,17 @@ bad:
if (informat == FORMAT_ASN1)
{
if (pubin)
- ecdsa = d2i_ECDSA_PUBKEY_bio(in, NULL);
+ eckey = d2i_EC_PUBKEY_bio(in, NULL);
else
- ecdsa = d2i_ECDSAPrivateKey_bio(in, NULL);
+ eckey = d2i_ECPrivateKey_bio(in, NULL);
}
else if (informat == FORMAT_PEM)
{
if (pubin)
- ecdsa = PEM_read_bio_ECDSA_PUBKEY(in, NULL, NULL,
+ eckey = PEM_read_bio_EC_PUBKEY(in, NULL, NULL,
NULL);
else
- ecdsa = PEM_read_bio_ECDSAPrivateKey(in, NULL, NULL,
+ eckey = PEM_read_bio_ECPrivateKey(in, NULL, NULL,
passin);
}
else
@@ -297,7 +297,7 @@ bad:
BIO_printf(bio_err, "bad input format specified for key\n");
goto end;
}
- if (ecdsa == NULL)
+ if (eckey == NULL)
{
BIO_printf(bio_err,"unable to load Key\n");
ERR_print_errors(bio_err);
@@ -325,15 +325,15 @@ bad:
if (new_form)
{
- EC_GROUP_set_point_conversion_form(ecdsa->group, form);
- ECDSA_set_conversion_form(ecdsa, form);
+ EC_GROUP_set_point_conversion_form(eckey->group, form);
+ eckey->conv_form = form;
}
if (new_asn1_flag)
- EC_GROUP_set_asn1_flag(ecdsa->group, asn1_flag);
+ EC_GROUP_set_asn1_flag(eckey->group, asn1_flag);
if (text)
- if (!ECDSA_print(out, ecdsa, 0))
+ if (!EC_KEY_print(out, eckey, 0))
{
perror(outfile);
ERR_print_errors(bio_err);
@@ -343,24 +343,24 @@ bad:
if (noout)
goto end;
- BIO_printf(bio_err, "writing ECDSA key\n");
+ BIO_printf(bio_err, "writing EC key\n");
if (outformat == FORMAT_ASN1)
{
if (param_out)
- i = i2d_ECPKParameters_bio(out, ecdsa->group);
+ i = i2d_ECPKParameters_bio(out, eckey->group);
else if (pubin || pubout)
- i = i2d_ECDSA_PUBKEY_bio(out, ecdsa);
+ i = i2d_EC_PUBKEY_bio(out, eckey);
else
- i = i2d_ECDSAPrivateKey_bio(out, ecdsa);
+ i = i2d_ECPrivateKey_bio(out, eckey);
}
else if (outformat == FORMAT_PEM)
{
if (param_out)
- i = PEM_write_bio_ECPKParameters(out, ecdsa->group);
+ i = PEM_write_bio_ECPKParameters(out, eckey->group);
else if (pubin || pubout)
- i = PEM_write_bio_ECDSA_PUBKEY(out, ecdsa);
+ i = PEM_write_bio_EC_PUBKEY(out, eckey);
else
- i = PEM_write_bio_ECDSAPrivateKey(out, ecdsa, enc,
+ i = PEM_write_bio_ECPrivateKey(out, eckey, enc,
NULL, 0, NULL, passout);
}
else
@@ -382,8 +382,8 @@ end:
BIO_free(in);
if (out)
BIO_free_all(out);
- if (ecdsa)
- ECDSA_free(ecdsa);
+ if (eckey)
+ EC_KEY_free(eckey);
if (passin)
OPENSSL_free(passin);
if (passout)
diff --git a/apps/ecparam.c b/apps/ecparam.c
index 4c3054ef50..228791decd 100644
--- a/apps/ecparam.c
+++ b/apps/ecparam.c
@@ -1,4 +1,7 @@
/* apps/ecparam.c */
+/*
+ * Originally written by Nils Larsch for the OpenSSL project.
+ */
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
@@ -78,7 +81,7 @@
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
-#ifndef OPENSSL_NO_ECDSA
+#ifndef OPENSSL_NO_EC
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -89,7 +92,9 @@
#include <openssl/err.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
+#ifndef OPENSSL_NO_ECDSA
#include <openssl/ecdsa.h>
+#endif
#include <openssl/x509.h>
#include <openssl/pem.h>
@@ -673,36 +678,36 @@ bad:
if (genkey)
{
- ECDSA *ecdsa = ECDSA_new();
+ EC_KEY *eckey = EC_KEY_new();
- if (ecdsa == NULL)
+ if (eckey == NULL)
goto end;
assert(need_rand);
- ecdsa->group = group;
+ eckey->group = group;
- if (!ECDSA_generate_key(ecdsa))
+ if (!EC_KEY_generate_key(eckey))
{
- ecdsa->group = NULL;
- ECDSA_free(ecdsa);
+ eckey->group = NULL;
+ EC_KEY_free(eckey);
goto end;
}
if (outformat == FORMAT_ASN1)
- i = i2d_ECDSAPrivateKey_bio(out, ecdsa);
+ i = i2d_ECPrivateKey_bio(out, eckey);
else if (outformat == FORMAT_PEM)
- i = PEM_write_bio_ECDSAPrivateKey(out, ecdsa, NULL,
+ i = PEM_write_bio_ECPrivateKey(out, eckey, NULL,
NULL, 0, NULL, NULL);
else
{
BIO_printf(bio_err, "bad output format specified "
"for outfile\n");
- ecdsa->group = NULL;
- ECDSA_free(ecdsa);
+ eckey->group = NULL;
+ EC_KEY_free(eckey);
goto end;
}
- ecdsa->group = NULL;
- ECDSA_free(ecdsa);
+ eckey->group = NULL;
+ EC_KEY_free(eckey);
}
if (need_rand)
diff --git a/apps/req.c b/apps/req.c
index cc87923159..af2db1628b 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -142,7 +142,7 @@ static int batch=0;
#define TYPE_RSA 1
#define TYPE_DSA 2
#define TYPE_DH 3
-#define TYPE_ECDSA 4
+#define TYPE_EC 4
int MAIN(int, char **);
@@ -152,8 +152,8 @@ int MAIN(int argc, char **argv)
#ifndef OPENSSL_NO_DSA
DSA *dsa_params=NULL;
#endif
-#ifndef OPENSSL_NO_ECDSA
- ECDSA *ecdsa_params = NULL;
+#ifndef OPENSSL_NO_EC
+ EC_KEY *ec_params = NULL;
#endif
unsigned long nmflag = 0;
int ex=1,x509=0,days=30;
@@ -327,41 +327,41 @@ int MAIN(int argc, char **argv)
}
else
#endif
-#ifndef OPENSSL_NO_ECDSA
+#ifndef OPENSSL_NO_EC
if (strncmp("ecdsa:",p,4) == 0)
{
X509 *xtmp=NULL;
EVP_PKEY *dtmp;
- pkey_type=TYPE_ECDSA;
+ pkey_type=TYPE_EC;
p+=6;
if ((in=BIO_new_file(p,"r")) == NULL)
{
perror(p);
goto end;
}
- if ((ecdsa_params = ECDSA_new()) == NULL)
+ if ((ec_params = EC_KEY_new()) == NULL)
goto end;
- if ((ecdsa_params->group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL)) == NULL)
+ if ((ec_params->group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL)) == NULL)
{
- if (ecdsa_params)
- ECDSA_free(ecdsa_params);
+ if (ec_params)
+ EC_KEY_free(ec_params);
ERR_clear_error();
(void)BIO_reset(in);
if ((xtmp=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL)
{
- BIO_printf(bio_err,"unable to load ECDSA parameters from file\n");
+ BIO_printf(bio_err,"unable to load EC parameters from file\n");
goto end;
}
if ((dtmp=X509_get_pubkey(xtmp)) == NULL) goto end;
- if (dtmp->type == EVP_PKEY_ECDSA)
- ecdsa_params = ECDSAParameters_dup(dtmp->pkey.ecdsa);
+ if (dtmp->type == EVP_PKEY_EC)
+ ec_params = ECParameters_dup(dtmp->pkey.eckey);
EVP_PKEY_free(dtmp);
X509_free(xtmp);
- if (ecdsa_params == NULL)
+ if (ec_params == NULL)
{
- BIO_printf(bio_err,"Certificate does not contain ECDSA parameters\n");
+ BIO_printf(bio_err,"Certificate does not contain EC parameters\n");
goto end;
}
}
@@ -374,7 +374,7 @@ int MAIN(int argc, char **argv)
if (!order)
goto end;
- if (!EC_GROUP_get_order(ecdsa_params->group, order, NULL))
+ if (!EC_GROUP_get_order(ec_params->group, order, NULL))
goto end;
newkey = BN_num_bits(order);
BN_free(order);
@@ -745,12 +745,13 @@ bad:
dsa_params=NULL;
}
#endif
-#ifndef OPENSSL_NO_ECDSA
- if (pkey_type == TYPE_ECDSA)
+#ifndef OPENSSL_NO_EC
+ if (pkey_type == TYPE_EC)
{
- if (!ECDSA_generate_key(ecdsa_params)) goto end;
- if (!EVP_PKEY_assign_ECDSA(pkey, ecdsa_params)) goto end;
- ecdsa_params = NULL;
+ if (!EC_KEY_generate_key(ec_params)) goto end;
+ if (!EVP_PKEY_assign_EC_KEY(pkey, ec_params))
+ goto end;
+ ec_params = NULL;
}
#endif
@@ -1144,8 +1145,8 @@ end:
#ifndef OPENSSL_NO_DSA
if (dsa_params != NULL) DSA_free(dsa_params);
#endif
-#ifndef OPENSSL_NO_ECDSA
- if (ecdsa_params != NULL) ECDSA_free(ecdsa_params);
+#ifndef OPENSSL_NO_EC
+ if (ec_params != NULL) EC_KEY_free(ec_params);
#endif
apps_shutdown();
EXIT(ex);