1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-11-26 12:25:24 +01:00

Merge branch '1.0' into 2.0

This commit is contained in:
terrafrost 2019-10-20 13:27:24 -05:00
commit e36f9388cb
2 changed files with 24 additions and 3 deletions

View File

@ -2762,7 +2762,7 @@ class RSA
// if $m is larger than two million terrabytes and you're using sha1, PKCS#1 suggests a "Label too long" error
// be output.
$emLen = ($emBits + 1) >> 3; // ie. ceil($emBits / 8);
$emLen = ($emBits + 7) >> 3; // ie. ceil($emBits / 8);
$sLen = $this->sLen !== null ? $this->sLen : $this->hLen;
$mHash = $this->hash->hash($m);
@ -2840,7 +2840,7 @@ class RSA
// RSA verification
$modBits = 8 * $this->k;
$modBits = strlen($this->modulus->toBits());
$s2 = $this->_os2ip($s);
$m2 = $this->_rsavp1($s2);
@ -2848,7 +2848,7 @@ class RSA
user_error('Invalid signature');
return false;
}
$em = $this->_i2osp($m2, $modBits >> 3);
$em = $this->_i2osp($m2, $this->k);
if ($em === false) {
user_error('Invalid signature');
return false;

View File

@ -94,4 +94,25 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$rsa->loadKey($rsa->getPublicKey());
$this->assertTrue($rsa->verify($plaintext, $sig));
}
/**
* @group github1423
*/
public function testPSSSigsWithNonPowerOf2Key()
{
$pub = '-----BEGIN PUBLIC KEY-----
MF0wDQYJKoZIhvcNAQEBBQADTAAwSQJCAmdYuOvii3I6ya3q/zSeZFoJprgF9fIq
k12yS6pCS3c+1wZ9cYFVtgfpSL4XpylLe9EnRT2GRVYCqUkR4AUeTuvnAgMBAAE=
-----END PUBLIC KEY-----';
$rsa = new Crypt_RSA();
$rsa->loadKey($pub);
$rsa->setHash('sha256');
$rsa->setSaltLength(32);
$rsa->setMGFHash('sha256');
$sig = base64_decode(strtr('Ad022bD-UCmWpBNMtsYJjG0FVxML-FFlN4IKrByP8rwjVzV_D-YqSjc_oW6LrooV7j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