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:
10
ecdh.go
10
ecdh.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user