summaryrefslogtreecommitdiff
path: root/nacl/curvecp/curvecpprintkey.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/curvecp/curvecpprintkey.c')
-rw-r--r--nacl/curvecp/curvecpprintkey.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/nacl/curvecp/curvecpprintkey.c b/nacl/curvecp/curvecpprintkey.c
new file mode 100644
index 00000000..8fd26bcf
--- /dev/null
+++ b/nacl/curvecp/curvecpprintkey.c
@@ -0,0 +1,46 @@
1#include <unistd.h>
2#include "die.h"
3#include "e.h"
4#include "load.h"
5#include "writeall.h"
6#include "crypto_box.h"
7
8unsigned char pk[crypto_box_PUBLICKEYBYTES];
9unsigned char out[crypto_box_PUBLICKEYBYTES * 2 + 1];
10
11void die_usage(void)
12{
13 die_1(111,"curvecpprintkey: usage: curvecpprintkey keydir\n");
14}
15
16void die_fatal(const char *trouble,const char *d,const char *fn)
17{
18 if (d) {
19 if (fn) die_9(111,"curvecpmakekey: fatal: ",trouble," ",d,"/",fn,": ",e_str(errno),"\n");
20 die_7(111,"curvecpmakekey: fatal: ",trouble," ",d,": ",e_str(errno),"\n");
21 }
22 die_5(111,"curvecpmakekey: fatal: ",trouble,": ",e_str(errno),"\n");
23}
24
25int main(int argc,char **argv)
26{
27 char *d;
28 long long j;
29
30 if (!argv[0]) die_usage();
31 if (!argv[1]) die_usage();
32 d = argv[1];
33
34 if (chdir(d) == -1) die_fatal("unable to chdir to directory",d,0);
35 if (load("publickey",pk,sizeof pk) == -1) die_fatal("unable to read",d,"publickey");
36
37 for (j = 0;j < crypto_box_PUBLICKEYBYTES;++j) {
38 out[2 * j + 0] = "0123456789abcdef"[15 & (int) (pk[j] >> 4)];
39 out[2 * j + 1] = "0123456789abcdef"[15 & (int) (pk[j] >> 0)];
40 }
41 out[2 * j] = '\n';
42
43 if (writeall(1,out,sizeof out) == -1) die_fatal("unable to write output",0,0);
44
45 return 0;
46}