this method does not need field_data1
[openssl.git] / crypto / ec / ecp_nist.c
index 3c2b4fa9786235001d3b78a1a80f27d15d9d568d..0b39bb6166535bd00a1fbb81f5f99d6d49294880 100644 (file)
@@ -109,9 +109,6 @@ const EC_METHOD *EC_GFp_nist_method(void)
        return &ret;
        }
 
-#define        ECP_MOD_CAST    \
-       (int (*)(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *))
-
 #if BN_BITS2 == 64 && UINT_MAX != 4294967295UL && ULONG_MAX != 4294967295UL
 #define        NO_32_BIT_TYPE
 #endif
@@ -121,7 +118,6 @@ int ec_GFp_nist_group_init(EC_GROUP *group)
        int ok;
 
        ok = ec_GFp_simple_group_init(group);
-       group->field_data1 = NULL;
        return ok;
        }
 
@@ -155,43 +151,52 @@ int ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
        if ((tmp_bn = BN_CTX_get(ctx)) == NULL) goto err;
 
        if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0)
-               group->field_data1 = (void *)BN_nist_mod_192;
+               group->field_mod_func = BN_nist_mod_192;
        else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0)
-#if !defined(ECP_NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
-               group->field_data1 = (void *)BN_nist_mod_224;
+               {
+#if !defined(NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
+               group->field_mod_func = BN_nist_mod_224;
 #else
+               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
                goto err;
 #endif
+               }
        else if (BN_ucmp(BN_get0_nist_prime_256(), p) == 0)
-#if !defined(ECP_NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
-               group->field_data1 = (void *)BN_nist_mod_256;
+               {
+#if !defined(NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
+               group->field_mod_func = BN_nist_mod_256;
 #else
+               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
                goto err;
 #endif
+               }
        else if (BN_ucmp(BN_get0_nist_prime_384(), p) == 0)
-#if !defined(ECP_NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
-               group->field_data1 = (void *)BN_nist_mod_384;
+               {
+#if !defined(NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
+               group->field_mod_func = BN_nist_mod_384;
 #else
+               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
                goto err;
 #endif
+               }
        else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0)
-               group->field_data1 = (void *)BN_nist_mod_521;
+               /* this one works in the NO_32_BIT_TYPE case */
+               group->field_mod_func = BN_nist_mod_521;
        else
                {
-               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, 
-                       EC_R_PRIME_IS_NOT_A_NIST_PRIME);
+               ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_NIST_PRIME);
                goto err;
                }
 
        /* group->field */
        if (!BN_copy(&group->field, p)) goto err;
-       group->field.neg = 0;
+       BN_set_sign(&group->field, 0);
 
        /* group->a */
-       (ECP_MOD_CAST group->field_data1)(&group->a, a, p, ctx);
+       if (!group->field_mod_func(&group->a, a, p, ctx)) goto err;
 
        /* group->b */
-       (ECP_MOD_CAST group->field_data1)(&group->b, b, p, ctx);
+       if (!group->field_mod_func(&group->b, b, p, ctx)) goto err;
 
        /* group->a_is_minus3 */
        if (!BN_add_word(tmp_bn, 3)) goto err;
@@ -222,8 +227,6 @@ int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src)
 
        dest->a_is_minus3 = src->a_is_minus3;
 
-       dest->field_data1 = src->field_data1;
-
        return 1;
        }
 
@@ -242,7 +245,7 @@ int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
                if ((ctx_new = ctx = BN_CTX_new()) == NULL) goto err;
 
        if (!BN_mul(r, a, b, ctx)) goto err;
-       if (!(ECP_MOD_CAST group->field_data1)(r, r, &group->field, ctx))
+       if (!group->field_mod_func(r, r, &group->field, ctx))
                goto err;
 
        ret=1;
@@ -267,7 +270,7 @@ int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
                if ((ctx_new = ctx = BN_CTX_new()) == NULL) goto err;
 
        if (!BN_sqr(r, a, ctx)) goto err;
-       if (!(ECP_MOD_CAST group->field_data1)(r, r, &group->field, ctx))
+       if (!group->field_mod_func(r, r, &group->field, ctx))
                goto err;
 
        ret=1;