Subversion Repositories oidplus

Rev

Rev 874 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 874 Rev 1042
Line 3... Line 3...
3
/**
3
/**
4
 * Pure-PHP implementation of Salsa20.
4
 * Pure-PHP implementation of Salsa20.
5
 *
5
 *
6
 * PHP version 5
6
 * PHP version 5
7
 *
7
 *
8
 * @category  Crypt
-
 
9
 * @package   Salsa20
-
 
10
 * @author    Jim Wigginton <terrafrost@php.net>
8
 * @author    Jim Wigginton <terrafrost@php.net>
11
 * @copyright 2019 Jim Wigginton
9
 * @copyright 2019 Jim Wigginton
12
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
10
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
13
 * @link      http://phpseclib.sourceforge.net
11
 * @link      http://phpseclib.sourceforge.net
14
 */
12
 */
Line 21... Line 19...
21
use phpseclib3\Exception\InsufficientSetupException;
19
use phpseclib3\Exception\InsufficientSetupException;
22
 
20
 
23
/**
21
/**
24
 * Pure-PHP implementation of Salsa20.
22
 * Pure-PHP implementation of Salsa20.
25
 *
23
 *
26
 * @package Salsa20
-
 
27
 * @author  Jim Wigginton <terrafrost@php.net>
24
 * @author  Jim Wigginton <terrafrost@php.net>
28
 * @access  public
-
 
29
 */
25
 */
30
class Salsa20 extends StreamCipher
26
class Salsa20 extends StreamCipher
31
{
27
{
32
    /**
28
    /**
33
     * Part 1 of the state
29
     * Part 1 of the state
Line 49... Line 45...
49
     * @var int
45
     * @var int
50
     */
46
     */
51
    protected $key_length = 32; // = 256 bits
47
    protected $key_length = 32; // = 256 bits
52
 
48
 
53
    /**
49
    /**
54
     * @access private
-
 
55
     * @see \phpseclib3\Crypt\Salsa20::crypt()
50
     * @see \phpseclib3\Crypt\Salsa20::crypt()
56
     */
51
     */
57
    const ENCRYPT = 0;
52
    const ENCRYPT = 0;
58
 
53
 
59
    /**
54
    /**
60
     * @access private
-
 
61
     * @see \phpseclib3\Crypt\Salsa20::crypt()
55
     * @see \phpseclib3\Crypt\Salsa20::crypt()
62
     */
56
     */
63
    const DECRYPT = 1;
57
    const DECRYPT = 1;
64
 
58
 
65
    /**
59
    /**
Line 408... Line 402...
408
     * @param int $n
402
     * @param int $n
409
     * @return int
403
     * @return int
410
     */
404
     */
411
    protected static function leftRotate($x, $n)
405
    protected static function leftRotate($x, $n)
412
    {
406
    {
413
        $r1 = $x << $n;
-
 
414
        if (PHP_INT_SIZE == 8) {
407
        if (PHP_INT_SIZE == 8) {
-
 
408
            $r1 = $x << $n;
415
            $r1 &= 0xFFFFFFFF;
409
            $r1 &= 0xFFFFFFFF;
416
            $r2 = ($x & 0xFFFFFFFF) >> (32 - $n);
410
            $r2 = ($x & 0xFFFFFFFF) >> (32 - $n);
417
        } else {
411
        } else {
-
 
412
            $x = (int) $x;
-
 
413
            $r1 = $x << $n;
418
            $r2 = $x >> (32 - $n);
414
            $r2 = $x >> (32 - $n);
419
            $r2 &= (1 << $n) - 1;
415
            $r2 &= (1 << $n) - 1;
420
        }
416
        }
421
        return $r1 | $r2;
417
        return $r1 | $r2;
422
    }
418
    }
Line 493... Line 489...
493
    /**
489
    /**
494
     * Calculates Poly1305 MAC
490
     * Calculates Poly1305 MAC
495
     *
491
     *
496
     * @see self::decrypt()
492
     * @see self::decrypt()
497
     * @see self::encrypt()
493
     * @see self::encrypt()
498
     * @access private
-
 
499
     * @param string $ciphertext
494
     * @param string $ciphertext
500
     * @return string
495
     * @return string
501
     */
496
     */
502
    protected function poly1305($ciphertext)
497
    protected function poly1305($ciphertext)
503
    {
498
    {