wok-next rev 20529

Up libblockdev (2.16), nspr (4.18), openssh (7.6p1), udisks2 (2.7.6).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Mar 24 15:55:55 2018 +0200 (2018-03-24)
parents 57f715384469
children af06991818fa
files cyrus-sasl/receipt dropbear/receipt libblockdev/receipt nspr/receipt openmpi/receipt openssh/receipt openssh/stuff/patches/openssh-7.6p1-openssl-1.1.0-1.patch openssh/stuff/patches/series samba/receipt sshfs-fuse/receipt udisks2/receipt
line diff
     1.1 --- a/cyrus-sasl/receipt	Sat Mar 24 11:10:32 2018 +0200
     1.2 +++ b/cyrus-sasl/receipt	Sat Mar 24 15:55:55 2018 +0200
     1.3 @@ -83,9 +83,9 @@
     1.4  }
     1.5  
     1.6  post_install_cyrus_sasl() {
     1.7 -	[ -d "$1/var/lib/sasl" ] || install -v -dm700 "$1/var/lib/sasl"
     1.8 +	[ -d "$1/var/lib/sasl" ] || install -dm700 "$1/var/lib/sasl"
     1.9  }
    1.10  
    1.11  post_install_cyrus_sasl_pam() {
    1.12 -	[ -d "$1/var/lib/sasl" ] || install -v -dm700 "$1/var/lib/sasl"
    1.13 +	[ -d "$1/var/lib/sasl" ] || install -dm700 "$1/var/lib/sasl"
    1.14  }
     2.1 --- a/dropbear/receipt	Sat Mar 24 11:10:32 2018 +0200
     2.2 +++ b/dropbear/receipt	Sat Mar 24 15:55:55 2018 +0200
     2.3 @@ -88,7 +88,6 @@
     2.4  			rm -r $fs/etc/pam.d/
     2.5  			DEPENDS="zlib"
     2.6  			CONFIG_FILES="/etc/dropbear"
     2.7 -			SUGGESTED="sftp-server"
     2.8  			PROVIDE="ssh"
     2.9  			TAGS="ssh"
    2.10  			;;
     3.1 --- a/libblockdev/receipt	Sat Mar 24 11:10:32 2018 +0200
     3.2 +++ b/libblockdev/receipt	Sat Mar 24 15:55:55 2018 +0200
     3.3 @@ -1,7 +1,7 @@
     3.4  # SliTaz package receipt v2.
     3.5  
     3.6  PACKAGE="libblockdev"
     3.7 -VERSION="2.11-1"
     3.8 +VERSION="2.16"
     3.9  CATEGORY="libs"
    3.10  SHORT_DESC="A library for manipulating block devices"
    3.11  MAINTAINER="al.bobylev@gmail.com"
    3.12 @@ -10,20 +10,19 @@
    3.13  LFS="http://www.linuxfromscratch.org/blfs/view/stable/general/libblockdev.html"
    3.14  
    3.15  TARBALL="$PACKAGE-$VERSION.tar.gz"
    3.16 -WGET_URL="https://github.com/storaged-project/libblockdev/archive/$TARBALL"
    3.17 +WGET_URL="https://github.com/storaged-project/libblockdev/releases/download/$VERSION-1/$TARBALL"
    3.18  
    3.19  BUILD_DEPENDS="automake libtool python glib-dev eudev-dev cryptsetup-dev \
    3.20  nss-dev coreutils-file-special libdevmapper-dev kmod-dev parted-dev \
    3.21 -util-linux-mount-dev util-linux-blkid-dev libbytesize-dev volume_key-dev"
    3.22 -SPLIT="libblockdev-python libblockdev libblockdev-dev"
    3.23 +util-linux-mount-dev util-linux-blkid-dev libbytesize-dev volume_key-dev \
    3.24 +python3"
    3.25 +SPLIT="libblockdev-python libblockdev-python3 libblockdev libblockdev-dev"
    3.26  
    3.27  compile_rules() {
    3.28 -	fix ld
    3.29 -	./autogen.sh &&
    3.30 -
    3.31  	./configure \
    3.32 +		--without-gtk-doc \
    3.33  		--without-dm \
    3.34 -		--sysconfdir=/etc \
    3.35 +		--with-python3 \
    3.36  		$CONFIGURE_ARGS &&
    3.37  	fix libtool &&
    3.38  	make && make install
    3.39 @@ -32,10 +31,15 @@
    3.40  genpkg_rules() {
    3.41  	case $PACKAGE in
    3.42  		*-python)
    3.43 -			copy *.py
    3.44 -			CAT="libs|python bindings"
    3.45 +			copy python2*/
    3.46 +			CAT="libs|Python2 bindings"
    3.47  			DEPENDS="libblockdev python"
    3.48  			;;
    3.49 +		*-python3)
    3.50 +			copy python3*/
    3.51 +			CAT="libs|Python3 bindings"
    3.52 +			DEPENDS="libblockdev python3"
    3.53 +			;;
    3.54  		libblockdev)
    3.55  			copy @std @rm
    3.56  			DEPENDS="cryptsetup eudev glib kmod libbytesize libdevmapper \
     4.1 --- a/nspr/receipt	Sat Mar 24 11:10:32 2018 +0200
     4.2 +++ b/nspr/receipt	Sat Mar 24 15:55:55 2018 +0200
     4.3 @@ -1,15 +1,16 @@
     4.4  # SliTaz package receipt v2.
     4.5  
     4.6  PACKAGE="nspr"
     4.7 -VERSION="4.13.1"
     4.8 +VERSION="4.18"
     4.9  CATEGORY="utilities"
    4.10  SHORT_DESC="Netscape Portable Runtime"
    4.11  MAINTAINER="rocky@slitaz.org"
    4.12  LICENSE="MPL2"
    4.13  WEB_SITE="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR"
    4.14 +LFS="http://www.linuxfromscratch.org/blfs/view/stable/general/nspr.html"
    4.15  
    4.16  TARBALL="nspr-$VERSION.tar.gz"
    4.17 -WGET_URL="https://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v$VERSION/src/$TARBALL"
    4.18 +WGET_URL="https://archive.mozilla.org/pub/nspr/releases/v$VERSION/src/$TARBALL"
    4.19  
    4.20  BUILD_DEPENDS="perl"
    4.21  SPLIT="nspr-dev"
     5.1 --- a/openmpi/receipt	Sat Mar 24 11:10:32 2018 +0200
     5.2 +++ b/openmpi/receipt	Sat Mar 24 15:55:55 2018 +0200
     5.3 @@ -1,12 +1,12 @@
     5.4  # SliTaz package receipt v2.
     5.5  
     5.6  PACKAGE="openmpi"
     5.7 -VERSION="1.5.3"
     5.8 +VERSION="1.5.3" # current stable is 3.0.0
     5.9  CATEGORY="development"
    5.10  SHORT_DESC="High performance message passing library (MPI)"
    5.11  MAINTAINER="slaxemulator@gmail.com"
    5.12  LICENSE="BSD"
    5.13 -WEB_SITE="http://www.open-mpi.org"
    5.14 +WEB_SITE="https://www.open-mpi.org/"
    5.15  
    5.16  TARBALL="$PACKAGE-$VERSION.tar.bz2"
    5.17  WGET_URL="http://www.open-mpi.org/software/ompi/v${VERSION%.*}/downloads/$TARBALL"
    5.18 @@ -15,6 +15,8 @@
    5.19  SPLIT="openmpi-dev"
    5.20  
    5.21  compile_rules() {
    5.22 +	sed -i '/sysconfdir=/ s|^|#|' /etc/slitaz/cook.site # default sysconfdir=/etc
    5.23 +
    5.24  	./configure \
    5.25  		--sysconfdir=/etc/openmpi \
    5.26  		--enable-mpi-f90 \
    5.27 @@ -34,12 +36,7 @@
    5.28  genpkg_rules() {
    5.29  	case $PACKAGE in
    5.30  		openmpi)
    5.31 -			mkdir -p $fs/usr/lib/$PACKAGE
    5.32 -			cp -a $install/etc $fs
    5.33 -			cp -a $install/usr/bin $fs/usr
    5.34 -			cp -a $install/usr/lib/*.so* $fs/usr/lib
    5.35 -			cp -a $install/usr/lib/$PACKAGE/*.so* $fs/usr/lib/$PACKAGE
    5.36 -			cp -a $install/usr/lib/mpi.mod $fs/usr/lib
    5.37 +			copy @std
    5.38  			DEPENDS="gcc gfortran libtool openssh valgrind"
    5.39  			;;
    5.40  		*-dev)
     6.1 --- a/openssh/receipt	Sat Mar 24 11:10:32 2018 +0200
     6.2 +++ b/openssh/receipt	Sat Mar 24 15:55:55 2018 +0200
     6.3 @@ -1,27 +1,27 @@
     6.4  # SliTaz package receipt v2.
     6.5  
     6.6  PACKAGE="openssh"
     6.7 -VERSION="7.5p1"
     6.8 +VERSION="7.6p1"
     6.9  CATEGORY="security"
    6.10  SHORT_DESC="OpenSSH clients and daemon"
    6.11  MAINTAINER="pascal.bellard@slitaz.org"
    6.12  LICENSE="BSD"
    6.13  WEB_SITE="https://www.openssh.com/"
    6.14 +LFS="http://www.linuxfromscratch.org/blfs/view/stable/postlfs/openssh.html"
    6.15  
    6.16  TARBALL="$PACKAGE-$VERSION.tar.gz"
    6.17  WGET_URL="http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/$TARBALL"
    6.18  
    6.19  BUILD_DEPENDS="openssl-dev zlib-dev openssl-dev perl mdocml-dev pam-dev" # groff
    6.20 -SPLIT="sftp-server openssh openssh-pam"
    6.21 +SPLIT="openssh openssh-pam:pam"
    6.22  
    6.23 -# Rules to configure and make the package.
    6.24 -compile_rules()
    6.25 -{
    6.26 -	# http://www.linuxfromscratch.org/blfs/view/stable/postlfs/openssh.html
    6.27 -	install  -v -m700 -d /var/lib/sshd &&
    6.28 -	chown    -v root:sys /var/lib/sshd &&
    6.29 +compile_rules() {
    6.30 +	sed -i '/sysconfdir=/ s|^|#|' /etc/slitaz/cook.site # default sysconfdir=/etc
    6.31  
    6.32 -	addgroup -g 50 -S sshd &&
    6.33 +	install -m700 -d /var/lib/sshd
    6.34 +	chown   root:sys /var/lib/sshd
    6.35 +
    6.36 +	addgroup -g 50 -S sshd
    6.37  	adduser \
    6.38  		-h /var/lib/sshd \
    6.39  		-g 'sshd PrivSep' \
    6.40 @@ -29,39 +29,30 @@
    6.41  		-G sshd \
    6.42  		-S -D \
    6.43  		-u 50 \
    6.44 -		sshd &&
    6.45 +		sshd
    6.46  
    6.47 -	cp -a $src $src-pam
    6.48 +	case $SET in
    6.49 +		pam) SET_ARGS='--with-pam    --with-xauth=/usr/bin/xauth';;
    6.50 +		*)   SET_ARGS='--without-pam --with-md5-passwords';;
    6.51 +	esac
    6.52 +
    6.53  	./configure \
    6.54  		--sysconfdir=/etc/ssh \
    6.55 -		--with-md5-passwords \
    6.56  		--with-privsep-path=/var/lib/sshd \
    6.57 -		--without-pam \
    6.58 -		--without-ssh1 \
    6.59 +		$SET_ARGS \
    6.60  		$CONFIGURE_ARGS &&
    6.61  	make && make DESTDIR=$DESTDIR install || return 1
    6.62  
    6.63 -	cd $src-pam
    6.64 -	./configure \
    6.65 -		--sysconfdir=/etc/ssh \
    6.66 -		--with-privsep-path=/var/lib/sshd \
    6.67 -		--with-pam \
    6.68 -		--with-xauth=/usr/bin/xauth \
    6.69 -		--without-ssh1 \
    6.70 -		$CONFIGURE_ARGS &&
    6.71 -	make && make DESTDIR=$DESTDIR-pam install || return 1
    6.72 +	install -vm755 contrib/ssh-copy-id $install/usr/bin/
    6.73  
    6.74 -	for inst in $install $install-pam ; do
    6.75 -		install -vm755 contrib/ssh-copy-id $inst/usr/bin
    6.76 +	cook_pick_manpages contrib/ssh-copy-id.1
    6.77 +	cook_pick_docs INSTALL LICENCE OVERVIEW README*
    6.78  
    6.79 -		install=$inst cook_pick_manpages contrib/ssh-copy-id.1
    6.80 -		install=$inst cook_pick_docs INSTALL LICENCE OVERVIEW README*
    6.81 +	# SliTaz stuff
    6.82  
    6.83 -		# SliTaz stuff
    6.84 +	install -Dm755 $stuff/openssh $install/etc/init.d/openssh
    6.85  
    6.86 -		mkdir -p $inst/etc/init.d
    6.87 -		cp $stuff/openssh $inst/etc/init.d
    6.88 -		cat >> $inst/etc/ssh/ssh_config <<EOT
    6.89 +	cat >> $install/etc/ssh/ssh_config <<EOT
    6.90  
    6.91  # client bug CVE-2016-0777 and CVE-2016-0778
    6.92  Host *
    6.93 @@ -72,35 +63,28 @@
    6.94    ProxyCommand ssh $(echo %h | sed 's/+[^+]*$//;s/\([^+%%]*\)%%\([^+]*\)$/\2 -l \1/;s/:/ -p /') exec nc -w1 $(echo %h | sed 's/^.*+//;/:/!s/$/ %p/;s/:/ /')
    6.95  
    6.96  EOT
    6.97 -	done
    6.98 +
    6.99 +	touch $install/etc/inetd.conf
   6.100  }
   6.101  
   6.102 -# Rules to gen a SliTaz package suitable for Tazpkg.
   6.103 -genpkg_rules()
   6.104 -{
   6.105 +genpkg_rules() {
   6.106  	case $PACKAGE in
   6.107 -		sftp-server)
   6.108 -			copy sftp-server
   6.109 -			CAT="security|secure FTP server"
   6.110 -			TAGS="ssh"
   6.111 -			DEPENDS="openssl zlib"
   6.112 -			;;
   6.113  		openssh)
   6.114  			copy @std sshd/
   6.115 -			DEPENDS="sftp-server openssl zlib"
   6.116 -			CONFIG_FILES="/etc/ssh/moduli /etc/ssh/ssh_config /etc/ssh/sshd_config \
   6.117 -			/etc/inetd.conf"
   6.118 +			DEPENDS="openssl zlib"
   6.119 +			CONFIG_FILES="/etc/ssh/moduli /etc/ssh/ssh_config \
   6.120 +			/etc/ssh/sshd_config /etc/inetd.conf"
   6.121  			TAGS="ssh security"
   6.122  			PROVIDE="ssh"
   6.123  			TAZPANEL_DAEMON="man::sshd|edit::/etc/ssh/sshd_config|options|web::$WEB_SITE"
   6.124  			;;
   6.125  		openssh-pam)
   6.126 -			install=$install-pam copy @std sshd/
   6.127 +			copy @std sshd/
   6.128  			sed -i 's/.*UsePAM.*/UsePAM yes/' $fs/etc/ssh/sshd_config
   6.129  			CAT="security|with PAM support"
   6.130 -			DEPENDS="sftp-server openssl zlib pam"
   6.131 -			CONFIG_FILES="/etc/ssh/moduli /etc/ssh/ssh_config /etc/ssh/sshd_config \
   6.132 -			/etc/inetd.conf"
   6.133 +			DEPENDS="openssl zlib pam"
   6.134 +			CONFIG_FILES="/etc/ssh/moduli /etc/ssh/ssh_config \
   6.135 +			/etc/ssh/sshd_config /etc/inetd.conf"
   6.136  			TAGS="ssh security"
   6.137  			PROVIDE="openssh:pam ssh:pam"
   6.138  			TAZPANEL_DAEMON="man::sshd|edit::/etc/ssh/sshd_config|options|web::$WEB_SITE"
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/openssh/stuff/patches/openssh-7.6p1-openssl-1.1.0-1.patch	Sat Mar 24 15:55:55 2018 +0200
     7.3 @@ -0,0 +1,1989 @@
     7.4 +Submitted by:            Bruce Dubbs (bdubbs@linuxfromscratch.org)
     7.5 +Date:                    2017-10-08
     7.6 +Initial Package Version: 7.6p1
     7.7 +Upstream Status:         Pending
     7.8 +Origin:                  https://git.archlinux.org/svntogit/packages.git/plain/trunk/openssl-1.1.0.patch?h=packages/openssh
     7.9 +Description:             Fixes build issues with OpenSSL-1.1.0.
    7.10 +
    7.11 +diff -Naur old/auth-pam.c new/auth-pam.c
    7.12 +--- old/auth-pam.c	2017-10-03 21:49:05.363829772 -1000
    7.13 ++++ new/auth-pam.c	2017-10-03 21:55:50.869718862 -1000
    7.14 +@@ -128,6 +128,10 @@
    7.15 + typedef pthread_t sp_pthread_t;
    7.16 + #else
    7.17 + typedef pid_t sp_pthread_t;
    7.18 ++# define pthread_create(a, b, c, d)    _ssh_compat_pthread_create(a, b, c, d)
    7.19 ++# define pthread_exit(a)               _ssh_compat_pthread_exit(a)
    7.20 ++# define pthread_cancel(a)             _ssh_compat_pthread_cancel(a)
    7.21 ++# define pthread_join(a, b)            _ssh_compat_pthread_join(a, b)
    7.22 + #endif
    7.23 + 
    7.24 + struct pam_ctxt {
    7.25 +diff -Naur old/cipher.c new/cipher.c
    7.26 +--- old/cipher.c	2017-10-03 21:49:05.367162904 -1000
    7.27 ++++ new/cipher.c	2017-10-03 21:55:50.869718862 -1000
    7.28 +@@ -297,7 +297,10 @@
    7.29 + 			goto out;
    7.30 + 		}
    7.31 + 	}
    7.32 +-	if (EVP_CipherInit(cc->evp, NULL, (u_char *)key, NULL, -1) == 0) {
    7.33 ++	/* in OpenSSL 1.1.0, EVP_CipherInit clears all previous setups;
    7.34 ++	   use EVP_CipherInit_ex for augmenting */
    7.35 ++	if (EVP_CipherInit_ex(cc->evp, NULL, NULL, (u_char *)key, NULL, -1) == 0)
    7.36 ++	{
    7.37 + 		ret = SSH_ERR_LIBCRYPTO_ERROR;
    7.38 + 		goto out;
    7.39 + 	}
    7.40 +@@ -486,7 +489,7 @@
    7.41 + 		   len, iv))
    7.42 + 		       return SSH_ERR_LIBCRYPTO_ERROR;
    7.43 + 	} else
    7.44 +-		memcpy(iv, cc->evp->iv, len);
    7.45 ++		memcpy(iv, EVP_CIPHER_CTX_iv(cc->evp), len);
    7.46 + #endif
    7.47 + 	return 0;
    7.48 + }
    7.49 +@@ -520,14 +523,19 @@
    7.50 + 		    EVP_CTRL_GCM_SET_IV_FIXED, -1, (void *)iv))
    7.51 + 			return SSH_ERR_LIBCRYPTO_ERROR;
    7.52 + 	} else
    7.53 +-		memcpy(cc->evp->iv, iv, evplen);
    7.54 ++		memcpy(EVP_CIPHER_CTX_iv(cc->evp), iv, evplen);
    7.55 + #endif
    7.56 + 	return 0;
    7.57 + }
    7.58 + 
    7.59 + #ifdef WITH_OPENSSL
    7.60 +-#define EVP_X_STATE(evp)	(evp)->cipher_data
    7.61 +-#define EVP_X_STATE_LEN(evp)	(evp)->cipher->ctx_size
    7.62 ++# if OPENSSL_VERSION_NUMBER >= 0x10100000UL
    7.63 ++#define EVP_X_STATE(evp)	EVP_CIPHER_CTX_get_cipher_data(evp)
    7.64 ++#define EVP_X_STATE_LEN(evp)	EVP_CIPHER_impl_ctx_size(EVP_CIPHER_CTX_cipher(evp))
    7.65 ++# else
    7.66 ++#define EVP_X_STATE(evp)	(evp).cipher_data
    7.67 ++#define EVP_X_STATE_LEN(evp)	(evp).cipher->ctx_size
    7.68 ++# endif
    7.69 + #endif
    7.70 + 
    7.71 + int
    7.72 +diff -Naur old/cipher.h new/cipher.h
    7.73 +--- old/cipher.h	2017-10-03 21:49:05.367162904 -1000
    7.74 ++++ new/cipher.h	2017-10-03 21:55:50.869718862 -1000
    7.75 +@@ -46,7 +46,18 @@
    7.76 + #define CIPHER_DECRYPT		0
    7.77 + 
    7.78 + struct sshcipher;
    7.79 ++#if 0
    7.80 ++struct sshcipher_ctx {
    7.81 ++	int	plaintext;
    7.82 ++	int	encrypt;
    7.83 ++	EVP_CIPHER_CTX *evp;
    7.84 ++	struct chachapoly_ctx cp_ctx; /* XXX union with evp? */
    7.85 ++	struct aesctr_ctx ac_ctx; /* XXX union with evp? */
    7.86 ++	const struct sshcipher *cipher;
    7.87 ++};
    7.88 ++#else
    7.89 + struct sshcipher_ctx;
    7.90 ++#endif
    7.91 + 
    7.92 + const struct sshcipher *cipher_by_name(const char *);
    7.93 + const char *cipher_warning_message(const struct sshcipher_ctx *);
    7.94 +diff -Naur old/configure new/configure
    7.95 +--- old/configure	2017-10-03 21:49:05.410493626 -1000
    7.96 ++++ new/configure	2017-10-03 22:01:49.159050540 -1000
    7.97 +@@ -12688,7 +12688,6 @@
    7.98 + 				100*)   ;; # 1.0.x
    7.99 + 				200*)   ;; # LibreSSL
   7.100 + 			        *)
   7.101 +-					as_fn_error $? "OpenSSL >= 1.1.0 is not yet supported (have \"$ssl_library_ver\")" "$LINENO" 5
   7.102 + 			                ;;
   7.103 + 			esac
   7.104 + 			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ssl_library_ver" >&5
   7.105 +diff -Naur old/dh.c new/dh.c
   7.106 +--- old/dh.c	2017-10-03 21:49:05.370496037 -1000
   7.107 ++++ new/dh.c	2017-10-03 21:55:50.869718862 -1000
   7.108 +@@ -212,14 +212,15 @@
   7.109 + /* diffie-hellman-groupN-sha1 */
   7.110 + 
   7.111 + int
   7.112 +-dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
   7.113 ++dh_pub_is_valid(const DH *dh, const BIGNUM *dh_pub)
   7.114 + {
   7.115 + 	int i;
   7.116 + 	int n = BN_num_bits(dh_pub);
   7.117 + 	int bits_set = 0;
   7.118 + 	BIGNUM *tmp;
   7.119 ++	const BIGNUM *p;
   7.120 + 
   7.121 +-	if (dh_pub->neg) {
   7.122 ++	if (BN_is_negative(dh_pub)) {
   7.123 + 		logit("invalid public DH value: negative");
   7.124 + 		return 0;
   7.125 + 	}
   7.126 +@@ -232,7 +233,8 @@
   7.127 + 		error("%s: BN_new failed", __func__);
   7.128 + 		return 0;
   7.129 + 	}
   7.130 +-	if (!BN_sub(tmp, dh->p, BN_value_one()) ||
   7.131 ++	DH_get0_pqg(dh, &p, NULL, NULL);
   7.132 ++	if (!BN_sub(tmp, p, BN_value_one()) ||
   7.133 + 	    BN_cmp(dh_pub, tmp) != -1) {		/* pub_exp > p-2 */
   7.134 + 		BN_clear_free(tmp);
   7.135 + 		logit("invalid public DH value: >= p-1");
   7.136 +@@ -243,14 +245,14 @@
   7.137 + 	for (i = 0; i <= n; i++)
   7.138 + 		if (BN_is_bit_set(dh_pub, i))
   7.139 + 			bits_set++;
   7.140 +-	debug2("bits set: %d/%d", bits_set, BN_num_bits(dh->p));
   7.141 ++	debug2("bits set: %d/%d", bits_set, BN_num_bits(p));
   7.142 + 
   7.143 + 	/*
   7.144 + 	 * if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial
   7.145 + 	 */
   7.146 + 	if (bits_set < 4) {
   7.147 + 		logit("invalid public DH value (%d/%d)",
   7.148 +-		   bits_set, BN_num_bits(dh->p));
   7.149 ++		   bits_set, BN_num_bits(p));
   7.150 + 		return 0;
   7.151 + 	}
   7.152 + 	return 1;
   7.153 +@@ -260,9 +262,13 @@
   7.154 + dh_gen_key(DH *dh, int need)
   7.155 + {
   7.156 + 	int pbits;
   7.157 ++	const BIGNUM *p, *pub_key;
   7.158 ++	BIGNUM *priv_key;
   7.159 + 
   7.160 +-	if (need < 0 || dh->p == NULL ||
   7.161 +-	    (pbits = BN_num_bits(dh->p)) <= 0 ||
   7.162 ++	DH_get0_pqg(dh, &p, NULL, NULL);
   7.163 ++
   7.164 ++	if (need < 0 || p == NULL ||
   7.165 ++	    (pbits = BN_num_bits(p)) <= 0 ||
   7.166 + 	    need > INT_MAX / 2 || 2 * need > pbits)
   7.167 + 		return SSH_ERR_INVALID_ARGUMENT;
   7.168 + 	if (need < 256)
   7.169 +@@ -271,10 +277,13 @@
   7.170 + 	 * Pollard Rho, Big step/Little Step attacks are O(sqrt(n)),
   7.171 + 	 * so double requested need here.
   7.172 + 	 */
   7.173 +-	dh->length = MINIMUM(need * 2, pbits - 1);
   7.174 +-	if (DH_generate_key(dh) == 0 ||
   7.175 +-	    !dh_pub_is_valid(dh, dh->pub_key)) {
   7.176 +-		BN_clear_free(dh->priv_key);
   7.177 ++	DH_set_length(dh, MIN(need * 2, pbits - 1));
   7.178 ++	if (DH_generate_key(dh) == 0) {
   7.179 ++		return SSH_ERR_LIBCRYPTO_ERROR;
   7.180 ++	}
   7.181 ++	DH_get0_key(dh, &pub_key, &priv_key);
   7.182 ++	if (!dh_pub_is_valid(dh, pub_key)) {
   7.183 ++		BN_clear(priv_key);
   7.184 + 		return SSH_ERR_LIBCRYPTO_ERROR;
   7.185 + 	}
   7.186 + 	return 0;
   7.187 +@@ -283,16 +292,27 @@
   7.188 + DH *
   7.189 + dh_new_group_asc(const char *gen, const char *modulus)
   7.190 + {
   7.191 +-	DH *dh;
   7.192 ++	DH *dh = NULL;
   7.193 ++	BIGNUM *p=NULL, *g=NULL;
   7.194 + 
   7.195 +-	if ((dh = DH_new()) == NULL)
   7.196 +-		return NULL;
   7.197 +-	if (BN_hex2bn(&dh->p, modulus) == 0 ||
   7.198 +-	    BN_hex2bn(&dh->g, gen) == 0) {
   7.199 +-		DH_free(dh);
   7.200 +-		return NULL;
   7.201 ++	if ((dh = DH_new()) == NULL ||
   7.202 ++	    (p = BN_new()) == NULL ||
   7.203 ++	    (g = BN_new()) == NULL)
   7.204 ++		goto null;
   7.205 ++	if (BN_hex2bn(&p, modulus) == 0 ||
   7.206 ++	    BN_hex2bn(&g, gen) == 0) {
   7.207 ++		goto null;
   7.208 + 	}
   7.209 ++	if (DH_set0_pqg(dh, p, NULL, g) == 0) {
   7.210 ++		goto null;
   7.211 ++	}
   7.212 ++	p = g = NULL;
   7.213 + 	return (dh);
   7.214 ++null:
   7.215 ++	BN_free(p);
   7.216 ++	BN_free(g);
   7.217 ++	DH_free(dh);
   7.218 ++	return NULL;
   7.219 + }
   7.220 + 
   7.221 + /*
   7.222 +@@ -307,8 +327,8 @@
   7.223 + 
   7.224 + 	if ((dh = DH_new()) == NULL)
   7.225 + 		return NULL;
   7.226 +-	dh->p = modulus;
   7.227 +-	dh->g = gen;
   7.228 ++	if (DH_set0_pqg(dh, modulus, NULL, gen) == 0)
   7.229 ++		return NULL;
   7.230 + 
   7.231 + 	return (dh);
   7.232 + }
   7.233 +diff -Naur old/dh.h new/dh.h
   7.234 +--- old/dh.h	2017-10-03 21:49:05.370496037 -1000
   7.235 ++++ new/dh.h	2017-10-03 21:55:50.869718862 -1000
   7.236 +@@ -42,7 +42,7 @@
   7.237 + DH	*dh_new_group_fallback(int);
   7.238 + 
   7.239 + int	 dh_gen_key(DH *, int);
   7.240 +-int	 dh_pub_is_valid(DH *, BIGNUM *);
   7.241 ++int	 dh_pub_is_valid(const DH *, const BIGNUM *);
   7.242 + 
   7.243 + u_int	 dh_estimate(int);
   7.244 + 
   7.245 +diff -Naur old/digest-openssl.c new/digest-openssl.c
   7.246 +--- old/digest-openssl.c	2017-10-03 21:49:05.370496037 -1000
   7.247 ++++ new/digest-openssl.c	2017-10-03 21:55:50.869718862 -1000
   7.248 +@@ -43,7 +43,7 @@
   7.249 + 
   7.250 + struct ssh_digest_ctx {
   7.251 + 	int alg;
   7.252 +-	EVP_MD_CTX mdctx;
   7.253 ++	EVP_MD_CTX *mdctx;
   7.254 + };
   7.255 + 
   7.256 + struct ssh_digest {
   7.257 +@@ -106,20 +106,21 @@
   7.258 + size_t
   7.259 + ssh_digest_blocksize(struct ssh_digest_ctx *ctx)
   7.260 + {
   7.261 +-	return EVP_MD_CTX_block_size(&ctx->mdctx);
   7.262 ++	return EVP_MD_CTX_block_size(ctx->mdctx);
   7.263 + }
   7.264 + 
   7.265 + struct ssh_digest_ctx *
   7.266 + ssh_digest_start(int alg)
   7.267 + {
   7.268 + 	const struct ssh_digest *digest = ssh_digest_by_alg(alg);
   7.269 +-	struct ssh_digest_ctx *ret;
   7.270 ++	struct ssh_digest_ctx *ret = NULL;
   7.271 + 
   7.272 + 	if (digest == NULL || ((ret = calloc(1, sizeof(*ret))) == NULL))
   7.273 + 		return NULL;
   7.274 + 	ret->alg = alg;
   7.275 +-	EVP_MD_CTX_init(&ret->mdctx);
   7.276 +-	if (EVP_DigestInit_ex(&ret->mdctx, digest->mdfunc(), NULL) != 1) {
   7.277 ++	if ((ret->mdctx = EVP_MD_CTX_new()) == NULL ||
   7.278 ++	    EVP_DigestInit_ex(ret->mdctx, digest->mdfunc(), NULL) != 1) {
   7.279 ++		EVP_MD_CTX_free(ret->mdctx);
   7.280 + 		free(ret);
   7.281 + 		return NULL;
   7.282 + 	}
   7.283 +@@ -132,7 +133,7 @@
   7.284 + 	if (from->alg != to->alg)
   7.285 + 		return SSH_ERR_INVALID_ARGUMENT;
   7.286 + 	/* we have bcopy-style order while openssl has memcpy-style */
   7.287 +-	if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx))
   7.288 ++	if (!EVP_MD_CTX_copy_ex(to->mdctx, from->mdctx))
   7.289 + 		return SSH_ERR_LIBCRYPTO_ERROR;
   7.290 + 	return 0;
   7.291 + }
   7.292 +@@ -140,7 +141,7 @@
   7.293 + int
   7.294 + ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
   7.295 + {
   7.296 +-	if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1)
   7.297 ++	if (EVP_DigestUpdate(ctx->mdctx, m, mlen) != 1)
   7.298 + 		return SSH_ERR_LIBCRYPTO_ERROR;
   7.299 + 	return 0;
   7.300 + }
   7.301 +@@ -161,7 +162,7 @@
   7.302 + 		return SSH_ERR_INVALID_ARGUMENT;
   7.303 + 	if (dlen < digest->digest_len) /* No truncation allowed */
   7.304 + 		return SSH_ERR_INVALID_ARGUMENT;
   7.305 +-	if (EVP_DigestFinal_ex(&ctx->mdctx, d, &l) != 1)
   7.306 ++	if (EVP_DigestFinal_ex(ctx->mdctx, d, &l) != 1)
   7.307 + 		return SSH_ERR_LIBCRYPTO_ERROR;
   7.308 + 	if (l != digest->digest_len) /* sanity */
   7.309 + 		return SSH_ERR_INTERNAL_ERROR;
   7.310 +@@ -172,7 +173,7 @@
   7.311 + ssh_digest_free(struct ssh_digest_ctx *ctx)
   7.312 + {
   7.313 + 	if (ctx != NULL) {
   7.314 +-		EVP_MD_CTX_cleanup(&ctx->mdctx);
   7.315 ++		EVP_MD_CTX_free(ctx->mdctx);
   7.316 + 		explicit_bzero(ctx, sizeof(*ctx));
   7.317 + 		free(ctx);
   7.318 + 	}
   7.319 +diff -Naur old/kexdhc.c new/kexdhc.c
   7.320 +--- old/kexdhc.c	2017-10-03 21:49:05.373829169 -1000
   7.321 ++++ new/kexdhc.c	2017-10-03 21:55:50.869718862 -1000
   7.322 +@@ -81,11 +81,16 @@
   7.323 + 		goto out;
   7.324 + 	}
   7.325 + 	debug("sending SSH2_MSG_KEXDH_INIT");
   7.326 +-	if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0 ||
   7.327 +-	    (r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 ||
   7.328 +-	    (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||
   7.329 ++	{
   7.330 ++	const BIGNUM *pub_key;
   7.331 ++	if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
   7.332 ++		goto out;
   7.333 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.334 ++	if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 ||
   7.335 ++	    (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||
   7.336 + 	    (r = sshpkt_send(ssh)) != 0)
   7.337 + 		goto out;
   7.338 ++	}
   7.339 + #ifdef DEBUG_KEXDH
   7.340 + 	DHparams_print_fp(stderr, kex->dh);
   7.341 + 	fprintf(stderr, "pub= ");
   7.342 +@@ -169,6 +174,9 @@
   7.343 + 
   7.344 + 	/* calc and verify H */
   7.345 + 	hashlen = sizeof(hash);
   7.346 ++	{
   7.347 ++	const BIGNUM *pub_key;
   7.348 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.349 + 	if ((r = kex_dh_hash(
   7.350 + 	    kex->hash_alg,
   7.351 + 	    kex->client_version_string,
   7.352 +@@ -176,11 +184,13 @@
   7.353 + 	    sshbuf_ptr(kex->my), sshbuf_len(kex->my),
   7.354 + 	    sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
   7.355 + 	    server_host_key_blob, sbloblen,
   7.356 +-	    kex->dh->pub_key,
   7.357 ++	    pub_key,
   7.358 + 	    dh_server_pub,
   7.359 + 	    shared_secret,
   7.360 +-	    hash, &hashlen)) != 0)
   7.361 ++	    hash, &hashlen)) != 0) {
   7.362 + 		goto out;
   7.363 ++	}
   7.364 ++	}
   7.365 + 
   7.366 + 	if ((r = sshkey_verify(server_host_key, signature, slen, hash, hashlen,
   7.367 + 	    ssh->compat)) != 0)
   7.368 +diff -Naur old/kexdhs.c new/kexdhs.c
   7.369 +--- old/kexdhs.c	2017-10-03 21:49:05.373829169 -1000
   7.370 ++++ new/kexdhs.c	2017-10-03 21:55:50.869718862 -1000
   7.371 +@@ -87,6 +87,10 @@
   7.372 + 	ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_INIT, &input_kex_dh_init);
   7.373 + 	r = 0;
   7.374 +  out:
   7.375 ++	if (r != 0) {
   7.376 ++		if (kex->dh) DH_free(kex->dh);
   7.377 ++		kex->dh = NULL;
   7.378 ++	}
   7.379 + 	return r;
   7.380 + }
   7.381 + 
   7.382 +@@ -163,6 +167,9 @@
   7.383 + 		goto out;
   7.384 + 	/* calc H */
   7.385 + 	hashlen = sizeof(hash);
   7.386 ++	{
   7.387 ++	const BIGNUM *pub_key;
   7.388 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.389 + 	if ((r = kex_dh_hash(
   7.390 + 	    kex->hash_alg,
   7.391 + 	    kex->client_version_string,
   7.392 +@@ -171,10 +178,12 @@
   7.393 + 	    sshbuf_ptr(kex->my), sshbuf_len(kex->my),
   7.394 + 	    server_host_key_blob, sbloblen,
   7.395 + 	    dh_client_pub,
   7.396 +-	    kex->dh->pub_key,
   7.397 ++	    pub_key,
   7.398 + 	    shared_secret,
   7.399 +-	    hash, &hashlen)) != 0)
   7.400 ++	    hash, &hashlen)) != 0) {
   7.401 + 		goto out;
   7.402 ++	}
   7.403 ++	}
   7.404 + 
   7.405 + 	/* save session id := H */
   7.406 + 	if (kex->session_id == NULL) {
   7.407 +@@ -195,12 +204,17 @@
   7.408 + 	/* destroy_sensitive_data(); */
   7.409 + 
   7.410 + 	/* send server hostkey, DH pubkey 'f' and singed H */
   7.411 ++	{
   7.412 ++	const BIGNUM *pub_key;
   7.413 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.414 + 	if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_REPLY)) != 0 ||
   7.415 + 	    (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
   7.416 +-	    (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||	/* f */
   7.417 ++	    (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||	/* f */
   7.418 + 	    (r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
   7.419 +-	    (r = sshpkt_send(ssh)) != 0)
   7.420 ++	    (r = sshpkt_send(ssh)) != 0) {
   7.421 + 		goto out;
   7.422 ++	}
   7.423 ++	}
   7.424 + 
   7.425 + 	if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) == 0)
   7.426 + 		r = kex_send_newkeys(ssh);
   7.427 +diff -Naur old/kexgexc.c new/kexgexc.c
   7.428 +--- old/kexgexc.c	2017-10-03 21:49:05.373829169 -1000
   7.429 ++++ new/kexgexc.c	2017-10-03 21:55:50.869718862 -1000
   7.430 +@@ -118,11 +118,17 @@
   7.431 + 	p = g = NULL; /* belong to kex->dh now */
   7.432 + 
   7.433 + 	/* generate and send 'e', client DH public key */
   7.434 +-	if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0 ||
   7.435 +-	    (r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_INIT)) != 0 ||
   7.436 +-	    (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||
   7.437 +-	    (r = sshpkt_send(ssh)) != 0)
   7.438 ++	{
   7.439 ++	const BIGNUM *pub_key;
   7.440 ++	if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
   7.441 ++		goto out;
   7.442 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.443 ++	if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_INIT)) != 0 ||
   7.444 ++	    (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||
   7.445 ++	    (r = sshpkt_send(ssh)) != 0) {
   7.446 + 		goto out;
   7.447 ++	}
   7.448 ++	}
   7.449 + 	debug("SSH2_MSG_KEX_DH_GEX_INIT sent");
   7.450 + #ifdef DEBUG_KEXDH
   7.451 + 	DHparams_print_fp(stderr, kex->dh);
   7.452 +@@ -134,10 +140,12 @@
   7.453 + 	ssh_dispatch_set(ssh, SSH2_MSG_KEX_DH_GEX_REPLY, &input_kex_dh_gex_reply);
   7.454 + 	r = 0;
   7.455 + out:
   7.456 +-	if (p)
   7.457 ++	if (r != 0) {
   7.458 + 		BN_clear_free(p);
   7.459 +-	if (g)
   7.460 + 		BN_clear_free(g);
   7.461 ++		DH_free(kex->dh);
   7.462 ++		kex->dh = NULL;
   7.463 ++	}
   7.464 + 	return r;
   7.465 + }
   7.466 + 
   7.467 +@@ -214,6 +222,10 @@
   7.468 + 
   7.469 + 	/* calc and verify H */
   7.470 + 	hashlen = sizeof(hash);
   7.471 ++	{
   7.472 ++	const BIGNUM *p, *g, *pub_key;
   7.473 ++	DH_get0_pqg(kex->dh, &p, NULL, &g);
   7.474 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.475 + 	if ((r = kexgex_hash(
   7.476 + 	    kex->hash_alg,
   7.477 + 	    kex->client_version_string,
   7.478 +@@ -222,12 +234,14 @@
   7.479 + 	    sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
   7.480 + 	    server_host_key_blob, sbloblen,
   7.481 + 	    kex->min, kex->nbits, kex->max,
   7.482 +-	    kex->dh->p, kex->dh->g,
   7.483 +-	    kex->dh->pub_key,
   7.484 ++	    p, g,
   7.485 ++	    pub_key,
   7.486 + 	    dh_server_pub,
   7.487 + 	    shared_secret,
   7.488 +-	    hash, &hashlen)) != 0)
   7.489 ++	    hash, &hashlen)) != 0) {
   7.490 + 		goto out;
   7.491 ++	}
   7.492 ++	}
   7.493 + 
   7.494 + 	if ((r = sshkey_verify(server_host_key, signature, slen, hash,
   7.495 + 	    hashlen, ssh->compat)) != 0)
   7.496 +diff -Naur old/kexgexs.c new/kexgexs.c
   7.497 +--- old/kexgexs.c	2017-10-03 21:49:05.373829169 -1000
   7.498 ++++ new/kexgexs.c	2017-10-03 21:55:50.869718862 -1000
   7.499 +@@ -101,11 +101,16 @@
   7.500 + 		goto out;
   7.501 + 	}
   7.502 + 	debug("SSH2_MSG_KEX_DH_GEX_GROUP sent");
   7.503 ++	{
   7.504 ++	const BIGNUM *p, *g;
   7.505 ++	DH_get0_pqg(kex->dh, &p, NULL, &g);
   7.506 + 	if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_GROUP)) != 0 ||
   7.507 +-	    (r = sshpkt_put_bignum2(ssh, kex->dh->p)) != 0 ||
   7.508 +-	    (r = sshpkt_put_bignum2(ssh, kex->dh->g)) != 0 ||
   7.509 +-	    (r = sshpkt_send(ssh)) != 0)
   7.510 ++	    (r = sshpkt_put_bignum2(ssh, p)) != 0 ||
   7.511 ++	    (r = sshpkt_put_bignum2(ssh, g)) != 0 ||
   7.512 ++	    (r = sshpkt_send(ssh)) != 0) {
   7.513 + 		goto out;
   7.514 ++	}
   7.515 ++	}
   7.516 + 
   7.517 + 	/* Compute our exchange value in parallel with the client */
   7.518 + 	if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
   7.519 +@@ -115,6 +120,10 @@
   7.520 + 	ssh_dispatch_set(ssh, SSH2_MSG_KEX_DH_GEX_INIT, &input_kex_dh_gex_init);
   7.521 + 	r = 0;
   7.522 +  out:
   7.523 ++	if (r != 0) {
   7.524 ++		DH_free(kex->dh);
   7.525 ++		kex->dh = NULL;
   7.526 ++	}
   7.527 + 	return r;
   7.528 + }
   7.529 + 
   7.530 +@@ -191,6 +200,10 @@
   7.531 + 		goto out;
   7.532 + 	/* calc H */
   7.533 + 	hashlen = sizeof(hash);
   7.534 ++	{
   7.535 ++	const BIGNUM *p, *g, *pub_key;
   7.536 ++	DH_get0_pqg(kex->dh, &p, NULL, &g);
   7.537 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.538 + 	if ((r = kexgex_hash(
   7.539 + 	    kex->hash_alg,
   7.540 + 	    kex->client_version_string,
   7.541 +@@ -199,12 +212,14 @@
   7.542 + 	    sshbuf_ptr(kex->my), sshbuf_len(kex->my),
   7.543 + 	    server_host_key_blob, sbloblen,
   7.544 + 	    kex->min, kex->nbits, kex->max,
   7.545 +-	    kex->dh->p, kex->dh->g,
   7.546 ++	    p, g,
   7.547 + 	    dh_client_pub,
   7.548 +-	    kex->dh->pub_key,
   7.549 ++	    pub_key,
   7.550 + 	    shared_secret,
   7.551 +-	    hash, &hashlen)) != 0)
   7.552 ++	    hash, &hashlen)) != 0) {
   7.553 + 		goto out;
   7.554 ++	}
   7.555 ++	}
   7.556 + 
   7.557 + 	/* save session id := H */
   7.558 + 	if (kex->session_id == NULL) {
   7.559 +@@ -225,12 +240,17 @@
   7.560 + 	/* destroy_sensitive_data(); */
   7.561 + 
   7.562 + 	/* send server hostkey, DH pubkey 'f' and singed H */
   7.563 ++	{
   7.564 ++	const BIGNUM *pub_key;
   7.565 ++	DH_get0_key(kex->dh, &pub_key, NULL);
   7.566 + 	if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REPLY)) != 0 ||
   7.567 + 	    (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
   7.568 +-	    (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||     /* f */
   7.569 ++	    (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||     /* f */
   7.570 + 	    (r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
   7.571 +-	    (r = sshpkt_send(ssh)) != 0)
   7.572 ++	    (r = sshpkt_send(ssh)) != 0) {
   7.573 + 		goto out;
   7.574 ++	}
   7.575 ++	}
   7.576 + 
   7.577 + 	if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) == 0)
   7.578 + 		r = kex_send_newkeys(ssh);
   7.579 +diff -Naur old/monitor.c new/monitor.c
   7.580 +--- old/monitor.c	2017-10-03 21:49:05.377162302 -1000
   7.581 ++++ new/monitor.c	2017-10-03 21:55:50.869718862 -1000
   7.582 +@@ -586,10 +586,12 @@
   7.583 + 		buffer_put_char(m, 0);
   7.584 + 		return (0);
   7.585 + 	} else {
   7.586 ++		const BIGNUM *p, *g;
   7.587 ++		DH_get0_pqg(dh, &p, NULL, &g);
   7.588 + 		/* Send first bignum */
   7.589 + 		buffer_put_char(m, 1);
   7.590 +-		buffer_put_bignum2(m, dh->p);
   7.591 +-		buffer_put_bignum2(m, dh->g);
   7.592 ++		buffer_put_bignum2(m, p);
   7.593 ++		buffer_put_bignum2(m, g);
   7.594 + 
   7.595 + 		DH_free(dh);
   7.596 + 	}
   7.597 +diff -Naur old/openbsd-compat/openssl-compat.c new/openbsd-compat/openssl-compat.c
   7.598 +--- old/openbsd-compat/openssl-compat.c	2017-10-03 21:49:05.397161097 -1000
   7.599 ++++ new/openbsd-compat/openssl-compat.c	2017-10-03 21:55:50.886387486 -1000
   7.600 +@@ -75,7 +75,6 @@
   7.601 + 	/* Enable use of crypto hardware */
   7.602 + 	ENGINE_load_builtin_engines();
   7.603 + 	ENGINE_register_all_complete();
   7.604 +-	OPENSSL_config(NULL);
   7.605 + }
   7.606 + #endif
   7.607 + 
   7.608 +diff -Naur old/regress/unittests/sshkey/test_file.c new/regress/unittests/sshkey/test_file.c
   7.609 +--- old/regress/unittests/sshkey/test_file.c	2017-10-03 21:49:05.387161699 -1000
   7.610 ++++ new/regress/unittests/sshkey/test_file.c	2017-10-03 21:55:50.883053761 -1000
   7.611 +@@ -60,9 +60,14 @@
   7.612 + 	a = load_bignum("rsa_1.param.n");
   7.613 + 	b = load_bignum("rsa_1.param.p");
   7.614 + 	c = load_bignum("rsa_1.param.q");
   7.615 +-	ASSERT_BIGNUM_EQ(k1->rsa->n, a);
   7.616 +-	ASSERT_BIGNUM_EQ(k1->rsa->p, b);
   7.617 +-	ASSERT_BIGNUM_EQ(k1->rsa->q, c);
   7.618 ++	{
   7.619 ++	const BIGNUM *n, *p, *q;
   7.620 ++	RSA_get0_key(k1->rsa, &n, NULL, NULL);
   7.621 ++	RSA_get0_factors(k1->rsa, &p, &q);
   7.622 ++	ASSERT_BIGNUM_EQ(n, a);
   7.623 ++	ASSERT_BIGNUM_EQ(p, b);
   7.624 ++	ASSERT_BIGNUM_EQ(q, c);
   7.625 ++	}
   7.626 + 	BN_free(a);
   7.627 + 	BN_free(b);
   7.628 + 	BN_free(c);
   7.629 +@@ -151,9 +156,14 @@
   7.630 + 	a = load_bignum("dsa_1.param.g");
   7.631 + 	b = load_bignum("dsa_1.param.priv");
   7.632 + 	c = load_bignum("dsa_1.param.pub");
   7.633 +-	ASSERT_BIGNUM_EQ(k1->dsa->g, a);
   7.634 +-	ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b);
   7.635 +-	ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c);
   7.636 ++	{
   7.637 ++	const BIGNUM *g, *priv_key, *pub_key;
   7.638 ++	DSA_get0_pqg(k1->dsa, NULL, NULL, &g);
   7.639 ++	DSA_get0_key(k1->dsa, &pub_key, &priv_key);
   7.640 ++	ASSERT_BIGNUM_EQ(g, a);
   7.641 ++	ASSERT_BIGNUM_EQ(priv_key, b);
   7.642 ++	ASSERT_BIGNUM_EQ(pub_key, c);
   7.643 ++	}
   7.644 + 	BN_free(a);
   7.645 + 	BN_free(b);
   7.646 + 	BN_free(c);
   7.647 +diff -Naur old/regress/unittests/sshkey/test_sshkey.c new/regress/unittests/sshkey/test_sshkey.c
   7.648 +--- old/regress/unittests/sshkey/test_sshkey.c	2017-10-03 21:49:05.387161699 -1000
   7.649 ++++ new/regress/unittests/sshkey/test_sshkey.c	2017-10-03 21:55:50.883053761 -1000
   7.650 +@@ -197,9 +197,14 @@
   7.651 + 	k1 = sshkey_new(KEY_RSA);
   7.652 + 	ASSERT_PTR_NE(k1, NULL);
   7.653 + 	ASSERT_PTR_NE(k1->rsa, NULL);
   7.654 +-	ASSERT_PTR_NE(k1->rsa->n, NULL);
   7.655 +-	ASSERT_PTR_NE(k1->rsa->e, NULL);
   7.656 +-	ASSERT_PTR_EQ(k1->rsa->p, NULL);
   7.657 ++	{
   7.658 ++	const BIGNUM *n, *e, *p;
   7.659 ++	RSA_get0_key(k1->rsa, &n, &e, NULL);
   7.660 ++	RSA_get0_factors(k1->rsa, &p, NULL);
   7.661 ++	ASSERT_PTR_NE(n, NULL);
   7.662 ++	ASSERT_PTR_NE(e, NULL);
   7.663 ++	ASSERT_PTR_EQ(p, NULL);
   7.664 ++	}
   7.665 + 	sshkey_free(k1);
   7.666 + 	TEST_DONE();
   7.667 + 
   7.668 +@@ -207,8 +212,13 @@
   7.669 + 	k1 = sshkey_new(KEY_DSA);
   7.670 + 	ASSERT_PTR_NE(k1, NULL);
   7.671 + 	ASSERT_PTR_NE(k1->dsa, NULL);
   7.672 +-	ASSERT_PTR_NE(k1->dsa->g, NULL);
   7.673 +-	ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
   7.674 ++	{
   7.675 ++	const BIGNUM *g, *priv_key;
   7.676 ++	DSA_get0_pqg(k1->dsa, NULL, NULL, &g);
   7.677 ++	DSA_get0_key(k1->dsa, NULL, &priv_key);
   7.678 ++	ASSERT_PTR_NE(g, NULL);
   7.679 ++	ASSERT_PTR_EQ(priv_key, NULL);
   7.680 ++	}
   7.681 + 	sshkey_free(k1);
   7.682 + 	TEST_DONE();
   7.683 + 
   7.684 +@@ -234,9 +244,14 @@
   7.685 + 	k1 = sshkey_new_private(KEY_RSA);
   7.686 + 	ASSERT_PTR_NE(k1, NULL);
   7.687 + 	ASSERT_PTR_NE(k1->rsa, NULL);
   7.688 +-	ASSERT_PTR_NE(k1->rsa->n, NULL);
   7.689 +-	ASSERT_PTR_NE(k1->rsa->e, NULL);
   7.690 +-	ASSERT_PTR_NE(k1->rsa->p, NULL);
   7.691 ++	{
   7.692 ++	const BIGNUM *n, *e, *p;
   7.693 ++	RSA_get0_key(k1->rsa, &n, &e, NULL);
   7.694 ++	RSA_get0_factors(k1->rsa, &p, NULL);
   7.695 ++	ASSERT_PTR_NE(n, NULL);
   7.696 ++	ASSERT_PTR_NE(e, NULL);
   7.697 ++	ASSERT_PTR_NE(p, NULL);
   7.698 ++	}
   7.699 + 	ASSERT_INT_EQ(sshkey_add_private(k1), 0);
   7.700 + 	sshkey_free(k1);
   7.701 + 	TEST_DONE();
   7.702 +@@ -245,8 +260,13 @@
   7.703 + 	k1 = sshkey_new_private(KEY_DSA);
   7.704 + 	ASSERT_PTR_NE(k1, NULL);
   7.705 + 	ASSERT_PTR_NE(k1->dsa, NULL);
   7.706 +-	ASSERT_PTR_NE(k1->dsa->g, NULL);
   7.707 +-	ASSERT_PTR_NE(k1->dsa->priv_key, NULL);
   7.708 ++	{
   7.709 ++	const BIGNUM *g, *priv_key;
   7.710 ++	DSA_get0_pqg(k1->dsa, NULL, NULL, &g);
   7.711 ++	DSA_get0_key(k1->dsa, NULL, &priv_key);
   7.712 ++	ASSERT_PTR_NE(g, NULL);
   7.713 ++	ASSERT_PTR_NE(priv_key, NULL);
   7.714 ++	}
   7.715 + 	ASSERT_INT_EQ(sshkey_add_private(k1), 0);
   7.716 + 	sshkey_free(k1);
   7.717 + 	TEST_DONE();
   7.718 +@@ -285,18 +305,28 @@
   7.719 + 	ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &kr), 0);
   7.720 + 	ASSERT_PTR_NE(kr, NULL);
   7.721 + 	ASSERT_PTR_NE(kr->rsa, NULL);
   7.722 +-	ASSERT_PTR_NE(kr->rsa->n, NULL);
   7.723 +-	ASSERT_PTR_NE(kr->rsa->e, NULL);
   7.724 +-	ASSERT_PTR_NE(kr->rsa->p, NULL);
   7.725 +-	ASSERT_INT_EQ(BN_num_bits(kr->rsa->n), 1024);
   7.726 ++	{
   7.727 ++	const BIGNUM *n, *e, *p;
   7.728 ++	RSA_get0_key(kr->rsa, &n, &e, NULL);
   7.729 ++	RSA_get0_factors(kr->rsa, &p, NULL);
   7.730 ++	ASSERT_PTR_NE(n, NULL);
   7.731 ++	ASSERT_PTR_NE(e, NULL);
   7.732 ++	ASSERT_PTR_NE(p, NULL);
   7.733 ++	ASSERT_INT_EQ(BN_num_bits(n), 1024);
   7.734 ++	}
   7.735 + 	TEST_DONE();
   7.736 + 
   7.737 + 	TEST_START("generate KEY_DSA");
   7.738 + 	ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0);
   7.739 + 	ASSERT_PTR_NE(kd, NULL);
   7.740 + 	ASSERT_PTR_NE(kd->dsa, NULL);
   7.741 +-	ASSERT_PTR_NE(kd->dsa->g, NULL);
   7.742 +-	ASSERT_PTR_NE(kd->dsa->priv_key, NULL);
   7.743 ++	{
   7.744 ++	const BIGNUM *g, *priv_key;
   7.745 ++	DSA_get0_pqg(kd->dsa, NULL, NULL, &g);
   7.746 ++	DSA_get0_key(kd->dsa, NULL, &priv_key);
   7.747 ++	ASSERT_PTR_NE(g, NULL);
   7.748 ++	ASSERT_PTR_NE(priv_key, NULL);
   7.749 ++	}
   7.750 + 	TEST_DONE();
   7.751 + 
   7.752 + #ifdef OPENSSL_HAS_ECC
   7.753 +@@ -323,9 +353,14 @@
   7.754 + 	ASSERT_PTR_NE(kr, k1);
   7.755 + 	ASSERT_INT_EQ(k1->type, KEY_RSA);
   7.756 + 	ASSERT_PTR_NE(k1->rsa, NULL);
   7.757 +-	ASSERT_PTR_NE(k1->rsa->n, NULL);
   7.758 +-	ASSERT_PTR_NE(k1->rsa->e, NULL);
   7.759 +-	ASSERT_PTR_EQ(k1->rsa->p, NULL);
   7.760 ++	{
   7.761 ++	const BIGNUM *n, *e, *p;
   7.762 ++	RSA_get0_key(k1->rsa, &n, &e, NULL);
   7.763 ++	RSA_get0_factors(k1->rsa, &p, NULL);
   7.764 ++	ASSERT_PTR_NE(n, NULL);
   7.765 ++	ASSERT_PTR_NE(e, NULL);
   7.766 ++	ASSERT_PTR_EQ(p, NULL);
   7.767 ++	}
   7.768 + 	TEST_DONE();
   7.769 + 
   7.770 + 	TEST_START("equal KEY_RSA/demoted KEY_RSA");
   7.771 +@@ -339,8 +374,13 @@
   7.772 + 	ASSERT_PTR_NE(kd, k1);
   7.773 + 	ASSERT_INT_EQ(k1->type, KEY_DSA);
   7.774 + 	ASSERT_PTR_NE(k1->dsa, NULL);
   7.775 +-	ASSERT_PTR_NE(k1->dsa->g, NULL);
   7.776 +-	ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
   7.777 ++	{
   7.778 ++	const BIGNUM *g, *priv_key;
   7.779 ++	DSA_get0_pqg(k1->dsa, NULL, NULL, &g);
   7.780 ++	DSA_get0_key(k1->dsa, NULL, &priv_key);
   7.781 ++	ASSERT_PTR_NE(g, NULL);
   7.782 ++	ASSERT_PTR_EQ(priv_key, NULL);
   7.783 ++	}
   7.784 + 	TEST_DONE();
   7.785 + 
   7.786 + 	TEST_START("equal KEY_DSA/demoted KEY_DSA");
   7.787 +diff -Naur old/ssh-dss.c new/ssh-dss.c
   7.788 +--- old/ssh-dss.c	2017-10-03 21:49:05.403827361 -1000
   7.789 ++++ new/ssh-dss.c	2017-10-03 21:55:50.869718862 -1000
   7.790 +@@ -53,6 +53,7 @@
   7.791 + 	DSA_SIG *sig = NULL;
   7.792 + 	u_char digest[SSH_DIGEST_MAX_LENGTH], sigblob[SIGBLOB_LEN];
   7.793 + 	size_t rlen, slen, len, dlen = ssh_digest_bytes(SSH_DIGEST_SHA1);
   7.794 ++	const BIGNUM *r, *s;
   7.795 + 	struct sshbuf *b = NULL;
   7.796 + 	int ret = SSH_ERR_INVALID_ARGUMENT;
   7.797 + 
   7.798 +@@ -76,15 +77,16 @@
   7.799 + 		goto out;
   7.800 + 	}
   7.801 + 
   7.802 +-	rlen = BN_num_bytes(sig->r);
   7.803 +-	slen = BN_num_bytes(sig->s);
   7.804 ++	DSA_SIG_get0(sig, &r, &s);
   7.805 ++	rlen = BN_num_bytes(r);
   7.806 ++	slen = BN_num_bytes(s);
   7.807 + 	if (rlen > INTBLOB_LEN || slen > INTBLOB_LEN) {
   7.808 + 		ret = SSH_ERR_INTERNAL_ERROR;
   7.809 + 		goto out;
   7.810 + 	}
   7.811 + 	explicit_bzero(sigblob, SIGBLOB_LEN);
   7.812 +-	BN_bn2bin(sig->r, sigblob + SIGBLOB_LEN - INTBLOB_LEN - rlen);
   7.813 +-	BN_bn2bin(sig->s, sigblob + SIGBLOB_LEN - slen);
   7.814 ++	BN_bn2bin(r, sigblob + SIGBLOB_LEN - INTBLOB_LEN - rlen);
   7.815 ++	BN_bn2bin(s, sigblob + SIGBLOB_LEN - slen);
   7.816 + 
   7.817 + 	if (compat & SSH_BUG_SIGBLOB) {
   7.818 + 		if (sigp != NULL) {
   7.819 +@@ -176,17 +178,26 @@
   7.820 + 	}
   7.821 + 
   7.822 + 	/* parse signature */
   7.823 ++	{
   7.824 ++	BIGNUM *r=NULL, *s=NULL;
   7.825 + 	if ((sig = DSA_SIG_new()) == NULL ||
   7.826 +-	    (sig->r = BN_new()) == NULL ||
   7.827 +-	    (sig->s = BN_new()) == NULL) {
   7.828 ++	    (r = BN_new()) == NULL ||
   7.829 ++	    (s = BN_new()) == NULL) {
   7.830 + 		ret = SSH_ERR_ALLOC_FAIL;
   7.831 ++		BN_free(r);
   7.832 ++		BN_free(s);
   7.833 + 		goto out;
   7.834 + 	}
   7.835 +-	if ((BN_bin2bn(sigblob, INTBLOB_LEN, sig->r) == NULL) ||
   7.836 +-	    (BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, sig->s) == NULL)) {
   7.837 ++	if ((BN_bin2bn(sigblob, INTBLOB_LEN, r) == NULL) ||
   7.838 ++	    (BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, s) == NULL)) {
   7.839 + 		ret = SSH_ERR_LIBCRYPTO_ERROR;
   7.840 ++		BN_free(r);
   7.841 ++		BN_free(s);
   7.842 + 		goto out;
   7.843 + 	}
   7.844 ++	DSA_SIG_set0(sig, r, s);
   7.845 ++	r = s = NULL;
   7.846 ++	}
   7.847 + 
   7.848 + 	/* sha1 the data */
   7.849 + 	if ((ret = ssh_digest_memory(SSH_DIGEST_SHA1, data, datalen,
   7.850 +diff -Naur old/ssh-ecdsa.c new/ssh-ecdsa.c
   7.851 +--- old/ssh-ecdsa.c	2017-10-03 21:49:05.403827361 -1000
   7.852 ++++ new/ssh-ecdsa.c	2017-10-03 21:55:50.869718862 -1000
   7.853 +@@ -80,9 +80,14 @@
   7.854 + 		ret = SSH_ERR_ALLOC_FAIL;
   7.855 + 		goto out;
   7.856 + 	}
   7.857 +-	if ((ret = sshbuf_put_bignum2(bb, sig->r)) != 0 ||
   7.858 +-	    (ret = sshbuf_put_bignum2(bb, sig->s)) != 0)
   7.859 ++	{
   7.860 ++	const BIGNUM *r, *s;
   7.861 ++	ECDSA_SIG_get0(sig, &r, &s);
   7.862 ++	if ((ret = sshbuf_put_bignum2(bb, r)) != 0 ||
   7.863 ++	    (ret = sshbuf_put_bignum2(bb, s)) != 0) {
   7.864 + 		goto out;
   7.865 ++	}
   7.866 ++	}
   7.867 + 	if ((ret = sshbuf_put_cstring(b, sshkey_ssh_name_plain(key))) != 0 ||
   7.868 + 	    (ret = sshbuf_put_stringb(b, bb)) != 0)
   7.869 + 		goto out;
   7.870 +@@ -151,11 +156,27 @@
   7.871 + 		ret = SSH_ERR_ALLOC_FAIL;
   7.872 + 		goto out;
   7.873 + 	}
   7.874 +-	if (sshbuf_get_bignum2(sigbuf, sig->r) != 0 ||
   7.875 +-	    sshbuf_get_bignum2(sigbuf, sig->s) != 0) {
   7.876 ++	{
   7.877 ++	BIGNUM *r=NULL, *s=NULL;
   7.878 ++	if ((r = BN_new()) == NULL ||
   7.879 ++	    (s = BN_new()) == NULL) {
   7.880 ++		ret = SSH_ERR_ALLOC_FAIL;
   7.881 ++		goto out_rs;
   7.882 ++	}
   7.883 ++	if (sshbuf_get_bignum2(sigbuf, r) != 0 ||
   7.884 ++	    sshbuf_get_bignum2(sigbuf, s) != 0) {
   7.885 + 		ret = SSH_ERR_INVALID_FORMAT;
   7.886 ++		goto out_rs;
   7.887 ++	}
   7.888 ++	if (ECDSA_SIG_set0(sig, r, s) == 0) {
   7.889 ++		ret = SSH_ERR_LIBCRYPTO_ERROR;
   7.890 ++out_rs:
   7.891 ++		BN_free(r);
   7.892 ++		BN_free(s);
   7.893 + 		goto out;
   7.894 + 	}
   7.895 ++	r = s = NULL;
   7.896 ++	}
   7.897 + 	if (sshbuf_len(sigbuf) != 0) {
   7.898 + 		ret = SSH_ERR_UNEXPECTED_TRAILING_DATA;
   7.899 + 		goto out;
   7.900 +diff -Naur old/ssh-keygen.c new/ssh-keygen.c
   7.901 +--- old/ssh-keygen.c	2017-10-03 21:49:05.403827361 -1000
   7.902 ++++ new/ssh-keygen.c	2017-10-03 21:55:50.869718862 -1000
   7.903 +@@ -496,11 +496,33 @@
   7.904 + 
   7.905 + 	switch (key->type) {
   7.906 + 	case KEY_DSA:
   7.907 +-		buffer_get_bignum_bits(b, key->dsa->p);
   7.908 +-		buffer_get_bignum_bits(b, key->dsa->g);
   7.909 +-		buffer_get_bignum_bits(b, key->dsa->q);
   7.910 +-		buffer_get_bignum_bits(b, key->dsa->pub_key);
   7.911 +-		buffer_get_bignum_bits(b, key->dsa->priv_key);
   7.912 ++		{
   7.913 ++		BIGNUM *p=NULL, *g=NULL, *q=NULL, *pub_key=NULL, *priv_key=NULL;
   7.914 ++		if ((p=BN_new()) == NULL ||
   7.915 ++		    (g=BN_new()) == NULL ||
   7.916 ++		    (q=BN_new()) == NULL ||
   7.917 ++		    (pub_key=BN_new()) == NULL ||
   7.918 ++		    (priv_key=BN_new()) == NULL) {
   7.919 ++			BN_free(p);
   7.920 ++			BN_free(g);
   7.921 ++			BN_free(q);
   7.922 ++			BN_free(pub_key);
   7.923 ++			BN_free(priv_key);
   7.924 ++			return NULL;
   7.925 ++		}
   7.926 ++		buffer_get_bignum_bits(b, p);
   7.927 ++		buffer_get_bignum_bits(b, g);
   7.928 ++		buffer_get_bignum_bits(b, q);
   7.929 ++		buffer_get_bignum_bits(b, pub_key);
   7.930 ++		buffer_get_bignum_bits(b, priv_key);
   7.931 ++		if (DSA_set0_pqg(key->dsa, p, q, g) == 0 ||
   7.932 ++		    DSA_set0_key(key->dsa, pub_key, priv_key) == 0) {
   7.933 ++			fatal("failed to set DSA key");
   7.934 ++			BN_free(p); BN_free(g); BN_free(q);
   7.935 ++			BN_free(pub_key); BN_free(priv_key);
   7.936 ++			return NULL;
   7.937 ++		}
   7.938 ++		}
   7.939 + 		break;
   7.940 + 	case KEY_RSA:
   7.941 + 		if ((r = sshbuf_get_u8(b, &e1)) != 0 ||
   7.942 +@@ -517,16 +539,52 @@
   7.943 + 			e += e3;
   7.944 + 			debug("e %lx", e);
   7.945 + 		}
   7.946 +-		if (!BN_set_word(key->rsa->e, e)) {
   7.947 ++		{
   7.948 ++		BIGNUM *rsa_e = NULL;
   7.949 ++		BIGNUM *d=NULL, *n=NULL, *iqmp=NULL, *q=NULL, *p=NULL;
   7.950 ++		BIGNUM *dmp1=NULL, *dmq1=NULL; /* dummy input to set in RSA_set0_crt_params */
   7.951 ++		rsa_e = BN_new();
   7.952 ++		if (!rsa_e || !BN_set_word(rsa_e, e)) {
   7.953 ++			if (rsa_e) BN_free(rsa_e);
   7.954 + 			sshbuf_free(b);
   7.955 + 			sshkey_free(key);
   7.956 + 			return NULL;
   7.957 + 		}
   7.958 +-		buffer_get_bignum_bits(b, key->rsa->d);
   7.959 +-		buffer_get_bignum_bits(b, key->rsa->n);
   7.960 +-		buffer_get_bignum_bits(b, key->rsa->iqmp);
   7.961 +-		buffer_get_bignum_bits(b, key->rsa->q);
   7.962 +-		buffer_get_bignum_bits(b, key->rsa->p);
   7.963 ++		if ((d=BN_new()) == NULL ||
   7.964 ++		    (n=BN_new()) == NULL ||
   7.965 ++		    (iqmp=BN_new()) == NULL ||
   7.966 ++		    (q=BN_new()) == NULL ||
   7.967 ++		    (p=BN_new()) == NULL ||
   7.968 ++		    (dmp1=BN_new()) == NULL ||
   7.969 ++		    (dmq1=BN_new()) == NULL) {
   7.970 ++			BN_free(d); BN_free(n); BN_free(iqmp);
   7.971 ++			BN_free(q); BN_free(p);
   7.972 ++			BN_free(dmp1); BN_free(dmq1);
   7.973 ++			return NULL;
   7.974 ++		}
   7.975 ++		BN_clear(dmp1); BN_clear(dmq1);
   7.976 ++		buffer_get_bignum_bits(b, d);
   7.977 ++		buffer_get_bignum_bits(b, n);
   7.978 ++		buffer_get_bignum_bits(b, iqmp);
   7.979 ++		buffer_get_bignum_bits(b, q);
   7.980 ++		buffer_get_bignum_bits(b, p);
   7.981 ++		if (RSA_set0_key(key->rsa, n, rsa_e, d) == 0)
   7.982 ++			goto null;
   7.983 ++		n = d = NULL;
   7.984 ++		if (RSA_set0_factors(key->rsa, p, q) == 0)
   7.985 ++			goto null;
   7.986 ++		p = q = NULL;
   7.987 ++		/* dmp1, dmq1 should not be NULL for initial set0 */
   7.988 ++		if (RSA_set0_crt_params(key->rsa, dmp1, dmq1, iqmp) == 0) {
   7.989 ++ null:
   7.990 ++			fatal("Failed to set RSA parameters");
   7.991 ++			BN_free(d); BN_free(n); BN_free(iqmp);
   7.992 ++			BN_free(q); BN_free(p);
   7.993 ++			BN_free(dmp1); BN_free(dmq1);
   7.994 ++			return NULL;
   7.995 ++		}
   7.996 ++		dmp1 = dmq1 = iqmp = NULL;
   7.997 ++		}
   7.998 + 		if ((r = ssh_rsa_generate_additional_parameters(key)) != 0)
   7.999 + 			fatal("generate RSA parameters failed: %s", ssh_err(r));
  7.1000 + 		break;
  7.1001 +@@ -636,7 +694,7 @@
  7.1002 + 		    identity_file);
  7.1003 + 	}
  7.1004 + 	fclose(fp);
  7.1005 +-	switch (EVP_PKEY_type(pubkey->type)) {
  7.1006 ++	switch (EVP_PKEY_type(EVP_PKEY_id(pubkey))) {
  7.1007 + 	case EVP_PKEY_RSA:
  7.1008 + 		if ((*k = sshkey_new(KEY_UNSPEC)) == NULL)
  7.1009 + 			fatal("sshkey_new failed");
  7.1010 +@@ -660,7 +718,7 @@
  7.1011 + #endif
  7.1012 + 	default:
  7.1013 + 		fatal("%s: unsupported pubkey type %d", __func__,
  7.1014 +-		    EVP_PKEY_type(pubkey->type));
  7.1015 ++		    EVP_PKEY_type(EVP_PKEY_id(pubkey)));
  7.1016 + 	}
  7.1017 + 	EVP_PKEY_free(pubkey);
  7.1018 + 	return;
  7.1019 +diff -Naur old/ssh-pkcs11-client.c new/ssh-pkcs11-client.c
  7.1020 +--- old/ssh-pkcs11-client.c	2017-10-03 21:49:05.403827361 -1000
  7.1021 ++++ new/ssh-pkcs11-client.c	2017-10-03 21:55:50.869718862 -1000
  7.1022 +@@ -143,12 +143,13 @@
  7.1023 + static int
  7.1024 + wrap_key(RSA *rsa)
  7.1025 + {
  7.1026 +-	static RSA_METHOD helper_rsa;
  7.1027 ++	static RSA_METHOD *helper_rsa;
  7.1028 + 
  7.1029 +-	memcpy(&helper_rsa, RSA_get_default_method(), sizeof(helper_rsa));
  7.1030 +-	helper_rsa.name = "ssh-pkcs11-helper";
  7.1031 +-	helper_rsa.rsa_priv_enc = pkcs11_rsa_private_encrypt;
  7.1032 +-	RSA_set_method(rsa, &helper_rsa);
  7.1033 ++	if ((helper_rsa = RSA_meth_dup(RSA_get_default_method())) == NULL)
  7.1034 ++		return (-1); /* XXX but caller isn't checking */
  7.1035 ++	RSA_meth_set1_name(helper_rsa, "ssh-pkcs11-helper");
  7.1036 ++	RSA_meth_set_priv_enc(helper_rsa, pkcs11_rsa_private_encrypt);
  7.1037 ++	RSA_set_method(rsa, helper_rsa);
  7.1038 + 	return (0);
  7.1039 + }
  7.1040 + 
  7.1041 +diff -Naur old/ssh-pkcs11.c new/ssh-pkcs11.c
  7.1042 +--- old/ssh-pkcs11.c	2017-10-03 21:49:05.403827361 -1000
  7.1043 ++++ new/ssh-pkcs11.c	2017-10-03 21:55:50.869718862 -1000
  7.1044 +@@ -67,7 +67,7 @@
  7.1045 + 	struct pkcs11_provider	*provider;
  7.1046 + 	CK_ULONG		slotidx;
  7.1047 + 	int			(*orig_finish)(RSA *rsa);
  7.1048 +-	RSA_METHOD		rsa_method;
  7.1049 ++	RSA_METHOD		*rsa_method;
  7.1050 + 	char			*keyid;
  7.1051 + 	int			keyid_len;
  7.1052 + };
  7.1053 +@@ -326,13 +326,15 @@
  7.1054 + 		k11->keyid = xmalloc(k11->keyid_len);
  7.1055 + 		memcpy(k11->keyid, keyid_attrib->pValue, k11->keyid_len);
  7.1056 + 	}
  7.1057 +-	k11->orig_finish = def->finish;
  7.1058 +-	memcpy(&k11->rsa_method, def, sizeof(k11->rsa_method));
  7.1059 +-	k11->rsa_method.name = "pkcs11";
  7.1060 +-	k11->rsa_method.rsa_priv_enc = pkcs11_rsa_private_encrypt;
  7.1061 +-	k11->rsa_method.rsa_priv_dec = pkcs11_rsa_private_decrypt;
  7.1062 +-	k11->rsa_method.finish = pkcs11_rsa_finish;
  7.1063 +-	RSA_set_method(rsa, &k11->rsa_method);
  7.1064 ++	k11->orig_finish = RSA_meth_get_finish(def);
  7.1065 ++
  7.1066 ++	if ((k11->rsa_method = RSA_meth_new("pkcs11", RSA_meth_get_flags(def))) == NULL)
  7.1067 ++		return -1;
  7.1068 ++	RSA_meth_set_priv_enc(k11->rsa_method, pkcs11_rsa_private_encrypt);
  7.1069 ++	RSA_meth_set_priv_dec(k11->rsa_method, pkcs11_rsa_private_decrypt);
  7.1070 ++	RSA_meth_set_finish(k11->rsa_method, pkcs11_rsa_finish);
  7.1071 ++
  7.1072 ++	RSA_set_method(rsa, k11->rsa_method);
  7.1073 + 	RSA_set_app_data(rsa, k11);
  7.1074 + 	return (0);
  7.1075 + }
  7.1076 +@@ -512,10 +514,19 @@
  7.1077 + 			if ((rsa = RSA_new()) == NULL) {
  7.1078 + 				error("RSA_new failed");
  7.1079 + 			} else {
  7.1080 +-				rsa->n = BN_bin2bn(attribs[1].pValue,
  7.1081 +-				    attribs[1].ulValueLen, NULL);
  7.1082 +-				rsa->e = BN_bin2bn(attribs[2].pValue,
  7.1083 +-				    attribs[2].ulValueLen, NULL);
  7.1084 ++				BIGNUM *n=NULL, *e=NULL;
  7.1085 ++				n = BN_new();
  7.1086 ++				e = BN_new();
  7.1087 ++				if (n == NULL || e == NULL)
  7.1088 ++					error("BN_new alloc failed");
  7.1089 ++				if (BN_bin2bn(attribs[1].pValue,
  7.1090 ++				      attribs[1].ulValueLen, n) == NULL ||
  7.1091 ++				    BN_bin2bn(attribs[2].pValue,
  7.1092 ++				      attribs[2].ulValueLen, e) == NULL)
  7.1093 ++					error("BN_bin2bn failed");
  7.1094 ++				if (RSA_set0_key(rsa, n, e, NULL) == 0)
  7.1095 ++					error("RSA_set0_key failed");
  7.1096 ++				n = e = NULL;
  7.1097 + 			}
  7.1098 + 		} else {
  7.1099 + 			cp = attribs[2].pValue;
  7.1100 +@@ -525,17 +536,20 @@
  7.1101 + 			    == NULL) {
  7.1102 + 				error("d2i_X509 failed");
  7.1103 + 			} else if ((evp = X509_get_pubkey(x509)) == NULL ||
  7.1104 +-			    evp->type != EVP_PKEY_RSA ||
  7.1105 +-			    evp->pkey.rsa == NULL) {
  7.1106 ++			    EVP_PKEY_id(evp) != EVP_PKEY_RSA ||
  7.1107 ++			    EVP_PKEY_get0_RSA(evp) == NULL) {
  7.1108 + 				debug("X509_get_pubkey failed or no rsa");
  7.1109 +-			} else if ((rsa = RSAPublicKey_dup(evp->pkey.rsa))
  7.1110 ++			} else if ((rsa = RSAPublicKey_dup(EVP_PKEY_get0_RSA(evp)))
  7.1111 + 			    == NULL) {
  7.1112 + 				error("RSAPublicKey_dup");
  7.1113 + 			}
  7.1114 + 			if (x509)
  7.1115 + 				X509_free(x509);
  7.1116 + 		}
  7.1117 +-		if (rsa && rsa->n && rsa->e &&
  7.1118 ++		{
  7.1119 ++		const BIGNUM *n, *e;
  7.1120 ++		RSA_get0_key(rsa, &n, &e, NULL);
  7.1121 ++		if (rsa && n && e &&
  7.1122 + 		    pkcs11_rsa_wrap(p, slotidx, &attribs[0], rsa) == 0) {
  7.1123 + 			if ((key = sshkey_new(KEY_UNSPEC)) == NULL)
  7.1124 + 				fatal("sshkey_new failed");
  7.1125 +@@ -555,6 +569,7 @@
  7.1126 + 		} else if (rsa) {
  7.1127 + 			RSA_free(rsa);
  7.1128 + 		}
  7.1129 ++		}
  7.1130 + 		for (i = 0; i < 3; i++)
  7.1131 + 			free(attribs[i].pValue);
  7.1132 + 	}
  7.1133 +diff -Naur old/ssh-rsa.c new/ssh-rsa.c
  7.1134 +--- old/ssh-rsa.c	2017-10-03 21:49:05.403827361 -1000
  7.1135 ++++ new/ssh-rsa.c	2017-10-03 22:06:32.005937158 -1000
  7.1136 +@@ -99,13 +99,27 @@
  7.1137 + 	}
  7.1138 + 	rsa = key->rsa;
  7.1139 + 
  7.1140 +-	if ((BN_sub(aux, rsa->q, BN_value_one()) == 0) ||
  7.1141 +-	    (BN_mod(rsa->dmq1, rsa->d, aux, ctx) == 0) ||
  7.1142 +-	    (BN_sub(aux, rsa->p, BN_value_one()) == 0) ||
  7.1143 +-	    (BN_mod(rsa->dmp1, rsa->d, aux, ctx) == 0)) {
  7.1144 ++	{
  7.1145 ++	const BIGNUM *q, *d, *p;
  7.1146 ++	BIGNUM *dmq1=NULL, *dmp1=NULL;
  7.1147 ++	if ((dmq1 = BN_new()) == NULL ||
  7.1148 ++	    (dmp1 = BN_new()) == NULL ) {
  7.1149 ++		r = SSH_ERR_ALLOC_FAIL;
  7.1150 ++		goto out;
  7.1151 ++	}
  7.1152 ++	RSA_get0_key(rsa, NULL, NULL, &d);
  7.1153 ++	RSA_get0_factors(rsa, &p, &q);
  7.1154 ++	if ((BN_sub(aux, q, BN_value_one()) == 0) ||
  7.1155 ++	    (BN_mod(dmq1, d, aux, ctx) == 0) ||
  7.1156 ++	    (BN_sub(aux, p, BN_value_one()) == 0) ||
  7.1157 ++	    (BN_mod(dmp1, d, aux, ctx) == 0) ||
  7.1158 ++	     RSA_set0_crt_params(rsa, dmp1, dmq1, NULL) == 0) {
  7.1159 + 		r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1160 ++		BN_clear_free(dmp1);
  7.1161 ++		BN_clear_free(dmq1);
  7.1162 + 		goto out;
  7.1163 + 	}
  7.1164 ++	}
  7.1165 + 	r = 0;
  7.1166 +  out:
  7.1167 + 	BN_clear_free(aux);
  7.1168 +@@ -136,7 +150,7 @@
  7.1169 + 	if (key == NULL || key->rsa == NULL || hash_alg == -1 ||
  7.1170 + 	    sshkey_type_plain(key->type) != KEY_RSA)
  7.1171 + 		return SSH_ERR_INVALID_ARGUMENT;
  7.1172 +-	if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE)
  7.1173 ++	if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE)
  7.1174 + 		return SSH_ERR_KEY_LENGTH;
  7.1175 + 	slen = RSA_size(key->rsa);
  7.1176 + 	if (slen <= 0 || slen > SSHBUF_MAX_BIGNUM)
  7.1177 +@@ -210,7 +224,7 @@
  7.1178 + 	    sshkey_type_plain(key->type) != KEY_RSA ||
  7.1179 + 	    sig == NULL || siglen == 0)
  7.1180 + 		return SSH_ERR_INVALID_ARGUMENT;
  7.1181 +-	if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE)
  7.1182 ++	if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE)
  7.1183 + 		return SSH_ERR_KEY_LENGTH;
  7.1184 + 
  7.1185 + 	if ((b = sshbuf_from(sig, siglen)) == NULL)
  7.1186 +diff -Naur old/sshkey.c new/sshkey.c
  7.1187 +--- old/sshkey.c	2017-10-03 21:49:05.407160494 -1000
  7.1188 ++++ new/sshkey.c	2017-10-03 22:16:31.124964276 -1000
  7.1189 +@@ -264,10 +264,18 @@
  7.1190 + #ifdef WITH_OPENSSL
  7.1191 + 	case KEY_RSA:
  7.1192 + 	case KEY_RSA_CERT:
  7.1193 +-		return BN_num_bits(k->rsa->n);
  7.1194 ++#if OPENSSL_VERSION_NUMBER >= 0x10100000UL
  7.1195 ++		return RSA_bits(k->rsa);
  7.1196 ++#else
  7.1197 ++		return RSA_bits(key->rsa);
  7.1198 ++#endif
  7.1199 + 	case KEY_DSA:
  7.1200 + 	case KEY_DSA_CERT:
  7.1201 ++#if OPENSSL_VERSION_NUMBER >= 0x10100000UL
  7.1202 ++		return DSA_bits(k->dsa);
  7.1203 ++#else
  7.1204 + 		return BN_num_bits(k->dsa->p);
  7.1205 ++#endif
  7.1206 + 	case KEY_ECDSA:
  7.1207 + 	case KEY_ECDSA_CERT:
  7.1208 + 		return sshkey_curve_nid_to_bits(k->ecdsa_nid);
  7.1209 +@@ -466,28 +474,55 @@
  7.1210 + #ifdef WITH_OPENSSL
  7.1211 + 	case KEY_RSA:
  7.1212 + 	case KEY_RSA_CERT:
  7.1213 ++		{
  7.1214 ++		BIGNUM *n=NULL, *e=NULL; /* just allocate */
  7.1215 + 		if ((rsa = RSA_new()) == NULL ||
  7.1216 +-		    (rsa->n = BN_new()) == NULL ||
  7.1217 +-		    (rsa->e = BN_new()) == NULL) {
  7.1218 ++		    (n = BN_new()) == NULL ||
  7.1219 ++		    (e = BN_new()) == NULL) {
  7.1220 ++			BN_free(n);
  7.1221 ++			BN_free(e);
  7.1222 + 			if (rsa != NULL)
  7.1223 + 				RSA_free(rsa);
  7.1224 + 			free(k);
  7.1225 + 			return NULL;
  7.1226 + 		}
  7.1227 ++		BN_clear(n); BN_clear(e);
  7.1228 ++		if (RSA_set0_key(rsa, n, e, NULL) == 0)
  7.1229 ++			return NULL;
  7.1230 ++		n = e = NULL;
  7.1231 ++		}
  7.1232 + 		k->rsa = rsa;
  7.1233 + 		break;
  7.1234 + 	case KEY_DSA:
  7.1235 + 	case KEY_DSA_CERT:
  7.1236 ++		{
  7.1237 ++		BIGNUM *p=NULL, *q=NULL, *g=NULL, *pubkey=NULL; /* just allocate */
  7.1238 + 		if ((dsa = DSA_new()) == NULL ||
  7.1239 +-		    (dsa->p = BN_new()) == NULL ||
  7.1240 +-		    (dsa->q = BN_new()) == NULL ||
  7.1241 +-		    (dsa->g = BN_new()) == NULL ||
  7.1242 +-		    (dsa->pub_key = BN_new()) == NULL) {
  7.1243 ++		    (p = BN_new()) == NULL ||
  7.1244 ++		    (q = BN_new()) == NULL ||
  7.1245 ++		    (g = BN_new()) == NULL ||
  7.1246 ++		    (pubkey = BN_new()) == NULL) {
  7.1247 ++			BN_free(p);
  7.1248 ++			BN_free(q);
  7.1249 ++			BN_free(g);
  7.1250 ++			BN_free(pubkey);
  7.1251 + 			if (dsa != NULL)
  7.1252 + 				DSA_free(dsa);
  7.1253 + 			free(k);
  7.1254 + 			return NULL;
  7.1255 + 		}
  7.1256 ++		if (DSA_set0_pqg(dsa, p, q, g) == 0) {
  7.1257 ++			BN_free(p); BN_free(q); BN_free(g);
  7.1258 ++			BN_free(pubkey);
  7.1259 ++			return NULL;
  7.1260 ++		}
  7.1261 ++		p = q = g = NULL;
  7.1262 ++		if (DSA_set0_key(dsa, pubkey, NULL) == 0) {
  7.1263 ++			BN_free(pubkey);
  7.1264 ++			return NULL;
  7.1265 ++		}
  7.1266 ++		pubkey = NULL;
  7.1267 ++		}
  7.1268 + 		k->dsa = dsa;
  7.1269 + 		break;
  7.1270 + 	case KEY_ECDSA:
  7.1271 +@@ -523,6 +558,51 @@
  7.1272 + #ifdef WITH_OPENSSL
  7.1273 + 	case KEY_RSA:
  7.1274 + 	case KEY_RSA_CERT:
  7.1275 ++#if OPENSSL_VERSION_NUMBER >= 0x10100000UL
  7.1276 ++		/* Allocate BIGNUM. This is a mess.
  7.1277 ++		   For OpenSSL 1.1.x API these shouldn't be mandatory,
  7.1278 ++		   but some regression tests for non-NULL pointer of
  7.1279 ++		   the data. */
  7.1280 ++#define new_or_dup(bn, nbn) \
  7.1281 ++		if (bn == NULL) { \
  7.1282 ++			if ((nbn = BN_new()) == NULL) \
  7.1283 ++				return SSH_ERR_ALLOC_FAIL; \
  7.1284 ++		} else { \
  7.1285 ++			/* otherwise use-after-free will occur */ \
  7.1286 ++			if ((nbn = BN_dup(bn)) == NULL) \
  7.1287 ++				return SSH_ERR_ALLOC_FAIL; \
  7.1288 ++		}
  7.1289 ++		{
  7.1290 ++		const BIGNUM *d, *iqmp, *q, *p, *dmq1, *dmp1; /* allocate if NULL */
  7.1291 ++		BIGNUM *nd, *niqmp, *nq, *np, *ndmq1, *ndmp1;
  7.1292 ++
  7.1293 ++		RSA_get0_key(k->rsa, NULL, NULL, &d);
  7.1294 ++		RSA_get0_factors(k->rsa, &p, &q);
  7.1295 ++		RSA_get0_crt_params(k->rsa, &dmp1, &dmq1, &iqmp);
  7.1296 ++
  7.1297 ++		new_or_dup(d, nd);
  7.1298 ++		new_or_dup(iqmp, niqmp);
  7.1299 ++		new_or_dup(q, nq);
  7.1300 ++		new_or_dup(p, np);
  7.1301 ++		new_or_dup(dmq1, ndmq1);
  7.1302 ++		new_or_dup(dmp1, ndmp1);
  7.1303 ++
  7.1304 ++		if (RSA_set0_key(k->rsa, NULL, NULL, nd) == 0)
  7.1305 ++			goto error1;
  7.1306 ++		nd = NULL;
  7.1307 ++		if (RSA_set0_factors(k->rsa, np, nq) == 0)
  7.1308 ++			goto error1;
  7.1309 ++		np = nq = NULL;
  7.1310 ++		if (RSA_set0_crt_params(k->rsa, ndmp1, ndmq1, niqmp) == 0) {
  7.1311 ++error1:
  7.1312 ++			BN_free(nd);
  7.1313 ++			BN_free(np); BN_free(nq);
  7.1314 ++			BN_free(ndmp1); BN_free(ndmq1); BN_free(niqmp);
  7.1315 ++			return SSH_ERR_LIBCRYPTO_ERROR;
  7.1316 ++		}
  7.1317 ++		ndmp1 = ndmq1 = niqmp = NULL;
  7.1318 ++		}
  7.1319 ++#else
  7.1320 + #define bn_maybe_alloc_failed(p) (p == NULL && (p = BN_new()) == NULL)
  7.1321 + 		if (bn_maybe_alloc_failed(k->rsa->d) ||
  7.1322 + 		    bn_maybe_alloc_failed(k->rsa->iqmp) ||
  7.1323 +@@ -531,13 +611,28 @@
  7.1324 + 		    bn_maybe_alloc_failed(k->rsa->dmq1) ||
  7.1325 + 		    bn_maybe_alloc_failed(k->rsa->dmp1))
  7.1326 + 			return SSH_ERR_ALLOC_FAIL;
  7.1327 ++#endif
  7.1328 + 		break;
  7.1329 + 	case KEY_DSA:
  7.1330 + 	case KEY_DSA_CERT:
  7.1331 ++#if OPENSSL_VERSION_NUMBER >= 0x10100000UL
  7.1332 ++		{
  7.1333 ++		const BIGNUM *priv_key;
  7.1334 ++		BIGNUM *npriv_key;
  7.1335 ++		DSA_get0_key(k->dsa, NULL, &priv_key);
  7.1336 ++		new_or_dup(priv_key, npriv_key);
  7.1337 ++		if (DSA_set0_key(k->dsa, NULL, npriv_key) == 0) {
  7.1338 ++			BN_free(npriv_key);
  7.1339 ++			return SSH_ERR_LIBCRYPTO_ERROR;
  7.1340 ++		}
  7.1341 ++		}
  7.1342 ++#else
  7.1343 + 		if (bn_maybe_alloc_failed(k->dsa->priv_key))
  7.1344 + 			return SSH_ERR_ALLOC_FAIL;
  7.1345 ++#endif
  7.1346 + 		break;
  7.1347 + #undef bn_maybe_alloc_failed
  7.1348 ++#undef new_or_dup
  7.1349 + 	case KEY_ECDSA:
  7.1350 + 	case KEY_ECDSA_CERT:
  7.1351 + 		/* Cannot do anything until we know the group */
  7.1352 +@@ -655,16 +750,34 @@
  7.1353 + #ifdef WITH_OPENSSL
  7.1354 + 	case KEY_RSA_CERT:
  7.1355 + 	case KEY_RSA:
  7.1356 +-		return a->rsa != NULL && b->rsa != NULL &&
  7.1357 +-		    BN_cmp(a->rsa->e, b->rsa->e) == 0 &&
  7.1358 +-		    BN_cmp(a->rsa->n, b->rsa->n) == 0;
  7.1359 ++		{
  7.1360 ++		const BIGNUM *a_e, *b_e, *a_n, *b_n;
  7.1361 ++		const BIGNUM *a_d, *b_d;
  7.1362 ++		if (a->rsa == NULL) return 0;
  7.1363 ++		if (b->rsa == NULL) return 0;
  7.1364 ++		RSA_get0_key(a->rsa, &a_n, &a_e, &a_d);
  7.1365 ++		RSA_get0_key(b->rsa, &b_n, &b_e, &b_d);
  7.1366 ++		return 
  7.1367 ++		    BN_cmp(a_e, b_e) == 0 &&
  7.1368 ++		    BN_cmp(a_n, b_n) == 0;
  7.1369 ++		}
  7.1370 + 	case KEY_DSA_CERT:
  7.1371 + 	case KEY_DSA:
  7.1372 +-		return a->dsa != NULL && b->dsa != NULL &&
  7.1373 +-		    BN_cmp(a->dsa->p, b->dsa->p) == 0 &&
  7.1374 +-		    BN_cmp(a->dsa->q, b->dsa->q) == 0 &&
  7.1375 +-		    BN_cmp(a->dsa->g, b->dsa->g) == 0 &&
  7.1376 +-		    BN_cmp(a->dsa->pub_key, b->dsa->pub_key) == 0;
  7.1377 ++		{
  7.1378 ++		const BIGNUM *a_p, *a_q, *a_g, *a_pub_key;
  7.1379 ++		const BIGNUM *b_p, *b_q, *b_g, *b_pub_key;
  7.1380 ++		if (a->dsa == NULL) return 0;
  7.1381 ++		if (b->dsa == NULL) return 0;
  7.1382 ++		DSA_get0_pqg(a->dsa, &a_p, &a_q, &a_g);
  7.1383 ++		DSA_get0_pqg(b->dsa, &b_p, &b_q, &b_g);
  7.1384 ++		DSA_get0_key(a->dsa, &a_pub_key, NULL);
  7.1385 ++		DSA_get0_key(b->dsa, &b_pub_key, NULL);
  7.1386 ++		return 
  7.1387 ++		    BN_cmp(a_p, b_p) == 0 &&
  7.1388 ++		    BN_cmp(a_q, b_q) == 0 &&
  7.1389 ++		    BN_cmp(a_g, b_g) == 0 &&
  7.1390 ++		    BN_cmp(a_pub_key, b_pub_key) == 0;
  7.1391 ++		}
  7.1392 + # ifdef OPENSSL_HAS_ECC
  7.1393 + 	case KEY_ECDSA_CERT:
  7.1394 + 	case KEY_ECDSA:
  7.1395 +@@ -742,12 +855,17 @@
  7.1396 + 	case KEY_DSA:
  7.1397 + 		if (key->dsa == NULL)
  7.1398 + 			return SSH_ERR_INVALID_ARGUMENT;
  7.1399 ++		{
  7.1400 ++		const BIGNUM *p, *q, *g, *pub_key;
  7.1401 ++		DSA_get0_pqg(key->dsa, &p, &q, &g);
  7.1402 ++		DSA_get0_key(key->dsa, &pub_key, NULL);
  7.1403 + 		if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
  7.1404 +-		    (ret = sshbuf_put_bignum2(b, key->dsa->p)) != 0 ||
  7.1405 +-		    (ret = sshbuf_put_bignum2(b, key->dsa->q)) != 0 ||
  7.1406 +-		    (ret = sshbuf_put_bignum2(b, key->dsa->g)) != 0 ||
  7.1407 +-		    (ret = sshbuf_put_bignum2(b, key->dsa->pub_key)) != 0)
  7.1408 ++		    (ret = sshbuf_put_bignum2(b, p)) != 0 ||
  7.1409 ++		    (ret = sshbuf_put_bignum2(b, q)) != 0 ||
  7.1410 ++		    (ret = sshbuf_put_bignum2(b, g)) != 0 ||
  7.1411 ++		    (ret = sshbuf_put_bignum2(b, pub_key)) != 0)
  7.1412 + 			return ret;
  7.1413 ++		}
  7.1414 + 		break;
  7.1415 + # ifdef OPENSSL_HAS_ECC
  7.1416 + 	case KEY_ECDSA:
  7.1417 +@@ -763,10 +881,14 @@
  7.1418 + 	case KEY_RSA:
  7.1419 + 		if (key->rsa == NULL)
  7.1420 + 			return SSH_ERR_INVALID_ARGUMENT;
  7.1421 ++		{
  7.1422 ++		const BIGNUM *e, *n;
  7.1423 ++		RSA_get0_key(key->rsa, &n, &e, NULL);
  7.1424 + 		if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
  7.1425 +-		    (ret = sshbuf_put_bignum2(b, key->rsa->e)) != 0 ||
  7.1426 +-		    (ret = sshbuf_put_bignum2(b, key->rsa->n)) != 0)
  7.1427 ++		    (ret = sshbuf_put_bignum2(b, e)) != 0 ||
  7.1428 ++		    (ret = sshbuf_put_bignum2(b, n)) != 0)
  7.1429 + 			return ret;
  7.1430 ++		}
  7.1431 + 		break;
  7.1432 + #endif /* WITH_OPENSSL */
  7.1433 + 	case KEY_ED25519:
  7.1434 +@@ -1643,13 +1765,32 @@
  7.1435 + 	case KEY_DSA_CERT:
  7.1436 + 		if ((n = sshkey_new(k->type)) == NULL)
  7.1437 + 			return SSH_ERR_ALLOC_FAIL;
  7.1438 +-		if ((BN_copy(n->dsa->p, k->dsa->p) == NULL) ||
  7.1439 +-		    (BN_copy(n->dsa->q, k->dsa->q) == NULL) ||
  7.1440 +-		    (BN_copy(n->dsa->g, k->dsa->g) == NULL) ||
  7.1441 +-		    (BN_copy(n->dsa->pub_key, k->dsa->pub_key) == NULL)) {
  7.1442 ++		{
  7.1443 ++		const BIGNUM *p, *q, *g, *pub_key, *priv_key;
  7.1444 ++		BIGNUM *cp=NULL, *cq=NULL, *cg=NULL, *cpub_key=NULL;
  7.1445 ++		DSA_get0_pqg(k->dsa, &p, &q, &g);
  7.1446 ++		DSA_get0_key(k->dsa, &pub_key, &priv_key);
  7.1447 ++		if ((cp = BN_dup(p)) == NULL ||
  7.1448 ++		    (cq = BN_dup(q)) == NULL ||
  7.1449 ++		    (cg = BN_dup(g)) == NULL ||
  7.1450 ++		    (cpub_key = BN_dup(pub_key)) == NULL) {
  7.1451 ++			BN_free(cp); BN_free(cq); BN_free(cg);
  7.1452 ++			BN_free(cpub_key);
  7.1453 + 			sshkey_free(n);
  7.1454 + 			return SSH_ERR_ALLOC_FAIL;
  7.1455 + 		}
  7.1456 ++		if (DSA_set0_pqg(n->dsa, cp, cq, cg) == 0)
  7.1457 ++			goto error1;
  7.1458 ++		cp = cq = cg = NULL;
  7.1459 ++		if (DSA_set0_key(n->dsa, cpub_key, NULL) == 0) {
  7.1460 ++error1:
  7.1461 ++			BN_free(cp); BN_free(cq); BN_free(cg);
  7.1462 ++			BN_free(cpub_key);
  7.1463 ++			sshkey_free(n);
  7.1464 ++			return SSH_ERR_LIBCRYPTO_ERROR;
  7.1465 ++		}
  7.1466 ++		cpub_key = NULL;
  7.1467 ++		}
  7.1468 + 		break;
  7.1469 + # ifdef OPENSSL_HAS_ECC
  7.1470 + 	case KEY_ECDSA:
  7.1471 +@@ -1673,11 +1814,23 @@
  7.1472 + 	case KEY_RSA_CERT:
  7.1473 + 		if ((n = sshkey_new(k->type)) == NULL)
  7.1474 + 			return SSH_ERR_ALLOC_FAIL;
  7.1475 +-		if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
  7.1476 +-		    (BN_copy(n->rsa->e, k->rsa->e) == NULL)) {
  7.1477 ++		{
  7.1478 ++		const BIGNUM *nn, *e, *d;
  7.1479 ++		BIGNUM *cn=NULL, *ce=NULL;
  7.1480 ++		RSA_get0_key(k->rsa, &nn, &e, &d);
  7.1481 ++		if ((cn = BN_dup(nn)) == NULL ||
  7.1482 ++		    (ce = BN_dup(e)) == NULL ) {
  7.1483 ++			BN_free(cn); BN_free(ce);
  7.1484 + 			sshkey_free(n);
  7.1485 + 			return SSH_ERR_ALLOC_FAIL;
  7.1486 + 		}
  7.1487 ++		if (RSA_set0_key(n->rsa, cn, ce, NULL) == 0) {
  7.1488 ++			BN_free(cn); BN_free(ce);
  7.1489 ++			sshkey_free(n);
  7.1490 ++			return SSH_ERR_LIBCRYPTO_ERROR;
  7.1491 ++		}
  7.1492 ++		cn = ce = NULL;
  7.1493 ++		}
  7.1494 + 		break;
  7.1495 + #endif /* WITH_OPENSSL */
  7.1496 + 	case KEY_ED25519:
  7.1497 +@@ -1875,12 +2028,27 @@
  7.1498 + 			ret = SSH_ERR_ALLOC_FAIL;
  7.1499 + 			goto out;
  7.1500 + 		}
  7.1501 +-		if (sshbuf_get_bignum2(b, key->rsa->e) != 0 ||
  7.1502 +-		    sshbuf_get_bignum2(b, key->rsa->n) != 0) {
  7.1503 ++		{
  7.1504 ++		BIGNUM *e=NULL, *n=NULL;
  7.1505 ++		if ((e = BN_new()) == NULL ||
  7.1506 ++		    (n = BN_new()) == NULL ) {
  7.1507 ++			ret = SSH_ERR_ALLOC_FAIL;
  7.1508 ++			BN_free(e); BN_free(n);
  7.1509 ++			goto out;
  7.1510 ++		}
  7.1511 ++		if (sshbuf_get_bignum2(b, e) != 0 ||
  7.1512 ++		    sshbuf_get_bignum2(b, n) != 0) {
  7.1513 + 			ret = SSH_ERR_INVALID_FORMAT;
  7.1514 ++			BN_free(e); BN_free(n);
  7.1515 + 			goto out;
  7.1516 + 		}
  7.1517 +-		if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1518 ++		if (RSA_set0_key(key->rsa, n, e, NULL) == 0) {
  7.1519 ++			BN_free(e); BN_free(n);
  7.1520 ++			return SSH_ERR_LIBCRYPTO_ERROR;
  7.1521 ++		}
  7.1522 ++		n = e = NULL;
  7.1523 ++		}
  7.1524 ++		if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1525 + 			ret = SSH_ERR_KEY_LENGTH;
  7.1526 + 			goto out;
  7.1527 + 		}
  7.1528 +@@ -1900,13 +2068,36 @@
  7.1529 + 			ret = SSH_ERR_ALLOC_FAIL;
  7.1530 + 			goto out;
  7.1531 + 		}
  7.1532 +-		if (sshbuf_get_bignum2(b, key->dsa->p) != 0 ||
  7.1533 +-		    sshbuf_get_bignum2(b, key->dsa->q) != 0 ||
  7.1534 +-		    sshbuf_get_bignum2(b, key->dsa->g) != 0 ||
  7.1535 +-		    sshbuf_get_bignum2(b, key->dsa->pub_key) != 0) {
  7.1536 ++		{
  7.1537 ++		BIGNUM *p=NULL, *q=NULL, *g=NULL, *pub_key=NULL;
  7.1538 ++		if ((p = BN_new()) == NULL ||
  7.1539 ++		    (q = BN_new()) == NULL ||
  7.1540 ++		    (g = BN_new()) == NULL ||
  7.1541 ++		    (pub_key = BN_new()) == NULL) {
  7.1542 ++			ret = SSH_ERR_ALLOC_FAIL;
  7.1543 ++			goto error1;
  7.1544 ++		}
  7.1545 ++		if (sshbuf_get_bignum2(b, p) != 0 ||
  7.1546 ++		    sshbuf_get_bignum2(b, q) != 0 ||
  7.1547 ++		    sshbuf_get_bignum2(b, g) != 0 ||
  7.1548 ++		    sshbuf_get_bignum2(b, pub_key) != 0) {
  7.1549 + 			ret = SSH_ERR_INVALID_FORMAT;
  7.1550 ++			goto error1;
  7.1551 ++		}
  7.1552 ++		if (DSA_set0_pqg(key->dsa, p, q, g) == 0) {
  7.1553 ++			ret = SSH_ERR_LIBCRYPTO_ERROR;
  7.1554 ++			goto error1;
  7.1555 ++		}
  7.1556 ++		p = q = g = NULL;
  7.1557 ++		if (DSA_set0_key(key->dsa, pub_key, NULL) == 0) {
  7.1558 ++			ret = SSH_ERR_LIBCRYPTO_ERROR;
  7.1559 ++error1:
  7.1560 ++			BN_free(p); BN_free(q); BN_free(g);
  7.1561 ++			BN_free(pub_key);
  7.1562 + 			goto out;
  7.1563 + 		}
  7.1564 ++		pub_key = NULL;
  7.1565 ++		}
  7.1566 + #ifdef DEBUG_PK
  7.1567 + 		DSA_print_fp(stderr, key->dsa, 8);
  7.1568 + #endif
  7.1569 +@@ -2140,26 +2331,63 @@
  7.1570 + 			goto fail;
  7.1571 + 		/* FALLTHROUGH */
  7.1572 + 	case KEY_RSA:
  7.1573 +-		if ((pk->rsa = RSA_new()) == NULL ||
  7.1574 +-		    (pk->rsa->e = BN_dup(k->rsa->e)) == NULL ||
  7.1575 +-		    (pk->rsa->n = BN_dup(k->rsa->n)) == NULL) {
  7.1576 ++		if ((pk->rsa = RSA_new()) == NULL ){
  7.1577 + 			ret = SSH_ERR_ALLOC_FAIL;
  7.1578 + 			goto fail;
  7.1579 + 			}
  7.1580 ++		{
  7.1581 ++		const BIGNUM *ke, *kn;
  7.1582 ++		BIGNUM *pke=NULL, *pkn=NULL;
  7.1583 ++		RSA_get0_key(k->rsa, &kn, &ke, NULL);
  7.1584 ++		 if ((pke = BN_dup(ke)) == NULL ||
  7.1585 ++		     (pkn = BN_dup(kn)) == NULL) {
  7.1586 ++			ret = SSH_ERR_ALLOC_FAIL;
  7.1587 ++			BN_free(pke); BN_free(pkn);
  7.1588 ++			goto fail;
  7.1589 ++			}
  7.1590 ++		if (RSA_set0_key(pk->rsa, pkn, pke, NULL) == 0) {
  7.1591 ++			ret = SSH_ERR_LIBCRYPTO_ERROR;
  7.1592 ++			BN_free(pke); BN_free(pkn);
  7.1593 ++			goto fail;
  7.1594 ++		}
  7.1595 ++		pkn = pke = NULL;
  7.1596 ++		}
  7.1597 + 		break;
  7.1598 + 	case KEY_DSA_CERT:
  7.1599 + 		if ((ret = sshkey_cert_copy(k, pk)) != 0)
  7.1600 + 			goto fail;
  7.1601 + 		/* FALLTHROUGH */
  7.1602 + 	case KEY_DSA:
  7.1603 +-		if ((pk->dsa = DSA_new()) == NULL ||
  7.1604 +-		    (pk->dsa->p = BN_dup(k->dsa->p)) == NULL ||
  7.1605 +-		    (pk->dsa->q = BN_dup(k->dsa->q)) == NULL ||
  7.1606 +-		    (pk->dsa->g = BN_dup(k->dsa->g)) == NULL ||
  7.1607 +-		    (pk->dsa->pub_key = BN_dup(k->dsa->pub_key)) == NULL) {
  7.1608 ++		if ((pk->dsa = DSA_new()) == NULL ) {
  7.1609 + 			ret = SSH_ERR_ALLOC_FAIL;
  7.1610 + 			goto fail;
  7.1611 + 		}
  7.1612 ++		{
  7.1613 ++		const BIGNUM *kp, *kq, *kg, *kpub_key;
  7.1614 ++		BIGNUM *pkp=NULL, *pkq=NULL, *pkg=NULL, *pkpub_key=NULL;
  7.1615 ++		DSA_get0_pqg(k->dsa, &kp, &kq, &kg);
  7.1616 ++		DSA_get0_key(k->dsa, &kpub_key, NULL);
  7.1617 ++		if ((pkp = BN_dup(kp)) == NULL ||
  7.1618 ++		    (pkq = BN_dup(kq)) == NULL ||
  7.1619 ++		    (pkg = BN_dup(kg)) == NULL ||
  7.1620 ++		    (pkpub_key = BN_dup(kpub_key)) == NULL) {
  7.1621 ++			ret = SSH_ERR_ALLOC_FAIL;
  7.1622 ++			goto error1;
  7.1623 ++		}
  7.1624 ++		if (DSA_set0_pqg(pk->dsa, pkp, pkq, pkg) == 0) {
  7.1625 ++			ret = SSH_ERR_LIBCRYPTO_ERROR;
  7.1626 ++			goto error1;
  7.1627 ++		}
  7.1628 ++		pkp = pkq = pkg = NULL;
  7.1629 ++		if (DSA_set0_key(pk->dsa, pkpub_key, NULL) == 0) {
  7.1630 ++			ret = SSH_ERR_LIBCRYPTO_ERROR;
  7.1631 ++error1:
  7.1632 ++			BN_free(pkp); BN_free(pkq); BN_free(pkg);
  7.1633 ++			BN_free(pkpub_key);
  7.1634 ++			goto fail;
  7.1635 ++		}
  7.1636 ++		pkpub_key = NULL;
  7.1637 ++		}
  7.1638 + 		break;
  7.1639 + 	case KEY_ECDSA_CERT:
  7.1640 + 		if ((ret = sshkey_cert_copy(k, pk)) != 0)
  7.1641 +@@ -2281,11 +2509,17 @@
  7.1642 + 	switch (k->type) {
  7.1643 + #ifdef WITH_OPENSSL
  7.1644 + 	case KEY_DSA_CERT:
  7.1645 +-		if ((ret = sshbuf_put_bignum2(cert, k->dsa->p)) != 0 ||
  7.1646 +-		    (ret = sshbuf_put_bignum2(cert, k->dsa->q)) != 0 ||
  7.1647 +-		    (ret = sshbuf_put_bignum2(cert, k->dsa->g)) != 0 ||
  7.1648 +-		    (ret = sshbuf_put_bignum2(cert, k->dsa->pub_key)) != 0)
  7.1649 ++		{
  7.1650 ++		const BIGNUM *p, *q, *g, *pub_key;
  7.1651 ++		DSA_get0_pqg(k->dsa, &p, &q, &g);
  7.1652 ++		DSA_get0_key(k->dsa, &pub_key, NULL);
  7.1653 ++		if ((ret = sshbuf_put_bignum2(cert, p)) != 0 ||
  7.1654 ++		    (ret = sshbuf_put_bignum2(cert, q)) != 0 ||
  7.1655 ++		    (ret = sshbuf_put_bignum2(cert, g)) != 0 ||
  7.1656 ++		    (ret = sshbuf_put_bignum2(cert, pub_key)) != 0) {
  7.1657 + 			goto out;
  7.1658 ++		}
  7.1659 ++		}
  7.1660 + 		break;
  7.1661 + # ifdef OPENSSL_HAS_ECC
  7.1662 + 	case KEY_ECDSA_CERT:
  7.1663 +@@ -2298,9 +2532,15 @@
  7.1664 + 		break;
  7.1665 + # endif /* OPENSSL_HAS_ECC */
  7.1666 + 	case KEY_RSA_CERT:
  7.1667 +-		if ((ret = sshbuf_put_bignum2(cert, k->rsa->e)) != 0 ||
  7.1668 +-		    (ret = sshbuf_put_bignum2(cert, k->rsa->n)) != 0)
  7.1669 ++		{
  7.1670 ++		const BIGNUM *e, *n;
  7.1671 ++		RSA_get0_key(k->rsa, &n, &e, NULL);
  7.1672 ++		if (n == NULL || e == NULL ||
  7.1673 ++		    (ret = sshbuf_put_bignum2(cert, e)) != 0 ||
  7.1674 ++		    (ret = sshbuf_put_bignum2(cert, n)) != 0) {
  7.1675 + 			goto out;
  7.1676 ++		}
  7.1677 ++		}
  7.1678 + 		break;
  7.1679 + #endif /* WITH_OPENSSL */
  7.1680 + 	case KEY_ED25519_CERT:
  7.1681 +@@ -2474,42 +2714,67 @@
  7.1682 + 	switch (key->type) {
  7.1683 + #ifdef WITH_OPENSSL
  7.1684 + 	case KEY_RSA:
  7.1685 +-		if ((r = sshbuf_put_bignum2(b, key->rsa->n)) != 0 ||
  7.1686 +-		    (r = sshbuf_put_bignum2(b, key->rsa->e)) != 0 ||
  7.1687 +-		    (r = sshbuf_put_bignum2(b, key->rsa->d)) != 0 ||
  7.1688 +-		    (r = sshbuf_put_bignum2(b, key->rsa->iqmp)) != 0 ||
  7.1689 +-		    (r = sshbuf_put_bignum2(b, key->rsa->p)) != 0 ||
  7.1690 +-		    (r = sshbuf_put_bignum2(b, key->rsa->q)) != 0)
  7.1691 ++		{
  7.1692 ++		const BIGNUM *n, *e, *d, *iqmp, *p, *q;
  7.1693 ++		RSA_get0_key(key->rsa, &n, &e, &d);
  7.1694 ++		RSA_get0_crt_params(key->rsa, NULL, NULL, &iqmp);
  7.1695 ++		RSA_get0_factors(key->rsa, &p, &q);
  7.1696 ++		if ((r = sshbuf_put_bignum2(b, n)) != 0 ||
  7.1697 ++		    (r = sshbuf_put_bignum2(b, e)) != 0 ||
  7.1698 ++		    (r = sshbuf_put_bignum2(b, d)) != 0 ||
  7.1699 ++		    (r = sshbuf_put_bignum2(b, iqmp)) != 0 ||
  7.1700 ++		    (r = sshbuf_put_bignum2(b, p)) != 0 ||
  7.1701 ++		    (r = sshbuf_put_bignum2(b, q)) != 0) {
  7.1702 + 			goto out;
  7.1703 ++		}
  7.1704 ++		}
  7.1705 + 		break;
  7.1706 + 	case KEY_RSA_CERT:
  7.1707 + 		if (key->cert == NULL || sshbuf_len(key->cert->certblob) == 0) {
  7.1708 + 			r = SSH_ERR_INVALID_ARGUMENT;
  7.1709 + 			goto out;
  7.1710 + 		}
  7.1711 ++		{
  7.1712 ++		const BIGNUM *d, *iqmp, *p, *q;
  7.1713 ++		RSA_get0_key(key->rsa, NULL, NULL, &d);
  7.1714 ++		RSA_get0_crt_params(key->rsa, NULL, NULL, &iqmp);
  7.1715 ++		RSA_get0_factors(key->rsa, &p, &q);
  7.1716 + 		if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
  7.1717 +-		    (r = sshbuf_put_bignum2(b, key->rsa->d)) != 0 ||
  7.1718 +-		    (r = sshbuf_put_bignum2(b, key->rsa->iqmp)) != 0 ||
  7.1719 +-		    (r = sshbuf_put_bignum2(b, key->rsa->p)) != 0 ||
  7.1720 +-		    (r = sshbuf_put_bignum2(b, key->rsa->q)) != 0)
  7.1721 ++		    (r = sshbuf_put_bignum2(b, d)) != 0 ||
  7.1722 ++		    (r = sshbuf_put_bignum2(b, iqmp)) != 0 ||
  7.1723 ++		    (r = sshbuf_put_bignum2(b, p)) != 0 ||
  7.1724 ++		    (r = sshbuf_put_bignum2(b, q)) != 0) {
  7.1725 + 			goto out;
  7.1726 ++		}
  7.1727 ++		}
  7.1728 + 		break;
  7.1729 + 	case KEY_DSA:
  7.1730 +-		if ((r = sshbuf_put_bignum2(b, key->dsa->p)) != 0 ||
  7.1731 +-		    (r = sshbuf_put_bignum2(b, key->dsa->q)) != 0 ||
  7.1732 +-		    (r = sshbuf_put_bignum2(b, key->dsa->g)) != 0 ||
  7.1733 +-		    (r = sshbuf_put_bignum2(b, key->dsa->pub_key)) != 0 ||
  7.1734 +-		    (r = sshbuf_put_bignum2(b, key->dsa->priv_key)) != 0)
  7.1735 ++		{
  7.1736 ++		const BIGNUM *p, *q, *g, *pub_key, *priv_key;
  7.1737 ++		DSA_get0_pqg(key->dsa, &p, &q, &g);
  7.1738 ++		DSA_get0_key(key->dsa, &pub_key, &priv_key);
  7.1739 ++		if ((r = sshbuf_put_bignum2(b, p)) != 0 ||
  7.1740 ++		    (r = sshbuf_put_bignum2(b, q)) != 0 ||
  7.1741 ++		    (r = sshbuf_put_bignum2(b, g)) != 0 ||
  7.1742 ++		    (r = sshbuf_put_bignum2(b, pub_key)) != 0 ||
  7.1743 ++		    (r = sshbuf_put_bignum2(b, priv_key)) != 0) {
  7.1744 + 			goto out;
  7.1745 ++		}
  7.1746 ++		}
  7.1747 + 		break;
  7.1748 + 	case KEY_DSA_CERT:
  7.1749 + 		if (key->cert == NULL || sshbuf_len(key->cert->certblob) == 0) {
  7.1750 + 			r = SSH_ERR_INVALID_ARGUMENT;
  7.1751 + 			goto out;
  7.1752 + 		}
  7.1753 ++		{
  7.1754 ++		const BIGNUM *priv_key;
  7.1755 ++		DSA_get0_key(key->dsa, NULL, &priv_key);
  7.1756 + 		if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
  7.1757 +-		    (r = sshbuf_put_bignum2(b, key->dsa->priv_key)) != 0)
  7.1758 ++		    (r = sshbuf_put_bignum2(b, priv_key)) != 0) {
  7.1759 + 			goto out;
  7.1760 ++		}
  7.1761 ++		}
  7.1762 + 		break;
  7.1763 + # ifdef OPENSSL_HAS_ECC
  7.1764 + 	case KEY_ECDSA:
  7.1765 +@@ -2585,18 +2850,61 @@
  7.1766 + 			r = SSH_ERR_ALLOC_FAIL;
  7.1767 + 			goto out;
  7.1768 + 		}
  7.1769 +-		if ((r = sshbuf_get_bignum2(buf, k->dsa->p)) != 0 ||
  7.1770 +-		    (r = sshbuf_get_bignum2(buf, k->dsa->q)) != 0 ||
  7.1771 +-		    (r = sshbuf_get_bignum2(buf, k->dsa->g)) != 0 ||
  7.1772 +-		    (r = sshbuf_get_bignum2(buf, k->dsa->pub_key)) != 0 ||
  7.1773 +-		    (r = sshbuf_get_bignum2(buf, k->dsa->priv_key)) != 0)
  7.1774 ++		{
  7.1775 ++		BIGNUM *p=NULL, *q=NULL, *g=NULL, *pub_key=NULL, *priv_key=NULL;
  7.1776 ++		if ((p = BN_new()) == NULL ||
  7.1777 ++		    (q = BN_new()) == NULL ||
  7.1778 ++		    (g = BN_new()) == NULL ||
  7.1779 ++		    (pub_key = BN_new()) == NULL ||
  7.1780 ++		    (priv_key = BN_new()) == NULL) {
  7.1781 ++			r = SSH_ERR_ALLOC_FAIL;
  7.1782 ++			goto error1;
  7.1783 ++		}
  7.1784 ++		if (p == NULL || q == NULL || g == NULL ||
  7.1785 ++		    pub_key == NULL || priv_key == NULL ||
  7.1786 ++		    (r = sshbuf_get_bignum2(buf, p)) != 0 ||
  7.1787 ++		    (r = sshbuf_get_bignum2(buf, q)) != 0 ||
  7.1788 ++		    (r = sshbuf_get_bignum2(buf, g)) != 0 ||
  7.1789 ++		    (r = sshbuf_get_bignum2(buf, pub_key)) != 0 ||
  7.1790 ++		    (r = sshbuf_get_bignum2(buf, priv_key)) != 0) {
  7.1791 ++			goto error1;
  7.1792 ++		}
  7.1793 ++		if (DSA_set0_pqg(k->dsa, p, q, g) == 0) {
  7.1794 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1795 ++			goto error1;
  7.1796 ++		}
  7.1797 ++		p = q = g = NULL;
  7.1798 ++		if (DSA_set0_key(k->dsa, pub_key, priv_key) == 0) {
  7.1799 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1800 ++error1:
  7.1801 ++			BN_free(p); BN_free(q); BN_free(g);
  7.1802 ++			BN_free(pub_key); BN_free(priv_key);
  7.1803 + 			goto out;
  7.1804 ++		}
  7.1805 ++		pub_key = priv_key = NULL;
  7.1806 ++		}
  7.1807 + 		break;
  7.1808 + 	case KEY_DSA_CERT:
  7.1809 +-		if ((r = sshkey_froms(buf, &k)) != 0 ||
  7.1810 ++		{
  7.1811 ++		BIGNUM *priv_key=NULL;
  7.1812 ++		if ((priv_key = BN_new()) == NULL) {
  7.1813 ++			r = SSH_ERR_ALLOC_FAIL;
  7.1814 ++			goto out;
  7.1815 ++		}
  7.1816 ++		if (priv_key == NULL ||
  7.1817 ++		    (r = sshkey_froms(buf, &k)) != 0 ||
  7.1818 + 		    (r = sshkey_add_private(k)) != 0 ||
  7.1819 +-		    (r = sshbuf_get_bignum2(buf, k->dsa->priv_key)) != 0)
  7.1820 ++		    (r = sshbuf_get_bignum2(buf, priv_key)) != 0) {
  7.1821 ++			BN_free(priv_key);
  7.1822 ++			goto out;
  7.1823 ++		}
  7.1824 ++		if (DSA_set0_key(k->dsa, NULL, priv_key) == 0) {
  7.1825 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1826 ++			BN_free(priv_key);
  7.1827 + 			goto out;
  7.1828 ++		}
  7.1829 ++		priv_key = NULL;
  7.1830 ++		}
  7.1831 + 		break;
  7.1832 + # ifdef OPENSSL_HAS_ECC
  7.1833 + 	case KEY_ECDSA:
  7.1834 +@@ -2655,29 +2963,104 @@
  7.1835 + 			r = SSH_ERR_ALLOC_FAIL;
  7.1836 + 			goto out;
  7.1837 + 		}
  7.1838 +-		if ((r = sshbuf_get_bignum2(buf, k->rsa->n)) != 0 ||
  7.1839 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->e)) != 0 ||
  7.1840 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->d)) != 0 ||
  7.1841 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->iqmp)) != 0 ||
  7.1842 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->p)) != 0 ||
  7.1843 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->q)) != 0 ||
  7.1844 +-		    (r = ssh_rsa_generate_additional_parameters(k)) != 0)
  7.1845 ++		{
  7.1846 ++		BIGNUM *n=NULL, *e=NULL, *d=NULL, *iqmp=NULL, *p=NULL, *q=NULL;
  7.1847 ++		BIGNUM *dmp1=NULL, *dmq1=NULL; /* dummy for RSA_set0_crt_params */
  7.1848 ++		if ((n = BN_new()) == NULL ||
  7.1849 ++		    (e = BN_new()) == NULL ||
  7.1850 ++		    (d = BN_new()) == NULL ||
  7.1851 ++		    (iqmp = BN_new()) == NULL ||
  7.1852 ++		    (p = BN_new()) == NULL ||
  7.1853 ++		    (q = BN_new()) == NULL ||
  7.1854 ++		    (dmp1 = BN_new()) == NULL ||
  7.1855 ++		    (dmq1 = BN_new()) == NULL) {
  7.1856 ++			r = SSH_ERR_ALLOC_FAIL;
  7.1857 ++			goto error2;
  7.1858 ++		}
  7.1859 ++		BN_clear(dmp1); BN_clear(dmq1);
  7.1860 ++		if ((r = sshbuf_get_bignum2(buf, n)) != 0 ||
  7.1861 ++		    (r = sshbuf_get_bignum2(buf, e)) != 0 ||
  7.1862 ++		    (r = sshbuf_get_bignum2(buf, d)) != 0 ||
  7.1863 ++		    (r = sshbuf_get_bignum2(buf, iqmp)) != 0 ||
  7.1864 ++		    (r = sshbuf_get_bignum2(buf, p)) != 0 ||
  7.1865 ++		    (r = sshbuf_get_bignum2(buf, q)) != 0) {
  7.1866 ++			goto error2;
  7.1867 ++		}
  7.1868 ++		if (RSA_set0_key(k->rsa, n, e, d) == 0) {
  7.1869 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1870 ++			goto error2;
  7.1871 ++		}
  7.1872 ++		n = e = d = NULL;
  7.1873 ++		/* dmp1,dmpq1 should be non NULL to set iqmp value */
  7.1874 ++		if (RSA_set0_crt_params(k->rsa, dmp1, dmq1, iqmp) == 0) {
  7.1875 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1876 ++			goto error2;
  7.1877 ++		}
  7.1878 ++		dmp1 = dmq1 = iqmp = NULL;
  7.1879 ++		if (RSA_set0_factors(k->rsa, p, q) == 0) {
  7.1880 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1881 ++ error2:
  7.1882 ++			BN_free(n); BN_free(e); BN_free(d);
  7.1883 ++			BN_free(iqmp);
  7.1884 ++			BN_free(p); BN_free(q);
  7.1885 ++			BN_free(dmp1); BN_free(dmq1);
  7.1886 ++			goto out;
  7.1887 ++		}
  7.1888 ++		p = q = NULL;
  7.1889 ++		if ((r = ssh_rsa_generate_additional_parameters(k)) != 0) {
  7.1890 + 			goto out;
  7.1891 +-		if (BN_num_bits(k->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1892 ++		}
  7.1893 ++		}
  7.1894 ++		if (RSA_bits(k->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1895 + 			r = SSH_ERR_KEY_LENGTH;
  7.1896 + 			goto out;
  7.1897 + 		}
  7.1898 + 		break;
  7.1899 + 	case KEY_RSA_CERT:
  7.1900 ++		{
  7.1901 ++		BIGNUM *d=NULL, *iqmp=NULL, *p=NULL, *q=NULL;
  7.1902 ++		BIGNUM *dmp1=NULL, *dmq1=NULL; /* dummy for RSA_set0_crt_params */
  7.1903 ++		if ((d = BN_new()) == NULL ||
  7.1904 ++		    (iqmp = BN_new()) == NULL ||
  7.1905 ++		    (p = BN_new()) == NULL ||
  7.1906 ++		    (q = BN_new()) == NULL ||
  7.1907 ++		    (dmp1 = BN_new()) == NULL ||
  7.1908 ++		    (dmq1 = BN_new()) == NULL) {
  7.1909 ++			r = SSH_ERR_ALLOC_FAIL;
  7.1910 ++			goto error3;
  7.1911 ++		}
  7.1912 ++		BN_clear(dmp1); BN_clear(dmq1);
  7.1913 + 		if ((r = sshkey_froms(buf, &k)) != 0 ||
  7.1914 + 		    (r = sshkey_add_private(k)) != 0 ||
  7.1915 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->d)) != 0 ||
  7.1916 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->iqmp)) != 0 ||
  7.1917 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->p)) != 0 ||
  7.1918 +-		    (r = sshbuf_get_bignum2(buf, k->rsa->q)) != 0 ||
  7.1919 +-		    (r = ssh_rsa_generate_additional_parameters(k)) != 0)
  7.1920 ++		    (r = sshbuf_get_bignum2(buf, d)) != 0 ||
  7.1921 ++		    (r = sshbuf_get_bignum2(buf, iqmp)) != 0 ||
  7.1922 ++		    (r = sshbuf_get_bignum2(buf, p)) != 0 ||
  7.1923 ++		    (r = sshbuf_get_bignum2(buf, q)) != 0) {
  7.1924 ++			goto error3;
  7.1925 ++		}
  7.1926 ++		if (RSA_set0_key(k->rsa, NULL, NULL, d) == 0) {
  7.1927 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1928 ++			goto error3;
  7.1929 ++		}
  7.1930 ++		/* dmp1,dmpq1 should be non NULL to set value */
  7.1931 ++		if (RSA_set0_crt_params(k->rsa, dmp1, dmq1, iqmp) == 0) {
  7.1932 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1933 ++			goto error3;
  7.1934 ++		}
  7.1935 ++		dmp1 = dmq1 = iqmp = NULL;
  7.1936 ++		if (RSA_set0_factors(k->rsa, p, q) == 0) {
  7.1937 ++			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1938 ++ error3:
  7.1939 ++			BN_free(d); BN_free(iqmp);
  7.1940 ++			BN_free(p); BN_free(q);
  7.1941 ++			BN_free(dmp1); BN_free(dmq1);
  7.1942 + 			goto out;
  7.1943 +-		if (BN_num_bits(k->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1944 ++		}
  7.1945 ++		p = q = NULL;
  7.1946 ++		if ((r = ssh_rsa_generate_additional_parameters(k)) != 0)
  7.1947 ++			goto out;
  7.1948 ++		}
  7.1949 ++		if (RSA_bits(k->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1950 + 			r = SSH_ERR_KEY_LENGTH;
  7.1951 + 			goto out;
  7.1952 + 		}
  7.1953 +@@ -3395,7 +3778,6 @@
  7.1954 + 		switch (pem_reason) {
  7.1955 + 		case EVP_R_BAD_DECRYPT:
  7.1956 + 			return SSH_ERR_KEY_WRONG_PASSPHRASE;
  7.1957 +-		case EVP_R_BN_DECODE_ERROR:
  7.1958 + 		case EVP_R_DECODE_ERROR:
  7.1959 + #ifdef EVP_R_PRIVATE_KEY_DECODE_ERROR
  7.1960 + 		case EVP_R_PRIVATE_KEY_DECODE_ERROR:
  7.1961 +@@ -3460,7 +3842,7 @@
  7.1962 + 		r = convert_libcrypto_error();
  7.1963 + 		goto out;
  7.1964 + 	}
  7.1965 +-	if (pk->type == EVP_PKEY_RSA &&
  7.1966 ++	if (EVP_PKEY_id(pk) == EVP_PKEY_RSA &&
  7.1967 + 	    (type == KEY_UNSPEC || type == KEY_RSA)) {
  7.1968 + 		if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
  7.1969 + 			r = SSH_ERR_ALLOC_FAIL;
  7.1970 +@@ -3475,11 +3857,11 @@
  7.1971 + 			r = SSH_ERR_LIBCRYPTO_ERROR;
  7.1972 + 			goto out;
  7.1973 + 		}
  7.1974 +-		if (BN_num_bits(prv->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1975 ++		if (RSA_bits(prv->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
  7.1976 + 			r = SSH_ERR_KEY_LENGTH;
  7.1977 + 			goto out;
  7.1978 + 		}
  7.1979 +-	} else if (pk->type == EVP_PKEY_DSA &&
  7.1980 ++	} else if (EVP_PKEY_id(pk) == EVP_PKEY_DSA &&
  7.1981 + 	    (type == KEY_UNSPEC || type == KEY_DSA)) {
  7.1982 + 		if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
  7.1983 + 			r = SSH_ERR_ALLOC_FAIL;
  7.1984 +@@ -3491,7 +3873,7 @@
  7.1985 + 		DSA_print_fp(stderr, prv->dsa, 8);
  7.1986 + #endif
  7.1987 + #ifdef OPENSSL_HAS_ECC
  7.1988 +-	} else if (pk->type == EVP_PKEY_EC &&
  7.1989 ++	} else if (EVP_PKEY_id(pk) == EVP_PKEY_EC &&
  7.1990 + 	    (type == KEY_UNSPEC || type == KEY_ECDSA)) {
  7.1991 + 		if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
  7.1992 + 			r = SSH_ERR_ALLOC_FAIL;
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/openssh/stuff/patches/series	Sat Mar 24 15:55:55 2018 +0200
     8.3 @@ -0,0 +1,2 @@
     8.4 +# from LFS
     8.5 +openssh-7.6p1-openssl-1.1.0-1.patch
     9.1 --- a/samba/receipt	Sat Mar 24 11:10:32 2018 +0200
     9.2 +++ b/samba/receipt	Sat Mar 24 15:55:55 2018 +0200
     9.3 @@ -7,8 +7,7 @@
     9.4  MAINTAINER="pascal.bellard@slitaz.org"
     9.5  LICENSE="GPL3"
     9.6  WEB_SITE="https://www.samba.org/"
     9.7 -BUGS="Open directory needs MIT kerberos support (krb5)"
     9.8 -COOKOPTS="!menus"
     9.9 +LFS="http://www.linuxfromscratch.org/blfs/view/stable/basicnet/samba.html"
    9.10  
    9.11  TARBALL="$PACKAGE-$VERSION.tar.gz"
    9.12  WGET_URL="https://download.samba.org/pub/samba/stable/$TARBALL"
    9.13 @@ -16,19 +15,22 @@
    9.14  BUILD_DEPENDS="python-dev perl acl-dev docbook-xsl openldap-dev   \
    9.15  gnutls-dev krb5-dev cyrus-sasl-dev zlib-dev popt-dev libtdb-dev talloc-dev \
    9.16  libgcrypt-dev nss-dev cups-dev dbus-dev pam pam-dev"
    9.17 -SPLIT="samba samba-pam samba-dev" # TODO: swat
    9.18 +SPLIT="samba samba-dev samba-pam:pam" # TODO: swat
    9.19 +
    9.20 +BUGS="Open directory needs MIT kerberos support (krb5)"
    9.21 +COOKOPTS="!menus"
    9.22  
    9.23  version() {
    9.24  	wget -O- -q https://download.samba.org/pub/samba/ | \
    9.25  	sed '/LATEST-IS-SAMBA/!d; s|.*SAMBA-\([^<]*\).*|\1|'
    9.26  }
    9.27  
    9.28 -# Rules to configure and make the package.
    9.29 -compile_rules()
    9.30 -{
    9.31 -	# http://www.linuxfromscratch.org/blfs/view/stable/basicnet/samba.html
    9.32 +compile_rules() {
    9.33 +	case $SET in
    9.34 +		'')  SET_ARGS='--without-pam';;
    9.35 +		pam) SET_ARGS='--with-pam';;
    9.36 +	esac
    9.37  
    9.38 -	cp -a $src $src-pam
    9.39  	./configure \
    9.40  		--prefix=/usr \
    9.41  		--sysconfdir=/etc \
    9.42 @@ -36,69 +38,44 @@
    9.43  		--with-piddir=/run/samba \
    9.44  		--with-pammodulesdir=/lib/security \
    9.45  		--enable-fhs \
    9.46 -		--without-pam \
    9.47  		--without-ad-dc \
    9.48  		--without-systemd \
    9.49  		--enable-selftest \
    9.50 +		$SET_ARGS \
    9.51  		$CONFIGURE_ARGS &&
    9.52  	make && make install || return 1
    9.53  
    9.54 -	cd $src-pam
    9.55 -	./configure \
    9.56 -		--prefix=/usr \
    9.57 -		--sysconfdir=/etc \
    9.58 -		--localstatedir=/var \
    9.59 -		--with-piddir=/run/samba \
    9.60 -		--with-pammodulesdir=/lib/security \
    9.61 -		--enable-fhs \
    9.62 -		--with-pam \
    9.63 -		--without-ad-dc \
    9.64 -		--without-systemd \
    9.65 -		--enable-selftest \
    9.66 -		$CONFIGURE_ARGS &&
    9.67 -	make && make DESTDIR=$DESTDIR-pam install || return 1
    9.68 +	mkdir -p $instsll/lib/
    9.69 +	mv $install/usr/lib/libnss_wins.so*  $install/usr/lib/libnss_winbind.so* \
    9.70 +		$install/lib
    9.71 +	ln -sf ../../lib/libnss_winbind.so.2 $install/usr/lib/libnss_winbind.so
    9.72 +	ln -sf ../../lib/libnss_wins.so.2    $install/usr/lib/libnss_wins.so
    9.73  
    9.74 -	for inst in $install $install-pam ; do
    9.75 -		mkdir -p $inst/lib
    9.76 -		mv $inst/usr/lib/libnss_wins.so* $inst/usr/lib/libnss_winbind.so* \
    9.77 -			$inst/lib
    9.78 -		ln -sf ../../lib/libnss_winbind.so.2 $inst/usr/lib/libnss_winbind.so
    9.79 -		ln -sf ../../lib/libnss_wins.so.2    $inst/usr/lib/libnss_wins.so
    9.80 +	install -m644 examples/smb.conf.default $install/etc/samba
    9.81  
    9.82 -		install -m644 examples/smb.conf.default $inst/etc/samba
    9.83 +	mkdir -pv                                  $install/etc/openldap/schema
    9.84 +	cp examples/LDAP/README                    $install/etc/openldap/schema/README.LDAP
    9.85 +	cp examples/LDAP/samba*                    $install/etc/openldap/schema
    9.86 +	cp -r examples/LDAP/get* examples/LDAP/ol* $install/etc/openldap/schema
    9.87  
    9.88 -		mkdir -pv $inst/etc/openldap/schema
    9.89 -		cp examples/LDAP/README $inst/etc/openldap/schema/README.LDAP
    9.90 -		cp examples/LDAP/samba* $inst/etc/openldap/schema
    9.91 -		cp -r examples/LDAP/get* examples/LDAP/ol* $inst/etc/openldap/schema
    9.92 +	cp -a $stuff/etc $install
    9.93  
    9.94 -		cp -a $stuff/etc $inst
    9.95 +	# Symlink smbspool to cups backend
    9.96 +	mkdir -p                 $install/usr/lib/cups/backend/
    9.97 +	ln -sf /usr/bin/smbspool $install/usr/lib/cups/backend/smb
    9.98  
    9.99 -		# Symlink smbspool to cups backend
   9.100 -		mkdir -p $inst/usr/lib/cups/backend
   9.101 -		ln -sf /usr/bin/smbspool $inst/usr/lib/cups/backend/smb
   9.102 +	# for swat package
   9.103 +#	icodir="$inst/usr/share/icons/hicolor/48x48/apps"
   9.104 +#	mkdir -p $icodir
   9.105 +#	cp $stuff/swat.png $icodir
   9.106  
   9.107 -		# for swat package
   9.108 -#		icodir="$inst/usr/share/icons/hicolor/48x48/apps"
   9.109 -#		mkdir -p $icodir
   9.110 -#		cp $stuff/swat.png $icodir
   9.111 -
   9.112 -		chown -R root:root $inst
   9.113 -	done
   9.114 +	chown -R root:root $install
   9.115  }
   9.116  
   9.117 -# Rules to gen a SliTaz package suitable for Tazpkg.
   9.118 -genpkg_rules()
   9.119 -{
   9.120 +genpkg_rules() {
   9.121  	# Note, packages samba-common, smbclient was removed due to circular dependencies:
   9.122  	# smbclient <--> samba <--> samba-common
   9.123  	case $PACKAGE in
   9.124 -#		smbclient)
   9.125 -#			copy smbclient smbspool smbget smbtree smbcacls smbcquotas smbtar \
   9.126 -#			rpcclient net nmblookup libnetapi.so* libsmbclient.so* smb
   9.127 -#			CAT="network|client"
   9.128 -#			DEPENDS="samba libldap libtdb popt talloc"
   9.129 -#			;;
   9.130  #		swat)
   9.131  #			copy swat/ swat.desktop swat.png
   9.132  #			CAT="development|Samba Web Administration Tool"
   9.133 @@ -106,7 +83,6 @@
   9.134  #			;;
   9.135  		samba)
   9.136  			copy @std
   9.137 -#			remove_already_packed
   9.138  			DEPENDS="acl attr dbus libcups libgnutls libldap libtdb ncurses \
   9.139  			ncurses-libform ncurses-libpanel perl popt python talloc \
   9.140  			talloc-python zlib"
   9.141 @@ -115,9 +91,8 @@
   9.142  			CONFIG_FILES="/etc/samba/smb.conf"
   9.143  			;;
   9.144  		samba-pam)
   9.145 +			copy @std
   9.146  			CAT="system-tools|using PAM"
   9.147 -			install=$install-pam copy @std
   9.148 -#			remove by hand already packed files...
   9.149  			DEPENDS="acl attr dbus libcups libgnutls libldap libtdb ncurses \
   9.150  			ncurses-libform ncurses-libpanel perl popt python talloc \
   9.151  			talloc-python zlib pam"
   9.152 @@ -132,7 +107,6 @@
   9.153  	esac
   9.154  }
   9.155  
   9.156 -# Pre and post install commands for Tazpkg.
   9.157  post_install_samba() {
   9.158  	[ -n "$quiet" ] || cat <<EOT
   9.159  
    10.1 --- a/sshfs-fuse/receipt	Sat Mar 24 11:10:32 2018 +0200
    10.2 +++ b/sshfs-fuse/receipt	Sat Mar 24 15:55:55 2018 +0200
    10.3 @@ -22,7 +22,7 @@
    10.4  
    10.5  genpkg_rules() {
    10.6  	copy @std
    10.7 -	DEPENDS="fuse3 openssh sftp-server glib"
    10.8 +	DEPENDS="fuse3 openssh glib"
    10.9  	PROVIDE="rsshfs sshfs"
   10.10  	TAGS="ssh"
   10.11  }
    11.1 --- a/udisks2/receipt	Sat Mar 24 11:10:32 2018 +0200
    11.2 +++ b/udisks2/receipt	Sat Mar 24 15:55:55 2018 +0200
    11.3 @@ -1,7 +1,7 @@
    11.4  # SliTaz package receipt v2.
    11.5  
    11.6  PACKAGE="udisks2"
    11.7 -VERSION="2.7.2"
    11.8 +VERSION="2.7.6"
    11.9  CATEGORY="system-tools"
   11.10  SHORT_DESC="D-Bus service to access and manipulate storage devices"
   11.11  MAINTAINER="pankso@slitaz.org"