[prev in list] [next in list] [prev in thread] [next in thread]
List: openssl-cvs
Subject: [CVS] OpenSSL: openssl/crypto/ec/ ec.h ec_lib.c openssl/crypto/evp/ p_...
From: "Bodo Moeller" <bodo () openssl ! org>
Date: 2003-07-21 13:43:29
[Download RAW message or body]
OpenSSL CVS Repository
http://cvs.openssl.org/
____________________________________________________________________________
Server: cvs.openssl.org Name: Bodo Moeller
Root: /e/openssl/cvs Email: bodo@openssl.org
Module: openssl Date: 21-Jul-2003 15:43:29
Branch: HEAD Handle: 2003072114432800
Modified files:
openssl/crypto/ec ec.h ec_lib.c
openssl/crypto/evp p_lib.c
Log:
new function EC_GROUP_cmp() (used by EVP_PKEY_cmp())
Submitted by: Nils Larsch
Summary:
Revision Changes Path
1.65 +3 -0 openssl/crypto/ec/ec.h
1.31 +75 -0 openssl/crypto/ec/ec_lib.c
1.29 +9 -0 openssl/crypto/evp/p_lib.c
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: openssl/crypto/ec/ec.h
============================================================================
$ cvs diff -u -r1.64 -r1.65 ec.h
--- openssl/crypto/ec/ec.h 20 Mar 2003 23:22:06 -0000 1.64
+++ openssl/crypto/ec/ec.h 21 Jul 2003 13:43:28 -0000 1.65
@@ -166,6 +166,9 @@
* elliptic curve is not zero, 0 otherwise */
int EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);
+/* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */
+int EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *);
+
/* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()
* after choosing an appropriate EC_METHOD */
EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
@@ .
patch -p0 <<'@@ .'
Index: openssl/crypto/ec/ec_lib.c
============================================================================
$ cvs diff -u -r1.30 -r1.31 ec_lib.c
--- openssl/crypto/ec/ec_lib.c 12 Feb 2003 18:30:16 -0000 1.30
+++ openssl/crypto/ec/ec_lib.c 21 Jul 2003 13:43:28 -0000 1.31
@@ -470,6 +470,81 @@
}
+int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
+ {
+ int r = 0;
+ BIGNUM *a1, *a2, *a3, *b1, *b2, *b3;
+ BN_CTX *ctx_new = NULL;
+
+ /* compare the field types*/
+ if (EC_METHOD_get_field_type(EC_GROUP_method_of(a)) !=
+ EC_METHOD_get_field_type(EC_GROUP_method_of(b)))
+ return 1;
+ /* compare the curve name (if present) */
+ if (EC_GROUP_get_nid(a) && EC_GROUP_get_nid(b) &&
+ EC_GROUP_get_nid(a) == EC_GROUP_get_nid(b))
+ return 0;
+
+ if (!ctx)
+ ctx_new = ctx = BN_CTX_new();
+ if (!ctx)
+ return -1;
+
+ BN_CTX_start(ctx);
+ a1 = BN_CTX_get(ctx);
+ a2 = BN_CTX_get(ctx);
+ a3 = BN_CTX_get(ctx);
+ b1 = BN_CTX_get(ctx);
+ b2 = BN_CTX_get(ctx);
+ b3 = BN_CTX_get(ctx);
+ if (!b3)
+ {
+ BN_CTX_end(ctx);
+ if (ctx_new)
+ BN_CTX_free(ctx);
+ return -1;
+ }
+
+ /* XXX This approach assumes that the external representation
+ * of curves over the same field type is the same.
+ */
+ if (!a->meth->group_get_curve(a, a1, a2, a3, ctx) ||
+ !b->meth->group_get_curve(b, b1, b2, b3, ctx))
+ r = 1;
+
+ if (r || BN_cmp(a1, b2) || BN_cmp(a2, b2) || BN_cmp(a3, b3))
+ r = 1;
+
+ /* XXX EC_POINT_cmp() assumes that the methods are equal */
+ if (r || EC_POINT_cmp(a, EC_GROUP_get0_generator(a),
+ EC_GROUP_get0_generator(b), ctx))
+ r = 1;
+
+ if (!r)
+ {
+ /* compare the order and cofactor */
+ if (!EC_GROUP_get_order(a, a1, ctx) ||
+ !EC_GROUP_get_order(b, b1, ctx) ||
+ !EC_GROUP_get_cofactor(a, a2, ctx) ||
+ !EC_GROUP_get_cofactor(b, b2, ctx))
+ {
+ BN_CTX_end(ctx);
+ if (ctx_new)
+ BN_CTX_free(ctx);
+ return -1;
+ }
+ if (BN_cmp(a1, b1) || BN_cmp(a2, b2))
+ r = 1;
+ }
+
+ BN_CTX_end(ctx);
+ if (ctx_new)
+ BN_CTX_free(ctx);
+
+ return r;
+ }
+
+
/* this has 'package' visibility */
int EC_GROUP_set_extra_data(EC_GROUP *group, void *data,
void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
@@ .
patch -p0 <<'@@ .'
Index: openssl/crypto/evp/p_lib.c
============================================================================
$ cvs diff -u -r1.28 -r1.29 p_lib.c
--- openssl/crypto/evp/p_lib.c 7 Apr 2003 10:15:32 -0000 1.28
+++ openssl/crypto/evp/p_lib.c 21 Jul 2003 13:43:28 -0000 1.29
@@ -234,6 +234,15 @@
return(1);
}
#endif
+#ifndef OPENSSL_NO_EC
+ if (a->type == EVP_PKEY_EC && b->type == EVP_PKEY_EC)
+ {
+ if (EC_GROUP_cmp(a->pkey.eckey->group, b->pkey.eckey->group, NULL))
+ return 0;
+ else
+ return 1;
+ }
+#endif
return(-1);
}
@@ .
______________________________________________________________________
OpenSSL Project http://www.openssl.org
CVS Repository Commit List openssl-cvs@openssl.org
Automated List Manager majordomo@openssl.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic