/var/www/html/wp-includes/sodium_compat/src/Core/AES/KeySchedule.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php

if (class_exists('ParagonIE_Sodium_Core_AES_KeySchedule'false)) {
    return;
}

/**
 * @internal This should only be used by sodium_compat
 */
class ParagonIE_Sodium_Core_AES_KeySchedule
{
    
/** @var array<int, int> $skey -- has size 120 */
    
protected $skey;

    
/** @var bool $expanded */
    
protected $expanded false;

    
/** @var int $numRounds */
    
private $numRounds;

    
/**
     * @param array $skey
     * @param int $numRounds
     */
    
public function __construct(array $skey$numRounds 10)
    {
        
$this->skey $skey;
        
$this->numRounds $numRounds;
    }

    
/**
     * Get a value at an arbitrary index. Mostly used for unit testing.
     *
     * @param int $i
     * @return int
     */
    
public function get($i)
    {
        return 
$this->skey[$i];
    }

    
/**
     * @return int
     */
    
public function getNumRounds()
    {
        return 
$this->numRounds;
    }

    
/**
     * @param int $offset
     * @return ParagonIE_Sodium_Core_AES_Block
     */
    
public function getRoundKey($offset)
    {
        return 
ParagonIE_Sodium_Core_AES_Block::fromArray(
            
array_slice($this->skey$offset8)
        );
    }

    
/**
     * Return an expanded key schedule
     *
     * @return ParagonIE_Sodium_Core_AES_Expanded
     */
    
public function expand()
    {
        
$exp = new ParagonIE_Sodium_Core_AES_Expanded(
            
array_fill(01200),
            
$this->numRounds
        
);
        
$n = ($exp->numRounds 1) << 2;
        for (
$u 0$v 0$u $n; ++$u$v += 2) {
            
$x $y $this->skey[$u];
            
$x &= 0x55555555;
            
$exp->skey[$v] = ($x | ($x << 1)) & ParagonIE_Sodium_Core_Util::U32_MAX;
            
$y &= 0xAAAAAAAA;
            
$exp->skey[$v 1] = ($y | ($y >> 1)) & ParagonIE_Sodium_Core_Util::U32_MAX;
        }
        return 
$exp;
    }
}