Discussion:
Fixup series for new --with-crypto option
Peter Stuge
2016-11-16 21:44:19 UTC
Permalink
[PATCH] docs/HACKING.CRYPTO: Improve documentation for autoconf build
[PATCH] acinclude.m4: Make saved variables in
[PATCH] acinclude.m4: Add CPPFLAGS=-I$prefix-dir/include in
[PATCH] acinclude.m4: The mbedtls crypto backend actually requires

These changes go from documentation improvements over cosmetics to
fixes for two severe problems in the case of the last patches.

I've tested these to work correctly with OpenSSL, mbedTLS and libgcrypt
in /usr and with OpenSSL and mbedTLS installed in prefix directories.


//Peter
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/l
Peter Stuge
2016-11-16 21:44:21 UTC
Permalink
---
acinclude.m4 | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index b6eb7eb..81efa06 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -393,14 +393,14 @@ dnl
dnl For conveniece, $4 is expanded if [lib]$1 is found.

AC_DEFUN([LIBSSH2_LIB_HAVE_LINKFLAGS], [
- libssh2_lib_have_linkflags_LDFLAGS="$LDFLAGS"
+ libssh2_save_LDFLAGS="$LDFLAGS"

test "${with_lib$1_prefix+set}" = set &&
LDFLAGS="$LDFLAGS${LDFLAGS:+ }-L${with_lib$1_prefix}/lib"

AC_LIB_HAVE_LINKFLAGS([$1], [$2], [$3])

- LDFLAGS="$libssh2_lib_have_linkflags_LDFLAGS"
+ LDFLAGS="$libssh2_save_LDFLAGS"

if test "$ac_cv_lib$1" = "yes"; then :
$4
@@ -416,10 +416,10 @@ m4_case([$1],
LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }libssl libcrypto"

# Not all OpenSSL have AES-CTR functions.
- save_LIBS="${LIBS}"
+ libssh2_save_LIBS="$LIBS"
LIBS="$LIBS $LIBSSL"
AC_CHECK_FUNCS(EVP_aes_128_ctr)
- LIBS="${save_LIBS}"
+ LIBS="$libssh2_save_LIBS"

found_crypto="$1"
found_crypto_str="OpenSSL (AES-CTR: ${ac_cv_func_EVP_aes_128_ctr:-N/A})"
--
_______________________________________________
libssh2-devel https:
Peter Stuge
2016-11-16 21:44:23 UTC
Permalink
Examples can't be linked with libmbedtls but need libmbedcrypto, and
any users of libssh2 which use libtool and libssh2.la would encounter
the same problem.

This changes the mbedtls detection to search for libmbedcrypto, which
is the actual dependency for the backend.
---
Makefile.mbedTLS.inc | 2 +-
acinclude.m4 | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile.mbedTLS.inc b/Makefile.mbedTLS.inc
index c22e51a..b9f19fc 100644
--- a/Makefile.mbedTLS.inc
+++ b/Makefile.mbedTLS.inc
@@ -1,3 +1,3 @@
CRYPTO_CSOURCES = mbedtls.c
CRYPTO_HHEADERS = mbedtls.h
-CRYPTO_LTLIBS = $(LTLIBMBEDTLS)
+CRYPTO_LTLIBS = $(LTLIBMBEDCRYPTO)
diff --git a/acinclude.m4 b/acinclude.m4
index 8a2ea6d..c0e89a1 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -439,7 +439,7 @@ m4_case([$1],
],

[mbedtls], [
- LIBSSH2_LIB_HAVE_LINKFLAGS([mbedtls], [], [#include <mbedtls/version.h>], [
+ LIBSSH2_LIB_HAVE_LINKFLAGS([mbedcrypto], [], [#include <mbedtls/version.h>], [
AC_DEFINE(LIBSSH2_MBEDTLS, 1, [Use $1])
found_crypto="$1"
support_clear_memory=yes
--
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/list
Peter Stuge
2016-11-16 21:44:22 UTC
Permalink
This is absolutely neccessary for header files to be found when
AC_LIB_HAVE_LINKFLAGS searches for libraries.
---
acinclude.m4 | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 81efa06..8a2ea6d 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -393,10 +393,13 @@ dnl
dnl For conveniece, $4 is expanded if [lib]$1 is found.

AC_DEFUN([LIBSSH2_LIB_HAVE_LINKFLAGS], [
+ libssh2_save_CPPFLAGS="$CPPFLAGS"
libssh2_save_LDFLAGS="$LDFLAGS"

- test "${with_lib$1_prefix+set}" = set &&
+ if test "${with_lib$1_prefix+set}" = set; then
+ CPPFLAGS="$CPPFLAGS${CPPFLAGS:+ }-I${with_lib$1_prefix}/include"
LDFLAGS="$LDFLAGS${LDFLAGS:+ }-L${with_lib$1_prefix}/lib"
+ fi

AC_LIB_HAVE_LINKFLAGS([$1], [$2], [$3])

@@ -404,6 +407,8 @@ AC_DEFUN([LIBSSH2_LIB_HAVE_LINKFLAGS], [

if test "$ac_cv_lib$1" = "yes"; then :
$4
+ else
+ CPPFLAGS="$libssh2_save_CPPFLAGS"
fi
])
--
_______________________________________________
libssh2-devel https://
Peter Stuge
2016-11-16 21:44:20 UTC
Permalink
---
docs/HACKING.CRYPTO | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/docs/HACKING.CRYPTO b/docs/HACKING.CRYPTO
index 381b2a9..91e91e0 100644
--- a/docs/HACKING.CRYPTO
+++ b/docs/HACKING.CRYPTO
@@ -15,29 +15,34 @@ indicates the libssh2 core modules never use the function result.

0) Build system.

-Add a new crypto backend to the autotools build system (./configure) as such:
+Adding a crypto backend to the autotools build system (./configure) is easy:

-* Add one new line to configure.ac:
+0.1) Add one new line in configure.ac

m4_set_add([crypto_backends], [newname])

-This automatically creates a new --with-crypto=newname option which users can
-specify when invoking configure at compile-time to select the new backend.
+This automatically creates a --with-crypto=newname option.

-* Add a new m4_case stanza to acinclude.m4 within LIBSSH2_CRYPTO_CHECK,
- with checks for library availability. A successful check should set
- library linking variables. The LIBSSH2_LIB_HAVE_LINKFLAGS macro creates
- such a variable automatically if the checked library can be found.
+0.2) Add an m4_case stanza to LIBSSH2_CRYPTO_CHECK in acinclude.m4

-* Add a Makefile.newname.inc in the top-level directory which sets
- CRYPTO_CSOURCES and CRYPTO_HHEADERS to the new backend source files,
- and CRYPTO_LTLIBS to the libtool linking parameters for the library, set
- e.g. by a LIBSSH2_LIB_HAVE_LINKFLAGS call in LIBSSH2_CRYPTO_CHECK.
+This must check for all required libraries, and if found set and AC_SUBST a
+variable with the library linking flags. The recommended method is to use
+LIBSSH2_LIB_HAVE_LINKFLAGS from LIBSSH2_CRYPTO_CHECK, which automatically
+creates and handles a --with-$newname-prefix option and sets an
+LTLIBNEWNAME variable on success.

-* Add a new block to src/Makefile.am:
- if NEWNAME
- include ../Makefile.newname.inc
- endif
+0.3) Create Makefile.newname.inc in the top-level directory
+
+This must set CRYPTO_CSOURCES, CRYPTO_HHEADERS and CRYPTO_LTLIBS.
+Set CRYPTO_CSOURCES and CRYPTO_HHEADERS to the new backend source files
+and set CRYPTO_LTLIBS to the required library linking parameters, e.g.
+$(LTLIBNEWNAME) as generated by by LIBSSH2_LIB_HAVE_LINKFLAGS.
+
+0.4) Add a new block in src/Makefile.am
+
+if NEWNAME
+include ../Makefile.newname.inc
+endif


1) Crypto library initialization/termination.
--
_______________________________________________
libssh2-devel https://cool.haxx.se
Alexander Lamaison
2016-11-19 16:08:54 UTC
Permalink
Post by Peter Stuge
[PATCH] docs/HACKING.CRYPTO: Improve documentation for autoconf build
[PATCH] acinclude.m4: Make saved variables in
[PATCH] acinclude.m4: Add CPPFLAGS=-I$prefix-dir/include in
[PATCH] acinclude.m4: The mbedtls crypto backend actually requires
These changes go from documentation improvements over cosmetics to
fixes for two severe problems in the case of the last patches.
I've tested these to work correctly with OpenSSL, mbedTLS and libgcrypt
in /usr and with OpenSSL and mbedTLS installed in prefix directories.
Could you push these to your repo? Makes it a little easier to merge.

Thanks,
Alex
--
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailm
Peter Stuge
2016-11-19 17:48:10 UTC
Permalink
Post by Alexander Lamaison
Post by Peter Stuge
These changes go from documentation improvements over cosmetics to
fixes for two severe problems in the case of the last patches.
I've tested these to work correctly with OpenSSL, mbedTLS and libgcrypt
in /usr and with OpenSSL and mbedTLS installed in prefix directories.
Could you push these to your repo? Makes it a little easier to merge.
Yes of course - now in the withcrypto branch. Thanks!


//Peter
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/lib
Alexander Lamaison
2016-11-27 18:36:44 UTC
Permalink
Post by Peter Stuge
Post by Alexander Lamaison
Post by Peter Stuge
These changes go from documentation improvements over cosmetics to
fixes for two severe problems in the case of the last patches.
I've tested these to work correctly with OpenSSL, mbedTLS and libgcrypt
in /usr and with OpenSSL and mbedTLS installed in prefix directories.
Could you push these to your repo? Makes it a little easier to merge.
Yes of course - now in the withcrypto branch. Thanks!
Merged. Thanks.
--
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
_______________________________________________
libssh2-devel http
Loading...