ifpps: Also display min hitter for IRQs
[netsniff-ng.git] / keypair.c
blobe61482c2184183f440ac78b23f3665704da13f75
1 #include <string.h>
2 #include <unistd.h>
3 #include <sys/types.h>
4 #include <pwd.h>
5 #include <stdio.h>
7 #include "rnd.h"
8 #include "die.h"
9 #include "str.h"
10 #include "crypto.h"
11 #include "ioops.h"
12 #include "config.h"
13 #include "keypair.h"
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];
20 char file[128];
22 xmemset(publickey, 0, sizeof(publickey));
23 xmemset(secretkey, 0, sizeof(secretkey));
25 printf("Reading from %s (this may take a while) ...\n",
26 HIG_ENTROPY_SOURCE);
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)
45 int result;
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];
50 char file[128];
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));
69 if (result)
70 panic("Keypair is corrupt! You need to regenerate!\n");