sick

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

commit ec3a06cca6264dbe7ba775a13af695750b752fd0
parent 6474eebf7cc43835889c573f0905530e4244e952
Author: z3bra <willyatmailoodotorg>
Date:   Mon May 16 09:09:22 2016

Use predifined error values

Diffstat:
 sick.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/sick.c b/sick.c @@ -95,7 +95,6 @@ extractsig(unsigned char **sig, char *buf) end = strstr(buf, SIGEND); if (!(begin && end)) { - puts("Signature not found"); return 0; } @@ -184,7 +183,7 @@ sign(FILE *fp, FILE *key) len = bufferize(&buf, fp); if (len == 0) - return -1; + return ERR_NOMSG; msg = malloc(len); memcpy(msg, buf, len); @@ -218,19 +217,27 @@ check(FILE *fp, FILE *key) char *buf = NULL; unsigned char *sig, *msg, pub[32]; - if (fread(pub, 1, 32, key) < 32) - return -1; + if (fread(pub, 1, 32, key) < 32) { + return ERR_NOKEY; + } - len = bufferize(&buf, fp); - if (len == 0) - return -1; + if ((len = bufferize(&buf, fp)) == 0) + return ERR_NOMSG; + + if (extractsig(&sig, buf) == 0) { + free(buf); + return ERR_NOSIG; + } - if (extractsig(&sig, buf)) { - len = extractmsg(&msg, buf); - ret = ed25519_verify(sig, msg, len, pub); - free(msg); + + if ((len = extractmsg(&msg, buf)) == 0) { + free(buf); + free(sig); } + ret = ed25519_verify(sig, msg, len, pub); + + free(msg); free(buf); free(sig);