crypto::x25519 +linux +x86_64

The crypto::x25519 module provides functions to generate key pairs and to derive shared keys between them, based on curve25519.

A key pair is created by generating a private key with newkey and deriving the public key with pubkey. A shared key can be found by using derive.

Do not use the same secret key for both key exchanges and signatures. The public keys are different and revealing both may leak information.

This is a low-level module which implements cryptographic primitives. Direct use of cryptographic primitives is not recommended for non-experts, as incorrect use of these primitives can easily lead to the introduction of security vulnerabilities. Non-experts are advised to use the high-level operations available in the top-level crypto module.

Be advised that Hare's cryptography implementations have not been audited.



type key;


fn derive(*key, *key, *key) void;
fn newkey(*key, *[32]u8) void;
fn pubkey(*key, const *key) void;


type key[link]

type key = [32]u8;

Type for private, public or shared keys.


fn derive[link]

fn derive(shared: *key, priv: *key, pub: *key) void;

Derives a 32-byte shared key from the private key of one key-pair and the public key of a second key-pair.

fn newkey[link]

fn newkey(priv: *key, seed: *[32]u8) void;

Initializes a new x25519 private key from the provided 32-byte seed, which should be generated with crypto::random.

fn pubkey[link]

fn pubkey(pub: *key, priv: const *key) void;

Derives the public key from a private key prepared with newkey, writing it to the 'pub' parameter.