RSA: Add CRYPT_RSA_PKCS15_COMPAT mode

This commit is contained in:
terrafrost 2013-03-23 14:13:24 -05:00
parent a3e3682feb
commit c5bd12dd14

View File

@ -2142,6 +2142,7 @@ class Crypt_RSA {
}
// EME-PKCS1-v1_5 encoding
$psLen = $this->k - $mLen - 3;
$ps = '';
while (strlen($ps) != $psLen) {
@ -2149,7 +2150,14 @@ class Crypt_RSA {
$temp = str_replace("\x00", '', $temp);
$ps.= $temp;
}
$em = chr(0) . chr(2) . $ps . chr(0) . $m;
$type = 2;
// see the comments of _rsaes_pkcs1_v1_5_decrypt() to understand why this is being done
if (defined('CRYPT_RSA_PKCS15_COMPAT') && (!isset($this->publicExponent) || $this->exponent !== $this->publicExponent)) {
$type = 1;
// "The padding string PS shall consist of k-3-||D|| octets. ... for block type 01, they shall have value FF"
$ps = str_repeat("\xFF", $psLen);
}
$em = chr(0) . chr($type) . $ps . chr(0) . $m;
// RSA encryption
$m = $this->_os2ip($em);
@ -2650,4 +2658,4 @@ class Crypt_RSA {
return $this->_rsassa_pss_verify($message, $signature);
}
}
}
}