Optimize ECDH functions to use windowed multiplication for improved performance

This commit updates the ECDH and ECDHXOnly functions to utilize optimized windowed multiplication instead of constant-time multiplication. This change is justified as the secret key is already known, allowing for variable-time operations. Additionally, new .idea configuration files are added, including .gitignore, misc.xml, modules.xml, p256k1.mleku.dev.iml, and vcs.xml, to enhance project management and version control settings.
This commit is contained in:
2025-11-02 00:29:51 +00:00
parent 8164e5461f
commit 3323d197ab
6 changed files with 47 additions and 4 deletions

10
ecdh.go
View File

@@ -204,9 +204,10 @@ func ECDH(output []byte, pubkey *PublicKey, seckey []byte, hashfp ECDHHashFuncti
return errors.New("secret key cannot be zero")
}
// Compute res = s * pt using constant-time multiplication
// Compute res = s * pt using optimized windowed multiplication (variable-time)
// ECDH doesn't require constant-time since the secret key is already known
var res GroupElementJacobian
EcmultConst(&res, &pt, &s)
ecmultWindowedVar(&res, &pt, &s)
// Convert to affine
var resAff GroupElementAffine
@@ -352,9 +353,10 @@ func ECDHXOnly(output []byte, pubkey *PublicKey, seckey []byte) error {
return errors.New("secret key cannot be zero")
}
// Compute res = s * pt
// Compute res = s * pt using optimized windowed multiplication (variable-time)
// ECDH doesn't require constant-time since the secret key is already known
var res GroupElementJacobian
EcmultConst(&res, &pt, &s)
ecmultWindowedVar(&res, &pt, &s)
// Convert to affine
var resAff GroupElementAffine