Commit 60428dbf authored by Bodo Möller's avatar Bodo Möller
Browse files

Some actual method functions (not enough yet to use the EC library, though),

including EC arithmetics derived from Lenka Fibikova's code (with some
additional optimizations).
parent 70d70a3c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ int EC_POINT_make_affine(const EC_GROUP *, const EC_POINT *, BN_CTX *);
/* Error codes for the EC functions. */

/* Function codes. */
#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR		 117
#define EC_F_EC_GROUP_CLEAR_FREE			 103
#define EC_F_EC_GROUP_COPY				 102
#define EC_F_EC_GROUP_FREE				 104
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@
#ifndef OPENSSL_NO_ERR
static ERR_STRING_DATA EC_str_functs[]=
	{
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR,0),	"EC_GFP_SIMPLE_GROUP_SET_GENERATOR"},
{ERR_PACK(0,EC_F_EC_GROUP_CLEAR_FREE,0),	"EC_GROUP_clear_free"},
{ERR_PACK(0,EC_F_EC_GROUP_COPY,0),	"EC_GROUP_copy"},
{ERR_PACK(0,EC_F_EC_GROUP_FREE,0),	"EC_GROUP_free"},
+11 −7
Original line number Diff line number Diff line
@@ -104,10 +104,10 @@ struct ec_method_st {

	/* internal functions */

	/* 'field_mult' and 'field_sqr' can be used by 'add' and 'dbl' so that
	/* 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that
	 * the same implementations of point operations can be used with different
	 * optimized implementations of expensive field operations: */
	int (*field_mult)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
	int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
	int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);

	int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */
@@ -128,7 +128,6 @@ struct ec_group_st {
	
	BIGNUM field; /* Field specification.
	               * For curves over GF(p), this is the modulus. */
	void *field_data; /* method-specific (e.g., Montgomery structure) */

	BIGNUM a, b; /* Curve coefficients.
	              * (Here the assumption is that BIGNUMs can be used
@@ -141,6 +140,8 @@ struct ec_group_st {

	EC_POINT *generator; /* optional */
	BIGNUM order, cofactor;

	void *field_data; /* method-specific (e.g., Montgomery structure) */
} /* EC_GROUP */;


@@ -197,7 +198,7 @@ int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *
int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
int ec_GFp_simple_make_affine(const EC_GROUP *, const EC_POINT *, BN_CTX *);
int ec_GFp_simple_field_mult(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);


@@ -206,7 +207,8 @@ int ec_GFp_mont_group_init(EC_GROUP *);
int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
void ec_GFp_mont_group_finish(EC_GROUP *);
void ec_GFp_mont_group_clear_finish(EC_GROUP *);
int ec_GFp_mont_field_mult(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
@@ -217,7 +219,8 @@ int ec_GFp_recp_group_init(EC_GROUP *);
int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
void ec_GFp_recp_group_finish(EC_GROUP *);
void ec_GFp_recp_group_clear_finish(EC_GROUP *);
int ec_GFp_recp_field_mult(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_recp_group_copy(EC_GROUP *, const EC_GROUP *);
int ec_GFp_recp_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_recp_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int ec_GFp_recp_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int ec_GFp_recp_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
@@ -228,7 +231,8 @@ int ec_GFp_nist_group_init(EC_GROUP *);
int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
void ec_GFp_nist_group_finish(EC_GROUP *);
void ec_GFp_nist_group_clear_finish(EC_GROUP *);
int ec_GFp_nist_field_mult(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_nist_group_copy(EC_GROUP *, const EC_GROUP *);
int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int ec_GFp_nist_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int ec_GFp_nist_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
+44 −3
Original line number Diff line number Diff line
/* TODO */
/* crypto/ec/ecp_mont.c */
/* ====================================================================
 * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
@@ -64,7 +63,7 @@ const EC_METHOD *EC_GFp_mont_method(void)
		ec_GFp_mont_group_set_curve_GFp,
		ec_GFp_mont_group_finish,
		ec_GFp_mont_group_clear_finish,
		ec_GFp_simple_group_copy,
		ec_GFp_mont_group_copy,
		ec_GFp_simple_group_set_generator,
		/* TODO: 'set' and 'get' functions for EC_GROUPs */
		ec_GFp_simple_point_init,
@@ -79,10 +78,52 @@ const EC_METHOD *EC_GFp_mont_method(void)
		ec_GFp_simple_is_at_infinity,
		ec_GFp_simple_is_on_curve,
		ec_GFp_simple_make_affine,
		ec_GFp_mont_field_mult,
		ec_GFp_mont_field_mul,
		ec_GFp_mont_field_sqr,
		ec_GFp_mont_field_encode,
		ec_GFp_mont_field_decode };

	return &ret;
	}


int ec_GFp_mont_group_init(EC_GROUP *group)
	{
	int ok;

	ok = ec_GFp_simple_group_init(group);
	group->field_data = NULL;
	return ok;
	}


int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
/* TODO */


void ec_GFp_mont_group_finish(EC_GROUP *group);
/* TODO */


void ec_GFp_mont_group_clear_finish(EC_GROUP *group);
/* TODO */


int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src);
/* TODO */


int ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
/* TODO */


int ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
/* TODO */


int ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
/* TODO */


int ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
/* TODO */
+44 −3
Original line number Diff line number Diff line
/* TODO */
/* crypto/ec/ecp_nist.c */
/* ====================================================================
 * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
@@ -64,7 +63,7 @@ const EC_METHOD *EC_GFp_nist_method(void)
		ec_GFp_nist_group_set_curve_GFp,
		ec_GFp_nist_group_finish,
		ec_GFp_nist_group_clear_finish,
		ec_GFp_simple_group_copy,
		ec_GFp_nist_group_copy,
		ec_GFp_simple_group_set_generator,
		/* TODO: 'set' and 'get' functions for EC_GROUPs */
		ec_GFp_simple_point_init,
@@ -79,10 +78,52 @@ const EC_METHOD *EC_GFp_nist_method(void)
		ec_GFp_simple_is_at_infinity,
		ec_GFp_simple_is_on_curve,
		ec_GFp_simple_make_affine,
		ec_GFp_nist_field_mult,
		ec_GFp_nist_field_mul,
		ec_GFp_nist_field_sqr,
		ec_GFp_nist_field_encode,
		ec_GFp_nist_field_decode };

	return &ret;
	}


int ec_GFp_nist_group_init(EC_GROUP *group)
	{
	int ok;

	ok = ec_GFp_simple_group_init(group);
	group->field_data = NULL;
	return ok;
	}


int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
/* TODO */


void ec_GFp_nist_group_finish(EC_GROUP *group);
/* TODO */


void ec_GFp_nist_group_clear_finish(EC_GROUP *group);
/* TODO */


int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
/* TODO */


int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
/* TODO */


int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
/* TODO */


int ec_GFp_nist_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
/* TODO */


int ec_GFp_nist_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
/* TODO */
Loading