1
0

curvecpprintkey.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. unsigned char pk[crypto_box_PUBLICKEYBYTES];
  8. unsigned char out[crypto_box_PUBLICKEYBYTES * 2 + 1];
  9. void die_usage(void)
  10. {
  11. die_1(111,"curvecpprintkey: usage: curvecpprintkey keydir\n");
  12. }
  13. void die_fatal(const char *trouble,const char *d,const char *fn)
  14. {
  15. if (d) {
  16. if (fn) die_9(111,"curvecpmakekey: fatal: ",trouble," ",d,"/",fn,": ",e_str(errno),"\n");
  17. die_7(111,"curvecpmakekey: fatal: ",trouble," ",d,": ",e_str(errno),"\n");
  18. }
  19. die_5(111,"curvecpmakekey: fatal: ",trouble,": ",e_str(errno),"\n");
  20. }
  21. int main(int argc,char **argv)
  22. {
  23. char *d;
  24. long long j;
  25. if (!argv[0]) die_usage();
  26. if (!argv[1]) die_usage();
  27. d = argv[1];
  28. if (chdir(d) == -1) die_fatal("unable to chdir to directory",d,0);
  29. if (load("publickey",pk,sizeof pk) == -1) die_fatal("unable to read",d,"publickey");
  30. for (j = 0;j < crypto_box_PUBLICKEYBYTES;++j) {
  31. out[2 * j + 0] = "0123456789abcdef"[15 & (int) (pk[j] >> 4)];
  32. out[2 * j + 1] = "0123456789abcdef"[15 & (int) (pk[j] >> 0)];
  33. }
  34. out[2 * j] = '\n';
  35. if (writeall(1,out,sizeof out) == -1) die_fatal("unable to write output",0,0);
  36. return 0;
  37. }