Mercurial > hg > quicktun
comparison src/proto.nacl0.c @ 37:bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Mon, 06 May 2013 21:28:45 +0200 |
parents | 5ba185ca7102 |
children | d9f5caa13898 |
comparison
equal
deleted
inserted
replaced
36:1fe62a94c28a | 37:bb4bbf380938 |
---|---|
60 memset(d->cnonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); | 60 memset(d->cnonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); |
61 unsigned char cpublickey[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES], csecretkey[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES]; | 61 unsigned char cpublickey[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES], csecretkey[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES]; |
62 if (!(envval = getconf("PUBLIC_KEY"))) return errorexit("Missing PUBLIC_KEY"); | 62 if (!(envval = getconf("PUBLIC_KEY"))) return errorexit("Missing PUBLIC_KEY"); |
63 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PUBLIC_KEY length"); | 63 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PUBLIC_KEY length"); |
64 hex2bin(cpublickey, envval, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); | 64 hex2bin(cpublickey, envval, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); |
65 if (!(envval = getconf("PRIVATE_KEY"))) return errorexit("Missing PRIVATE_KEY"); | 65 if (envval = getconf("PRIVATE_KEY")) { |
66 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PRIVATE_KEY length"); | 66 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PRIVATE_KEY length"); |
67 hex2bin(csecretkey, envval, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); | 67 hex2bin(csecretkey, envval, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
68 } else if (envval = getconf("PRIVATE_KEY_FILE")) { | |
69 FILE* pkfile = fopen(envval, "rb"); | |
70 if (!pkfile) return errorexitp("Could not open PRIVATE_KEY_FILE"); | |
71 char pktextbuf[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES * 2]; | |
72 size_t pktextsize = fread(pktextbuf, 1, sizeof(pktextbuf), pkfile); | |
73 if (pktextsize == crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { | |
74 memcpy(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); | |
75 } else if (pktextsize = 2 * crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { | |
76 hex2bin(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); | |
77 } else { | |
78 return errorexit("PRIVATE_KEY length"); | |
79 } | |
80 fclose(pkfile); | |
81 } else { | |
82 return errorexit("Missing PRIVATE_KEY"); | |
83 } | |
68 crypto_box_curve25519xsalsa20poly1305_beforenm(d->cbefore, cpublickey, csecretkey); | 84 crypto_box_curve25519xsalsa20poly1305_beforenm(d->cbefore, cpublickey, csecretkey); |
69 return 0; | 85 return 0; |
70 } | 86 } |
71 | 87 |
72 struct qtproto qtproto_nacl0 = { | 88 struct qtproto qtproto_nacl0 = { |