tInitial commit - sick - sign and check files using ed25519
 (HTM) git clone git://z3bra.org/sick
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit efa917d9e3ed2304b728d4263944ecc86120656d
 (HTM) Author: z3bra <willyatmailoodotorg>
       Date:   Tue,  3 May 2016 22:17:23 +0200
       
       Initial commit
       
       Only function implemented yet is createkeypair() to generate a private
       and public keys for the given alias.
       
       Diffstat:
         A .gitmodules                         |       3 +++
         A LICENSE                             |      13 +++++++++++++
         A README                              |      11 +++++++++++
         A arg.h                               |      65 +++++++++++++++++++++++++++++++
         A config.mk                           |      12 ++++++++++++
         A ed25519                             |       1 +
         A mkfile                              |      27 +++++++++++++++++++++++++++
         A sick.1                              |      19 +++++++++++++++++++
         A sick.c                              |      85 +++++++++++++++++++++++++++++++
       
       9 files changed, 236 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/.gitmodules b/.gitmodules
       t@@ -0,0 +1,3 @@
       +[submodule "ed25519"]
       +        path = ed25519
       +        url = https://github.com/rdeker/ed25519.git
 (DIR) diff --git a/LICENSE b/LICENSE
       t@@ -0,0 +1,13 @@
       +Copyright (c) 2016 Willy Goiffon <willyatmailoodotorg>
       +
       +Permission to use, copy, modify, and/or distribute this software for any
       +purpose with or without fee is hereby granted, provided that the above
       +copyright notice and this permission notice appear in all copies.
       +
       +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
       +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
       +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
       +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
       +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
       +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
       +PERFORMANCE OF THIS SOFTWARE.
 (DIR) diff --git a/README b/README
       t@@ -0,0 +1,11 @@
       +# sick
       +
       +Sign and check files using ed25519.
       +sick(1) will let you generate private/public key pairs, sign files using your
       +private key, and check a file signature using public keys stored in a keyring.
       +
       +## Generating keys
       +
       +To generate a key pair, run
       +
       +        $ sick -g alice
 (DIR) diff --git a/arg.h b/arg.h
       t@@ -0,0 +1,65 @@
       +/*
       + * Copy me if you can.
       + * by 20h
       + */
       +
       +#ifndef ARG_H__
       +#define ARG_H__
       +
       +extern char *argv0;
       +
       +/* use main(int argc, char *argv[]) */
       +#define ARGBEGIN        for (argv0 = *argv, argv++, argc--;\
       +                                        argv[0] && argv[0][1]\
       +                                        && argv[0][0] == '-';\
       +                                        argc--, argv++) {\
       +                                char argc_;\
       +                                char **argv_;\
       +                                int brk_;\
       +                                if (argv[0][1] == '-' && argv[0][2] == '\0') {\
       +                                        argv++;\
       +                                        argc--;\
       +                                        break;\
       +                                }\
       +                                for (brk_ = 0, argv[0]++, argv_ = argv;\
       +                                                argv[0][0] && !brk_;\
       +                                                argv[0]++) {\
       +                                        if (argv_ != argv)\
       +                                                break;\
       +                                        argc_ = argv[0][0];\
       +                                        switch (argc_)
       +
       +/* Handles obsolete -NUM syntax */
       +#define ARGNUM                                case '0':\
       +                                        case '1':\
       +                                        case '2':\
       +                                        case '3':\
       +                                        case '4':\
       +                                        case '5':\
       +                                        case '6':\
       +                                        case '7':\
       +                                        case '8':\
       +                                        case '9'
       +
       +#define ARGEND                        }\
       +                        }
       +
       +#define ARGC()                argc_
       +
       +#define ARGNUMF()        (brk_ = 1, estrtonum(argv[0], 0, INT_MAX))
       +
       +#define EARGF(x)        ((argv[0][1] == '\0' && argv[1] == NULL)?\
       +                                ((x), abort(), (char *)0) :\
       +                                (brk_ = 1, (argv[0][1] != '\0')?\
       +                                        (&argv[0][1]) :\
       +                                        (argc--, argv++, argv[0])))
       +
       +#define ARGF()                ((argv[0][1] == '\0' && argv[1] == NULL)?\
       +                                (char *)0 :\
       +                                (brk_ = 1, (argv[0][1] != '\0')?\
       +                                        (&argv[0][1]) :\
       +                                        (argc--, argv++, argv[0])))
       +
       +#define LNGARG()        &argv[0][0]
       +
       +#endif
 (DIR) diff --git a/config.mk b/config.mk
       t@@ -0,0 +1,12 @@
       +VERSION = 0.0
       +
       +CC = cc
       +LD = ${CC}
       +
       +PREFIX = /usr/local
       +MANDIR = ${PREFIX}/man
       +
       +CPPFLAGS = -I./ed25519/src -DVERSION=\"${VERSION}\"
       +CFLAGS = ${CPPFLAGS} -Wall -Wextra -pedantic
       +LDFLAGS =
       +LIBS =
 (DIR) diff --git a/ed25519 b/ed25519
       t@@ -0,0 +1 @@
       +Subproject commit 13a0661670949bc2e1cfcd8720082d9670768041
 (DIR) diff --git a/mkfile b/mkfile
       t@@ -0,0 +1,27 @@
       +<config.mk
       +
       +ED25519_SRC = `{find ed25519/src -name '*.c'}
       +
       +SRC = sick.c ${ED25519_SRC}
       +OBJ = ${SRC:%.c=%.o}
       +
       +sick: $OBJ
       +        ${CC} $OBJ ${LDFLAGS} ${LIBS} -o sick
       +
       +%.o: %.c
       +        ${CC} ${CFLAGS} -c $stem.c -o $stem.o
       +
       +clean:V:
       +        rm -f $OBJ sick
       +
       +install:V: sick
       +        mkdir -p ${DESTDIR}${PREFIX}/bin
       +        cp sick ${DESTDIR}${PREFIX}/bin/sick
       +        chmod 755 ${DESTDIR}${PREFIX}/bin/sick
       +        mkdir -p ${DESTDIR}${MANDIR}/man1
       +        cp sick.1 ${DESTDIR}${MANDIR}/man1/sick.1
       +        chmod 644 ${DESTDIR}${MANDIR}/man1/sick.1
       +
       +uninstall:V:
       +        rm ${DESTDIR}${PREFIX}/bin/sick
       +        rm ${DESTDIR}${MANDIR}/man1/sick.1
 (DIR) diff --git a/sick.1 b/sick.1
       t@@ -0,0 +1,18 @@
       +.Dd 2016-05-03
       +.Dt SICK 1
       +.Os POSIX.1-2008
       +.Sh NAME
       +.Nm sick
       +.Nd sign/check files using ed25519 signatures
       +.Sh SYNOPSIS
       +.Nm sick
       +.Op Fl g Ar ALIAS
       +.Sh DESCRIPTION
       +.Nm
       +generates key pairs, signs, checks and remove signatures for a file or stream.
       +.Bl -tag -width Ds
       +.It Fl g Ar ALIAS
       +Generates an ed25519 key pairs: `ALIAS.key` and `ALIAS.pub`
       +.El
       +.Sh AUTHORS
       +.An Willy Goiffon Aq Mt willy@mailoo.org
       +\ No newline at end of file
 (DIR) diff --git a/sick.c b/sick.c
       t@@ -0,0 +1,85 @@
       +/* See LICENSE file for copyright and license details. */
       +#include <limits.h>
       +#include <stdio.h>
       +#include <stdlib.h>
       +#include <string.h>
       +
       +#include "arg.h"
       +#include "ed25519.h"
       +
       +static void usage();
       +static int createkeypair(const char *);
       +
       +char *argv0;
       +
       +static void
       +usage()
       +{
       +        fprintf(stderr, "usage: %s [-g ALIAS]\n", argv0);
       +        exit(EXIT_FAILURE);
       +}
       +
       +
       +/*
       + * Creates a set of ed25519 key pairs on disk.
       + */
       +static int
       +createkeypair(const char *alias)
       +{
       +        size_t len = 0;
       +        FILE *fp = NULL;
       +        char fn[PATH_MAX];
       +        unsigned char seed[32], pub[32], priv[64];
       +
       +        /*
       +         * don't bother checking if `len > 0`. If the user wants to create
       +         * files named ".key" and ".pub", that's OK.
       +         */
       +        len = strnlen(alias, PATH_MAX);
       +
       +        ed25519_create_seed(seed);
       +        ed25519_create_keypair(pub, priv, seed);
       +
       +        /* write private key to "<alias>.key" */
       +        memcpy(fn, alias, len);
       +        memcpy(fn+len, ".key", 4);
       +        if ((fp = fopen(fn, "w")) == NULL) {
       +                perror(fn);
       +                return -1;
       +        }
       +        if (fwrite(priv, 1, sizeof(priv), fp) < sizeof(priv)) {
       +                fclose(fp);
       +                perror(fn);
       +                return -1;
       +        }
       +        fclose(fp);
       +
       +        /* write public key to "<alias>.pub" */
       +        memcpy(fn+len, ".pub", 4);
       +        if ((fp = fopen(fn, "w")) == NULL) {
       +                perror(fn);
       +                return -1;
       +        }
       +        if (fwrite(priv, 1, sizeof(pub), fp) < sizeof(pub)) {
       +                fclose(fp);
       +                perror(fn);
       +                return -1;
       +        }
       +        fclose(fp);
       +
       +        return 0;
       +}
       +
       +int
       +main(int argc, char *argv[])
       +{
       +        ARGBEGIN{
       +        case 'g':
       +                createkeypair(EARGF(usage()));
       +                break;
       +        default:
       +                usage();
       +        }ARGEND;
       +
       +        return 0;
       +}