dcrypt.ecc.ed25519

Members

Functions

secret_to_public
ubyte[32] secret_to_public(in ubyte[] sk)

Generate public key from secret key.

sign
ubyte[64] sign(in ubyte[] m, in ubyte[] sk, in ubyte[] publicKey = null)

Sign a message with your secret key.

verify
bool verify(in ubyte[] signature, in ubyte[] m, in ubyte[] pk)

Verify a signature sig of message m with public key pk.

Examples

Generate a ed25519 public key from a secret key.

1 t {
2 	//	draft-josefsson-eddsa-ed25519-03
3 	//	-----TEST 1
4 	
5 	immutable ubyte[32] sk = cast(const ubyte[]) x"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60";
6 	immutable ubyte[32] expectedPk = cast(const ubyte[]) x"d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a";
7 
8 	immutable ubyte[32] pk = secret_to_public(sk);
9 
10 	assert(pk == expectedPk, "ed25519 crypto_sign_pubkey failed."

Test signing and verifying. Test vectors from http://ed25519.cr.yp.to/python/sign.input.

1 t {
2 
3 	immutable ubyte[32] sk = cast(const ubyte[]) x"9d61b19deffd5a60ba844af492ec2cc4 4449c5697b326919703bac031cae7f60";
4 	immutable ubyte[32] pk = secret_to_public(sk);
5 
6 	assert(pk == x"d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a", "Ed25519 generated unexpected public key.");
7 
8 	immutable ubyte[0] message = cast(const ubyte[]) "";
9 
10 	immutable ubyte[64] signature = sign(message, sk);
11 
12 	immutable auto expectedSig = x"e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b";
13 	assert(signature[0..32] == expectedSig[0..32], "Ed25519 signature: wrong R.");
14 	assert(signature[32..64] == expectedSig[32..64], "Ed25519 produced unexpected signature.");
15 
16 	immutable bool valid = verify(signature, message, pk);
17 	assert(valid, "Ed25519 signature verificaton failed.");
18 
19 	assert(!verify(signature, cast(const ubyte[]) "asdf", pk), "Ed25519 signature verificaton failed."

Meta