Commit eb791696 authored by Andy Polyakov's avatar Andy Polyakov
Browse files

ec/ecp_nistz256.c: improve ECDSA sign by 30-40%.

This is based on RT#3810, which added dedicated modular inversion.
ECDSA verify results improves as well, but not as much.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5001)
parent 617b49db
Loading
Loading
Loading
Loading
+1031 −13

File changed.

Preview size limit exceeded, changes collapsed.

+2
Changes for crypto/ec/ec_err.c: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ static const ERR_STRING_DATA EC_str_functs[] = {
     "ECPKParameters_print_fp"},
    {ERR_PACK(ERR_LIB_EC, EC_F_ECP_NISTZ256_GET_AFFINE, 0),
     "ecp_nistz256_get_affine"},
    {ERR_PACK(ERR_LIB_EC, EC_F_ECP_NISTZ256_INV_MOD_ORD, 0),
     "ecp_nistz256_inv_mod_ord"},
    {ERR_PACK(ERR_LIB_EC, EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, 0),
     "ecp_nistz256_mult_precompute"},
    {ERR_PACK(ERR_LIB_EC, EC_F_ECP_NISTZ256_POINTS_MUL, 0),
+6 −1
Changes for crypto/ec/ec_lcl.h: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -155,6 +155,9 @@ struct ec_method_st {
    /* custom ECDH operation */
    int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen,
                            const EC_POINT *pub_key, const EC_KEY *ecdh);
    /* Inverse modulo order */
    int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r, BIGNUM *x,
                                 BN_CTX *ctx);
};

/*
@@ -520,7 +523,6 @@ void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array,
void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign,
                                     unsigned char *digit, unsigned char in);
#endif
int ec_precompute_mont_data(EC_GROUP *);
int ec_group_simple_order_bits(const EC_GROUP *group);

#ifdef ECP_NISTZ256_ASM
@@ -604,3 +606,6 @@ int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
           const uint8_t peer_public_value[32]);
void X25519_public_from_private(uint8_t out_public_value[32],
                                const uint8_t private_key[32]);

int EC_GROUP_do_inverse_ord(const EC_GROUP *group, BIGNUM *res,
                            BIGNUM *x, BN_CTX *ctx);
+12 −1
Changes for crypto/ec/ec_lib.c: 12 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -261,6 +261,8 @@ int EC_METHOD_get_field_type(const EC_METHOD *meth)
    return meth->field_type;
}

static int ec_precompute_mont_data(EC_GROUP *);

int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
                           const BIGNUM *order, const BIGNUM *cofactor)
{
@@ -961,7 +963,7 @@ int EC_GROUP_have_precompute_mult(const EC_GROUP *group)
 * ec_precompute_mont_data sets |group->mont_data| from |group->order| and
 * returns one on success. On error it returns zero.
 */
int ec_precompute_mont_data(EC_GROUP *group)
static int ec_precompute_mont_data(EC_GROUP *group)
{
    BN_CTX *ctx = BN_CTX_new();
    int ret = 0;
@@ -1006,3 +1008,12 @@ int ec_group_simple_order_bits(const EC_GROUP *group)
        return 0;
    return BN_num_bits(group->order);
}

int EC_GROUP_do_inverse_ord(const EC_GROUP *group, BIGNUM *res,
                            BIGNUM *x, BN_CTX *ctx)
{
    if (group->meth->field_inverse_mod_ord != NULL)
        return group->meth->field_inverse_mod_ord(group, res, x, ctx);
    else
        return 0;
}
+10 −4

File changed.

Preview size limit exceeded, changes collapsed.

Loading