sick

sign and check files using ed25519
Log | Files | Refs | Submodules | README | LICENSE

commit 7ecf401609eb89626e79c80bd037e529e5f33511
parent f25a0ec2408627875aea874ec4384e1cc0ad0d2e
Author: z3bra <willyatmailoodotorg>
Date:   Sun May 15 19:37:43 +12000

check() verifies the signature of the message

Diffstat:
sick.c | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/sick.c b/sick.c @@ -23,6 +23,7 @@ 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); +static int check(FILE *fp, FILE *key); static int verbose = 0; char *argv0; @@ -203,6 +204,33 @@ sign(FILE *fp, FILE *key) return 0; } +static int +check(FILE *fp, FILE *key) +{ + int ret = 0; + size_t len; + char *buf = NULL; + unsigned char *sig, *msg, pub[32]; + + if (fread(pub, 1, 32, key) < 32) + return -1; + + len = bufferize(&buf, fp); + if (len == 0) + return -1; + + if (extractsig(&sig, buf)) { + len = extractmsg(&msg, buf); + ret = ed25519_verify(sig, msg, len, pub); + free(msg); + } + + free(buf); + free(sig); + + return !ret; +} + int main(int argc, char *argv[]) {