Skip to content

Conversation

@AndrewScull
Copy link
Contributor

Use the utilities that the library already provides but that were being re-implemented and use for ECDSA signatures, like it is for X25519 signatures, for a more consistent interface and allowing Tink to apply the provider preferences and perform the extra safety checks that are known to be appropriate.

Switch to using the Tink methods for converting ECDSA signatures to and
from DER. This replaces a custom implementation using BC.
Use Tink's helper functions for converting between byte and BigInteger
representations and for generating EC key pairs. Delete custom
implementations of the same logic.
When there is no security provider passed to the sign and verify
methods, rely on Tink to select a good and fast implementation from the
available options. Currently, Tink prefers to use Conscrypt if it's
available for improved performance.
ECPoint pubPoint = ((ECPublicKey) keyPair.getPublic()).getW();
byte[] x = arrayFromBigNum(pubPoint.getAffineX(), keySize);
byte[] y = arrayFromBigNum(pubPoint.getAffineY(), keySize);
int keySize = fieldSizeInBytes(getCurveSpec(curveType).getCurve());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not sure if we would benefit from computing the value vs having a fixed value here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know your preference. The current CL preferred fewer magic values.

signature = Signature.getInstance(algorithm.getJavaAlgorithmId());
} else {
signature = Signature.getInstance(algorithm.getJavaAlgorithmId(), provider);
return new EcdsaSignJce(key, getHashType(algorithm), EcdsaEncoding.DER).sign(message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we instead do this if we are asked to use tink provider rather than putting tink by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tink isn't a security provider but a library that uses the available providers. In the case of ECDSA signatures, it has a preference for the conscrypt provider if it's available because it's known to have much better performance. I thought it worth trying to capture that performance benefit.

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

Successfully merging this pull request may close these issues.

2 participants