summaryrefslogtreecommitdiffstats
path: root/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-28 20:47:06 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-28 20:47:06 +0200
commit14a44b4016d3350c85c419e1e1b683c1574cd86e (patch)
tree3804218093a4ea3f56396efbc2c1e92b4a416dc3 /src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
parentc8ea4868b37f53e138548b7adee756834ad7ea66 (diff)
downloadfastd-14a44b4016d3350c85c419e1e1b683c1574cd86e.tar
fastd-14a44b4016d3350c85c419e1e1b683c1574cd86e.zip
Add keygen function
Diffstat (limited to 'src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c')
-rw-r--r--src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
index 93f0432..33f20b3 100644
--- a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
+++ b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
@@ -691,6 +691,34 @@ static void protocol_free_peer_state(fastd_context *ctx, fastd_peer *peer) {
}
+static void hexdump(const char *desc, unsigned char d[32]) {
+ printf("%s", desc);
+
+ int i;
+ for (i = 0; i < 32; i++)
+ printf("%02x", d[i]);
+
+ printf("\n");
+}
+
+static void protocol_generate_key(fastd_context *ctx) {
+ ecc_secret_key_256 secret_key;
+ ecc_public_key_256 public_key;
+
+ pr_info(ctx, "Reading 32 bytes from /dev/random...");
+
+ fastd_random_bytes(ctx, secret_key.s, 32, true);
+ ecc_25519_secret_sanitize(&secret_key, &secret_key);
+
+ ecc_25519_work work;
+ ecc_25519_scalarmult_base(&work, &secret_key);
+ ecc_25519_store(&public_key, &work);
+
+ hexdump("Secret: ", secret_key.s);
+ hexdump("Public: ", public_key.p);
+}
+
+
const fastd_protocol fastd_protocol_ec25519_fhmqvc_xsalsa20_poly1305 = {
.name = "ec25519-fhmqvc-xsalsa20-poly1305",
@@ -705,4 +733,6 @@ const fastd_protocol fastd_protocol_ec25519_fhmqvc_xsalsa20_poly1305 = {
.send = protocol_send,
.free_peer_state = protocol_free_peer_state,
+
+ .generate_key = protocol_generate_key,
};