simplify asn1_flag
authorBodo Möller <bodo@openssl.org>
Wed, 12 Jun 2002 14:01:17 +0000 (14:01 +0000)
committerBodo Möller <bodo@openssl.org>
Wed, 12 Jun 2002 14:01:17 +0000 (14:01 +0000)
Submitted by: Nils Larsch
Reviewed by: Bodo Moeller

CHANGES
apps/ecdsaparam.c
crypto/asn1/x_pubkey.c
crypto/ec/ec.h
crypto/ec/ec_asn1.c
crypto/ec/ec_lcl.h
crypto/ec/ec_lib.c

diff --git a/CHANGES b/CHANGES
index 4a47eac400233620474863aa3508cca9085e1b5b..512b802f71c460e7af6cc9d5ba7cfc31ce2bf9f3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,12 +4,20 @@
 
  Changes between 0.9.7 and 0.9.8  [xx XXX 2002]
 
-  *) Add 'nid' and 'asn1_flag' members to EC_GROUP, and functions
-          EC_GROUP_get_nid()
-          EC_GROUP_get_set_asn1_flag()
-          EC_GROUP_get_get_asn1_flag()
-     'nid' is an optional NID for named curves.  'asn1_flag'
-     determines the encoding to be used for ASN1 purposes.
+  *) Add 'asn1_flag' and 'asn1_form' member to EC_GROUP with access
+     functions
+          EC_GROUP_set_asn1_flag()
+          EC_GROUP_get_asn1_flag()
+          EC_GROUP_set_point_conversion_form()
+          EC_GROUP_get_point_conversion_form()
+     These control ASN1 encoding details:
+     - Curve are encoded explicitly unless asn1_flag has been set to
+       OPENSSL_EC_NAMED_CURVE.
+     - Points are encoded in compressed form by default; options for
+       asn1_for are as for point2oct, namely
+          POINT_CONVERSION_COMPRESSED
+          POINT_CONVERSION_UNCOMPRESSED
+          POINT_CONVERSION_HYBRID
      [Nils Larsch <nla@trustcenter.de>]
 
   *) Add 'field_type' member to EC_METHOD, which holds the NID
@@ -69,8 +77,8 @@
      functions
           EC_GROUP_new_by_nid()
           EC_GROUP_new_by_name()
-     Also add a 'nid' field to EC_GROUP objects, which can be accessed
-     via
+     Also add a 'curve_name' member to EC_GROUP objects, which can be
+     accessed via
          EC_GROUP_set_nid()
          EC_GROUP_get_nid()
      [Nils Larsch <nla@trustcenter.de, Bodo Moeller]
index 9f78af668aa409b4808e1ae5387a6c0a5dc53923..ab6a428d0850af2aaa3fa6f693e120dac9837deb 100644 (file)
@@ -432,8 +432,7 @@ bad:
                ecdsa->group = EC_GROUP_new_by_name(curve_type);
                if (named_curve)
                        EC_GROUP_set_asn1_flag(ecdsa->group, 
-                                OPENSSL_EC_NAMED_CURVE |
-                               (EC_GROUP_get_asn1_flag(ecdsa->group) & ~0x3));
+                                               OPENSSL_EC_NAMED_CURVE);
        }
        else if (informat == FORMAT_ASN1)
                ecdsa = d2i_ECDSAParameters_bio(in,NULL);
index 13c753aff30e1b54625d759e7e51d15116eb7d7c..68ddeb43f20f94077683f4201adacf7d35e4c9d4 100644 (file)
@@ -145,7 +145,7 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
                        goto err;
                        }
 
-               if ((EC_GROUP_get_asn1_flag(ecdsa->group) & OPENSSL_EC_NAMED_CURVE) 
+               if (EC_GROUP_get_asn1_flag(ecdsa->group)
                      && (nid = EC_GROUP_get_nid(ecdsa->group)))
                        {
                        /* just set the OID */
@@ -312,8 +312,8 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
                        if ((ecdsa->group = EC_GROUP_new_by_name(
                              OBJ_obj2nid(a->parameter->value.object))) == NULL)
                                goto err;
-                       EC_GROUP_set_asn1_flag(ecdsa->group, OPENSSL_EC_NAMED_CURVE |
-                               (EC_GROUP_get_asn1_flag(ecdsa->group) & ~0x03));
+                       EC_GROUP_set_asn1_flag(ecdsa->group, 
+                                               OPENSSL_EC_NAMED_CURVE);
                        }
                        /* the case implicitlyCA is currently not implemented */
                ret->save_parameters = 1;
index 1d79dd6a47cf4298175b4995721055d895a4f6bb..e3bae734f1b3acd7a44734739be2e61a009f7f9f 100644 (file)
@@ -229,11 +229,7 @@ int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
 
 
 /* ASN1 stuff */
-#define OPENSSL_EC_EXPLICIT    0x001
-#define OPENSSL_EC_NAMED_CURVE 0x002
-#define OPENSSL_EC_COMPRESSED  0x010
-#define OPENSSL_EC_UNCOMPRESSED        0x020
-#define OPENSSL_EC_HYBRID      0x040
+#define OPENSSL_EC_NAMED_CURVE 0x001
 
 typedef struct ec_parameters_st ECPARAMETERS;
 typedef struct ecpk_parameters_st ECPKPARAMETERS;
@@ -249,6 +245,9 @@ ECPKPARAMETERS *EC_ASN1_group2pkparameters(const EC_GROUP *, ECPKPARAMETERS *);
 void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
 int EC_GROUP_get_asn1_flag(const EC_GROUP *);
 
+void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
+point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
+
 EC_GROUP *d2i_ECParameters(EC_GROUP **, const unsigned char **in, long len);
 int i2d_ECParameters(const EC_GROUP *, unsigned char **out);
 
index 9a8b7c9c7ae5aec855d793d05fe04e04c684341e..5a97e9f70a711ad9f0507f0a4893d4c2bf6bc778 100644 (file)
@@ -394,7 +394,7 @@ err :       if (!ok)
 static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group,
                                               ECPARAMETERS *param)
        {
-       int     ok=0, i;
+       int     ok=0;
        size_t  len=0;
        ECPARAMETERS   *ret=NULL;
        BIGNUM         *tmp=NULL;
@@ -455,15 +455,7 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group,
                goto err;
                }
 
-       i = EC_GROUP_get_asn1_flag(group);
-       if (i | OPENSSL_EC_COMPRESSED)
-               form = POINT_CONVERSION_COMPRESSED;
-       else if (i | OPENSSL_EC_UNCOMPRESSED)
-               form = POINT_CONVERSION_UNCOMPRESSED;
-       else if (i | OPENSSL_EC_HYBRID)
-               form = POINT_CONVERSION_HYBRID;
-       else 
-               goto err;
+       form = EC_GROUP_get_point_conversion_form(group);
 
        len = EC_POINT_point2oct(group, point, form, NULL, len, NULL);
        if (len == 0)
@@ -556,9 +548,7 @@ ECPKPARAMETERS *EC_ASN1_group2pkparameters(const EC_GROUP *group,
                        ECPARAMETERS_free(ret->value.parameters);
                }
 
-       tmp = EC_GROUP_get_asn1_flag(group);
-
-       if (tmp & OPENSSL_EC_NAMED_CURVE)
+       if (EC_GROUP_get_asn1_flag(group))
                {
                /* use the asn1 OID to describe the
                 * the elliptic curve parameters
@@ -581,7 +571,7 @@ ECPKPARAMETERS *EC_ASN1_group2pkparameters(const EC_GROUP *group,
                                ok = 0;
                        }
                }
-       else if (tmp & OPENSSL_EC_EXPLICIT)
+       else
                {       
                /* use the ECPARAMETERS structure */
                ret->type = 1;
@@ -589,8 +579,6 @@ ECPKPARAMETERS *EC_ASN1_group2pkparameters(const EC_GROUP *group,
                     group, NULL)) == NULL)
                        ok = 0;
                }
-       else
-               ok = 0;
 
        if (!ok)
                {
@@ -759,9 +747,7 @@ EC_GROUP *EC_ASN1_pkparameters2group(const ECPKPARAMETERS *params)
                              EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
                        return NULL;
                        }
-               tmp = EC_GROUP_get_asn1_flag(ret);
-               tmp = (tmp & ~0x03) | OPENSSL_EC_NAMED_CURVE;
-               EC_GROUP_set_asn1_flag(ret, tmp);
+               EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_NAMED_CURVE);
                }
        else if (params->type == 1)
                { /* the parameters are given by a ECPARAMETERS
@@ -772,9 +758,7 @@ EC_GROUP *EC_ASN1_pkparameters2group(const ECPKPARAMETERS *params)
                        ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, ERR_R_EC_LIB);
                        return NULL;
                        }
-               tmp = EC_GROUP_get_asn1_flag(ret);
-               tmp = (tmp & ~0x03) | OPENSSL_EC_EXPLICIT;
-               EC_GROUP_set_asn1_flag(ret, tmp);
+               EC_GROUP_set_asn1_flag(ret, 0x0);
                }
        else if (params->type == 2)
                { /* implicitlyCA */
index 037c7d95a6d95d2dd6e52f6d53506b93a0944852..1c2ae93bb6ab198d580694779208e441aba3061c 100644 (file)
@@ -144,8 +144,9 @@ struct ec_group_st {
        EC_POINT *generator; /* optional */
        BIGNUM order, cofactor;
 
-       int nid;       /* optional NID for named curve */
+       int curve_name;/* optional NID for named curve */
        int asn1_flag; /* flag to control the asn1 encoding */
+       point_conversion_form_t asn1_form;
 
        void *extra_data;
        void *(*extra_data_dup_func)(void *);
index 06d45e998f8326b0aa3d6d2afed1fd4f4a4f76ab..965c229dea7ef820401bdededc776bfc6ae696ea 100644 (file)
@@ -98,8 +98,9 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
        BN_init(&ret->order);
        BN_init(&ret->cofactor);
 
-       ret->nid = 0;   
-       ret->asn1_flag = OPENSSL_EC_EXPLICIT | OPENSSL_EC_COMPRESSED;
+       ret->curve_name = 0;    
+       ret->asn1_flag  = 0;
+       ret->asn1_form  = POINT_CONVERSION_COMPRESSED;
 
        ret->seed = NULL;
        ret->seed_len = 0;
@@ -214,8 +215,9 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
        if (!BN_copy(&dest->order, &src->order)) return 0;
        if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
 
-       dest->nid = src->nid;
-       dest->asn1_flag = src->asn1_flag;
+       dest->curve_name = src->curve_name;
+       dest->asn1_flag  = src->asn1_flag;
+       dest->asn1_form  = src->asn1_form;
 
        if (src->seed)
                {
@@ -308,13 +310,13 @@ int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
 
 void EC_GROUP_set_nid(EC_GROUP *group, int nid)
        {
-       group->nid = nid;
+       group->curve_name = nid;
        }
 
 
 int EC_GROUP_get_nid(const EC_GROUP *group)
        {
-       return group->nid;
+       return group->curve_name;
        }
 
 
@@ -330,6 +332,19 @@ int EC_GROUP_get_asn1_flag(const EC_GROUP *group)
        }
 
 
+void EC_GROUP_set_point_conversion_form(EC_GROUP *group, 
+                                        point_conversion_form_t form)
+       {
+       group->asn1_form = form;
+       }
+
+
+point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *group)
+       {
+       return group->asn1_form;
+       }
+
+
 int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
        {
        if (group->meth->group_set_curve_GFp == 0)