aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-03-08 19:26:38 +0100
committerDuncaen <mail@duncano.de>2017-03-08 19:31:14 +0100
commit2eb043784fdc12b618a76fe0d929cd2d77a9d724 (patch)
tree0f92138adf8986ce07725dd3d4d09bc750dd7d96
parent7e765cdd84cb177ed08550be48ae94ef235c335b (diff)
downloadlobase-2eb043784fdc12b618a76fe0d929cd2d77a9d724.tar.gz
lib/libopenbsd: move headers to include and move some code into subdirs
-rw-r--r--include/compat.h (renamed from lib/libopenbsd/openbsd.h)16
-rw-r--r--include/readpassphrase.h (renamed from lib/libopenbsd/readpassphrase.h)0
-rw-r--r--include/unistd.h1
-rw-r--r--include/vis.h (renamed from lib/libopenbsd/vis.h)0
-rw-r--r--lib/libopenbsd/Makefile82
-rw-r--r--lib/libopenbsd/chacha.h48
-rw-r--r--lib/libopenbsd/config.mk.in4
-rw-r--r--lib/libopenbsd/crypt/chacha-merged.c270
-rw-r--r--lib/libopenbsd/crypt/chacha.c77
-rw-r--r--lib/libopenbsd/crypt/chacha_private.h2
-rw-r--r--lib/libopenbsd/gen/unvis.3 (renamed from lib/libopenbsd/unvis.3)0
-rw-r--r--lib/libopenbsd/gen/unvis.c (renamed from lib/libopenbsd/unvis.c)0
-rw-r--r--lib/libopenbsd/gen/vis.3 (renamed from lib/libopenbsd/vis.3)0
-rw-r--r--lib/libopenbsd/gen/vis.c (renamed from lib/libopenbsd/vis.c)0
-rwxr-xr-xlib/libopenbsd/getfsstatbin11024 -> 0 bytes
-rw-r--r--lib/libopenbsd/getfsstat.2149
-rw-r--r--lib/libopenbsd/getfsstat.c120
-rw-r--r--lib/libopenbsd/getmntinfo.c2
-rw-r--r--lib/libopenbsd/include/namespace.h164
-rw-r--r--lib/libopenbsd/pledge-noop.c2
-rw-r--r--lib/libopenbsd/stdlib/malloc.3526
-rw-r--r--lib/libopenbsd/string/strlcpy.3188
-rw-r--r--lib/libopenbsd/util.h2
23 files changed, 900 insertions, 753 deletions
diff --git a/lib/libopenbsd/openbsd.h b/include/compat.h
index f1488d2..a5f3990 100644
--- a/lib/libopenbsd/openbsd.h
+++ b/include/compat.h
@@ -1,15 +1,10 @@
-#ifndef _OPENBSD_H
-#define _OPENBSD_H
-/* #define _GNU_SOURCE */
-/* #include <stdarg.h> */
-/* #include <stdint.h> */
-/* #include <limits.h> */
-/* #include <sys/types.h> */
-/* #undef _GNU_SOURCE */
-/* #undef _FEATURES_H */
+#ifndef _COMPAT_H_
+#define _COMPAT_H_
#define FAIL_INSTEAD_OF_TRYING_FALLBACK
+#define __warn_references(x,y)
+
#ifndef ALIGN
/* XXX: x86_64 only, see sys/arch/$arch/include/_types.h */
#define ALIGNBYTES (sizeof(long) - 1)
@@ -34,9 +29,6 @@
#define __weak_alias(new, old) \
extern __typeof(old) new __attribute__((weak, alias(#old)))
-#define MAKE_CLONE(new, old) \
- extern __typeof(old) new __attribute__((weak, alias(#old)))
-
#ifndef SA_LEN
#define SA_LEN(X) \
(((struct sockaddr*)(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
diff --git a/lib/libopenbsd/readpassphrase.h b/include/readpassphrase.h
index 5444597..5444597 100644
--- a/lib/libopenbsd/readpassphrase.h
+++ b/include/readpassphrase.h
diff --git a/include/unistd.h b/include/unistd.h
index 061192e..0d3cbd6 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -51,6 +51,7 @@ int getresuid(uid_t *, uid_t *, uid_t *);
void *setmode(const char *);
int setresgid(gid_t, gid_t, gid_t);
int setresuid(uid_t, uid_t, uid_t);
+int pledge(const char *, const char *[]);
#endif /* _COMPAT_UNISTD_H_ */
diff --git a/lib/libopenbsd/vis.h b/include/vis.h
index ad05b07..ad05b07 100644
--- a/lib/libopenbsd/vis.h
+++ b/include/vis.h
diff --git a/lib/libopenbsd/Makefile b/lib/libopenbsd/Makefile
index 6732bbc..d24b4a3 100644
--- a/lib/libopenbsd/Makefile
+++ b/lib/libopenbsd/Makefile
@@ -1,85 +1,31 @@
-LIB=openbsd
-CPPFLAGS += -I. -Ihidden -include openbsd.h -I.. -include config.h
+.TOPDIR?=../..
+.CURDIR?=.
-GEN_SRCS = hash/md5hl.c hash/rmd160hl.c hash/sha1hl.c hash/sha224hl.c \
- hash/sha256hl.c hash/sha384hl.c hash/sha512hl.c
+LIB=openbsd
-CLEANFILES+=$(GEN_SRCS)
+# CPPFLAGS += -include include/compat.h -include config.h
-SRCS = closefrom.c \
+SRCS+= closefrom.c \
heapsort.c merge.c pledge-noop.c progname.c \
qsort.c radixsort.c random.c readpassphrase.c \
setproctitle.c strtoimax.c strtonum.c strtoumax.c \
- vis.c unvis.c pwcache.c pw_dup.c getbsize.c \
- strmode.c crypt/arc4random.c crypt/arc4random_uniform.c \
- crypt/chacha.c crypt/blowfish.c hash/md5.c hash/rmd160.c hash/sha1.c \
- hash/sha2.c $(GEN_SRCS)
-
-SRCS += gen/errc.c gen/fts.c gen/warnc.c gen/verrc.c gen/vwarnc.c gen/setmode.c\
- gen/basename.c gen/dirname.c
-SRCS += stdio/fgetwln.c
-SRCS += net/base64.c
-
-SRCS += regex/regcomp.c regex/regerror.c regex/regexec.c regex/regfree.c
-
-include config.mk
-
-ifneq ($(HAVE_EXPLICIT_BZERO),1)
- SRCS += string/explicit_bzero.c
-endif
+ pwcache.c pw_dup.c getbsize.c \
+ strmode.c
-ifneq ($(HAVE_REALLOCARRAY),1)
- SRCS += stdlib/reallocarray.c
-endif
-ifneq ($(HAVE_STRLCPY),1)
- SRCS += string/strlcpy.c
-endif
+LIBCSRCDIR=${.CURDIR}
+include ${LIBCSRCDIR}/Makefile.inc
-ifneq ($(HAVE_STRLCAT),1)
- SRCS += string/strlcat.c
-endif
+include ${.TOPDIR}/config.mk
ifneq ($(HAVE_ISSETUGID),1)
- SRCS += issetugid.c
-endif
-
-ifneq ($(HAVE_FGETLN),1)
- SRCS += stdio/fgetln.c
+SRCS+= issetugid.c
endif
ifneq ($(HAVE_GETENTROPY),1)
- SRCS += getentropy_linux.c
+# XXX: fix fstatfs
+SRCS+= getentropy_linux.c
getentropy_linux.o : CPPFLAGS += -D_GNU_SOURCE
endif
-ifneq ($(HAVE_GETDTABLECOUNT),1)
- SRCS += sys/getdtablecount.c
-endif
-
-ifneq ($(HAVE_GETFSSTAT),1)
- SRCS += sys/getfsstat.c
- SRCS += sys/statfs.c
-endif
-
-ifneq ($(HAVE_GETMNTINFO),1)
- SRCS += gen/getmntinfo.c
-endif
-
-$(GEN_SRCS) : % : hash/helper.c
-
-hash/sha1hl.c:
- sed -e 's/hashinc/sha1.h/g;s/HASH/SHA1/g' hash/helper.c > $@
-
-hash/sha%hl.c:
- sed -e 's/hashinc/sha2.h/g;s/HASH_CTX/SHA2_CTX/g' \
- -e 's/HASH/SHA$*/g' hash/helper.c > $@
-
-hash/md5hl.c:
- sed -e "s/hashinc/md5.h/g;s/HASH/MD5/g" hash/helper.c > $@
-
-hash/rmd160hl.c:
- sed -e "s/hashinc/rmd160.h/g;s/HASH/RMD160/g" hash/helper.c > $@
-
-
-include bsd.lib.mk
+include ${.TOPDIR}/mk/bsd.lib.mk
diff --git a/lib/libopenbsd/chacha.h b/lib/libopenbsd/chacha.h
deleted file mode 100644
index 01388b7..0000000
--- a/lib/libopenbsd/chacha.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $OpenBSD: chacha.h,v 1.6 2014/07/25 14:04:51 jsing Exp $ */
-/*
- * Copyright (c) 2014 Joel Sing <jsing@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.
- */
-
-#ifndef HEADER_CHACHA_H
-#define HEADER_CHACHA_H
-
-#include <stddef.h>
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- unsigned int input[16];
- unsigned char ks[64];
- unsigned char unused;
-} ChaCha_ctx;
-
-void ChaCha_set_key(ChaCha_ctx *ctx, const unsigned char *key,
- unsigned int keybits);
-void ChaCha_set_iv(ChaCha_ctx *ctx, const unsigned char *iv,
- const unsigned char *counter);
-void ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in,
- size_t len);
-
-void CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len,
- const unsigned char key[32], const unsigned char iv[8], uint64_t counter);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* HEADER_CHACHA_H */
diff --git a/lib/libopenbsd/config.mk.in b/lib/libopenbsd/config.mk.in
deleted file mode 100644
index 257bdc9..0000000
--- a/lib/libopenbsd/config.mk.in
+++ /dev/null
@@ -1,4 +0,0 @@
-HAVE_STRLCAT = @HAVE_STRLCAT@
-HAVE_STRLCPY = @HAVE_STRLCPY@
-HAVE_GETENTROPY = @HAVE_GETENTROPY@
-include ../config.mk
diff --git a/lib/libopenbsd/crypt/chacha-merged.c b/lib/libopenbsd/crypt/chacha-merged.c
deleted file mode 100644
index b6eaf85..0000000
--- a/lib/libopenbsd/crypt/chacha-merged.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/* $OpenBSD: chacha-merged.c,v 1.6 2014/06/24 18:12:09 jsing Exp $ */
-/*
-chacha-merged.c version 20080118
-D. J. Bernstein
-Public domain.
-*/
-
-#include <sys/types.h>
-
-#include <stdint.h>
-
-#define CHACHA_MINKEYLEN 16
-#define CHACHA_NONCELEN 8
-#define CHACHA_CTRLEN 8
-#define CHACHA_STATELEN (CHACHA_NONCELEN+CHACHA_CTRLEN)
-#define CHACHA_BLOCKLEN 64
-
-struct chacha_ctx {
- u_int input[16];
- uint8_t ks[CHACHA_BLOCKLEN];
- uint8_t unused;
-};
-
-static inline void chacha_keysetup(struct chacha_ctx *x, const u_char *k,
- u_int kbits)
- __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN)));
-static inline void chacha_ivsetup(struct chacha_ctx *x, const u_char *iv,
- const u_char *ctr)
- __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN)))
- __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN)));
-static inline void chacha_encrypt_bytes(struct chacha_ctx *x, const u_char *m,
- u_char *c, u_int bytes)
- __attribute__((__bounded__(__buffer__, 2, 4)))
- __attribute__((__bounded__(__buffer__, 3, 4)));
-
-typedef unsigned char u8;
-typedef unsigned int u32;
-
-typedef struct chacha_ctx chacha_ctx;
-
-#define U8C(v) (v##U)
-#define U32C(v) (v##U)
-
-#define U8V(v) ((u8)(v) & U8C(0xFF))
-#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
-
-#define ROTL32(v, n) \
- (U32V((v) << (n)) | ((v) >> (32 - (n))))
-
-#define U8TO32_LITTLE(p) \
- (((u32)((p)[0])) | \
- ((u32)((p)[1]) << 8) | \
- ((u32)((p)[2]) << 16) | \
- ((u32)((p)[3]) << 24))
-
-#define U32TO8_LITTLE(p, v) \
- do { \
- (p)[0] = U8V((v)); \
- (p)[1] = U8V((v) >> 8); \
- (p)[2] = U8V((v) >> 16); \
- (p)[3] = U8V((v) >> 24); \
- } while (0)
-
-#define ROTATE(v,c) (ROTL32(v,c))
-#define XOR(v,w) ((v) ^ (w))
-#define PLUS(v,w) (U32V((v) + (w)))
-#define PLUSONE(v) (PLUS((v),1))
-
-#define QUARTERROUND(a,b,c,d) \
- a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
- c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
- a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
- c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
-
-static const char sigma[16] = "expand 32-byte k";
-static const char tau[16] = "expand 16-byte k";
-
-static inline void
-chacha_keysetup(chacha_ctx *x, const u8 *k, u32 kbits)
-{
- const char *constants;
-
- x->input[4] = U8TO32_LITTLE(k + 0);
- x->input[5] = U8TO32_LITTLE(k + 4);
- x->input[6] = U8TO32_LITTLE(k + 8);
- x->input[7] = U8TO32_LITTLE(k + 12);
- if (kbits == 256) { /* recommended */
- k += 16;
- constants = sigma;
- } else { /* kbits == 128 */
- constants = tau;
- }
- x->input[8] = U8TO32_LITTLE(k + 0);
- x->input[9] = U8TO32_LITTLE(k + 4);
- x->input[10] = U8TO32_LITTLE(k + 8);
- x->input[11] = U8TO32_LITTLE(k + 12);
- x->input[0] = U8TO32_LITTLE(constants + 0);
- x->input[1] = U8TO32_LITTLE(constants + 4);
- x->input[2] = U8TO32_LITTLE(constants + 8);
- x->input[3] = U8TO32_LITTLE(constants + 12);
-}
-
-static inline void
-chacha_ivsetup(chacha_ctx *x, const u8 *iv, const u8 *counter)
-{
- x->input[12] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 0);
- x->input[13] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 4);
- x->input[14] = U8TO32_LITTLE(iv + 0);
- x->input[15] = U8TO32_LITTLE(iv + 4);
-}
-
-static inline void
-chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, u32 bytes)
-{
- u32 x0, x1, x2, x3, x4, x5, x6, x7;
- u32 x8, x9, x10, x11, x12, x13, x14, x15;
- u32 j0, j1, j2, j3, j4, j5, j6, j7;
- u32 j8, j9, j10, j11, j12, j13, j14, j15;
- u8 *ctarget = NULL;
- u8 tmp[64];
- u_int i;
-
- if (!bytes)
- return;
-
- j0 = x->input[0];
- j1 = x->input[1];
- j2 = x->input[2];
- j3 = x->input[3];
- j4 = x->input[4];
- j5 = x->input[5];
- j6 = x->input[6];
- j7 = x->input[7];
- j8 = x->input[8];
- j9 = x->input[9];
- j10 = x->input[10];
- j11 = x->input[11];
- j12 = x->input[12];
- j13 = x->input[13];
- j14 = x->input[14];
- j15 = x->input[15];
-
- for (;;) {
- if (bytes < 64) {
- for (i = 0; i < bytes; ++i)
- tmp[i] = m[i];
- m = tmp;
- ctarget = c;
- c = tmp;
- }
- x0 = j0;
- x1 = j1;
- x2 = j2;
- x3 = j3;
- x4 = j4;
- x5 = j5;
- x6 = j6;
- x7 = j7;
- x8 = j8;
- x9 = j9;
- x10 = j10;
- x11 = j11;
- x12 = j12;
- x13 = j13;
- x14 = j14;
- x15 = j15;
- for (i = 20; i > 0; i -= 2) {
- QUARTERROUND(x0, x4, x8, x12)
- QUARTERROUND(x1, x5, x9, x13)
- QUARTERROUND(x2, x6, x10, x14)
- QUARTERROUND(x3, x7, x11, x15)
- QUARTERROUND(x0, x5, x10, x15)
- QUARTERROUND(x1, x6, x11, x12)
- QUARTERROUND(x2, x7, x8, x13)
- QUARTERROUND(x3, x4, x9, x14)
- }
- x0 = PLUS(x0, j0);
- x1 = PLUS(x1, j1);
- x2 = PLUS(x2, j2);
- x3 = PLUS(x3, j3);
- x4 = PLUS(x4, j4);
- x5 = PLUS(x5, j5);
- x6 = PLUS(x6, j6);
- x7 = PLUS(x7, j7);
- x8 = PLUS(x8, j8);
- x9 = PLUS(x9, j9);
- x10 = PLUS(x10, j10);
- x11 = PLUS(x11, j11);
- x12 = PLUS(x12, j12);
- x13 = PLUS(x13, j13);
- x14 = PLUS(x14, j14);
- x15 = PLUS(x15, j15);
-
- if (bytes < 64) {
- U32TO8_LITTLE(x->ks + 0, x0);
- U32TO8_LITTLE(x->ks + 4, x1);
- U32TO8_LITTLE(x->ks + 8, x2);
- U32TO8_LITTLE(x->ks + 12, x3);
- U32TO8_LITTLE(x->ks + 16, x4);
- U32TO8_LITTLE(x->ks + 20, x5);
- U32TO8_LITTLE(x->ks + 24, x6);
- U32TO8_LITTLE(x->ks + 28, x7);
- U32TO8_LITTLE(x->ks + 32, x8);
- U32TO8_LITTLE(x->ks + 36, x9);
- U32TO8_LITTLE(x->ks + 40, x10);
- U32TO8_LITTLE(x->ks + 44, x11);
- U32TO8_LITTLE(x->ks + 48, x12);
- U32TO8_LITTLE(x->ks + 52, x13);
- U32TO8_LITTLE(x->ks + 56, x14);
- U32TO8_LITTLE(x->ks + 60, x15);
- }
-
- x0 = XOR(x0, U8TO32_LITTLE(m + 0));
- x1 = XOR(x1, U8TO32_LITTLE(m + 4));
- x2 = XOR(x2, U8TO32_LITTLE(m + 8));
- x3 = XOR(x3, U8TO32_LITTLE(m + 12));
- x4 = XOR(x4, U8TO32_LITTLE(m + 16));
- x5 = XOR(x5, U8TO32_LITTLE(m + 20));
- x6 = XOR(x6, U8TO32_LITTLE(m + 24));
- x7 = XOR(x7, U8TO32_LITTLE(m + 28));
- x8 = XOR(x8, U8TO32_LITTLE(m + 32));
- x9 = XOR(x9, U8TO32_LITTLE(m + 36));
- x10 = XOR(x10, U8TO32_LITTLE(m + 40));
- x11 = XOR(x11, U8TO32_LITTLE(m + 44));
- x12 = XOR(x12, U8TO32_LITTLE(m + 48));
- x13 = XOR(x13, U8TO32_LITTLE(m + 52));
- x14 = XOR(x14, U8TO32_LITTLE(m + 56));
- x15 = XOR(x15, U8TO32_LITTLE(m + 60));
-
- j12 = PLUSONE(j12);
- if (!j12) {
- j13 = PLUSONE(j13);
- /*
- * Stopping at 2^70 bytes per nonce is the user's
- * responsibility.
- */
- }
-
- U32TO8_LITTLE(c + 0, x0);
- U32TO8_LITTLE(c + 4, x1);
- U32TO8_LITTLE(c + 8, x2);
- U32TO8_LITTLE(c + 12, x3);
- U32TO8_LITTLE(c + 16, x4);
- U32TO8_LITTLE(c + 20, x5);
- U32TO8_LITTLE(c + 24, x6);
- U32TO8_LITTLE(c + 28, x7);
- U32TO8_LITTLE(c + 32, x8);
- U32TO8_LITTLE(c + 36, x9);
- U32TO8_LITTLE(c + 40, x10);
- U32TO8_LITTLE(c + 44, x11);
- U32TO8_LITTLE(c + 48, x12);
- U32TO8_LITTLE(c + 52, x13);
- U32TO8_LITTLE(c + 56, x14);
- U32TO8_LITTLE(c + 60, x15);
-
- if (bytes <= 64) {
- if (bytes < 64) {
- for (i = 0; i < bytes; ++i)
- ctarget[i] = c[i];
- }
- x->input[12] = j12;
- x->input[13] = j13;
- x->unused = 64 - bytes;
- return;
- }
- bytes -= 64;
- c += 64;
- m += 64;
- }
-}
diff --git a/lib/libopenbsd/crypt/chacha.c b/lib/libopenbsd/crypt/chacha.c
deleted file mode 100644
index e79435f..0000000
--- a/lib/libopenbsd/crypt/chacha.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/* $OpenBSD: chacha.c,v 1.6 2014/07/08 14:30:23 bcook Exp $ */
-/*
- * Copyright (c) 2014 Joel Sing <jsing@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 <stdint.h>
-
-#include <chacha.h>
-
-#include "chacha-merged.c"
-
-void
-ChaCha_set_key(ChaCha_ctx *ctx, const unsigned char *key, uint32_t keybits)
-{
- chacha_keysetup((chacha_ctx *)ctx, key, keybits);
- ctx->unused = 0;
-}
-
-void
-ChaCha_set_iv(ChaCha_ctx *ctx, const unsigned char *iv,
- const unsigned char *counter)
-{
- chacha_ivsetup((chacha_ctx *)ctx, iv, counter);
- ctx->unused = 0;
-}
-
-void
-ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, size_t len)
-{
- unsigned char *k;
- int i, l;
-
- /* Consume remaining keystream, if any exists. */
- if (ctx->unused > 0) {
- k = ctx->ks + 64 - ctx->unused;
- l = (len > ctx->unused) ? ctx->unused : len;
- for (i = 0; i < l; i++)
- *(out++) = *(in++) ^ *(k++);
- ctx->unused -= l;
- len -= l;
- }
-
- chacha_encrypt_bytes((chacha_ctx *)ctx, in, out, (uint32_t)len);
-}
-
-void
-CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len,
- const unsigned char key[32], const unsigned char iv[8], uint64_t counter)
-{
- struct chacha_ctx ctx;
-
- /*
- * chacha_ivsetup expects the counter to be in u8. Rather than
- * converting size_t to u8 and then back again, pass a counter of
- * NULL and manually assign it afterwards.
- */
- chacha_keysetup(&ctx, key, 256);
- chacha_ivsetup(&ctx, iv, NULL);
- if (counter != 0) {
- ctx.input[12] = (uint32_t)counter;
- ctx.input[13] = (uint32_t)(counter >> 32);
- }
-
- chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len);
-}
diff --git a/lib/libopenbsd/crypt/chacha_private.h b/lib/libopenbsd/crypt/chacha_private.h
index b720d93..7c3680f 100644
--- a/lib/libopenbsd/crypt/chacha_private.h
+++ b/lib/libopenbsd/crypt/chacha_private.h
@@ -4,7 +4,7 @@ D. J. Bernstein
Public domain.
*/
-/* $OpenBSD$ */
+/* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */
typedef unsigned char u8;
typedef unsigned int u32;
diff --git a/lib/libopenbsd/unvis.3 b/lib/libopenbsd/gen/unvis.3
index 11ea34f..11ea34f 100644
--- a/lib/libopenbsd/unvis.3
+++ b/lib/libopenbsd/gen/unvis.3
diff --git a/lib/libopenbsd/unvis.c b/lib/libopenbsd/gen/unvis.c
index 05749aa..05749aa 100644
--- a/lib/libopenbsd/unvis.c
+++ b/lib/libopenbsd/gen/unvis.c
diff --git a/lib/libopenbsd/vis.3 b/lib/libopenbsd/gen/vis.3
index 08ee3b5..08ee3b5 100644
--- a/lib/libopenbsd/vis.3
+++ b/lib/libopenbsd/gen/vis.3
diff --git a/lib/libopenbsd/vis.c b/lib/libopenbsd/gen/vis.c
index 4400c7b..4400c7b 100644
--- a/lib/libopenbsd/vis.c
+++ b/lib/libopenbsd/gen/vis.c
diff --git a/lib/libopenbsd/getfsstat b/lib/libopenbsd/getfsstat
deleted file mode 100755
index 58bce77..0000000
--- a/lib/libopenbsd/getfsstat
+++ /dev/null
Binary files differ
diff --git a/lib/libopenbsd/getfsstat.2 b/lib/libopenbsd/getfsstat.2
deleted file mode 100644
index ff79c94..0000000
--- a/lib/libopenbsd/getfsstat.2
+++ /dev/null
@@ -1,149 +0,0 @@
-.\" $OpenBSD: getfsstat.2,v 1.20 2014/12/16 00:06:49 schwarze Exp $
-.\" $NetBSD: getfsstat.2,v 1.6 1995/06/29 11:40:44 cgd Exp $
-.\"
-.\" Copyright (c) 1989, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)getfsstat.2 8.1 (Berkeley) 6/9/93
-.\"
-.Dd $Mdocdate: December 16 2014 $
-.Dt GETFSSTAT 2
-.Os
-.Sh NAME
-.Nm getfsstat
-.Nd get list of all mounted file systems
-.Sh SYNOPSIS
-.In sys/param.h
-.In sys/mount.h
-.Ft int
-.Fn getfsstat "struct statfs *buf" "size_t bufsize" "int flags"
-.Sh DESCRIPTION
-.Fn getfsstat
-returns information about all mounted file systems.
-.Fa buf
-is a pointer to an array of
-.Xr statfs 2
-structures defined as follows:
-.Bd -literal
-typedef struct { int32_t val[2]; } fsid_t;
-
-#define MFSNAMELEN 16 /* length of fs type name, including nul */
-#define MNAMELEN 90 /* length of buffer for returned name */
-
-struct statfs {
- u_int32_t f_flags; /* copy of mount flags */
- u_int32_t f_bsize; /* file system block size */
- u_int32_t f_iosize; /* optimal transfer block size */
-
- /* unit is f_bsize */
- u_int64_t f_blocks; /* total data blocks in file system */
- u_int64_t f_bfree; /* free blocks in fs */
- int64_t f_bavail; /* free blocks avail to non-superuser */
-
- u_int64_t f_files; /* total file nodes in file system */
- u_int64_t f_ffree; /* free file nodes in fs */
- int64_t f_favail; /* free file nodes avail to non-root */
-
- u_int64_t f_syncwrites; /* count of sync writes since mount */
- u_int64_t f_syncreads; /* count of sync reads since mount */
- u_int64_t f_asyncwrites; /* count of async writes since mount */
- u_int64_t f_asyncreads; /* count of async reads since mount */
-
- fsid_t f_fsid; /* file system id */
- u_int32_t f_namemax; /* maximum filename length */
- uid_t f_owner; /* user that mounted the file system */
- u_int64_t f_ctime; /* last mount [-u] time */
-
- char f_fstypename[MFSNAMELEN]; /* fs type name */
- char f_mntonname[MNAMELEN]; /* directory on which mounted */
- char f_mntfromname[MNAMELEN]; /* mounted file system */
- char f_mntfromspec[MNAMELEN]; /* special for mount request */
- union mount_info mount_info; /* per-filesystem mount options */
-};
-.Ed
-.Pp
-The buffer is filled with an array of
-.Fa statfs
-structures, one for each mounted file system
-up to the size specified by
-.Fa bufsize .
-.Pp
-If
-.Fa buf
-is
-.Dv NULL ,
-.Fn getfsstat
-returns just the number of mounted file systems.
-.Pp
-Normally
-.Fa flags
-should be specified as
-.Dv MNT_WAIT .
-If
-.Fa flags
-is set to
-.Dv MNT_NOWAIT ,
-.Fn getfsstat
-will return the information it has available without requesting
-an update from each file system.
-Thus, some of the information will be out of date, but
-.Fn getfsstat
-will not block waiting for information from a file system that is
-unable to respond.
-If no flags are provided,
-.Dv MNT_WAIT
-is assumed.
-.Pp
-Note that
-.Fa f_fsid
-will be empty unless the user is the superuser.
-.Sh RETURN VALUES
-Upon successful completion, the number of
-.Fa statfs
-structures is returned.
-Otherwise, \-1 is returned and the global variable
-.Va errno
-is set to indicate the error.
-.Sh ERRORS
-.Fn getfsstat
-fails if one or more of the following are true:
-.Bl -tag -width Er
-.It Bq Er EFAULT
-.Fa buf
-points to an invalid address.
-.It Bq Er EIO
-An I/O error occurred while reading from or writing to the file system.
-.El
-.Sh SEE ALSO
-.Xr statfs 2 ,
-.Xr fstab 5 ,
-.Xr mount 8
-.Sh HISTORY
-The
-.Fn getfsstat
-function first appeared in
-.Bx 4.4 .
diff --git a/lib/libopenbsd/getfsstat.c b/lib/libopenbsd/getfsstat.c
deleted file mode 100644
index ad32f04..0000000
--- a/lib/libopenbsd/getfsstat.c
+++ /dev/null
@@ -1,120 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/statfs.h>
-#include <sys/types.h>
-#include <mntent.h>
-
-typedef struct { int32_t val[2]; } obsd_fsid_t;
-
-#define MFSNAMELEN 16 /* length of fs type name, including nul */
-#define MNAMELEN 90 /* length of buffer for returned name */
-
-/* per-filesystem mount options */
-union mount_info {
- struct ufs_args ufs_args;
- struct mfs_args mfs_args;
- struct nfs_args nfs_args;
- struct iso_args iso_args;
- struct msdosfs_args msdosfs_args;
- struct ntfs_args ntfs_args;
- struct tmpfs_args tmpfs_args;
- char __align[160]; /* 64-bit alignment and room to grow */
-};
-
-
-struct obsd_statfs {
- u_int32_t f_flags; /* copy of mount flags */
- u_int32_t f_bsize; /* file system block size */
- u_int32_t f_iosize; /* optimal transfer block size */
-
- /* unit is f_bsize */
- u_int64_t f_blocks; /* total data blocks in file system */
- u_int64_t f_bfree; /* free blocks in fs */
- int64_t f_bavail; /* free blocks avail to non-superuser */
-
- u_int64_t f_files; /* total file nodes in file system */
- u_int64_t f_ffree; /* free file nodes in fs */
- int64_t f_favail; /* free file nodes avail to non-root */
-
- u_int64_t f_syncwrites; /* count of sync writes since mount */
- u_int64_t f_syncreads; /* count of sync reads since mount */
- u_int64_t f_asyncwrites; /* count of async writes since mount */
- u_int64_t f_asyncreads; /* count of async reads since mount */
-
- obsd_fsid_t f_fsid; /* file system id */
- u_int32_t f_namemax; /* maximum filename length */
- uid_t f_owner; /* user that mounted the file system */
- u_int64_t f_ctime; /* last mount [-u] time */
-
- char f_fstypename[MFSNAMELEN]; /* fs type name */
- char f_mntonname[MNAMELEN]; /* directory on which mounted */
- char f_mntfromname[MNAMELEN]; /* mounted file system */
- char f_mntfromspec[MNAMELEN]; /* special for mount request */
- union mount_info mount_info; /* per-filesystem mount options */
-};
-
-static char linebuf[256];
-
-static int
-nummounts(FILE *f)
-{
- int rv;
-
- rv = 0;
-
- for (;;) {
- fgets(linebuf, sizeof linebuf, f);
- if (ferror(f)) {
- rv = -1;
- break;
- }
- if (!strchr(linebuf, '\n')) {
- errno = ERANGE;
- rv = -1;
- break;
- }
- if (feof(f))
- break;
- rv++;
- }
-
- return rv;
-}
-
-int
-statfs(const char *path, struct statfs *buf)
-{
- static struct ln_statfs fs;
-}
-
-int
-getfsstat(struct statfs *buf, size_t bufsize, int flags)
-{
- static struct mntent mnt;
- FILE *f;
- int i;
-
- if (!(f = fopen("/etc/mtab", "r")))
- return -1;
-
- if(!buf) {
- i = nummounts(f);
- fclose(f);
- return i;
- }
-
- for (i = 0; i < bufsize; i++) {
- getmntent_r(f, &mnt, linebuf, sizeof linebuf);
- }
-
- fclose(f);
- return i;
-}
-
-int
-main()
-{
- printf("num %d error %s\n", getfsstat(0, 0, 0), strerror(errno));
-}
diff --git a/lib/libopenbsd/getmntinfo.c b/lib/libopenbsd/getmntinfo.c
index 5781340..2bbde41 100644
--- a/lib/libopenbsd/getmntinfo.c
+++ b/lib/libopenbsd/getmntinfo.c
@@ -30,7 +30,9 @@
#include <sys/types.h>
#include <sys/mount.h>
+
#include <stdlib.h>
+#include <mntent.h>
/*
* Return information about mounted filesystems.
diff --git a/lib/libopenbsd/include/namespace.h b/lib/libopenbsd/include/namespace.h
new file mode 100644
index 0000000..65d739a
--- /dev/null
+++ b/lib/libopenbsd/include/namespace.h
@@ -0,0 +1,164 @@
+/* $OpenBSD: namespace.h,v 1.10 2016/05/07 19:05:22 guenther Exp $ */
+
+#ifndef _LIBC_NAMESPACE_H_
+#define _LIBC_NAMESPACE_H_
+
+/*
+ * Copyright (c) 2015 Philip Guenther <guenther@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.
+ */
+
+/*
+ * The goal: calls from inside libc to other libc functions should be via
+ * identifiers that are of hidden visibility and--to avoid confusion--are
+ * in the reserved namespace. By doing this these calls are protected
+ * from overriding by applications and on many platforms can avoid creation
+ * or use of GOT or PLT entries. I've chosen a prefix of underbar-C-underbar
+ * ("_libc_") for this. These will not be declared directly; instead, the
+ * gcc "asm labels" extension will be used rename the function.
+ *
+ * For syscalls which are cancellation points, such as wait4(), there
+ * are identifiers that do not provide cancellation:
+ * _libc_wait4 hidden alias, for use internal to libc only
+ * _thread_sys_wait4 global name, for use outside libc only
+ * ...and identifiers that do provide cancellation:
+ * wait4 weak alias, for general use
+ * _libc_wait4_cancel hidden alias, for use internal to libc only
+ * Inside libc, the bare name ("wait4") binds to the version *without*
+ * cancellation; the few times where cancellation is desired it can be
+ * obtained by calling CANCEL(x) instead of just x.
+ *
+ * Some other calls need to be wrapped for reasons other than cancellation,
+ * such as to provide functionality beyond the underlying syscall (e.g.,
+ * sigaction). For these, there are identifiers for the raw call, without
+ * the wrapping:
+ * _libc_sigaction hidden alias, for use internal to libc only
+ * _thread_sys_sigaction global name, for use outside libc only
+ * ...and identifiers that do provide the libc wrapping:
+ * sigaction weak alias, for general use
+ * _libc_sigaction_wrap hidden alias, for use internal to libc only
+ * Inside libc, the bare name ("sigaction") binds to the wrapper; when the
+ * raw version is necessary it can be obtained by calling HIDDEN(x) instead of
+ * just x.
+ *
+ * For syscalls which are not cancellation points, such as getpid(),
+ * the identifiers are just:
+ * _libc_getpid hidden alias, for use internal to libc only
+ * _thread_sys_getpid global name, for use outside libc only
+ * getpid weak alias, for use outside libc only
+ *
+ * By using gcc's "asm label" extension, we can usually avoid having
+ * to type those prefixes in the .h and .c files. However, for those
+ * cases where a non-default binding is necessary we can use these macros
+ * to get the desired identifier:
+ *
+ * CANCEL(x)
+ * This expands to the internal, hidden name of a cancellation
+ * wrapper: _libc_x_cancel. ex: CANCEL(fsync)(fd)
+ *
+ * WRAP(x)
+ * This expands to the internal, hidden name of a non-cancellation
+ * wrapper: _libc_x_wrap. ex: WRAP(sigprocmask)(set)
+ *
+ *
+ * In order to actually set up the desired asm labels, we use these in
+ * the internal .h files:
+ * PROTO_NORMAL(x) Symbols used both internally and externally
+ * This makes gcc convert use of x to use _libc_x instead
+ * ex: PROTO_NORMAL(getpid)
+ *
+ * PROTO_STD_DEPRECATED(x) Standard C symbols that we don't want to use
+ * This just marks the symbol as deprecated, with no renaming.
+ * ex: PROTO_STD_DEPRECATED(strcpy)
+ *
+ * PROTO_DEPRECATED(x) Symbols not in ISO C that we don't want to use
+ * This marks the symbol as both weak and deprecated, with no renaming
+ * ex: PROTO_DEPRECATED(creat)
+ *
+ * PROTO_CANCEL(x) Functions that have cancellation wrappers
+ * Like PROTO_NORMAL(x), but also declares _libc_x_cancel
+ * ex: PROTO_CANCEL(wait4)
+ *
+ * PROTO_WRAP(x) Functions that have wrappers for other reasons
+ * Like PROTO_NORMAL(x), but also declares _libc_x_wrap. Internal
+ * calls that want the wrapper's processing should invoke WRAP(x)(...)
+ * ex: PROTO_WRAP(sigaction)
+ *
+ *
+ * Finally, to create the expected aliases, we use these in the .c files
+ * where the definitions are:
+ * DEF_STRONG(x) Symbols reserved to or specified by ISO C
+ * This defines x as a strong alias for _libc_x; this must only
+ * be used for symbols that are reserved by the C standard
+ * (or reserved in the external identifier namespace).
+ * Matches with PROTO_NORMAL()
+ * ex: DEF_STRONG(fopen)
+ *
+ * DEF_WEAK(x) Symbols used internally and not in ISO C
+ * This defines x as a weak alias for _libc_x
+ * Matches with PROTO_NORMAL()
+ * ex: DEF_WEAK(lseek)
+ *
+ * DEF_CANCEL(x) Symbols that have a cancellation wrapper
+ * This defines x as a weak alias for _libc_x_cancel.
+ * Matches with PROTO_CANCEL()
+ * ex: DEF_CANCEL(read)
+ *
+ * DEF_WRAP(x)
+ * This defines x as a weak alias for _libc_x_wrap.
+ * Matches with PROTO_WRAP()
+ * ex: DEF_WRAP(sigaction)
+ *
+ * DEF_SYS(x)
+ * This defines _thread_sys_x as a strong alias for _libc_x. This should
+ * only be needed for syscalls that have C instead of asm stubs.
+ * Matches with PROTO_NORMAL(), PROTO_CANCEL(), or PROTO_WRAP()
+ * ex: DEF_SYS(pread)
+ *
+ * MAKE_CLONE(dst, src) Symbols that are exact clones of other symbols
+ * This declares _libc_dst as being the same type as dst, and makes
+ * _libc_dst a strong, hidden alias for _libc_src. You still need to
+ * DEF_STRONG(dst) or DEF_WEAK(dst) to alias dst itself
+ * ex: MAKE_CLONE(SHA224Pad, SHA256Pad)
+ */
+
+/* #include <sys/cdefs.h> /1* for __dso_hidden and __{weak,strong}_alias *1/ */
+#define __dso_hidden __attribute__((__visibility__("hidden")))
+
+#define HIDDEN(x) _libc_##x
+/* #define CANCEL(x) _libc_##x##_cancel */
+/* #define WRAP(x) _libc_##x##_wrap */
+#define HIDDEN_STRING(x) "_libc_" __STRING(x)
+/* #define CANCEL_STRING(x) "_libc_" __STRING(x) "_cancel" */
+/* #define WRAP_STRING(x) "_libc_" __STRING(x) "_wrap" */
+
+/* #define PROTO_NORMAL(x) __dso_hidden typeof(x) x asm(HIDDEN_STRING(x)) */
+/* #define PROTO_STD_DEPRECATED(x) typeof(x) x __attribute__((deprecated)) */
+/* #define PROTO_DEPRECATED(x) typeof(x) x __attribute__((deprecated, weak)) */
+/* #define PROTO_CANCEL(x) __dso_hidden typeof(x) HIDDEN(x), \ */
+/* x asm(CANCEL_STRING(x)) */
+/* #define PROTO_WRAP(x) PROTO_NORMAL(x), WRAP(x) */
+
+/* #define DEF_STRONG(x) __strong_alias(x, HIDDEN(x)) */
+/* #define DEF_WEAK(x) __weak_alias(x, HIDDEN(x)) */
+/* #define DEF_CANCEL(x) __weak_alias(x, CANCEL(x)) */
+/* #define DEF_WRAP(x) __weak_alias(x, WRAP(x)) */
+/* #define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x)) */
+
+#define MAKE_CLONE(dst, src) __dso_hidden typeof(dst) (dst) \
+ __attribute__((alias (__STRING(src))))
+
+
+#endif /* _LIBC_NAMESPACE_H_ */
+
diff --git a/lib/libopenbsd/pledge-noop.c b/lib/libopenbsd/pledge-noop.c
index 0a1b610..eb4f4c4 100644
--- a/lib/libopenbsd/pledge-noop.c
+++ b/lib/libopenbsd/pledge-noop.c
@@ -1,5 +1,3 @@
-#include "openbsd.h"
-
int
pledge(__UNUSED const char *promises, __UNUSED const char *paths[])
{
diff --git a/lib/libopenbsd/stdlib/malloc.3 b/lib/libopenbsd/stdlib/malloc.3
new file mode 100644
index 0000000..1f80c35
--- /dev/null
+++ b/lib/libopenbsd/stdlib/malloc.3
@@ -0,0 +1,526 @@
+.\"
+.\" Copyright (c) 1980, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $OpenBSD: malloc.3,v 1.101 2017/02/12 10:46:09 otto Exp $
+.\"
+.Dd $Mdocdate: February 12 2017 $
+.Dt MALLOC 3
+.Os
+.Sh NAME
+.Nm malloc ,
+.Nm calloc ,
+.Nm reallocarray ,
+.Nm realloc ,
+.Nm free
+.Nd memory allocation and deallocation
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft void *
+.Fn malloc "size_t size"
+.Ft void *
+.Fn calloc "size_t nmemb" "size_t size"
+.Ft void *
+.Fn reallocarray "void *ptr" "size_t nmemb" "size_t size"
+.Ft void *
+.Fn realloc "void *ptr" "size_t size"
+.Ft void
+.Fn free "void *ptr"
+.Vt char *malloc_options ;
+.Sh DESCRIPTION
+The
+.Fn malloc
+function allocates uninitialized space for an object of
+the specified
+.Fa size .
+.Fn malloc
+maintains multiple lists of free blocks according to size, allocating
+space from the appropriate list.
+The allocated space is suitably aligned (after possible pointer coercion) for
+storage of any type of object.
+.Pp
+The
+.Fn calloc
+function allocates space for an array of
+.Fa nmemb
+objects, each of the specified
+.Fa size .
+The space is initialized to zero.
+.Pp
+The
+.Fn realloc
+function changes the size of the object pointed to by
+.Fa ptr
+to
+.Fa size
+bytes and returns a pointer to the (possibly moved) object.
+The contents of the object are unchanged up to the lesser
+of the new and old sizes.
+If the new size is larger, the value of the newly allocated portion
+of the object is indeterminate and uninitialized.
+If the space cannot be allocated, the object
+pointed to by
+.Fa ptr
+is unchanged.
+If
+.Fa ptr
+is
+.Dv NULL ,
+.Fn realloc
+behaves like
+.Fn malloc
+and allocates a new object.
+.Pp
+The
+.Fn reallocarray
+function is similar to
+.Fn realloc
+except it operates on
+.Fa nmemb
+members of size
+.Fa size
+and checks for integer overflow in the calculation
+.Fa nmemb
+*
+.Fa size .
+.Pp
+The
+.Fn free
+function causes the space pointed to by
+.Fa ptr
+to be either placed on a list of free pages to make it available for future
+allocation or, if required, to be returned to the kernel using
+.Xr munmap 2 .
+If
+.Fa ptr
+is a
+.Dv NULL
+pointer, no action occurs.
+If
+.Fa ptr
+was previously freed by
+.Fn free ,
+.Fn realloc ,
+or
+.Fn reallocarray ,
+the behavior is undefined and the double free is a security concern.
+.Sh RETURN VALUES
+Upon successful completion, the functions
+.Fn malloc ,
+.Fn calloc ,
+.Fn realloc ,
+and
+.Fn reallocarray
+return a pointer to the allocated space; otherwise, a
+.Dv NULL
+pointer is returned and
+.Va errno
+is set to
+.Er ENOMEM .
+.Pp
+If
+.Fa size
+or
+.Fa nmemb
+is equal to 0, a unique pointer to an access protected,
+zero sized object is returned.
+Access via this pointer will generate a
+.Dv SIGSEGV
+exception.
+.Pp
+If multiplying
+.Fa nmemb
+and
+.Fa size
+results in integer overflow,
+.Fn calloc
+and
+.Fn reallocarray
+return
+.Dv NULL
+and set
+.Va errno
+to
+.Er ENOMEM .
+.Sh IDIOMS
+Consider
+.Fn calloc
+or the extension
+.Fn reallocarray
+when there is multiplication in the
+.Fa size
+argument of
+.Fn malloc
+or
+.Fn realloc .
+For example, avoid this common idiom as it may lead to integer overflow:
+.Bd -literal -offset indent
+if ((p = malloc(num * size)) == NULL)
+ err(1, NULL);
+.Ed
+.Pp
+A drop-in replacement is the
+.Ox
+extension
+.Fn reallocarray :
+.Bd -literal -offset indent
+if ((p = reallocarray(NULL, num, size)) == NULL)
+ err(1, NULL);
+.Ed
+.Pp
+Alternatively,
+.Fn calloc
+may be used at the cost of initialization overhead.
+.Pp
+When using
+.Fn realloc ,
+be careful to avoid the following idiom:
+.Bd -literal -offset indent
+size += 50;
+if ((p = realloc(p, size)) == NULL)
+ return (NULL);
+.Ed
+.Pp
+Do not adjust the variable describing how much memory has been allocated
+until the allocation has been successful.
+This can cause aberrant program behavior if the incorrect size value is used.
+In most cases, the above sample will also result in a leak of memory.
+As stated earlier, a return value of
+.Dv NULL
+indicates that the old object still remains allocated.
+Better code looks like this:
+.Bd -literal -offset indent
+newsize = size + 50;
+if ((newp = realloc(p, newsize)) == NULL) {
+ free(p);
+ p = NULL;
+ size = 0;
+ return (NULL);
+}
+p = newp;
+size = newsize;
+.Ed
+.Pp
+As with
+.Fn malloc ,
+it is important to ensure the new size value will not overflow;
+i.e. avoid allocations like the following:
+.Bd -literal -offset indent
+if ((newp = realloc(p, num * size)) == NULL) {
+ ...
+.Ed
+.Pp
+Instead, use
+.Fn reallocarray :
+.Bd -literal -offset indent
+if ((newp = reallocarray(p, num, size)) == NULL) {
+ ...
+.Ed
+.Pp
+Calling
+.Fn realloc
+with a
+.Dv NULL
+.Fa ptr
+is equivalent to calling
+.Fn malloc .
+Instead of this idiom:
+.Bd -literal -offset indent
+if (p == NULL)
+ newp = malloc(newsize);
+else
+ newp = realloc(p, newsize);
+.Ed
+.Pp
+Use the following:
+.Bd -literal -offset indent
+newp = realloc(p, newsize);
+.Ed
+.Sh ENVIRONMENT
+.Bl -tag -width "/etc/malloc.conf"
+.It Ev MALLOC_OPTIONS
+String of flags documented in
+.Xr malloc.conf 5 .
+.El
+.Sh FILES
+.Bl -tag -width "/etc/malloc.conf"
+.It Pa /etc/malloc.conf
+Symbolic link to filename containing option flags.
+.El
+.Sh EXAMPLES
+If
+.Fn malloc
+must be used with multiplication, be sure to test for overflow:
+.Bd -literal -offset indent
+size_t num, size;
+\&...
+
+/* Check for size_t overflow */
+if (size && num > SIZE_MAX / size)
+ errc(1, EOVERFLOW, "overflow");
+
+if ((p = malloc(size * num)) == NULL)
+ err(1, NULL);
+.Ed
+.Pp
+The above test is not sufficient in all cases.
+For example, multiplying ints requires a different set of checks:
+.Bd -literal -offset indent
+int num, size;
+\&...
+
+/* Avoid invalid requests */
+if (size < 0 || num < 0)
+ errc(1, EOVERFLOW, "overflow");
+
+/* Check for signed int overflow */
+if (size && num > INT_MAX / size)
+ errc(1, EOVERFLOW, "overflow");
+
+if ((p = malloc(size * num)) == NULL)
+ err(1, NULL);
+.Ed
+.Pp
+Assuming the implementation checks for integer overflow as
+.Ox
+does, it is much easier to use
+.Fn calloc
+or
+.Fn reallocarray .
+.Pp
+The above examples could be simplified to:
+.Bd -literal -offset indent
+if ((p = reallocarray(NULL, num, size)) == NULL)
+ err(1, NULL);
+.Ed
+.Pp
+or at the cost of initialization:
+.Bd -literal -offset indent
+if ((p = calloc(num, size)) == NULL)
+ err(1, NULL);
+.Ed
+.Sh DIAGNOSTICS
+If
+.Fn malloc ,
+.Fn calloc ,
+.Fn realloc ,
+.Fn reallocarray ,
+or
+.Fn free
+detect an error condition,
+a message will be printed to file descriptor
+2 (not using stdio).
+Errors will result in the process being aborted.
+.Pp
+Here is a brief description of the error messages and what they mean:
+.Bl -tag -width Ds
+.It Dq out of memory
+If the
+.Cm X
+option is specified it is an error for
+.Fn malloc ,
+.Fn calloc ,
+.Fn realloc ,
+or
+.Fn reallocarray
+to return
+.Dv NULL .
+.It Dq malloc init mmap failed
+This is a rather weird condition that is most likely to indicate a
+seriously overloaded system or a ulimit restriction.
+.It Dq bogus pointer (double free?)
+An attempt to
+.Fn free ,
+.Fn realloc ,
+or
+.Fn reallocarray
+an unallocated pointer was made.
+.It Dq chunk is already free
+There was an attempt to free a chunk that had already been freed.
+.It Dq use after free
+A chunk has been modified after it was freed.
+.It Dq modified chunk-pointer
+The pointer passed to
+.Fn free ,
+.Fn realloc ,
+or
+.Fn reallocarray
+has been modified.
+.It Dq chunk canary corrupted address offset@length
+A byte after the requested size has been overwritten,
+indicating a heap overflow.
+The offset at which corruption was detected is printed before the @,
+and the requested length of the allocation after the @.
+.It Dq recursive call
+An attempt was made to call recursively into these functions, i.e., from a
+signal handler.
+This behavior is not supported.
+In particular, signal handlers should
+.Em not
+use any of the
+.Fn malloc
+functions nor utilize any other functions which may call
+.Fn malloc
+(e.g.,
+.Xr stdio 3
+routines).
+.It Dq unknown char in MALLOC_OPTIONS
+We found something we didn't understand.
+.It Dq malloc cache overflow/underflow
+The internal malloc page cache has been corrupted.
+.It Dq malloc free slot lost
+The internal malloc page cache has been corrupted.
+.It Dq guard size
+An inconsistent guard size was detected.
+.It any other error
+.Fn malloc
+detected an internal error;
+consult sources and/or wizards.
+.El
+.Sh SEE ALSO
+.Xr brk 2 ,
+.Xr mmap 2 ,
+.Xr munmap 2 ,
+.Xr alloca 3 ,
+.Xr getpagesize 3 ,
+.Xr posix_memalign 3 ,
+.Xr sysconf 3 ,
+.Xr malloc.conf 5
+.Sh STANDARDS
+The
+.Fn malloc ,
+.Fn calloc ,
+.Fn realloc ,
+and
+.Fn free
+functions conform to
+.St -ansiC .
+.Pp
+If
+.Fa size
+or
+.Fa nmemb
+are 0, the return value is implementation defined;
+other conforming implementations may return
+.Dv NULL
+in this case.
+.Pp
+The
+.Ev MALLOC_OPTIONS
+environment variable, the file
+.Pa /etc/malloc.conf ,
+and the
+.Sx DIAGNOSTICS
+output are extensions to the standard.
+.Sh HISTORY
+A
+.Fn free
+internal kernel function and a predecessor to
+.Fn malloc ,
+.Fn alloc ,
+first appeared in
+.At v1 .
+C library functions
+.Fn alloc
+and
+.Fn free
+appeared in
+.At v6 .
+The functions
+.Fn malloc ,
+.Fn calloc ,
+and
+.Fn realloc
+first appeared in
+.At v7 .
+.Pp
+A new implementation by Chris Kingsley was introduced in
+.Bx 4.2 ,
+followed by a complete rewrite by Poul-Henning Kamp which appeared in
+.Fx 2.2
+and was included in
+.Ox 2.0 .
+These implementations were all
+.Xr sbrk 2
+based.
+In
+.Ox 3.8 ,
+Thierry Deval rewrote
+.Nm
+to use the
+.Xr mmap 2
+system call,
+making the page addresses returned by
+.Nm
+random.
+A rewrite by Otto Moerbeek introducing a new central data structure and more
+randomization appeared in
+.Ox 4.4 .
+.Pp
+The
+.Fn reallocarray
+function appeared in
+.Ox 5.6 .
+.Sh CAVEATS
+When using
+.Fn malloc ,
+be wary of signed integer and
+.Vt size_t
+overflow especially when there is multiplication in the
+.Fa size
+argument.
+.Pp
+Signed integer overflow will cause undefined behavior which compilers
+typically handle by wrapping back around to negative numbers.
+Depending on the input, this can result in allocating more or less
+memory than intended.
+.Pp
+An unsigned overflow has defined behavior which will wrap back around and
+return less memory than intended.
+.Pp
+A signed or unsigned integer overflow is a
+.Em security
+risk if less memory is returned than intended.
+Subsequent code may corrupt the heap by writing beyond the memory that was
+allocated.
+An attacker may be able to leverage this heap corruption to execute arbitrary
+code.
+.Pp
+Consider using
+.Fn calloc
+or
+.Fn reallocarray
+instead of using multiplication in
+.Fn malloc
+and
+.Fn realloc
+to avoid these problems on
+.Ox .
diff --git a/lib/libopenbsd/string/strlcpy.3 b/lib/libopenbsd/string/strlcpy.3
new file mode 100644
index 0000000..044c959
--- /dev/null
+++ b/lib/libopenbsd/string/strlcpy.3
@@ -0,0 +1,188 @@
+.\" $OpenBSD: strlcpy.3,v 1.26 2013/09/30 12:02:35 millert Exp $
+.\"
+.\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller@courtesan.com>
+.\"
+.\" 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.
+.\"
+.Dd $Mdocdate: September 30 2013 $
+.Dt STRLCPY 3
+.Os
+.Sh NAME
+.Nm strlcpy ,
+.Nm strlcat
+.Nd size-bounded string copying and concatenation
+.Sh SYNOPSIS
+.In string.h
+.Ft size_t
+.Fn strlcpy "char *dst" "const char *src" "size_t dstsize"
+.Ft size_t
+.Fn strlcat "char *dst" "const char *src" "size_t dstsize"
+.Sh DESCRIPTION
+The
+.Fn strlcpy
+and
+.Fn strlcat
+functions copy and concatenate strings with the
+same input parameters and output result as
+.Xr snprintf 3 .
+They are designed to be safer, more consistent, and less error
+prone replacements for the easily misused functions
+.Xr strncpy 3
+and
+.Xr strncat 3 .
+.Pp
+.Fn strlcpy
+and
+.Fn strlcat
+take the full size of the destination buffer and guarantee
+NUL-termination if there is room.
+Note that room for the NUL should be included in
+.Fa dstsize .
+.Pp
+.Fn strlcpy
+copies up to
+.Fa dstsize
+\- 1 characters from the string
+.Fa src
+to
+.Fa dst ,
+NUL-terminating the result if
+.Fa dstsize
+is not 0.
+.Pp
+.Fn strlcat
+appends string
+.Fa src
+to the end of
+.Fa dst .
+It will append at most
+.Fa dstsize
+\- strlen(dst) \- 1 characters.
+It will then NUL-terminate, unless
+.Fa dstsize
+is 0 or the original
+.Fa dst
+string was longer than
+.Fa dstsize
+(in practice this should not happen
+as it means that either
+.Fa dstsize
+is incorrect or that
+.Fa dst
+is not a proper string).
+.Pp
+If the
+.Fa src
+and
+.Fa dst
+strings overlap, the behavior is undefined.
+.Sh RETURN VALUES
+Besides quibbles over the return type
+.Pf ( Va size_t
+versus
+.Va int )
+and signal handler safety
+.Pf ( Xr snprintf 3
+is not entirely safe on some systems), the
+following two are equivalent:
+.Bd -literal -offset indent
+n = strlcpy(dst, src, len);
+n = snprintf(dst, len, "%s", src);
+.Ed
+.Pp
+Like
+.Xr snprintf 3 ,
+the
+.Fn strlcpy
+and
+.Fn strlcat
+functions return the total length of the string they tried to create.
+For
+.Fn strlcpy
+that means the length of
+.Fa src .
+For
+.Fn strlcat
+that means the initial length of
+.Fa dst
+plus
+the length of
+.Fa src .
+.Pp
+If the return value is
+.Cm >=
+.Va dstsize ,
+the output string has been truncated.
+It is the caller's responsibility to handle this.
+.Sh EXAMPLES
+The following code fragment illustrates the simple case:
+.Bd -literal -offset indent
+char *s, *p, buf[BUFSIZ];
+
+\&...
+
+(void)strlcpy(buf, s, sizeof(buf));
+(void)strlcat(buf, p, sizeof(buf));
+.Ed
+.Pp
+To detect truncation, perhaps while building a pathname, something
+like the following might be used:
+.Bd -literal -offset indent
+char *dir, *file, pname[PATH_MAX];
+
+\&...
+
+if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
+ goto toolong;
+if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
+ goto toolong;
+.Ed
+.Pp
+Since it is known how many characters were copied the first time, things
+can be sped up a bit by using a copy instead of an append:
+.Bd -literal -offset indent
+char *dir, *file, pname[PATH_MAX];
+size_t n;
+
+\&...
+
+n = strlcpy(pname, dir, sizeof(pname));
+if (n >= sizeof(pname))
+ goto toolong;
+if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n)
+ goto toolong;
+.Ed
+.Pp
+However, one may question the validity of such optimizations, as they
+defeat the whole purpose of
+.Fn strlcpy
+and
+.Fn strlcat .
+As a matter of fact, the first version of this manual page got it wrong.
+.Sh SEE ALSO
+.Xr snprintf 3 ,
+.Xr strncat 3 ,
+.Xr strncpy 3 ,
+.Xr wcslcpy 3
+.Sh HISTORY
+.Fn strlcpy
+and
+.Fn strlcat
+first appeared in
+.Ox 2.4 .
+.Sh AUTHORS
+.Fn strlcpy
+and
+.Fn strlcat
+were created by
+.An Todd C. Miller Aq Mt Todd.Miller@courtesan.com .
diff --git a/lib/libopenbsd/util.h b/lib/libopenbsd/util.h
deleted file mode 100644
index 75c1545..0000000
--- a/lib/libopenbsd/util.h
+++ /dev/null
@@ -1,2 +0,0 @@
-
-void logwtmp(const char *, const char *, const char *);