@@ -61,16 +61,13 @@ public static function sign(string $signatureBase, string $privateKey, string $a
6161 return sodium_crypto_sign_detached ($ signatureBase , $ privateKey );
6262 }
6363
64- [$ opensslAlgo , $ padding , $ encoding ] = self ::opensslParametersForAlgorithm ($ normalized );
64+ [$ opensslAlgo , $ encoding ] = self ::opensslParametersForAlgorithm ($ normalized );
6565
66- // Padding is only valid for RSA keys; passing it for ECDSA triggers a
67- // PHP warning and rejection.
68- if ($ padding === null ) {
69- $ ok = openssl_sign ($ signatureBase , $ signature , $ privateKey , $ opensslAlgo );
70- } else {
71- /** @psalm-suppress TooManyArguments - the 5-arg form is supported on PHP 8 */
72- $ ok = openssl_sign ($ signatureBase , $ signature , $ privateKey , $ opensslAlgo , $ padding );
73- }
66+ // We do not pass an explicit padding mode: openssl_sign's 5th argument
67+ // only became available in PHP 8.5, and the algorithms we still
68+ // support (RSA-PKCS1-v1_5, ECDSA) all use the function's default
69+ // padding behaviour (PKCS1 v1.5 for RSA, ignored for ECDSA).
70+ $ ok = openssl_sign ($ signatureBase , $ signature , $ privateKey , $ opensslAlgo );
7471 if (!$ ok ) {
7572 throw new SignatureException ('openssl_sign failed for ' . $ normalized );
7673 }
@@ -111,7 +108,7 @@ public static function verify(string $signatureBase, string $signature, Jwk $jwk
111108 return sodium_crypto_sign_verify_detached ($ signature , $ signatureBase , $ rawPublicKey );
112109 }
113110
114- [$ opensslAlgo , $ padding , $ encoding ] = self ::opensslParametersForAlgorithm ($ resolved );
111+ [$ opensslAlgo , $ encoding ] = self ::opensslParametersForAlgorithm ($ resolved );
115112
116113 if ($ encoding === 'ecdsa ' ) {
117114 $ signature = self ::ecdsaRawToDer ($ signature , self ::ecdsaCoordinateSize ($ resolved ));
@@ -125,11 +122,10 @@ public static function verify(string $signatureBase, string $signature, Jwk $jwk
125122 throw new SignatureException ('cannot derive public key from JWK ' );
126123 }
127124
128- if ($ padding === null ) {
129- return openssl_verify ($ signatureBase , $ signature , $ publicKey , $ opensslAlgo ) === 1 ;
130- }
131- /** @psalm-suppress TooManyArguments - the 5-arg form is supported on PHP 8 */
132- return openssl_verify ($ signatureBase , $ signature , $ publicKey , $ opensslAlgo , $ padding ) === 1 ;
125+ // See comment in sign(): padding is the openssl_verify default for
126+ // the algorithms we still support, and the 5-arg form requires
127+ // PHP 8.5.
128+ return openssl_verify ($ signatureBase , $ signature , $ publicKey , $ opensslAlgo ) === 1 ;
133129 }
134130
135131 /**
@@ -176,18 +172,18 @@ public static function normalize(string $algorithm): string {
176172 }
177173
178174 /**
179- * @return array{0: int, 1: int|null, 2: string} [openssl algo, padding (null = omit for non-RSA) , wire encoding]
175+ * @return array{0: int, 1: string} [openssl digest , wire encoding]
180176 */
181177 private static function opensslParametersForAlgorithm (string $ native ): array {
182178 // Ed25519 is handled by libsodium upstream of this method and never
183179 // reaches it; only RSA-PKCS1-v1_5 and ECDSA go through OpenSSL.
184180 // RSA-PSS is not supported (see class docblock).
185181 return match ($ native ) {
186- 'rsa-v1_5-sha256 ' => [OPENSSL_ALGO_SHA256 , OPENSSL_PKCS1_PADDING , 'raw ' ],
187- 'rsa-v1_5-sha384 ' => [OPENSSL_ALGO_SHA384 , OPENSSL_PKCS1_PADDING , 'raw ' ],
188- 'rsa-v1_5-sha512 ' => [OPENSSL_ALGO_SHA512 , OPENSSL_PKCS1_PADDING , 'raw ' ],
189- 'ecdsa-p256-sha256 ' => [OPENSSL_ALGO_SHA256 , null , 'ecdsa ' ],
190- 'ecdsa-p384-sha384 ' => [OPENSSL_ALGO_SHA384 , null , 'ecdsa ' ],
182+ 'rsa-v1_5-sha256 ' => [OPENSSL_ALGO_SHA256 , 'raw ' ],
183+ 'rsa-v1_5-sha384 ' => [OPENSSL_ALGO_SHA384 , 'raw ' ],
184+ 'rsa-v1_5-sha512 ' => [OPENSSL_ALGO_SHA512 , 'raw ' ],
185+ 'ecdsa-p256-sha256 ' => [OPENSSL_ALGO_SHA256 , 'ecdsa ' ],
186+ 'ecdsa-p384-sha384 ' => [OPENSSL_ALGO_SHA384 , 'ecdsa ' ],
191187 default => throw new SignatureException ('unsupported signature algorithm: ' . $ native ),
192188 };
193189 }
0 commit comments