-
Notifications
You must be signed in to change notification settings - Fork 280
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
Add support for Ed25519 to NativeCrypto #1287
base: master
Are you sure you want to change the base?
Conversation
BoringSSL doesn't support Ed25519 with EVP_DigestUpdate, only with EVP_DigestSign and EVP_DigestVerify. So we need to add wrappers of these functions to NativeCrypto.
Test org.conscrypt.java.security.cert.X509CertificateTest.utcTimeWithOffset fails. I don't see how this is related to my changes. |
Yeah, that's a BoringSSL change, I'll ping them. |
if (md == nullptr && (EVP_PKEY_id(pkey) != EVP_PKEY_ED25519)) { | ||
JNI_TRACE("ctx=%p %s => md == null", mdCtx, jniName); |
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.
n00b question: Why is this?
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.
For all other key types, md must not be null. But for Ed25519, it must always be null, see:
https://docs.openssl.org/3.0/man7/EVP_SIGNATURE-ED25519/#ed25519-and-ed448-signature-parameters
or
https://github.com/google/boringssl/blob/master/include/openssl/evp.h#L239
Maybe I should make this check stronger, and reject a non-null md for ed25519.
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.
Understood. Maybe just add a comment so the next person along understands :)
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.
Also raises the question of what we do in SignatureSpi... Have update() cache the data and do a one-shot operation on sign() or verify(), I guess?
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.
Overall LGTM but I want to re-check my working later on a couple of bits and maybe ask davidben to give it a quick once over in case we're missing anything on the BoringSSL side.
Is the intention to then call this from the higher level Java bits, just in a separate PR? (My understanding was that NativeCrypto was not public API in Conscrypt.) |
Exactly! Next steps would would be to wire up Java implementations of Further down the road we should make this (and X25519) able to use the RI interface and key classes, but there's a whole conditional compilation issue there as those classes don't exist on many of the platforms we need to support. |
if (md == nullptr && (EVP_PKEY_id(pkey) != EVP_PKEY_ED25519)) { | ||
JNI_TRACE("ctx=%p %s => md == null", mdCtx, jniName); |
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.
Also raises the question of what we do in SignatureSpi... Have update() cache the data and do a one-shot operation on sign() or verify(), I guess?
|
||
size_t array_size = static_cast<size_t>(env->GetArrayLength(inJavaBytes)); | ||
if (ARRAY_CHUNK_INVALID(array_size, inOffset, inLength)) { | ||
conscrypt::jniutil::throwException(env, "java/lang/ArrayIndexOutOfBoundsException", |
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.
Not this CL but we should add a method for this as it gets thrown in a many places so we might as well cache the class.
|
||
if (outPublic.size() != ED25519_PUBLIC_KEY_LEN) { | ||
conscrypt::jniutil::throwException(env, "java/lang/IllegalArgumentException", | ||
"Output public key array length != 32"); |
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.
conscrypt::jniutil::throwIllegalArgumentException()
} | ||
|
||
if (outPrivate.size() != ED25519_PRIVATE_KEY_LEN) { | ||
conscrypt::jniutil::throwException(env, "java/lang/IllegalArgumentException", |
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.
ditto
BoringSSL doesn't support Ed25519 with EVP_DigestUpdate, only with EVP_DigestSign and EVP_DigestVerify. So we need to add wrappers of these functions to NativeCrypto.