summaryrefslogtreecommitdiff
path: root/nacl/curvecp/curvecpmakekey.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/curvecp/curvecpmakekey.c')
-rw-r--r--nacl/curvecp/curvecpmakekey.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/nacl/curvecp/curvecpmakekey.c b/nacl/curvecp/curvecpmakekey.c
new file mode 100644
index 00000000..dfa181b0
--- /dev/null
+++ b/nacl/curvecp/curvecpmakekey.c
@@ -0,0 +1,57 @@
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <unistd.h>
4#include "die.h"
5#include "e.h"
6#include "savesync.h"
7#include "randombytes.h"
8#include "crypto_box.h"
9
10void die_usage(void)
11{
12 die_1(111,"curvecpmakekey: usage: curvecpmakekey keydir\n");
13}
14
15void die_fatal(const char *trouble,const char *d,const char *fn)
16{
17 if (fn) die_9(111,"curvecpmakekey: fatal: ",trouble," ",d,"/",fn,": ",e_str(errno),"\n");
18 die_7(111,"curvecpmakekey: fatal: ",trouble," ",d,": ",e_str(errno),"\n");
19}
20
21unsigned char pk[crypto_box_PUBLICKEYBYTES];
22unsigned char sk[crypto_box_SECRETKEYBYTES];
23unsigned char lock[1];
24unsigned char noncekey[32];
25unsigned char noncecounter[8];
26
27void create(const char *d,const char *fn,const unsigned char *x,long long xlen)
28{
29 if (savesync(fn,x,xlen) == -1) die_fatal("unable to create",d,fn);
30}
31
32int main(int argc,char **argv)
33{
34 char *d;
35
36 if (!argv[0]) die_usage();
37 if (!argv[1]) die_usage();
38 d = argv[1];
39
40 umask(022);
41 if (mkdir(d,0755) == -1) die_fatal("unable to create directory",d,0);
42 if (chdir(d) == -1) die_fatal("unable to chdir to directory",d,0);
43 if (mkdir(".expertsonly",0700) == -1) die_fatal("unable to create directory",d,".expertsonly");
44
45 crypto_box_keypair(pk,sk);
46 create(d,"publickey",pk,sizeof pk);
47
48 randombytes(noncekey,sizeof noncekey);
49
50 umask(077);
51 create(d,".expertsonly/secretkey",sk,sizeof sk);
52 create(d,".expertsonly/lock",lock,sizeof lock);
53 create(d,".expertsonly/noncekey",noncekey,sizeof noncekey);
54 create(d,".expertsonly/noncecounter",noncecounter,sizeof noncecounter);
55
56 return 0;
57}