-
Notifications
You must be signed in to change notification settings - Fork 47
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
Argon2 Example #282
Argon2 Example #282
Conversation
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.
The
Argon2
struct requires a lifetime, which makes the empty struct pattern somewhat unintuitive without an example and requires aPhantomData
to work.
A secret isn't used in this case, so using a 'static
lifetime avoids the workaround with a PhantomData
.
- I'd like to also make an example on how to specify the derivation params instead on relying on RustCrypto's default, but I'm not sure doing it in the
simple_login
example is the best idea since it's supposed to be simple.
We can add this to the example with a custom KSF.
2. @daxpedda also suggested adding a custom KDF example. I think copying the
simple_login
file but implementingKsf
on, let's say, scrypt would be a good idea for that? If you expect to eventually first-party supportscrypt
we could go with something more obscure like PBKDF2-BLAKE2/3 instead so the example stays relevant.
I think scrypt is appropriate considering it's also suggested by the draft. I'm happy with whatever tough. This can also be added in a separate PR if desired.
So I made the changes you asked for in the PR. A few notes:
|
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.
- I made sure that using
'static
for Argon2 does not break even if you use custom parameters. While you probably still need thePhantomData
workaround if using a secret key, I can't tell how much of a niche use case that would be (I'm thinking about a case where you'd want to authenticate using both your password and some device key or keyfile).
Great! I'm not entirely sure what the point would be of using a secret key in OPAQUE. If you have a device key or keyfile, you wouldn't need OPAQUE in the first place.
- For the custom
Ksf
example, I copied the entiresimple_login
example and modified it. I also included custom derivation parameters. I'm not sure if that's too overkill, but because of custom parameters we basically need the full login process, so I'm not sure how we could have a shorter "runnable" example.
I don't mind, but any ideas are welcome.
- I think maybe we shouldn't use
Default
for the Ciphersuite because it conflicts withcore::default::Default
. I'd suggest renaming itDefaultCiphersuite
or something like that while I'm at it.
Yeah, sounds good to me.
Thanks for putting this up! I wonder, instead of adding a new runnable example that is mostly a copy of simple_login, could we move the custom KSF example into the docs of lib.rs? I was thinking that we could put it under the "Advanced Usage" section. And the code snippets there could just consist of what you have in the custom_ksf.rs file (the struct definition for |
…ith core::default::Default
It's a somewhat common practice in password managers to use both a password and a keyfile as a form of cryptographically strong 2FA. I know for instance KeePass(XC) allows is and 1Password enforces it.
That's a good idea! I did a bit of research and just learned that you can put the |
This is a bit off-topic now, but I really enjoy discussing these things 😅.
Argon2 is hopefully not bad enough to actually significantly affect our CI times, hopefully |
So I transferred the examples to the doc. I use
With that said, I'm happy with the current result, so I'll move the PR out of the draft state! |
I would strongly discourage from ignoring any documentation test, ultimately it will turn stale and we will have somebody opening an issue saying the code doesn't work.
All our documentation tests have a huge amount of boilerplate code.
You can simply put a
The current test suit executes a ton of asymmetric cryptography, which is already damn slow, adding a one second Argon2 hashing run is completely insignificant.
Indeed, looks great! |
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.
Other then actually getting the test to run this is great!
Co-authored-by: daxpedda <[email protected]>
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.
Requesting changes due to failing CI
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.
If the CI is fixed, and except that tiny improvement, LGTM! 🎉
Co-authored-by: daxpedda <[email protected]>
Both doctests now runs, and the CI passes! |
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.
This is great, thanks very much for the contribution @zer0x64 !
As discussed here:
#281
This PR aims to update the
simple_login
example to add an example on how to use Argon2 as the client-side KDF, as recommended. TheArgon2
struct requires a lifetime, which makes the empty struct pattern somewhat unintuitive without an example and requires aPhantomData
to work.I'm opening as a draft for now because:
simple_login
example is the best idea since it's supposed to be simple.simple_login
file but implementingKsf
on, let's say, scrypt would be a good idea for that? If you expect to eventually first-party supportscrypt
we could go with something more obscure like PBKDF2-BLAKE2/3 instead so the example stays relevant.