Error checking and memory leak fixes in NISTZ256.
[oweals/openssl.git] / crypto / ec / ecp_smpl.c
index 34ae6d5ff5200d55be698cc29f05bcfdd952eecc..2d42d34f51cb8dd580fc937b1b36b8ec72d7b82d 100644 (file)
@@ -133,12 +133,9 @@ int ec_GFp_simple_group_init(EC_GROUP *group)
     group->a = BN_new();
     group->b = BN_new();
     if (!group->field || !group->a || !group->b) {
-        if (!group->field)
-            BN_free(group->field);
-        if (!group->a)
-            BN_free(group->a);
-        if (!group->b)
-            BN_free(group->b);
+        BN_free(group->field);
+        BN_free(group->a);
+        BN_free(group->b);
         return 0;
     }
     group->a_is_minus3 = 0;
@@ -909,10 +906,10 @@ int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
             goto err;
         if (!BN_mod_add_quick(n1, n0, n1, p))
             goto err;
-                /*-
-                 * n1 = 3 * (X_a + Z_a^2) * (X_a - Z_a^2)
-                 *    = 3 * X_a^2 - 3 * Z_a^4
-                 */
+        /*-
+         * n1 = 3 * (X_a + Z_a^2) * (X_a - Z_a^2)
+         *    = 3 * X_a^2 - 3 * Z_a^4
+         */
     } else {
         if (!field_sqr(group, n0, a->X, ctx))
             goto err;
@@ -1033,15 +1030,15 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
     if (Z6 == NULL)
         goto err;
 
-       /*-
-        * We have a curve defined by a Weierstrass equation
-        *      y^2 = x^3 + a*x + b.
-        * The point to consider is given in Jacobian projective coordinates
-        * where  (X, Y, Z)  represents  (x, y) = (X/Z^2, Y/Z^3).
-        * Substituting this and multiplying by  Z^6  transforms the above equation into
-        *      Y^2 = X^3 + a*X*Z^4 + b*Z^6.
-        * To test this, we add up the right-hand side in 'rh'.
-        */
+    /*-
+     * We have a curve defined by a Weierstrass equation
+     *      y^2 = x^3 + a*x + b.
+     * The point to consider is given in Jacobian projective coordinates
+     * where  (X, Y, Z)  represents  (x, y) = (X/Z^2, Y/Z^3).
+     * Substituting this and multiplying by  Z^6  transforms the above equation into
+     *      Y^2 = X^3 + a*X*Z^4 + b*Z^6.
+     * To test this, we add up the right-hand side in 'rh'.
+     */
 
     /* rh := X^2 */
     if (!field_sqr(group, rh, point->X, ctx))
@@ -1108,12 +1105,12 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
                       const EC_POINT *b, BN_CTX *ctx)
 {
-        /*-
-         * return values:
-         *  -1   error
-         *   0   equal (in affine coordinates)
-         *   1   not equal
-         */
+    /*-
+     * return values:
+     *  -1   error
+     *   0   equal (in affine coordinates)
+     *   1   not equal
+     */
 
     int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *,
                       const BIGNUM *, BN_CTX *);
@@ -1151,12 +1148,12 @@ int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
     if (Zb23 == NULL)
         goto end;
 
-       /*-
-        * We have to decide whether
-        *     (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3),
-        * or equivalently, whether
-        *     (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
-        */
+    /*-
+     * We have to decide whether
+     *     (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3),
+     * or equivalently, whether
+     *     (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
+     */
 
     if (!b->Z_is_one) {
         if (!field_sqr(group, Zb23, b->Z, ctx))