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

(Feature) Curve25519 API that's harder to misuse. #237

Open
Yawning opened this issue Jan 29, 2015 · 3 comments
Open

(Feature) Curve25519 API that's harder to misuse. #237

Yawning opened this issue Jan 29, 2015 · 3 comments

Comments

@Yawning
Copy link

Yawning commented Jan 29, 2015

As discussed in #236, having something like this along with the NaCl box primitives will allow significantly easier use of the library, for the "I just want to encrypt/decrypt stuff without shooting myself in the foot with a shotgun" userbase.

This is probably related to #228.

Maybe something like: https://github.com/Yawning/rust-crypto/tree/curve25519_usability

use crypto::curve25519;
use std::rand::{OsRng, Rng};

let mut rng = try!(OsRng::new());
let my_private = curve25519::PrivateKey::new(&mut rng);
let my_public = my_private.as_bytes();

// Send public key to Bob...

let bobs_raw_public = /* a u8 slice with 32 bytes, read it off the network or something. */;
let bobs_public = curve25519::PublicKey::from_bytes(&bobs_raw_public);

let shared_secret = my_private.key_exchange(bobs_public); // <- [u8; 32] that's shared.

// Pass shared_secret through a KDF of your choice (really, use HKDF).

No pull request because the API more than likely could be improved, and it's a quick and dirty thing that tries to get the general idea across.

@Philipp91
Copy link

rust-crypto depends on rand anyway, why make the caller instantiate and pass in the rng? You could just have ::new_random() or sth like that. Some users might not know which of the RNGs to use.

let my_public = my_private.as_bytes(); That's confusing. When I call .as_bytes() on something, I expect to receive its raw contents, not something else. So the getter should have a different name, say, .get_public_key().

[u8; 32] is it always 32 bytes? Even when this API gets generalized a bit more?

@aep
Copy link

aep commented Apr 19, 2018

since this is rather dead, did you go for a different crate @Yawning ? If not it might be useful to use your code in a separate high level crate

@Yawning
Copy link
Author

Yawning commented Apr 19, 2018

I haven't touched Rust in a personal capacity since around the time I last commented on this issue, sorry.

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

No branches or pull requests

3 participants