sick

sign and check files using ed25519
git clone git://z3bra.org/sick
Log | Files | Refs | Submodules | README | LICENSE

commit f25a0ec2408627875aea874ec4384e1cc0ad0d2e
parent 7da5e6eeeaafa4f29f629e0fe3b4ea4ee7db5f02
Author: z3bra <willyatmailoodotorg>
Date:   Sun May 15 19:35:25 2016

extractsig() copies the signature to the buffer

Diffstat:
 sick.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+), 0 deletions(-)

diff --git a/sick.c b/sick.c @@ -20,6 +20,7 @@ enum { static void usage(); static size_t bufferize(char **buf, FILE *fp); static size_t extractmsg(unsigned char *msg[], char *buf); +static size_t extractsig(unsigned char *sig[], char *buf); static int createkeypair(const char *); static int sign(FILE *fp, FILE *key); @@ -75,6 +76,44 @@ extractmsg(unsigned char **msg, char *buf) return len; } +static size_t +extractsig(unsigned char **sig, char *buf) +{ + off_t i; + size_t n, len = 0; + char *begin, *end, *tmp; + unsigned char base64[76]; + + begin = strstr(buf, SIGBEGIN) + strlen(SIGBEGIN); + end = strstr(buf, SIGEND); + + if (!(begin && end)) { + puts("Signature not found"); + return 0; + } + + *sig = malloc(64); + if (*sig == NULL) + return 0; + + memset(*sig, 0, 64); + + /* base64 signature are wrapped at 76 chars */ + for (i = 0; begin+i < end; i+=77) { + /* black magic pointer arithmetic there */ + n = begin+i+76 < end ? 76 : end - (begin + i); + memset(base64, 0, 76); + memcpy(base64, begin+i, n); + + n = base64_decode(&tmp, base64, n); + memcpy((*sig) + len, tmp, n); + len += n; + free(tmp); + } + + return len; +} + /* * Creates a set of ed25519 key pairs on disk. */