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) |
||
133 | |||
134 | /** |
||
135 | * @param string $kek The Key Encryption Key |
||
136 | * @param string $key The key to unwrap |
||
137 | * @param bool $padding_enabled If false, the AIV check must be RFC3394 compliant, else it must be RFC5649 or RFC3394 compliant |
||
138 | * |
||
139 | * @return string The key unwrapped |
||
140 | */ |
||
141 | public static function unwrap($kek, $key, $padding_enabled = false) |
||
173 | |||
174 | /** |
||
175 | * @param int $bits |
||
176 | * @param int $value |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | private static function toXBits($bits, $value) |
||
184 | |||
185 | /** |
||
186 | * @param string $value |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | private static function getMSB($value) |
||
194 | |||
195 | /** |
||
196 | * @param string $value |
||
197 | * |
||
198 | * @return string |
||
199 | */ |
||
200 | private static function getLSB($value) |
||
204 | |||
205 | /** |
||
206 | * @param string $kek |
||
207 | * |
||
208 | * @return \AESKW\EncryptorInterface |
||
209 | */ |
||
210 | private static function getEncryptor($kek) |
||
218 | } |
||
219 |