Initial support for pluggable public key ASN1 support. Process most public
[openssl.git] / crypto / ec / ec_mult.c
index c71a69ac0d45676304cb3b0b2ce0e4ee557c4a8e..a045139a0015099360a06b67af6eb142d9ae1498 100644 (file)
@@ -203,7 +203,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
        next_bit = bit << 1; /* at most 256 */
        mask = next_bit - 1; /* at most 255 */
 
-       if (BN_get_sign(scalar))
+       if (BN_is_negative(scalar))
                {
                sign = -1;
                }
@@ -307,12 +307,13 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
  *       (thus the boundaries should be increased)
  */
 #define EC_window_bits_for_scalar_size(b) \
-               ((b) >= 2000 ? 6 : \
-                (b) >=  800 ? 5 : \
-                (b) >=  300 ? 4 : \
-                (b) >=   70 ? 3 : \
-                (b) >=   20 ? 2 : \
-                 1)
+               ((size_t) \
+                ((b) >= 2000 ? 6 : \
+                 (b) >=  800 ? 5 : \
+                 (b) >=  300 ? 4 : \
+                 (b) >=   70 ? 3 : \
+                 (b) >=   20 ? 2 : \
+                 1))
 
 /* Compute
  *      \sum scalars[i]*points[i],
@@ -324,7 +325,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
        size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
        {
        BN_CTX *new_ctx = NULL;
-       EC_POINT *generator = NULL;
+       const EC_POINT *generator = NULL;
        EC_POINT *tmp = NULL;
        size_t totalnum;
        size_t blocksize = 0, numblocks = 0; /* for wNAF splitting */
@@ -384,7 +385,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
                
                /* look if we can use precomputed multiples of generator */
 
-               pre_comp = EC_GROUP_get_extra_data(group, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);
+               pre_comp = EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);
 
                if (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0))
                        {
@@ -743,7 +744,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
        int ret = 0;
 
        /* if there is an old EC_PRE_COMP object, throw it away */
-       EC_GROUP_free_extra_data(group, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);
+       EC_EX_DATA_free_data(&group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);
 
        if ((pre_comp = ec_pre_comp_new(group)) == NULL)
                return 0;
@@ -871,14 +872,15 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
        points = NULL;
        pre_comp->num = num;
 
-       if (!EC_GROUP_set_extra_data(group, pre_comp,
+       if (!EC_EX_DATA_set_data(&group->extra_data, pre_comp,
                ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free))
                goto err;
        pre_comp = NULL;
 
        ret = 1;
  err:
-       BN_CTX_end(ctx);
+       if (ctx != NULL)
+               BN_CTX_end(ctx);
        if (new_ctx != NULL)
                BN_CTX_free(new_ctx);
        if (pre_comp)
@@ -901,7 +903,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
 
 int ec_wNAF_have_precompute_mult(const EC_GROUP *group)
        {
-       if (EC_GROUP_get_extra_data(group, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free) != NULL)
+       if (EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free) != NULL)
                return 1;
        else
                return 0;