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

Add hkdf::Prk::expand_to_secret() #891

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

djc
Copy link
Contributor

@djc djc commented Aug 23, 2019

Something like this seems to work.

@briansmith
Copy link
Owner

Thanks for this. This was in fact the exact type signature that I had originally given to Prk::expand() but for some reason it didn't work...I think rustc's type inference didn't work as well for the combined function (like you have it here) vs. the separate steps (as expand currently is in the current source). Did you run into this yourself?

@djc
Copy link
Contributor Author

djc commented Sep 1, 2019

Yes, I ended up incorporating something like this in Quinn:

https://github.com/djc/quinn/blob/master/quinn-proto/src/crypto/ring.rs#L238

@briansmith
Copy link
Owner

Did you run into this yourself?

Sorry if I wasn't clear. What I mean is, did you find that your new function failed to work because of type inference problems, or did you find that there were no type inference problems in your usage, or something in between?

@briansmith
Copy link
Owner

Also, since Quinn is based on Rustls, IMO Rustls should just expose an API that makes all that Quinn code unnecessary. Quinn shouldn't be doing HKDF at all, AFAICT.

@djc
Copy link
Contributor Author

djc commented Sep 1, 2019

It took me a while to figure out the correct incantation, so it would be nice if that could live in ring. Especially since it took me quite some time to grok how to use the current API, and this new method makes it clearer how the pieces fit together.

@djc
Copy link
Contributor Author

djc commented Sep 1, 2019

@ctz took the opinion back when I started that he wanted rustls to know as little as possible QUIC-specific stuff, but maybe we ought to reconsider that position.

@briansmith
Copy link
Owner

@ctz took the opinion back when I started that he wanted rustls to know as little as possible QUIC-specific stuff, but maybe we ought to reconsider that position.

Off-topic, but I think Rustls would actually be simpler if it did everything related to key derivation for QUIC, even not considering how much simpler Quinn would be. Rustls already has duplicate code for QUIC- and non-QUIC- code paths. I suggest making a Rustls PR so we can see how much better Rustls would get.

@briansmith
Copy link
Owner

It took me a while to figure out the correct incantation, so it would be nice if that could live in ring. Especially since it took me quite some time to grok how to use the current API, and this new method makes it clearer how the pieces fit together.

Oh, I 100% agree. My point was that I implemented the harder-to-understand API because the easier-to-understand API didn't work as well due to type inference issues. I am wondering if you found that to be the case too, or if the stuff I was trying to do before was an anomaly. I'll double-check when I have some time.

@djc
Copy link
Contributor Author

djc commented Sep 2, 2019

Oh, I 100% agree. My point was that I implemented the harder-to-understand API because the easier-to-understand API didn't work as well due to type inference issues. I am wondering if you found that to be the case too, or if the stuff I was trying to do before was an anomaly. I'll double-check when I have some time.

IIRC rustc still can't figure out the return type of my hkdf_expand() method unless the target binding is clearly typed (which ends up usually being the case for my code). Is that what you mean? "type inference issues" can be different kinds of things in my experience.

@djc
Copy link
Contributor Author

djc commented Apr 20, 2020

@briansmith are you still interested in this? If yes, does it need any further work?

@briansmith briansmith changed the base branch from master to main June 19, 2020 16:56
@briansmith
Copy link
Owner

@djc Yes, I think it would be good to have this. It isn't being tested in hkdf_tests, which is the main blocker that I see.

@djc
Copy link
Contributor Author

djc commented Jul 2, 2020

I've updated the hkdf_tests() to use expand_to_secret() directly. Since hkdf_output_len_tests() still exercise the separate expand().into() idiom, this seems like a decent way to get coverage for this.

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.

None yet

2 participants