fix typo, add prototype
[oweals/openssl.git] / crypto / ec / ec2_smpt.c
index f7e3d3815040367bdb50c9dbe9ce495a263d2861..72a8d570517f3119686ccdd7f4463d1521aabe96 100644 (file)
@@ -77,6 +77,9 @@ int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p
        BIGNUM *tmp, *x, *y, *z;
        int ret = 0, z0;
 
+       /* clear error queue */
+       ERR_clear_error();
+
        if (ctx == NULL)
                {
                ctx = new_ctx = BN_CTX_new();
@@ -104,7 +107,19 @@ int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p
                if (!group->meth->field_div(group, tmp, &group->b, tmp, ctx)) goto err;
                if (!BN_GF2m_add(tmp, &group->a, tmp)) goto err;
                if (!BN_GF2m_add(tmp, x, tmp)) goto err;
-               if (!BN_GF2m_mod_solve_quad_arr(z, tmp, group->poly, ctx)) goto err;
+               if (!BN_GF2m_mod_solve_quad_arr(z, tmp, group->poly, ctx))
+                       {
+                       unsigned long err = ERR_peek_last_error();
+                       
+                       if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NO_SOLUTION)
+                               {
+                               ERR_clear_error();
+                               ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);
+                               }
+                       else
+                               ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB);
+                       goto err;
+                       }
                z0 = (BN_is_odd(z)) ? 1 : 0;
                if (!group->meth->field_mul(group, y, x, z, ctx)) goto err;
                if (z0 != y_bit)