diff options
author | kinichiro <kinichiro.inoguchi@gmail.com> | 2017-04-22 23:08:17 +0900 |
---|---|---|
committer | kinichiro <kinichiro.inoguchi@gmail.com> | 2017-04-22 23:37:20 +0900 |
commit | 048625cf2b36a91bcf04c5a1adc02fc5803491ca (patch) | |
tree | 5f328c5237ea412b17c7c7f3d5c8132115c7e790 | |
parent | 9d2418ae3a0b9577fdea0bac90802d8c0147f7f4 (diff) | |
download | portable-048625cf2b36a91bcf04c5a1adc02fc5803491ca.tar.gz portable-048625cf2b36a91bcf04c5a1adc02fc5803491ca.tar.bz2 portable-048625cf2b36a91bcf04c5a1adc02fc5803491ca.zip |
Add freezero support
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | crypto/CMakeLists.txt | 5 | ||||
-rw-r--r-- | crypto/Makefile.am | 4 | ||||
-rw-r--r-- | crypto/compat/freezero.c | 13 | ||||
-rw-r--r-- | include/compat/stdlib.h | 4 | ||||
-rw-r--r-- | m4/check-libc.m4 | 8 |
6 files changed, 33 insertions, 2 deletions
@@ -143,6 +143,7 @@ include/openssl/*.h | |||
143 | !/crypto/compat/arc4random.h | 143 | !/crypto/compat/arc4random.h |
144 | !/crypto/compat/b_win.c | 144 | !/crypto/compat/b_win.c |
145 | !/crypto/compat/explicit_bzero_win.c | 145 | !/crypto/compat/explicit_bzero_win.c |
146 | !/crypto/compat/freezero.c | ||
146 | !/crypto/compat/getpagesize.c | 147 | !/crypto/compat/getpagesize.c |
147 | !/crypto/compat/posix_win.c | 148 | !/crypto/compat/posix_win.c |
148 | !/crypto/compat/bsd_asprintf.c | 149 | !/crypto/compat/bsd_asprintf.c |
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index d7b65e2..028d840 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt | |||
@@ -681,6 +681,11 @@ if(NOT HAVE_ASPRINTF) | |||
681 | set(EXTRA_EXPORT ${EXTRA_EXPORT} vasprintf) | 681 | set(EXTRA_EXPORT ${EXTRA_EXPORT} vasprintf) |
682 | endif() | 682 | endif() |
683 | 683 | ||
684 | if(NOT HAVE_FREEZERO) | ||
685 | set(CRYPTO_SRC ${CRYPTO_SRC} compat/freezero.c) | ||
686 | set(EXTRA_EXPORT ${EXTRA_EXPORT} freezero) | ||
687 | endif() | ||
688 | |||
684 | if(NOT HAVE_GETPAGESIZE) | 689 | if(NOT HAVE_GETPAGESIZE) |
685 | set(CRYPTO_SRC ${CRYPTO_SRC} compat/getpagesize.c) | 690 | set(CRYPTO_SRC ${CRYPTO_SRC} compat/getpagesize.c) |
686 | endif() | 691 | endif() |
diff --git a/crypto/Makefile.am b/crypto/Makefile.am index 04b67aa..0e7f9c8 100644 --- a/crypto/Makefile.am +++ b/crypto/Makefile.am | |||
@@ -84,6 +84,10 @@ if !HAVE_ASPRINTF | |||
84 | libcompat_la_SOURCES += compat/bsd-asprintf.c | 84 | libcompat_la_SOURCES += compat/bsd-asprintf.c |
85 | endif | 85 | endif |
86 | 86 | ||
87 | if !HAVE_FREEZERO | ||
88 | libcompat_la_SOURCES += compat/freezero.c | ||
89 | endif | ||
90 | |||
87 | if !HAVE_GETPAGESIZE | 91 | if !HAVE_GETPAGESIZE |
88 | libcompat_la_SOURCES += compat/getpagesize.c | 92 | libcompat_la_SOURCES += compat/getpagesize.c |
89 | endif | 93 | endif |
diff --git a/crypto/compat/freezero.c b/crypto/compat/freezero.c new file mode 100644 index 0000000..8becc00 --- /dev/null +++ b/crypto/compat/freezero.c | |||
@@ -0,0 +1,13 @@ | |||
1 | #include <string.h> | ||
2 | #include <stdlib.h> | ||
3 | |||
4 | void | ||
5 | freezero(void *ptr, size_t sz) | ||
6 | { | ||
7 | /* This is legal. */ | ||
8 | if (ptr == NULL) | ||
9 | return; | ||
10 | |||
11 | explicit_bzero(ptr, sz); | ||
12 | free(ptr); | ||
13 | } | ||
diff --git a/include/compat/stdlib.h b/include/compat/stdlib.h index 11f82ba..cc04856 100644 --- a/include/compat/stdlib.h +++ b/include/compat/stdlib.h | |||
@@ -25,6 +25,10 @@ void arc4random_buf(void *_buf, size_t n); | |||
25 | uint32_t arc4random_uniform(uint32_t upper_bound); | 25 | uint32_t arc4random_uniform(uint32_t upper_bound); |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | #ifndef HAVE_FREEZERO | ||
29 | void freezero(void *ptr, size_t sz); | ||
30 | #endif | ||
31 | |||
28 | #ifndef HAVE_REALLOCARRAY | 32 | #ifndef HAVE_REALLOCARRAY |
29 | void *reallocarray(void *, size_t, size_t); | 33 | void *reallocarray(void *, size_t, size_t); |
30 | #endif | 34 | #endif |
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 066b394..d9b7b88 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 | |||
@@ -2,11 +2,12 @@ AC_DEFUN([CHECK_LIBC_COMPAT], [ | |||
2 | # Check for libc headers | 2 | # Check for libc headers |
3 | AC_CHECK_HEADERS([err.h readpassphrase.h]) | 3 | AC_CHECK_HEADERS([err.h readpassphrase.h]) |
4 | # Check for general libc functions | 4 | # Check for general libc functions |
5 | AC_CHECK_FUNCS([asprintf getpagesize inet_ntop inet_pton memmem readpassphrase]) | 5 | AC_CHECK_FUNCS([asprintf freezero getpagesize inet_ntop inet_pton memmem]) |
6 | AC_CHECK_FUNCS([reallocarray recallocarray]) | 6 | AC_CHECK_FUNCS([readpassphrase reallocarray recallocarray]) |
7 | AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) | 7 | AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) |
8 | AC_CHECK_FUNCS([timegm _mkgmtime]) | 8 | AC_CHECK_FUNCS([timegm _mkgmtime]) |
9 | AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) | 9 | AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) |
10 | AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) | ||
10 | AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) | 11 | AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) |
11 | AM_CONDITIONAL([HAVE_INET_NTOP], [test "x$ac_cv_func_inet_ntop" = xyes]) | 12 | AM_CONDITIONAL([HAVE_INET_NTOP], [test "x$ac_cv_func_inet_ntop" = xyes]) |
12 | AM_CONDITIONAL([HAVE_INET_PTON], [test "x$ac_cv_func_inet_pton" = xyes]) | 13 | AM_CONDITIONAL([HAVE_INET_PTON], [test "x$ac_cv_func_inet_pton" = xyes]) |
@@ -170,6 +171,9 @@ fi | |||
170 | if test "x$ac_cv_func_explicit_bzero" = "xno" ; then | 171 | if test "x$ac_cv_func_explicit_bzero" = "xno" ; then |
171 | echo explicit_bzero >> $crypto_p_sym | 172 | echo explicit_bzero >> $crypto_p_sym |
172 | fi | 173 | fi |
174 | if test "x$ac_cv_func_freezero" = "xno" ; then | ||
175 | echo freezero >> $crypto_p_sym | ||
176 | fi | ||
173 | if test "x$ac_cv_func_inet_pton" = "xno" ; then | 177 | if test "x$ac_cv_func_inet_pton" = "xno" ; then |
174 | echo inet_pton >> $crypto_p_sym | 178 | echo inet_pton >> $crypto_p_sym |
175 | fi | 179 | fi |