add support for named curves
[openssl.git] / crypto / ec / ec_lib.c
index e0d78d67fb9c3891860c3d83987dc0f1e65c34be..5cbc6874d2f7c4e7f39de8e818360343514628e7 100644 (file)
@@ -93,7 +93,11 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
        ret->extra_data_dup_func = 0;
        ret->extra_data_free_func = 0;
        ret->extra_data_clear_free_func = 0;
-       
+
+       ret->nid = 0;   
+
+       ret->references = 1;
+
        if (!meth->group_init(ret))
                {
                OPENSSL_free(ret);
@@ -106,6 +110,12 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
 
 void EC_GROUP_free(EC_GROUP *group)
        {
+       int i;
+
+       i = CRYPTO_add(&group->references, -1, CRYPTO_LOCK_EC);
+       if (i > 0)
+               return;
+       
        if (group->meth->group_finish != 0)
                group->meth->group_finish(group);
 
@@ -117,6 +127,12 @@ void EC_GROUP_free(EC_GROUP *group)
 
 void EC_GROUP_clear_free(EC_GROUP *group)
        {
+       int i;
+
+       i = CRYPTO_add(&group->references, -1, CRYPTO_LOCK_EC);
+       if (i > 0)
+               return;
+
        if (group->meth->group_clear_finish != 0)
                group->meth->group_clear_finish(group);
        else if (group->meth != NULL && group->meth->group_finish != 0)
@@ -297,6 +313,16 @@ void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
        group->extra_data_clear_free_func = 0;
        }
 
+void EC_GROUP_set_nid(EC_GROUP *group, int nid)
+{
+       group->nid = nid;
+}
+
+int EC_GROUP_get_nid(const EC_GROUP *group)
+{
+       return group->nid;
+}
+
 
 
 /* functions for EC_POINT objects */