Use EC_GROUP_dup and EC_POINT_dup in EC_KEY_copy.

They do the same thing. This removes all callers of EC_GROUP_copy outside
EC_GROUP_dup.

Change-Id: I65433ee36040de79e56483dfece774e01e2e2743
Reviewed-on: https://boringssl-review.googlesource.com/3630
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index 7f4ffe6..050d77f 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -170,35 +170,27 @@
     OPENSSL_PUT_ERROR(EC, EC_KEY_copy, ERR_R_PASSED_NULL_PARAMETER);
     return NULL;
   }
-  /* copy the parameters */
+  /* Copy the parameters. */
   if (src->group) {
     /* TODO(fork): duplicating the group seems wasteful. */
-    const EC_METHOD *meth = src->group->meth;
-    /* clear the old group */
     if (dest->group) {
       EC_GROUP_free(dest->group);
     }
-    dest->group = ec_group_new(meth);
+    dest->group = EC_GROUP_dup(src->group);
     if (dest->group == NULL) {
       return NULL;
     }
-    if (!EC_GROUP_copy(dest->group, src->group)) {
-      return NULL;
-    }
   }
 
-  /*  copy the public key */
+  /* Copy the public key. */
   if (src->pub_key && src->group) {
     if (dest->pub_key) {
       EC_POINT_free(dest->pub_key);
     }
-    dest->pub_key = EC_POINT_new(src->group);
+    dest->pub_key = EC_POINT_dup(src->pub_key, src->group);
     if (dest->pub_key == NULL) {
       return NULL;
     }
-    if (!EC_POINT_copy(dest->pub_key, src->pub_key)) {
-      return NULL;
-    }
   }
 
   /* copy the private key */