You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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?
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
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.
The text was updated successfully, but these errors were encountered: