Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScalarBaseMult and Add: Deprecated low-level unsafe API #1195

Open
mariajdab opened this issue Nov 20, 2023 · 2 comments
Open

ScalarBaseMult and Add: Deprecated low-level unsafe API #1195

mariajdab opened this issue Nov 20, 2023 · 2 comments

Comments

@mariajdab
Copy link
Contributor

mariajdab commented Nov 20, 2023

Reading the crypto related package in vocdoni-node repository, I realized that in the file saltedkey.go is using deprecated Curve methods described as low-level unsafe API :

ScalarBaseMult : Deprecated

Used in:

// SaltBlindPubKey returns the salted blind public key of pubKey applying the salt.
func SaltBlindPubKey(pubKey *blind.PublicKey, salt []byte) (*blind.PublicKey, error) {
	if len(salt) < SaltSize {
		return nil, fmt.Errorf("provided salt is not large enough (need %d bytes)", SaltSize)
	}
	if pubKey == nil {
		return nil, fmt.Errorf("public key is nil")
	}
	var salt2 [SaltSize]byte
	copy(salt2[:], salt[:SaltSize])
	x, y := ethcrypto.S256().ScalarBaseMult(salt2[:])
	s := blind.Point{
		X: x,
		Y: y,
	}
	return (*blind.PublicKey)(pubKey.Point().Add(&s)), nil
}
// SaltECDSAPubKey returns the salted plain public key of pubKey applying the salt.
func SaltECDSAPubKey(pubKey *ecdsa.PublicKey, salt []byte) (*ecdsa.PublicKey, error) {
  if len(salt) < SaltSize {
  	return nil, fmt.Errorf("provided salt is not large enough (need %d bytes)", SaltSize)
  }
  if pubKey == nil {
  	return nil, fmt.Errorf("public key is nil")
  }
  var salt2 [SaltSize]byte
  copy(salt2[:], salt[:SaltSize])
  x, y := pubKey.Curve.ScalarBaseMult(salt2[:])
  pubKey.X, pubKey.Y = pubKey.Curve.Add(pubKey.X, pubKey.Y, x, y)
  return pubKey, nil
}

Also, the Curve method Add is Deprecated and this is a low-level unsafe API.

I assume that this could be a breaking change.

@mariajdab
Copy link
Contributor Author

@p4u

@p4u
Copy link
Member

p4u commented Nov 21, 2023

Umm, interesting. Could you create a test to check if both ways are compatible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants