Subversion Repositories oidplus

Rev

Rev 846 | Rev 1042 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 846 Rev 874
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/**
3
/**
4
 * RSA Public Key
4
 * RSA Public Key
5
 *
5
 *
-
 
6
 * @category  Crypt
-
 
7
 * @package   RSA
6
 * @author    Jim Wigginton <terrafrost@php.net>
8
 * @author    Jim Wigginton <terrafrost@php.net>
7
 * @copyright 2015 Jim Wigginton
9
 * @copyright 2015 Jim Wigginton
8
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
10
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
9
 * @link      http://phpseclib.sourceforge.net
11
 * @link      http://phpseclib.sourceforge.net
10
 */
12
 */
Line 24... Line 26...
24
use phpseclib3\Math\BigInteger;
26
use phpseclib3\Math\BigInteger;
25
 
27
 
26
/**
28
/**
27
 * Raw RSA Key Handler
29
 * Raw RSA Key Handler
28
 *
30
 *
-
 
31
 * @package RSA
29
 * @author  Jim Wigginton <terrafrost@php.net>
32
 * @author  Jim Wigginton <terrafrost@php.net>
-
 
33
 * @access  public
30
 */
34
 */
31
class PublicKey extends RSA implements Common\PublicKey
35
class PublicKey extends RSA implements Common\PublicKey
32
{
36
{
33
    use Common\Traits\Fingerprint;
37
    use Common\Traits\Fingerprint;
34
 
38
 
Line 46... Line 50...
46
    /**
50
    /**
47
     * RSAVP1
51
     * RSAVP1
48
     *
52
     *
49
     * See {@link http://tools.ietf.org/html/rfc3447#section-5.2.2 RFC3447#section-5.2.2}.
53
     * See {@link http://tools.ietf.org/html/rfc3447#section-5.2.2 RFC3447#section-5.2.2}.
50
     *
54
     *
-
 
55
     * @access private
51
     * @param \phpseclib3\Math\BigInteger $s
56
     * @param \phpseclib3\Math\BigInteger $s
52
     * @return bool|\phpseclib3\Math\BigInteger
57
     * @return bool|\phpseclib3\Math\BigInteger
53
     */
58
     */
54
    private function rsavp1($s)
59
    private function rsavp1($s)
55
    {
60
    {
Line 62... Line 67...
62
    /**
67
    /**
63
     * RSASSA-PKCS1-V1_5-VERIFY
68
     * RSASSA-PKCS1-V1_5-VERIFY
64
     *
69
     *
65
     * See {@link http://tools.ietf.org/html/rfc3447#section-8.2.2 RFC3447#section-8.2.2}.
70
     * See {@link http://tools.ietf.org/html/rfc3447#section-8.2.2 RFC3447#section-8.2.2}.
66
     *
71
     *
-
 
72
     * @access private
67
     * @param string $m
73
     * @param string $m
68
     * @param string $s
74
     * @param string $s
69
     * @throws \LengthException if the RSA modulus is too short
75
     * @throws \LengthException if the RSA modulus is too short
70
     * @return bool
76
     * @return bool
71
     */
77
     */
Line 130... Line 136...
130
     * whether the underlying BER encoding is a DER encoding and hence whether the signature
136
     * whether the underlying BER encoding is a DER encoding and hence whether the signature
131
     * is valid with respect to the specification given in [PKCS1 v2.0+]". so if you do
137
     * is valid with respect to the specification given in [PKCS1 v2.0+]". so if you do
132
     * $rsa->getLastPadding() and get RSA::PADDING_RELAXED_PKCS1 back instead of
138
     * $rsa->getLastPadding() and get RSA::PADDING_RELAXED_PKCS1 back instead of
133
     * RSA::PADDING_PKCS1... that means BER encoding was used.
139
     * RSA::PADDING_PKCS1... that means BER encoding was used.
134
     *
140
     *
-
 
141
     * @access private
135
     * @param string $m
142
     * @param string $m
136
     * @param string $s
143
     * @param string $s
137
     * @return bool
144
     * @return bool
138
     */
145
     */
139
    private function rsassa_pkcs1_v1_5_relaxed_verify($m, $s)
146
    private function rsassa_pkcs1_v1_5_relaxed_verify($m, $s)
Line 215... Line 222...
215
    /**
222
    /**
216
     * EMSA-PSS-VERIFY
223
     * EMSA-PSS-VERIFY
217
     *
224
     *
218
     * See {@link http://tools.ietf.org/html/rfc3447#section-9.1.2 RFC3447#section-9.1.2}.
225
     * See {@link http://tools.ietf.org/html/rfc3447#section-9.1.2 RFC3447#section-9.1.2}.
219
     *
226
     *
-
 
227
     * @access private
220
     * @param string $m
228
     * @param string $m
221
     * @param string $em
229
     * @param string $em
222
     * @param int $emBits
230
     * @param int $emBits
223
     * @return string
231
     * @return string
224
     */
232
     */
Line 261... Line 269...
261
    /**
269
    /**
262
     * RSASSA-PSS-VERIFY
270
     * RSASSA-PSS-VERIFY
263
     *
271
     *
264
     * See {@link http://tools.ietf.org/html/rfc3447#section-8.1.2 RFC3447#section-8.1.2}.
272
     * See {@link http://tools.ietf.org/html/rfc3447#section-8.1.2 RFC3447#section-8.1.2}.
265
     *
273
     *
-
 
274
     * @access private
266
     * @param string $m
275
     * @param string $m
267
     * @param string $s
276
     * @param string $s
268
     * @return bool|string
277
     * @return bool|string
269
     */
278
     */
270
    private function rsassa_pss_verify($m, $s)
279
    private function rsassa_pss_verify($m, $s)
Line 315... Line 324...
315
    /**
324
    /**
316
     * RSAES-PKCS1-V1_5-ENCRYPT
325
     * RSAES-PKCS1-V1_5-ENCRYPT
317
     *
326
     *
318
     * See {@link http://tools.ietf.org/html/rfc3447#section-7.2.1 RFC3447#section-7.2.1}.
327
     * See {@link http://tools.ietf.org/html/rfc3447#section-7.2.1 RFC3447#section-7.2.1}.
319
     *
328
     *
-
 
329
     * @access private
320
     * @param string $m
330
     * @param string $m
321
     * @param bool $pkcs15_compat optional
331
     * @param bool $pkcs15_compat optional
322
     * @throws \LengthException if strlen($m) > $this->k - 11
332
     * @throws \LengthException if strlen($m) > $this->k - 11
323
     * @return bool|string
333
     * @return bool|string
324
     */
334
     */
Line 358... Line 368...
358
     * RSAES-OAEP-ENCRYPT
368
     * RSAES-OAEP-ENCRYPT
359
     *
369
     *
360
     * See {@link http://tools.ietf.org/html/rfc3447#section-7.1.1 RFC3447#section-7.1.1} and
370
     * See {@link http://tools.ietf.org/html/rfc3447#section-7.1.1 RFC3447#section-7.1.1} and
361
     * {http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding OAES}.
371
     * {http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding OAES}.
362
     *
372
     *
-
 
373
     * @access private
363
     * @param string $m
374
     * @param string $m
364
     * @throws \LengthException if strlen($m) > $this->k - 2 * $this->hLen - 2
375
     * @throws \LengthException if strlen($m) > $this->k - 2 * $this->hLen - 2
365
     * @return string
376
     * @return string
366
     */
377
     */
367
    private function rsaes_oaep_encrypt($m)
378
    private function rsaes_oaep_encrypt($m)
Line 403... Line 414...
403
    /**
414
    /**
404
     * RSAEP
415
     * RSAEP
405
     *
416
     *
406
     * See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.1}.
417
     * See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.1}.
407
     *
418
     *
-
 
419
     * @access private
408
     * @param \phpseclib3\Math\BigInteger $m
420
     * @param \phpseclib3\Math\BigInteger $m
409
     * @return bool|\phpseclib3\Math\BigInteger
421
     * @return bool|\phpseclib3\Math\BigInteger
410
     */
422
     */
411
    private function rsaep($m)
423
    private function rsaep($m)
412
    {
424
    {
Line 419... Line 431...
419
    /**
431
    /**
420
     * Raw Encryption / Decryption
432
     * Raw Encryption / Decryption
421
     *
433
     *
422
     * Doesn't use padding and is not recommended.
434
     * Doesn't use padding and is not recommended.
423
     *
435
     *
-
 
436
     * @access private
424
     * @param string $m
437
     * @param string $m
425
     * @return bool|string
438
     * @return bool|string
426
     * @throws \LengthException if strlen($m) > $this->k
439
     * @throws \LengthException if strlen($m) > $this->k
427
     */
440
     */
428
    private function raw_encrypt($m)
441
    private function raw_encrypt($m)
Line 442... Line 455...
442
     * Both self::PADDING_OAEP and self::PADDING_PKCS1 both place limits on how long $plaintext can be.
455
     * Both self::PADDING_OAEP and self::PADDING_PKCS1 both place limits on how long $plaintext can be.
443
     * If $plaintext exceeds those limits it will be broken up so that it does and the resultant ciphertext's will
456
     * If $plaintext exceeds those limits it will be broken up so that it does and the resultant ciphertext's will
444
     * be concatenated together.
457
     * be concatenated together.
445
     *
458
     *
446
     * @see self::decrypt()
459
     * @see self::decrypt()
-
 
460
     * @access public
447
     * @param string $plaintext
461
     * @param string $plaintext
448
     * @return bool|string
462
     * @return bool|string
449
     * @throws \LengthException if the RSA modulus is too short
463
     * @throws \LengthException if the RSA modulus is too short
450
     */
464
     */
451
    public function encrypt($plaintext)
465
    public function encrypt($plaintext)