aboutsummaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2014-07-10 06:21:51 -0500
committerBrent Cook <busterb@gmail.com>2014-07-10 06:22:54 -0500
commit2b6dbc39ef274d5298daad1ff864be8fc3c56537 (patch)
treebed05f6232bad0278f952bcfa173c50c202f4309 /crypto
parente9eff5016a4ec2153c037c1b888acd2755965755 (diff)
downloadportable-2b6dbc39ef274d5298daad1ff864be8fc3c56537.tar.gz
portable-2b6dbc39ef274d5298daad1ff864be8fc3c56537.tar.bz2
portable-2b6dbc39ef274d5298daad1ff864be8fc3c56537.zip
initial top-level import of subdirectories
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Makefile.am.tpl69
-rw-r--r--crypto/compat/issetugid_linux.c47
-rw-r--r--crypto/compat/thread_private.h6
3 files changed, 122 insertions, 0 deletions
diff --git a/crypto/Makefile.am.tpl b/crypto/Makefile.am.tpl
new file mode 100644
index 0000000..6f94fdf
--- /dev/null
+++ b/crypto/Makefile.am.tpl
@@ -0,0 +1,69 @@
1include $(top_srcdir)/Makefile.am.common
2
3AM_CPPFLAGS += -I$(top_srcdir)/crypto/asn1
4AM_CPPFLAGS += -I$(top_srcdir)/crypto/evp
5AM_CPPFLAGS += -I$(top_srcdir)/crypto/modes
6
7lib_LTLIBRARIES = libcrypto.la
8
9libcrypto_la_LIBADD = libcompat.la libcompatnoopt.la
10libcrypto_la_LDFLAGS = -version-info libcrypto-version
11libcrypto_la_CFLAGS = $(CFLAGS) $(USER_CFLAGS) -DOPENSSL_NO_HW_PADLOCK
12
13noinst_LTLIBRARIES = libcompat.la libcompatnoopt.la
14
15# compatibility functions that need to be built without optimizations
16libcompatnoopt_la_CFLAGS = -O0
17libcompatnoopt_la_SOURCES = compat/explicit_bzero.c
18
19# other compatibility functions
20libcompat_la_CFLAGS = $(CFLAGS) $(USER_CFLAGS)
21libcompat_la_SOURCES =
22
23if NO_STRLCAT
24libcompat_la_SOURCES += compat/strlcat.c
25endif
26
27if NO_STRLCPY
28libcompat_la_SOURCES += compat/strlcpy.c
29endif
30
31if NO_REALLOCARRAY
32libcompat_la_SOURCES += compat/reallocarray.c
33endif
34
35if NO_TIMINGSAFE_MEMCMP
36libcompat_la_SOURCES += compat/timingsafe_memcmp.c
37endif
38
39if NO_TIMINGSAFE_BCMP
40libcompat_la_SOURCES += compat/timingsafe_bcmp.c
41endif
42
43if NO_ARC4RANDOM_BUF
44libcompat_la_SOURCES += compat/arc4random.c
45
46if NO_GETENTROPY
47if TARGET_LINUX
48libcompat_la_SOURCES += compat/getentropy_linux.c
49endif
50if TARGET_DARWIN
51libcompat_la_SOURCES += compat/getentropy_osx.c
52endif
53if TARGET_SOLARIS
54libcompat_la_SOURCES += compat/getentropy_solaris.c
55endif
56endif
57
58endif
59
60if NO_ISSETUGID
61libcompat_la_SOURCES += compat/issetugid_linux.c
62endif
63if NO_STRTONUM
64libcompat_la_SOURCES += compat/strtonum.c
65endif
66
67noinst_HEADERS = des/ncbc_enc.c
68libcrypto_la_SOURCES =
69EXTRA_libcrypto_la_SOURCES =
diff --git a/crypto/compat/issetugid_linux.c b/crypto/compat/issetugid_linux.c
new file mode 100644
index 0000000..669edce
--- /dev/null
+++ b/crypto/compat/issetugid_linux.c
@@ -0,0 +1,47 @@
1/*
2 * issetugid implementation for Linux
3 * Public domain
4 */
5
6#include <errno.h>
7#include <gnu/libc-version.h>
8#include <string.h>
9#include <sys/types.h>
10#include <unistd.h>
11
12/*
13 * Linux-specific glibc 2.16+ interface for determining if a process was
14 * launched setuid/setgid or with additional capabilities.
15 */
16#ifdef HAVE_GETAUXVAL
17#include <sys/auxv.h>
18#endif
19
20int issetugid(void)
21{
22#ifdef HAVE_GETAUXVAL
23 /*
24 * The API for glibc < 2.19 does not indicate if there is an error with
25 * getauxval. While it should not be the case that any 2.6 or greater
26 * kernel ever does not supply AT_SECURE, an emulated software environment
27 * might rewrite the aux vector.
28 *
29 * See https://sourceware.org/bugzilla/show_bug.cgi?id=15846
30 *
31 * Perhaps this code should just read the aux vector itself, so we have
32 * backward-compatibility and error handling in older glibc versions.
33 * info: http://lwn.net/Articles/519085/
34 *
35 */
36 const char *glcv = gnu_get_libc_version();
37 if (strverscmp(glcv, "2.19") >= 0) {
38 errno = 0;
39 if (getauxval(AT_SECURE) == 0) {
40 if (errno != ENOENT) {
41 return 0;
42 }
43 }
44 }
45#endif
46 return 1;
47}
diff --git a/crypto/compat/thread_private.h b/crypto/compat/thread_private.h
new file mode 100644
index 0000000..3286a7c
--- /dev/null
+++ b/crypto/compat/thread_private.h
@@ -0,0 +1,6 @@
1#include <pthread.h>
2
3static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
4
5#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
6#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)