-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
crypto/rsa: allow hash.Hash for OAEP and MGF1 to be specified independently #19974
Comments
As another data point, Android P has introduced usage of https://developer.android.com/reference/android/security/keystore/WrappedKeyEntry |
the same issue. |
Hi guys, I could help to implement the resolution for this issue, but I need your help to decide what's the best scenario for this. Do you think the OEAPOptions is the best way? Thank you |
OAEP is one of those unfortunate standards with a million parameters, which the Go standard library intentionally culls to a reasonable subset. For example, there is no good reason I know of to use different hashes at different stages of the algorithm. On balance, I'm mostly ok with adding a field to Would having support for independent hashes only for decryption make sense for your use cases, or would it be useless without encryption? (It makes sense to me also because the library is already asymmetrical due to crypto.Decrypter not having an encryption counterpart, and decryption is more likely to be about compatibility with a third party.) |
I got your point, but thinking in interoperability maybe is the deal here. I think that it could reduce the fricction along another implementations. As the use case that I exposed related to android. I think that makes sense use for both encrypt/decrypt. Well, this is my understood at reading RFC 3447, starting chapter "7. Encryption schemes" and keeping up beyond this section. But, looking to the implementation that we have at the golang, I think that is a gonna be just a decision to update of the usage context and allow the encryption besides the decryption. Thanks |
Android and Java sometimes uses separate hash functions for the OAEP digest and MGF1 mask generating function. By allowing the OAEPOption to support overriding the mask generating function's hash algorithm it is possible to support decryption of RSA-OAEP payloads generated with such a configuration. Fixes golang#19974
Android and Java sometimes uses separate hash functions for the OAEP digest and MGF1 mask generating function. By allowing the OAEPOption to support overriding the mask generating function's hash algorithm it is possible to support decryption of RSA-OAEP payloads generated with such a configuration. Fixes golang#19974
Update on this? Saw @sakjur commits but I couldn't find any PRs related |
@vieiramanoel That was mostly an experiment that didn't lead anywhere and I later ended up not needing to complete 🙂 I'm not sure if whatever I have in my branch works at all, and it was mostly an accident that my WIP commits ended up being linked from here. |
Any Update on this? |
Still waiting for this feature, |
Any updates on this? Me personally is not quite sure about the status of this issue. I'm more than open to implement it and file a PR, but I'm unsure whether such work is appropriate for the go standard library :D |
Hello everyone! Long time user, first time contributor :-) This is something we recently ran into while attempting to decrypt ciphertexts sent to us by a third-party. Unfortunately, we do not have the ability to change the parameters they use in this protocol. I am very interested (and motivated!) to work on upstreaming a change to resolve this. It has been a while, but it sounds like the right direction was to add something to DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext []byte, label []byte) And it is desirable to not change the signature of this function. As a general approach, how would you feel about creating a new non-exported function ( cc @FiloSottile |
Change https://go.dev/cl/418874 mentions this issue: |
@FiloSottile I see you might be looking at my pull request. I expect we will want to add test coverage for any change. However, it looks like there is an existing set of hard-coded test vectors that are used for OAEP, and it wasn't clear to me how those are being generated. |
I've rebased the PR on the latest code. It's been a while, but I'm still interested in discussing this change :-) |
Throwing in proposal review bucket since this is an API change. |
Thank you so much @ianlancetaylor and @andybons. Please let me know if there are any updates needed to the API change. |
The proposed new API is to add MGFHash to rsa.OAEPOptions:
(The CL uses *crypto.Hash but we can use the plain zero value for a presence check instead.) Does anyone object to this API? |
CC @golang/security |
This proposal has been added to the active column of the proposals project |
Does anyone object to adding OAEPOptions.MGFHash as in #19974 (comment)? |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
I've updated the change to reflect the proposed API: https://go-review.googlesource.com/c/go/+/418874 |
rsa.EncryptOAEP
andrsa.DecryptOAEP
both take ahash.Hash
as input, and this hash function is used as the hash function for both OAEP and the MGF1 XOR. However, an option should be provided to specify the hash function for OAEP and MGF1 separately, as it is permissible for the hash functions for these two operations to be different.This is pertinent for compatibility with other languages and RSA implementations, as the Sun JDK's implementation of the
RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING
provider uses SHA-256 for OAEP but SHA-1 for MGF1. As it currently stands, thersa
package in Go is not compatible with this encryption mode in Java.For reference, the OpenSSL API also allows for the hash functions for OAEP and MGF1 to be specified separately: https://github.com/openssl/openssl/blob/master/crypto/rsa/rsa_oaep.c#L44,
const EVP_MD *md, const EVP_MD *mgf1md
.The text was updated successfully, but these errors were encountered: