15 void generate_keypair(void)
17 struct passwd
*pw
= getpwuid(getuid());
18 unsigned char publickey
[crypto_box_pub_key_size
];
19 unsigned char secretkey
[crypto_box_sec_key_size
];
22 xmemset(publickey
, 0, sizeof(publickey
));
23 xmemset(secretkey
, 0, sizeof(secretkey
));
25 printf("Reading from %s (this may take a while) ...\n",
28 gen_key_bytes(secretkey
, sizeof(secretkey
));
29 crypto_scalarmult_curve25519_base(publickey
, secretkey
);
31 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PUBKEY
);
32 write_blob_or_die(file
, publickey
, sizeof(publickey
));
33 printf("Public key written to %s!\n", file
);
35 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PRIVKEY
);
36 write_blob_or_die(file
, secretkey
, sizeof(secretkey
));
37 printf("Secret key written to %s!\n", file
);
39 xmemset(publickey
, 0, sizeof(publickey
));
40 xmemset(secretkey
, 0, sizeof(secretkey
));
43 void verify_keypair(void)
46 struct passwd
*pw
= getpwuid(getuid());
47 unsigned char publickey
[crypto_box_pub_key_size
];
48 unsigned char publicres
[crypto_box_pub_key_size
];
49 unsigned char secretkey
[crypto_box_sec_key_size
];
52 xmemset(publickey
, 0, sizeof(publickey
));
53 xmemset(publicres
, 0, sizeof(publicres
));
54 xmemset(secretkey
, 0, sizeof(secretkey
));
56 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PUBKEY
);
57 read_blob_or_die(file
, publickey
, sizeof(publickey
));
59 slprintf(file
, sizeof(file
), "%s/%s", pw
->pw_dir
, FILE_PRIVKEY
);
60 read_blob_or_die(file
, secretkey
, sizeof(secretkey
));
62 crypto_scalarmult_curve25519_base(publicres
, secretkey
);
63 result
= crypto_verify_32(publicres
, publickey
);
65 xmemset(publickey
, 0, sizeof(publickey
));
66 xmemset(publicres
, 0, sizeof(publicres
));
67 xmemset(secretkey
, 0, sizeof(secretkey
));
70 panic("Keypair is corrupt! You need to regenerate!\n");