sick

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

commit 398fc545a7d63eafa6764cf0ca320798ec3b88b3
parent cc294e4bf70f3e2bb907a15c94b18f3535011105
Author: z3bra <willyatmailoodotorg>
Date:   Wed Sep 14 23:52:23 +0200

Search signature backward from end of stream

Diffstat:
sick.c | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/sick.c b/sick.c @@ -51,12 +51,14 @@ usage() /* * Find a string within a memory chunk, stupid style! + * Search is done backward, as the signature will be appended at the + * end of the stream. */ char * memstr(const void *h0, size_t k, const char *n0, size_t l) { - size_t i; - const char *h = h0; + ssize_t i; + const unsigned char *h = h0; /* Return immediately on empty needle */ if (!l) return (char *)h; @@ -64,7 +66,7 @@ memstr(const void *h0, size_t k, const char *n0, size_t l) /* Return immediately when needle is longer than haystack */ if (k<l) return 0; - for (i=0; i<=(k-l); i++) { + for (i=k-l; i>0; i--) { if (memcmp(h+i, n0, l) == 0) return (char *)(h+i); }