* Hudson (tjh@cryptsoft.com).
*
*/
+/* ====================================================================
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
+ * Binary polynomial ECC support in OpenSSL originally developed by
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
+ */
#include <string.h>
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_UNCOMPRESSED;
ret->seed = NULL;
ret->seed_len = 0;
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)
{
}
+EC_GROUP *EC_GROUP_dup(const EC_GROUP *a)
+ {
+ EC_GROUP *t = NULL;
+ int ok = 0;
+
+ if (a == NULL) return NULL;
+
+ if ((t = EC_GROUP_new(a->meth)) == NULL) return(NULL);
+ if (!EC_GROUP_copy(t, a)) goto err;
+
+ ok = 1;
+
+ err:
+ if (!ok)
+ {
+ if (t) EC_GROUP_free(t);
+ return NULL;
+ }
+ else return t;
+ }
+
+
const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group)
{
return group->meth;
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;
}
}
+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;
+ }
+
+
+size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len)
+ {
+ if (group->seed)
+ {
+ OPENSSL_free(group->seed);
+ group->seed = NULL;
+ group->seed_len = 0;
+ }
+
+ if (!len || !p)
+ return 1;
+
+ if ((group->seed = OPENSSL_malloc(len)) == NULL)
+ return 0;
+ memcpy(group->seed, p, len);
+ group->seed_len = len;
+
+ return len;
+ }
+
+
+unsigned char *EC_GROUP_get0_seed(const EC_GROUP *group)
+ {
+ return group->seed;
+ }
+
+
+size_t EC_GROUP_get_seed_len(const EC_GROUP *group)
+ {
+ return group->seed_len;
+ }
+
+
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)
+ if (group->meth->group_set_curve == 0)
{
ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
- return group->meth->group_set_curve_GFp(group, p, a, b, ctx);
+ return group->meth->group_set_curve(group, p, a, b, ctx);
}
int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
{
- if (group->meth->group_get_curve_GFp == 0)
+ if (group->meth->group_get_curve == 0)
{
ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
- return group->meth->group_get_curve_GFp(group, p, a, b, ctx);
+ return group->meth->group_get_curve(group, p, a, b, ctx);
+ }
+
+
+int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
+ {
+ if (group->meth->group_set_curve == 0)
+ {
+ ECerr(EC_F_EC_GROUP_SET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ return group->meth->group_set_curve(group, p, a, b, ctx);
+ }
+
+
+int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
+ {
+ if (group->meth->group_get_curve == 0)
+ {
+ ECerr(EC_F_EC_GROUP_GET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ return group->meth->group_get_curve(group, p, a, b, ctx);
+ }
+
+
+int EC_GROUP_get_degree(const EC_GROUP *group)
+ {
+ if (group->meth->group_get_degree == 0)
+ {
+ ECerr(EC_F_EC_GROUP_GET_DEGREE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ return group->meth->group_get_degree(group);
}
}
+EC_POINT *EC_POINT_dup(const EC_POINT *a, const EC_GROUP *group)
+ {
+ EC_POINT *t;
+ int r;
+
+ if (a == NULL) return NULL;
+
+ t = EC_POINT_new(group);
+ if (t == NULL) return(NULL);
+ r = EC_POINT_copy(t, a);
+ if (!r)
+ {
+ EC_POINT_free(t);
+ return NULL;
+ }
+ else return t;
+ }
+
+
const EC_METHOD *EC_POINT_method_of(const EC_POINT *point)
{
return point->meth;
int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
{
- if (group->meth->point_set_Jprojective_coordinates_GFp == 0)
+ if (group->meth->point_set_Jprojective_coordinates == 0)
{
ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
- return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
+ return group->meth->point_set_Jprojective_coordinates(group, point, x, y, z, ctx);
}
int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
{
- if (group->meth->point_get_Jprojective_coordinates_GFp == 0)
+ if (group->meth->point_get_Jprojective_coordinates == 0)
{
ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
- return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
+ return group->meth->point_get_Jprojective_coordinates(group, point, x, y, z, ctx);
}
int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
{
- if (group->meth->point_set_affine_coordinates_GFp == 0)
+ if (group->meth->point_set_affine_coordinates == 0)
{
ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
- return group->meth->point_set_affine_coordinates_GFp(group, point, x, y, ctx);
+ return group->meth->point_set_affine_coordinates(group, point, x, y, ctx);
}
int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
{
- if (group->meth->point_get_affine_coordinates_GFp == 0)
+ if (group->meth->point_get_affine_coordinates == 0)
{
ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
- return group->meth->point_get_affine_coordinates_GFp(group, point, x, y, ctx);
+ return group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
}
int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, int y_bit, BN_CTX *ctx)
{
- if (group->meth->point_set_compressed_coordinates_GFp == 0)
+ if (group->meth->point_set_compressed_coordinates == 0)
{
ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
- return group->meth->point_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx);
+ return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx);
+ }
+
+
+int EC_POINT_set_Jprojective_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
+ const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
+ {
+ if (group->meth->point_set_Jprojective_coordinates == 0)
+ {
+ ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ if (group->meth != point->meth)
+ {
+ ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
+ return 0;
+ }
+ return group->meth->point_set_Jprojective_coordinates(group, point, x, y, z, ctx);
+ }
+
+
+int EC_POINT_get_Jprojective_coordinates_GF2m(const EC_GROUP *group, const EC_POINT *point,
+ BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
+ {
+ if (group->meth->point_get_Jprojective_coordinates == 0)
+ {
+ ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ if (group->meth != point->meth)
+ {
+ ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
+ return 0;
+ }
+ return group->meth->point_get_Jprojective_coordinates(group, point, x, y, z, ctx);
+ }
+
+
+int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
+ const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
+ {
+ if (group->meth->point_set_affine_coordinates == 0)
+ {
+ ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ if (group->meth != point->meth)
+ {
+ ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
+ return 0;
+ }
+ return group->meth->point_set_affine_coordinates(group, point, x, y, ctx);
+ }
+
+
+int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, const EC_POINT *point,
+ BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
+ {
+ if (group->meth->point_get_affine_coordinates == 0)
+ {
+ ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ if (group->meth != point->meth)
+ {
+ ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
+ return 0;
+ }
+ return group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
+ }
+
+
+int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
+ const BIGNUM *x, int y_bit, BN_CTX *ctx)
+ {
+ if (group->meth->point_set_compressed_coordinates == 0)
+ {
+ ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ if (group->meth != point->meth)
+ {
+ ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
+ return 0;
+ }
+ return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx);
}