Consolidate keypairs in core. (#972)

* Consolidate keypairs in core.

Introduce the concept of a node's identity keypair in libp2p-core,
instead of only the public key:

  * New module: libp2p_core::identity with submodules for the currently
    supported key types. An identity::Keypair and identity::PublicKey
    support the creation and verification of signatures. The public key
    supports encoding/decoding according to the libp2p specs.

  * The secio protocol is simplified as a result of moving code to libp2p-core.

  * The noise protocol is slightly simplified by consolidating ed25519
    keypairs in libp2p-core and using x25519-dalek for DH. Furthermore,
    Ed25519 to X25519 keypair conversion is now complete and tested.

Generalise over the DH keys in the noise protocol.

Generalise over the DH keys and thus DH parameter in handshake patterns
of the Noise protocol, such that it is easy to support other DH schemes
in the future, e.g. X448.

* Address new review comments.
This commit is contained in:
Roman Borschel
2019-03-11 13:42:53 +01:00
committed by GitHub
parent 26df15641c
commit 2c66f82b11
37 changed files with 1742 additions and 1020 deletions

View File

@ -18,8 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use libp2p_core::PeerId;
use libp2p_secio::SecioKeyPair;
use libp2p_core::identity;
use std::{env, str, thread, time::Duration};
fn main() {
@ -67,13 +66,13 @@ fn main() {
for _ in 0..num_cpus::get() {
let prefix = prefix.clone();
thread::spawn(move || loop {
let private_key: [u8; 32] = rand::random();
let generated = SecioKeyPair::secp256k1_raw_key(private_key).unwrap();
let peer_id: PeerId = generated.to_public_key().into_peer_id();
let keypair = identity::ed25519::Keypair::generate();
let secret = keypair.secret();
let peer_id = identity::PublicKey::Ed25519(keypair.public()).into_peer_id();
let base58 = peer_id.to_base58();
if base58[2..].starts_with(&prefix) {
println!("Found {:?}", peer_id);
println!("=> Private key = {:?}", private_key);
println!("=> Private key = {:?}", secret.as_ref());
}
});
}