From e3557220d7b4f10b4b8420ba71845e88b3b69c50 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 13 Nov 2019 23:47:16 -0600 Subject: [PATCH] SSH2: sodium_compat doesn't support memzero --- phpseclib/Net/SSH2.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index fae64fc5..84104fc2 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -1713,7 +1713,14 @@ class SSH2 return false; } $key = new BigInteger(sodium_crypto_scalarmult($x, $fBytes), 256); - sodium_memzero($x); + // sodium_compat doesn't emulate sodium_memzero + // also, with v1 of libsodium API the extension identifies itself as + // libsodium whereas v2 of the libsodium API (what PHP 7.2+ includes) + // identifies itself as sodium. sodium_compat uses the v1 API to + // emulate the v2 API if it's the v1 API that's available + if (extension_loaded('sodium') || extension_loaded('libsodium')) { + sodium_memzero($x); + } } else { $f = new BigInteger($fBytes, -256); $key = $f->modPow($x, $prime);