16 void generate_keypair(void)
18 struct passwd
*pw
= getpwuid(getuid());
19 unsigned char publickey
[crypto_box_pub_key_size
];
20 unsigned char secretkey
[crypto_box_sec_key_size
];
23 xmemset(publickey
, 0, sizeof(publickey
));
24 xmemset(secretkey
, 0, sizeof(secretkey
));
26 curve25519_selftest();
28 printf("Reading from %s (this may take a while) ...\n",
31 gen_key_bytes(secretkey
, sizeof(secretkey
));
32 crypto_scalarmult_curve25519_base(publickey
, secretkey
);
34 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PUBKEY
);
35 write_blob_or_die(file
, publickey
, sizeof(publickey
));
36 printf("Public key written to %s!\n", file
);
38 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PRIVKEY
);
39 write_blob_or_die(file
, secretkey
, sizeof(secretkey
));
40 printf("Secret key written to %s!\n", file
);
42 xmemset(publickey
, 0, sizeof(publickey
));
43 xmemset(secretkey
, 0, sizeof(secretkey
));
46 void verify_keypair(void)
49 struct passwd
*pw
= getpwuid(getuid());
50 unsigned char publickey
[crypto_box_pub_key_size
];
51 unsigned char publicres
[crypto_box_pub_key_size
];
52 unsigned char secretkey
[crypto_box_sec_key_size
];
55 curve25519_selftest();
57 xmemset(publickey
, 0, sizeof(publickey
));
58 xmemset(publicres
, 0, sizeof(publicres
));
59 xmemset(secretkey
, 0, sizeof(secretkey
));
61 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PUBKEY
);
62 read_blob_or_die(file
, publickey
, sizeof(publickey
));
64 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PRIVKEY
);
65 read_blob_or_die(file
, secretkey
, sizeof(secretkey
));
67 crypto_scalarmult_curve25519_base(publicres
, secretkey
);
68 result
= crypto_verify_32(publicres
, publickey
);
70 xmemset(publickey
, 0, sizeof(publickey
));
71 xmemset(publicres
, 0, sizeof(publicres
));
72 xmemset(secretkey
, 0, sizeof(secretkey
));
75 panic("Keypair is corrupt! You need to regenerate!\n");