From 2276cf51c0bbda0d8c849d084e961afe26026618 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 1 Aug 2024 09:54:53 -0500 Subject: [PATCH 1/2] Strings: make it so base64url_encode() does not do padding base64url_decode() already doesn't do padding --- phpseclib/Common/Functions/Strings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Common/Functions/Strings.php b/phpseclib/Common/Functions/Strings.php index eac793a6..fa750ba2 100644 --- a/phpseclib/Common/Functions/Strings.php +++ b/phpseclib/Common/Functions/Strings.php @@ -473,7 +473,7 @@ abstract class Strings // return str_replace(['+', '/'], ['-', '_'], self::base64_encode($data)); return function_exists('sodium_bin2base64') ? - sodium_bin2base64($data, SODIUM_BASE64_VARIANT_URLSAFE) : + sodium_bin2base64($data, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING) : Base64UrlSafe::encode($data); } From 45b98d8cb39230019612ddcca3abbdc574152834 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 2 Aug 2024 09:04:47 -0500 Subject: [PATCH 2/2] fix IEEE length calculations secp521r1 has length of 521 so we want 66 to cover that last extra bit - not 65 --- phpseclib/Crypt/EC/Formats/Signature/IEEE.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Crypt/EC/Formats/Signature/IEEE.php b/phpseclib/Crypt/EC/Formats/Signature/IEEE.php index 26ff7404..6bfd9311 100644 --- a/phpseclib/Crypt/EC/Formats/Signature/IEEE.php +++ b/phpseclib/Crypt/EC/Formats/Signature/IEEE.php @@ -62,7 +62,7 @@ abstract class IEEE { $r = $r->toBytes(); $s = $s->toBytes(); - $length >>= 3; + $length = (int) ceil($length / 8); return str_pad($r, $length, "\0", STR_PAD_LEFT) . str_pad($s, $length, "\0", STR_PAD_LEFT); } }