/* * Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */#include<string.h>#include<openssl/err.h>#include<openssl/opensslv.h>#include"ec_local.h"/* functions for EC_GROUP objects */EC_GROUP*EC_GROUP_new(constEC_METHOD*meth){EC_GROUP*ret;if(meth==NULL){ECerr(EC_F_EC_GROUP_NEW,EC_R_SLOT_FULL);returnNULL;}if(meth->group_init==0){ECerr(EC_F_EC_GROUP_NEW,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);returnNULL;}ret=OPENSSL_zalloc(sizeof(*ret));if(ret==NULL){ECerr(EC_F_EC_GROUP_NEW,ERR_R_MALLOC_FAILURE);returnNULL;}ret->meth=meth;if((ret->meth->flags&EC_FLAGS_CUSTOM_CURVE)==0){ret->order=BN_new();if(ret->order==NULL)gotoerr;ret->cofactor=BN_new();if(ret->cofactor==NULL)gotoerr;}ret->asn1_flag=OPENSSL_EC_NAMED_CURVE;ret->asn1_form=POINT_CONVERSION_UNCOMPRESSED;if(!meth->group_init(ret))gotoerr;returnret;err:BN_free(ret->order);BN_free(ret->cofactor);OPENSSL_free(ret);returnNULL;}voidEC_pre_comp_free(EC_GROUP*group){switch(group->pre_comp_type){casePCT_none:break;casePCT_nistz256:#ifdef ECP_NISTZ256_ASMEC_nistz256_pre_comp_free(group->pre_comp.nistz256);#endifbreak;#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128casePCT_nistp224:EC_nistp224_pre_comp_free(group->pre_comp.nistp224);break;casePCT_nistp256:EC_nistp256_pre_comp_free(group->pre_comp.nistp256);break;casePCT_nistp521:EC_nistp521_pre_comp_free(group->pre_comp.nistp521);break;#elsecasePCT_nistp224:casePCT_nistp256:casePCT_nistp521:break;#endifcasePCT_ec:EC_ec_pre_comp_free(group->pre_comp.ec);break;}group->pre_comp.ec=NULL;}voidEC_GROUP_free(EC_GROUP*group){if(!group)return;if(group->meth->group_finish!=0