Bladeren bron

Abstract scalar inversion in EC_METHOD.

This introduces a hook for the OpenSSL assembly.

Change-Id: I35e0588f0ed5bed375b12f738d16c9f46ceedeea
Reviewed-on: https://boringssl-review.googlesource.com/27592
Reviewed-by: Adam Langley <alangley@gmail.com>
kris/onging/CECPQ3_patch15
David Benjamin 6 jaren geleden
committed by Adam Langley
bovenliggende
commit
364a51ec3a
6 gewijzigde bestanden met toevoegingen van 19 en 2 verwijderingen
  1. +1
    -0
      crypto/fipsmodule/ec/ec_montgomery.c
  2. +8
    -0
      crypto/fipsmodule/ec/internal.h
  3. +1
    -0
      crypto/fipsmodule/ec/p224-64.c
  4. +1
    -0
      crypto/fipsmodule/ec/p256-x86_64.c
  5. +7
    -2
      crypto/fipsmodule/ec/scalar.c
  6. +1
    -0
      third_party/fiat/p256.c

+ 1
- 0
crypto/fipsmodule/ec/ec_montgomery.c Bestand weergeven

@@ -267,4 +267,5 @@ DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_mont_method) {
out->field_sqr = ec_GFp_mont_field_sqr;
out->field_encode = ec_GFp_mont_field_encode;
out->field_decode = ec_GFp_mont_field_decode;
out->scalar_inv_montgomery = ec_simple_scalar_inv_montgomery;
}

+ 8
- 0
crypto/fipsmodule/ec/internal.h Bestand weergeven

@@ -133,6 +133,12 @@ struct ec_method_st {
BN_CTX *); // e.g. to Montgomery
int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
BN_CTX *); // e.g. from Montgomery

// scalar_inv_mont sets |out| to |in|^-1, where both input and output are in
// Montgomery form.
void (*scalar_inv_montgomery)(const EC_GROUP *group, EC_SCALAR *out,
const EC_SCALAR *in);

} /* EC_METHOD */;

const EC_METHOD *EC_GFp_mont_method(void);
@@ -271,6 +277,8 @@ int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num,
EC_POINT * [], BN_CTX *);
void ec_simple_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
const EC_SCALAR *a);

// method functions in montgomery.c
int ec_GFp_mont_group_init(EC_GROUP *);


+ 1
- 0
crypto/fipsmodule/ec/p224-64.c Bestand weergeven

@@ -1127,6 +1127,7 @@ DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_nistp224_method) {
out->field_sqr = ec_GFp_nistp224_field_sqr;
out->field_encode = NULL;
out->field_decode = NULL;
out->scalar_inv_montgomery = ec_simple_scalar_inv_montgomery;
};

#endif // BORINGSSL_HAS_UINT128 && !SMALL

+ 1
- 0
crypto/fipsmodule/ec/p256-x86_64.c Bestand weergeven

@@ -441,6 +441,7 @@ DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_nistz256_method) {
out->field_sqr = ec_GFp_mont_field_sqr;
out->field_encode = ec_GFp_mont_field_encode;
out->field_decode = ec_GFp_mont_field_decode;
out->scalar_inv_montgomery = ec_simple_scalar_inv_montgomery;
};

#endif /* !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && \


+ 7
- 2
crypto/fipsmodule/ec/scalar.c Bestand weergeven

@@ -61,9 +61,14 @@ void ec_scalar_mul_montgomery(const EC_GROUP *group, EC_SCALAR *r,
group->order_mont);
}

void ec_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
const EC_SCALAR *a) {
void ec_simple_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
const EC_SCALAR *a) {
const BIGNUM *order = &group->order;
bn_mod_inverse_prime_mont_small(r->words, a->words, order->width,
group->order_mont);
}

void ec_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
const EC_SCALAR *a) {
group->meth->scalar_inv_montgomery(group, r, a);
}

+ 1
- 0
third_party/fiat/p256.c Bestand weergeven

@@ -1819,6 +1819,7 @@ DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_nistp256_method) {
out->field_sqr = ec_GFp_mont_field_sqr;
out->field_encode = ec_GFp_mont_field_encode;
out->field_decode = ec_GFp_mont_field_decode;
out->scalar_inv_montgomery = ec_simple_scalar_inv_montgomery;
};

#undef BORINGSSL_NISTP256_64BIT

Laden…
Annuleren
Opslaan