-
Notifications
You must be signed in to change notification settings - Fork 24
Make better use of Tink #22
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
base: main
Are you sure you want to change the base?
Conversation
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.