aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2015-05-02 01:40:33 -0500
committerBrent Cook <busterb@gmail.com>2015-05-23 19:27:57 -0500
commit769d58e4946b35976c4da2ab54c56f6430a45d89 (patch)
tree5ff27229f208de7077c9e8f9894c32a1ef8f6f1f
parentd3771a41cb106c945e0f538073d0a6e7b35d145b (diff)
downloadportable-769d58e4946b35976c4da2ab54c56f6430a45d89.tar.gz
portable-769d58e4946b35976c4da2ab54c56f6430a45d89.tar.bz2
portable-769d58e4946b35976c4da2ab54c56f6430a45d89.zip
further refactoring, working libtls-standalone
-rw-r--r--.gitignore6
-rw-r--r--crypto/Makefile.am44
-rw-r--r--libtls-standalone/Makefile.am2
-rw-r--r--libtls-standalone/VERSION2
-rw-r--r--libtls-standalone/app/Makefile.am6
-rw-r--r--libtls-standalone/app/test.c6
-rw-r--r--libtls-standalone/compat/Makefile.am45
-rw-r--r--libtls-standalone/configure.ac246
-rw-r--r--libtls-standalone/include/Makefile.am28
-rw-r--r--libtls-standalone/include/string.h49
-rw-r--r--libtls-standalone/src/Makefile.am6
-rwxr-xr-xupdate.sh48
12 files changed, 172 insertions, 316 deletions
diff --git a/.gitignore b/.gitignore
index 290088b..a3071b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -122,7 +122,11 @@ include/openssl/*.he
122/libtls-standalone/include/*.h 122/libtls-standalone/include/*.h
123/libtls-standalone/src/*.c 123/libtls-standalone/src/*.c
124/libtls-standalone/src/*.h 124/libtls-standalone/src/*.h
125/libtls-standalone/src/compat 125/libtls-standalone/src
126/libtls-standalone/compat
127!/libtls-standalone/compat/Makefile.am
128/libtls-standalone/VERSION
129/libtls-standalone/m4
126 130
127openbsd/ 131openbsd/
128 132
diff --git a/crypto/Makefile.am b/crypto/Makefile.am
index 757197f..ad26168 100644
--- a/crypto/Makefile.am
+++ b/crypto/Makefile.am
@@ -65,49 +65,7 @@ if !HAVE_TIMINGSAFE_BCMP
65libcompat_la_SOURCES += compat/timingsafe_bcmp.c 65libcompat_la_SOURCES += compat/timingsafe_bcmp.c
66endif 66endif
67 67
68if !HAVE_ARC4RANDOM_BUF 68include Makefile.am.arc4random
69libcompat_la_SOURCES += compat/arc4random.c
70
71if !HAVE_GETENTROPY
72if HOST_AIX
73libcompat_la_SOURCES += compat/getentropy_aix.c
74endif
75if HOST_FREEBSD
76libcompat_la_SOURCES += compat/getentropy_freebsd.c
77endif
78if HOST_HPUX
79libcompat_la_SOURCES += compat/getentropy_hpux.c
80endif
81if HOST_LINUX
82libcompat_la_SOURCES += compat/getentropy_linux.c
83endif
84if HOST_NETBSD
85libcompat_la_SOURCES += compat/getentropy_netbsd.c
86endif
87if HOST_DARWIN
88libcompat_la_SOURCES += compat/getentropy_osx.c
89endif
90if HOST_SOLARIS
91libcompat_la_SOURCES += compat/getentropy_solaris.c
92endif
93if HOST_WIN
94libcompat_la_SOURCES += compat/getentropy_win.c
95endif
96endif
97
98endif
99
100noinst_HEADERS =
101noinst_HEADERS += compat/arc4random.h
102noinst_HEADERS += compat/arc4random_aix.h
103noinst_HEADERS += compat/arc4random_freebsd.h
104noinst_HEADERS += compat/arc4random_hpux.h
105noinst_HEADERS += compat/arc4random_linux.h
106noinst_HEADERS += compat/arc4random_netbsd.h
107noinst_HEADERS += compat/arc4random_osx.h
108noinst_HEADERS += compat/arc4random_solaris.h
109noinst_HEADERS += compat/arc4random_win.h
110noinst_HEADERS += compat/chacha_private.h
111 69
112libcrypto_la_SOURCES = 70libcrypto_la_SOURCES =
113EXTRA_libcrypto_la_SOURCES = 71EXTRA_libcrypto_la_SOURCES =
diff --git a/libtls-standalone/Makefile.am b/libtls-standalone/Makefile.am
index 8881d8c..a108ada 100644
--- a/libtls-standalone/Makefile.am
+++ b/libtls-standalone/Makefile.am
@@ -1,4 +1,4 @@
1SUBDIRS = include src 1SUBDIRS = include compat src app
2ACLOCAL_AMFLAGS = -I m4 2ACLOCAL_AMFLAGS = -I m4
3 3
4pkgconfigdir = $(libdir)/pkgconfig 4pkgconfigdir = $(libdir)/pkgconfig
diff --git a/libtls-standalone/VERSION b/libtls-standalone/VERSION
index 81ece01..fd2a018 100644
--- a/libtls-standalone/VERSION
+++ b/libtls-standalone/VERSION
@@ -1 +1 @@
3:1:0 3.1.0
diff --git a/libtls-standalone/app/Makefile.am b/libtls-standalone/app/Makefile.am
new file mode 100644
index 0000000..75a3dd6
--- /dev/null
+++ b/libtls-standalone/app/Makefile.am
@@ -0,0 +1,6 @@
1AM_CFLAGS = -I$(top_srcdir)/include
2
3bin_PROGRAMS = test
4
5test_SOURCES = test.c
6test_LDADD = -lcrypto -lssl $(top_builddir)/src/libtls.la
diff --git a/libtls-standalone/app/test.c b/libtls-standalone/app/test.c
new file mode 100644
index 0000000..e3c3f76
--- /dev/null
+++ b/libtls-standalone/app/test.c
@@ -0,0 +1,6 @@
1#include <tls.h>
2
3int main()
4{
5 tls_init();
6}
diff --git a/libtls-standalone/compat/Makefile.am b/libtls-standalone/compat/Makefile.am
new file mode 100644
index 0000000..e1ec939
--- /dev/null
+++ b/libtls-standalone/compat/Makefile.am
@@ -0,0 +1,45 @@
1#
2# Copyright (c) 2014-2015 Brent Cook
3#
4# Permission to use, copy, modify, and distribute this software for any
5# purpose with or without fee is hereby granted, provided that the above
6# copyright notice and this permission notice appear in all copies.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
17
18noinst_LTLIBRARIES = libcompat.la libcompatnoopt.la
19
20# compatibility functions that need to be built without optimizations
21libcompatnoopt_la_CFLAGS = -O0
22libcompatnoopt_la_SOURCES =
23
24if !HAVE_EXPLICIT_BZERO
25libcompatnoopt_la_SOURCES += explicit_bzero.c
26endif
27
28# other compatibility functions
29libcompat_la_CFLAGS = $(CFLAGS) $(USER_CFLAGS)
30libcompat_la_SOURCES =
31libcompat_la_LIBADD = $(PLATFORM_LDADD)
32
33if !HAVE_ASPRINTF
34libcompat_la_SOURCES += bsd-asprintf.c
35endif
36
37if !HAVE_STRLCPY
38libcompat_la_SOURCES += strlcpy.c
39endif
40
41if !HAVE_STRSEP
42libcompat_la_SOURCES += strsep.c
43endif
44
45include Makefile.am.arc4random
diff --git a/libtls-standalone/configure.ac b/libtls-standalone/configure.ac
index babb266..d52e22a 100644
--- a/libtls-standalone/configure.ac
+++ b/libtls-standalone/configure.ac
@@ -1,3 +1,17 @@
1# Copyright (c) 2014-2015 Brent Cook
2#
3# Permission to use, copy, modify, and distribute this software for any
4# purpose with or without fee is hereby granted, provided that the above
5# copyright notice and this permission notice appear in all copies.
6#
7# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
1AC_INIT([libtls], m4_esyscmd([tr -d '\n' < VERSION])) 15AC_INIT([libtls], m4_esyscmd([tr -d '\n' < VERSION]))
2 16
3AC_CANONICAL_HOST 17AC_CANONICAL_HOST
@@ -15,238 +29,20 @@ AM_PROG_CC_C_O
15AC_PROG_LIBTOOL 29AC_PROG_LIBTOOL
16LT_INIT 30LT_INIT
17 31
18CFLAGS="$CFLAGS -Wall -std=gnu99" 32CHECK_OS_OPTIONS
19
20case $host_os in
21 *aix*)
22 HOST_OS=aix
23 if test "`echo $CC | cut -d ' ' -f 1`" != "gcc" ; then
24 CFLAGS="$USER_CFLAGS"
25 fi
26 ;;
27 *cygwin*)
28 HOST_OS=cygwin
29 ;;
30 *darwin*)
31 HOST_OS=darwin
32 HOST_ABI=macosx
33 ;;
34 *freebsd*)
35 HOST_OS=freebsd
36 HOST_ABI=elf
37 ;;
38 *hpux*)
39 HOST_OS=hpux;
40 if test "`echo $CC | cut -d ' ' -f 1`" = "gcc" ; then
41 CFLAGS="$CFLAGS -mlp64"
42 else
43 CFLAGS="-g -O2 +DD64 $USER_CFLAGS"
44 fi
45 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600 -D__STRICT_ALIGNMENT"
46 AC_SUBST([PLATFORM_LDADD], ['-lpthread'])
47 ;;
48 *linux*)
49 HOST_OS=linux
50 HOST_ABI=elf
51 CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE"
52 ;;
53 *netbsd*)
54 HOST_OS=netbsd
55 CPPFLAGS="$CPPFLAGS -D_OPENBSD_SOURCE"
56 ;;
57 *openbsd*)
58 HOST_ABI=elf
59 AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD gcc has bounded])
60 ;;
61 *mingw*)
62 HOST_OS=win
63 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE -D_POSIX -D_POSIX_SOURCE -D__USE_MINGW_ANSI_STDIO"
64 CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS"
65 CPPFLAGS="$CPPFLAGS -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600"
66 CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_SPEED -DNO_SYSLOG"
67 CFLAGS="$CFLAGS -static-libgcc"
68 LDFLAGS="$LDFLAGS -static-libgcc"
69 AC_SUBST([PLATFORM_LDADD], ['-lws2_32'])
70 ;;
71 *solaris*)
72 HOST_OS=solaris
73 HOST_ABI=elf
74 CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
75 AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
76 ;;
77 *) ;;
78esac
79
80AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix])
81AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin])
82AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
83AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
84AM_CONDITIONAL([HOST_HPUX], [test x$HOST_OS = xhpux])
85AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
86AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd])
87AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
88AM_CONDITIONAL([HOST_WIN], [test x$HOST_OS = xwin])
89
90AC_MSG_CHECKING([if compiling with clang])
91AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
92#ifndef __clang__
93 not clang
94#endif
95 ]])],
96 [CLANG=yes],
97 [CLANG=no]
98)
99AC_MSG_RESULT([$CLANG])
100AS_IF([test "x$CLANG" = "xyes"], [CLANG_FLAGS=-Qunused-arguments])
101
102CFLAGS="$CFLAGS $CLANG_FLAGS"
103LDFLAGS="$LDFLAGS $CLANG_FLAGS"
104 33
105# We want to check for compiler flag support. Prior to clang v5.1, there was no 34CHECK_C_HARDENING_OPTIONS
106# way to make clang's "argument unused" warning fatal. So we invoke the
107# compiler through a wrapper script that greps for this message.
108saved_CC="$CC"
109saved_LD="$LD"
110flag_wrap="$srcdir/scripts/wrap-compiler-for-flag-check"
111CC="$flag_wrap $CC"
112LD="$flag_wrap $LD"
113
114AC_ARG_ENABLE([hardening],
115 [AS_HELP_STRING([--disable-hardening],
116 [Disable options to frustrate memory corruption exploits])],
117 [], [enable_hardening=yes])
118
119AC_ARG_ENABLE([windows-ssp],
120 [AS_HELP_STRING([--enable-windows-ssp],
121 [Enable building the stack smashing protection on
122 Windows. This currently distributing libssp-0.dll.])])
123
124AC_DEFUN([CHECK_CFLAG], [
125 AC_LANG_ASSERT(C)
126 AC_MSG_CHECKING([if $saved_CC supports "$1"])
127 old_cflags="$CFLAGS"
128 CFLAGS="$1 -Wall -Werror"
129 AC_TRY_LINK([
130 #include <stdio.h>
131 ],
132 [printf("Hello")],
133 AC_MSG_RESULT([yes])
134 CFLAGS=$old_cflags
135 HARDEN_CFLAGS="$HARDEN_CFLAGS $1",
136 AC_MSG_RESULT([no])
137 CFLAGS=$old_cflags
138 [$2])
139])
140
141AC_DEFUN([CHECK_LDFLAG], [
142 AC_LANG_ASSERT(C)
143 AC_MSG_CHECKING([if $saved_LD supports "$1"])
144 old_ldflags="$LDFLAGS"
145 LDFLAGS="$1 -Wall -Werror"
146 AC_TRY_LINK([
147 #include <stdio.h>
148 ],
149 [printf("Hello")],
150 AC_MSG_RESULT([yes])
151 LDFLAGS=$old_ldflags
152 HARDEN_LDFLAGS="$HARDEN_LDFLAGS $1",
153 AC_MSG_RESULT([no])
154 LDFLAGS=$old_ldflags
155 [$2])
156])
157 35
158AS_IF([test "x$enable_hardening" = "xyes"], [ 36DISABLE_COMPILER_WARNINGS
159 # Tell GCC to NOT optimize based on signed arithmetic overflow
160 CHECK_CFLAG([[-fno-strict-overflow]])
161 37
162 # _FORTIFY_SOURCE replaces builtin functions with safer versions. 38CHECK_LIBC_COMPAT
163 CHECK_CFLAG([[-D_FORTIFY_SOURCE=2]]) 39CHECK_LIBC_CRYPTO_COMPAT
164
165 # Enable read only relocations
166 CHECK_LDFLAG([[-Wl,-z,relro]])
167 CHECK_LDFLAG([[-Wl,-z,now]])
168
169 # Windows security flags
170 AS_IF([test "x$HOST_OS" = "xwin"], [
171 CHECK_LDFLAG([[-Wl,--nxcompat]])
172 CHECK_LDFLAG([[-Wl,--dynamicbase]])
173 CHECK_LDFLAG([[-Wl,--high-entropy-va]])
174 ])
175
176 # Use stack-protector-strong if available; if not, fallback to
177 # stack-protector-all which is considered to be overkill
178 AS_IF([test "x$enable_windows_ssp" = "xyes" -o "x$HOST_OS" != "xwin"], [
179 CHECK_CFLAG([[-fstack-protector-strong]],
180 CHECK_CFLAG([[-fstack-protector-all]],
181 AC_MSG_WARN([compiler does not appear to support stack protection])
182 )
183 )
184 AS_IF([test "x$HOST_OS" = "xwin"], [
185 AC_SEARCH_LIBS([__stack_chk_guard],[ssp])
186 ])
187 ])
188])
189
190
191# Restore CC, LD
192CC="$saved_CC"
193LD="$saved_LD"
194
195CFLAGS="$CFLAGS $HARDEN_CFLAGS"
196LDFLAGS="$LDFLAGS $HARDEN_LDFLAGS"
197
198# Removing the dependency on -Wno-pointer-sign should be a goal
199save_cflags="$CFLAGS"
200CFLAGS=-Wno-pointer-sign
201AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
202AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
203 [AC_MSG_RESULT([yes])]
204 [AM_CFLAGS=-Wno-pointer-sign],
205 [AC_MSG_RESULT([no])]
206)
207CFLAGS="$save_cflags $AM_CFLAGS"
208
209save_cflags="$CFLAGS"
210CFLAGS=
211AC_MSG_CHECKING([whether AS supports .note.GNU-stack])
212AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
213__asm__(".section .note.GNU-stack,\"\",@progbits");]])],
214 [AC_MSG_RESULT([yes])]
215 [AM_CFLAGS=-DHAVE_GNU_STACK],
216 [AC_MSG_RESULT([no])]
217)
218CFLAGS="$save_cflags $AM_CFLAGS"
219AM_PROG_AS
220
221AC_CHECK_FUNCS([explicit_bzero strsep])
222AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
223AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes])
224
225#AC_CHECK_FUNCS([arc4random_buf asprintf explicit_bzero funopen getauxval])
226#AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
227#AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
228#AC_CHECK_FUNCS([symlink])
229#AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp])
230#
231## Share test results with automake
232#AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes])
233#AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
234#AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
235#AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
236#AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
237#AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
238#AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
239#AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
240#AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
241#AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
242#AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
243#AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes])
244#AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes])
245#AM_CONDITIONAL([BUILD_CERTHASH], [test "x$ac_cv_func_symlink" = xyes])
246 40
247AC_CONFIG_FILES([ 41AC_CONFIG_FILES([
248 Makefile 42 Makefile
249 include/Makefile 43 include/Makefile
44 app/Makefile
45 compat/Makefile
250 src/Makefile 46 src/Makefile
251 libtls.pc 47 libtls.pc
252]) 48])
diff --git a/libtls-standalone/include/Makefile.am b/libtls-standalone/include/Makefile.am
index 7fbefdc..0783318 100644
--- a/libtls-standalone/include/Makefile.am
+++ b/libtls-standalone/include/Makefile.am
@@ -1,27 +1,5 @@
1#noinst_HEADERS = err.h 1noinst_HEADERS = stdlib.h
2#noinst_HEADERS += netdb.h 2noinst_HEADERS += string.h
3#noinst_HEADERS += poll.h 3noinst_HEADERS += unistd.h
4#noinst_HEADERS += pqueue.h
5#noinst_HEADERS += stdio.h
6#noinst_HEADERS += stdlib.h
7#noinst_HEADERS += string.h
8#noinst_HEADERS += syslog.h
9#noinst_HEADERS += unistd.h
10#noinst_HEADERS += win32netcompat.h
11#
12#noinst_HEADERS += arpa/inet.h
13#
14#noinst_HEADERS += machine/endian.h
15#
16#noinst_HEADERS += netinet/in.h
17#noinst_HEADERS += netinet/tcp.h
18#
19#noinst_HEADERS += sys/ioctl.h
20#noinst_HEADERS += sys/mman.h
21#noinst_HEADERS += sys/select.h
22#noinst_HEADERS += sys/socket.h
23#noinst_HEADERS += sys/times.h
24#noinst_HEADERS += sys/types.h
25#noinst_HEADERS += sys/uio.h
26 4
27include_HEADERS = tls.h 5include_HEADERS = tls.h
diff --git a/libtls-standalone/include/string.h b/libtls-standalone/include/string.h
index c42fcba..05d1ffc 100644
--- a/libtls-standalone/include/string.h
+++ b/libtls-standalone/include/string.h
@@ -17,12 +17,57 @@
17#include <strings.h> 17#include <strings.h>
18#endif 18#endif
19 19
20#ifndef HAVE_EXPLICIT_BZERO 20#ifndef HAVE_STRLCPY
21void explicit_bzero(void *, size_t); 21size_t strlcpy(char *dst, const char *src, size_t siz);
22#endif
23
24#ifndef HAVE_STRLCAT
25size_t strlcat(char *dst, const char *src, size_t siz);
26#endif
27
28#ifndef HAVE_STRNDUP
29char * strndup(const char *str, size_t maxlen);
30/* the only user of strnlen is strndup, so only build it if needed */
31#ifndef HAVE_STRNLEN
32size_t strnlen(const char *str, size_t maxlen);
33#endif
22#endif 34#endif
23 35
24#ifndef HAVE_STRSEP 36#ifndef HAVE_STRSEP
25char *strsep(char **stringp, const char *delim); 37char *strsep(char **stringp, const char *delim);
26#endif 38#endif
27 39
40#ifndef HAVE_EXPLICIT_BZERO
41void explicit_bzero(void *, size_t);
42#endif
43
44#ifndef HAVE_TIMINGSAFE_BCMP
45int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
46#endif
47
48#ifndef HAVE_TIMINGSAFE_MEMCMP
49int timingsafe_memcmp(const void *b1, const void *b2, size_t len);
50#endif
51
52#ifndef HAVE_MEMMEM
53void * memmem(const void *big, size_t big_len, const void *little,
54 size_t little_len);
55#endif
56
57#ifdef _WIN32
58#include <errno.h>
59
60static inline char *
61posix_strerror(int errnum)
62{
63 if (errnum == ECONNREFUSED) {
64 return "Connection refused";
65 }
66 return strerror(errnum);
67}
68
69#define strerror(errnum) posix_strerror(errnum)
70
71#endif
72
28#endif 73#endif
diff --git a/libtls-standalone/src/Makefile.am b/libtls-standalone/src/Makefile.am
index d5bcc49..cb9dd7f 100644
--- a/libtls-standalone/src/Makefile.am
+++ b/libtls-standalone/src/Makefile.am
@@ -4,6 +4,8 @@ lib_LTLIBRARIES = libtls.la
4 4
5libtls_la_LDFLAGS = -no-undefined 5libtls_la_LDFLAGS = -no-undefined
6libtls_la_LIBADD = -lcrypto -lssl $(PLATFORM_LDADD) 6libtls_la_LIBADD = -lcrypto -lssl $(PLATFORM_LDADD)
7libtls_la_LIBADD += $(top_builddir)/compat/libcompat.la
8libtls_la_LIBADD += $(top_builddir)/compat/libcompatnoopt.la
7 9
8libtls_la_SOURCES = tls.c 10libtls_la_SOURCES = tls.c
9libtls_la_SOURCES += tls_client.c 11libtls_la_SOURCES += tls_client.c
@@ -12,7 +14,3 @@ libtls_la_SOURCES += tls_server.c
12libtls_la_SOURCES += tls_util.c 14libtls_la_SOURCES += tls_util.c
13libtls_la_SOURCES += tls_verify.c 15libtls_la_SOURCES += tls_verify.c
14noinst_HEADERS = tls_internal.h 16noinst_HEADERS = tls_internal.h
15
16if !HAVE_STRSEP
17libtls_la_SOURCES += strsep.c
18endif
diff --git a/update.sh b/update.sh
index d2e74c7..06a70d7 100755
--- a/update.sh
+++ b/update.sh
@@ -43,7 +43,7 @@ source $libtls_src/shlib_version
43libtls_version=$major:$minor:0 43libtls_version=$major:$minor:0
44echo "libtls version $libtls_version" 44echo "libtls version $libtls_version"
45echo $libtls_version > tls/VERSION 45echo $libtls_version > tls/VERSION
46echo $libtls_version > libtls-standalone/VERSION 46echo $major.$minor.0 > libtls-standalone/VERSION
47 47
48do_mv() { 48do_mv() {
49 if ! cmp -s "$1" "$2" 49 if ! cmp -s "$1" "$2"
@@ -62,21 +62,35 @@ $CP $libcrypto_src/crypto/arch/amd64/opensslconf.h include/openssl
62$CP $libssl_src/src/crypto/opensslfeatures.h include/openssl 62$CP $libssl_src/src/crypto/opensslfeatures.h include/openssl
63$CP $libssl_src/src/e_os2.h include/openssl 63$CP $libssl_src/src/e_os2.h include/openssl
64$CP $libssl_src/src/ssl/pqueue.h include 64$CP $libssl_src/src/ssl/pqueue.h include
65$CP $libtls_src/tls.h include
66$CP $libtls_src/tls.h libtls-standalone/include
67 65
68for i in explicit_bzero.c strlcpy.c strlcat.c strndup.c strnlen.c \ 66sed -e "s/#define HEADER_TLS_H/#define HEADER_TLS_H\n#include <stddef.h>\n#include <stdint.h>/" \
69 timingsafe_bcmp.c timingsafe_memcmp.c; do 67 $libtls_src/tls.h > include/tls.h
70 $CP $libc_src/string/$i crypto/compat 68$CP include/tls.h libtls-standalone/include
69
70for i in crypto/compat libtls-standalone/compat; do
71 $CP $libc_src/crypt/arc4random.c \
72 $libc_src/crypt/chacha_private.h \
73 $libc_src/string/explicit_bzero.c \
74 $libc_src/stdlib/reallocarray.c \
75 $libc_src/string/strlcpy.c \
76 $libc_src/string/strlcat.c \
77 $libc_src/string/strndup.c \
78 $libc_src/string/strnlen.c \
79 $libc_src/string/timingsafe_bcmp.c \
80 $libc_src/string/timingsafe_memcmp.c \
81 $libcrypto_src/crypto/getentropy_*.c \
82 $libcrypto_src/crypto/arc4random_*.h \
83 $i
71done 84done
72$CP $libc_src/stdlib/reallocarray.c crypto/compat
73$CP $libc_src/crypt/arc4random.c crypto/compat
74$CP $libc_src/crypt/chacha_private.h crypto/compat
75$CP $libcrypto_src/crypto/getentropy_*.c crypto/compat
76$CP $libcrypto_src/crypto/arc4random_*.h crypto/compat
77 85
78$CP $libcrypto_src/crypto/getentropy_*.c libtls-standalone/src/compat 86$CP include/stdlib.h \
79$CP $libcrypto_src/crypto/arc4random_*.h libtls-standalone/src/compat 87 include/string.h \
88 include/unistd.h \
89 libtls-standalone/include
90
91$CP crypto/compat/arc4random*.h \
92 crypto/compat/bsd-asprintf.c \
93 libtls-standalone/compat
80 94
81(cd $libssl_src/src/crypto/objects/; 95(cd $libssl_src/src/crypto/objects/;
82 perl objects.pl objects.txt obj_mac.num obj_mac.h; 96 perl objects.pl objects.txt obj_mac.num obj_mac.h;
@@ -179,7 +193,13 @@ for i in `awk '/SOURCES|HEADERS/ { print $3 }' tls/Makefile.am` ; do
179 fi 193 fi
180done 194done
181$CP $libc_src/string/strsep.c tls 195$CP $libc_src/string/strsep.c tls
182$CP $libc_src/string/strsep.c libtls-standalone/src/compat 196$CP $libc_src/string/strsep.c libtls-standalone/compat
197mkdir -p libtls-standalone/m4
198$CP m4/check*.m4 \
199 m4/disable*.m4 \
200 libtls-standalone/m4
201sed -e "s/compat\///" crypto/Makefile.am.arc4random > \
202 libtls-standalone/compat/Makefile.am.arc4random
183 203
184# copy openssl(1) source 204# copy openssl(1) source
185echo "copying openssl(1) source" 205echo "copying openssl(1) source"