summaryrefslogtreecommitdiff
path: root/distrib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-04-17 03:48:36 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-04-17 03:48:36 +0000
commit989923a2c8d9cab91554f65b9e88863e1c837ec0 (patch)
treec58615036cc5dc92e22e434b66fad4672e54a9bb /distrib
parent43db761fb49da8aa05d4062449dc298d387a9314 (diff)
A very small sha256 program for the base media. Use it by piping data
through it... input | sha256 outfile | output, then check the contents of outfile after.
Diffstat (limited to 'distrib')
-rw-r--r--distrib/special/Makefile6
-rw-r--r--distrib/special/sha256/Makefile7
-rw-r--r--distrib/special/sha256/sha256.c56
3 files changed, 66 insertions, 3 deletions
diff --git a/distrib/special/Makefile b/distrib/special/Makefile
index 62381b606b3..6bde97dbe2e 100644
--- a/distrib/special/Makefile
+++ b/distrib/special/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.17 2007/11/26 15:36:38 deraadt Exp $
+# $OpenBSD: Makefile,v 1.18 2009/04/17 03:48:33 deraadt Exp $
-SUBDIR= dd ftp pppd rsh dhclient init disknames dmesg grep kbd newfs less \
- more gzip ccdconfig ifconfig libstubs
+SUBDIR= dd ftp pppd rsh dhclient init disknames dmesg grep kbd \
+ newfs less more gzip ccdconfig ifconfig sha256 libstubs
install:
diff --git a/distrib/special/sha256/Makefile b/distrib/special/sha256/Makefile
new file mode 100644
index 00000000000..53daf2bfe29
--- /dev/null
+++ b/distrib/special/sha256/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.1 2009/04/17 03:48:35 deraadt Exp $
+
+PROG= sha256
+MAN=
+COPTS+=-Os
+
+.include <bsd.prog.mk>
diff --git a/distrib/special/sha256/sha256.c b/distrib/special/sha256/sha256.c
new file mode 100644
index 00000000000..b579b7fe59a
--- /dev/null
+++ b/distrib/special/sha256/sha256.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: sha256.c,v 1.1 2009/04/17 03:48:35 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2009 Theo de Raadt <deraadt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and 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.
+ */
+#include <sys/types.h>
+#include <err.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sha2.h>
+
+int
+main(int argc, char *argv[])
+{
+ u_int8_t results[SHA256_DIGEST_LENGTH];
+ size_t nread, nwrite, i;
+ char buf[BUFSIZ];
+ SHA2_CTX ctx;
+ FILE *fp;
+
+ if (argv[1] == NULL) {
+ fprintf(stderr, "usage: sha256 outfile\n");
+ exit(1);
+ }
+
+ fp = fopen(argv[1], "w");
+
+ SHA256Init(&ctx);
+ while ((nread = read(STDIN_FILENO, buf, sizeof buf)) > 0) {
+ SHA256Update(&ctx, (u_int8_t *)buf, nread);
+ for (i = 0; i < nread ; ) {
+ nwrite = write(STDOUT_FILENO, buf + i, nread - i);
+ if (nwrite == -1)
+ exit(1);
+ i += nwrite;
+ }
+ }
+ SHA256End(&ctx, results);
+ fprintf(fp, "%s\n", results);
+ fclose(fp);
+ exit(0);
+}