1 | <?php |
||
16 | trait AESKW |
||
17 | { |
||
18 | /** |
||
19 | * The initial value used to wrap the key and check the integrity when unwrapped. |
||
20 | * The RFC3394 set this value to 0xA6A6A6A6A6A6A6A6 |
||
21 | * The RFC5649 set this value to 0xA65959A6XXXXXXXX (The part with XXXXXXXX is the MLI, depends on the padding). |
||
22 | * |
||
23 | * @param string $key The key |
||
24 | * @param bool $padding_enabled Enable padding (RFC5649) |
||
25 | * |
||
26 | * @return string |
||
27 | * |
||
28 | * @see https://tools.ietf.org/html/rfc3394#section-2.2.3.1 |
||
29 | */ |
||
30 | private static function getInitialValue(&$key, $padding_enabled) |
||
44 | |||
45 | /** |
||
46 | * @param string $key |
||
47 | * @param bool $padding_enabled |
||
48 | * @param string $iv |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | private static function checkInitialValue(&$key, $padding_enabled, $iv) |
||
86 | |||
87 | /** |
||
88 | * @param string $key The Key to wrap |
||
89 | * @param bool $padding_enabled |
||
90 | */ |
||
91 | private static function checkKeySize($key, $padding_enabled) |
||
96 | |||
97 | /** |
||
98 | * @param string $kek The Key Encryption Key |
||
99 | * @param string $key The key to wrap |
||
100 | * @param bool $padding_enabled If false, the key to wrap must be a sequence of one or more 64-bit blocks (RFC3394 compliant), else the key size must be at least one octet (RFC5649 compliant) |
||
101 | * |
||
102 | * @return string The wrapped key |
||
103 | */ |
||
104 | public static function wrap($kek, $key, $padding_enabled = false) |
||
135 | |||
136 | /** |
||
137 | * @param string $kek The Key Encryption Key |
||
138 | * @param string $key The key to unwrap |
||
139 | * @param bool $padding_enabled If false, the AIV check must be RFC3394 compliant, else it must be RFC5649 or RFC3394 compliant |
||
140 | * |
||
141 | * @return string The key unwrapped |
||
142 | */ |
||
143 | public static function unwrap($kek, $key, $padding_enabled = false) |
||
177 | |||
178 | /** |
||
179 | * @param int $bits |
||
180 | * @param int $value |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | private static function toXBits($bits, $value) |
||
188 | |||
189 | /** |
||
190 | * @param string $value |
||
191 | * |
||
192 | * @return string |
||
193 | */ |
||
194 | private static function getMSB($value) |
||
198 | |||
199 | /** |
||
200 | * @param string $value |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | private static function getLSB($value) |
||
208 | |||
209 | /** |
||
210 | * @param string $kek |
||
211 | * |
||
212 | * @return \AESKW\EncryptorInterface |
||
213 | */ |
||
214 | private static function getEncryptor($kek) |
||
224 | } |
||
225 |