Home GnuPG

ec-nist: fix 'mod p' carry adjustment and output masking

Description

ec-nist: fix 'mod p' carry adjustment and output masking

* mpi/ec-inline.h (MASK_AND64, LIMB_OR64): New.
[__x86_64__]: Use "rme" operand type instead of "g" to fix use
of large 32-bit constants.
* mpi/ec-nist.c (_gcry_mpi_ec_nist192_mod, _gcry_mpi_ec_nist224_mod)
(_gcry_mpi_ec_nist256_mod, _gcry_mpi_ec_nist384_mod): At end,
check if 's[]' is negative instead result of last addition, for
output masks; Use 'p_mult' table entry for P instead of 'ctx->p'.
(_gcry_mpi_ec_nist256_mod): Handle corner case were 2*P needs to be
added after carry based subtraction.
* tests/t-mpi-point.c (check_ec_mul_reduction): New.
(main): Call 'check_ec_mul_reduction'.
  • GnuPG-bug-id: T5510
  • Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>

Details

Provenance
jukiviliAuthored on Jun 28 2021, 8:01 PM
Parents
rC6dfab8cfb94c: mpi/ec: add fast reduction for secp256k1
Branches
Unknown
Tags
Unknown
Tasks
T5510: libgcrypt: incorrect computation for secp192r1