1 | <?php |
||
23 | final class RSA |
||
24 | { |
||
25 | /** |
||
26 | * Probabilistic Signature Scheme. |
||
27 | */ |
||
28 | public const SIGNATURE_PSS = 1; |
||
29 | |||
30 | /** |
||
31 | * Use the PKCS#1. |
||
32 | */ |
||
33 | public const SIGNATURE_PKCS1 = 2; |
||
34 | |||
35 | /** |
||
36 | * @param BigInteger $x |
||
37 | * @param int $xLen |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | private static function convertIntegerToOctetString(BigInteger $x, int $xLen): string |
||
50 | |||
51 | /** |
||
52 | * MGF1. |
||
53 | * |
||
54 | * @param string $mgfSeed |
||
55 | * @param int $maskLen |
||
56 | * @param Hash $mgfHash |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | private static function getMGF1(string $mgfSeed, int $maskLen, Hash $mgfHash): string |
||
71 | |||
72 | /** |
||
73 | * EMSA-PSS-ENCODE. |
||
74 | * |
||
75 | * @param string $message |
||
76 | * @param int $modulusLength |
||
77 | * @param Hash $hash |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | private static function encodeEMSAPSS(string $message, int $modulusLength, Hash $hash): string |
||
101 | |||
102 | /** |
||
103 | * EMSA-PSS-VERIFY. |
||
104 | * |
||
105 | * @param string $m |
||
106 | * @param string $em |
||
107 | * @param int $emBits |
||
108 | * @param Hash $hash |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | private static function verifyEMSAPSS(string $m, string $em, int $emBits, Hash $hash): bool |
||
145 | |||
146 | /** |
||
147 | * @param string $m |
||
148 | * @param int $emBits |
||
149 | * @param Hash $hash |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | private static function encodeEMSA15(string $m, int $emBits, Hash $hash): string |
||
182 | |||
183 | /** |
||
184 | * @param RSAKey $key |
||
185 | * @param string $message |
||
186 | * @param string $hash |
||
187 | * @param int $mode |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | public static function sign(RSAKey $key, string $message, string $hash, int $mode): string |
||
202 | |||
203 | /** |
||
204 | * Create a signature. |
||
205 | * |
||
206 | * @param RSAKey $key |
||
207 | * @param string $message |
||
208 | * @param string $hash |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | public static function signWithPSS(RSAKey $key, string $message, string $hash): string |
||
220 | |||
221 | /** |
||
222 | * Create a signature. |
||
223 | * |
||
224 | * @param RSAKey $key |
||
225 | * @param string $message |
||
226 | * @param string $hash |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | public static function signWithPKCS15(RSAKey $key, string $message, string $hash): string |
||
238 | |||
239 | /** |
||
240 | * @param RSAKey $key |
||
241 | * @param string $message |
||
242 | * @param string $signature |
||
243 | * @param string $hash |
||
244 | * @param int $mode |
||
245 | * |
||
246 | * @return bool |
||
247 | */ |
||
248 | public static function verify(RSAKey $key, string $message, string $signature, string $hash, int $mode): bool |
||
259 | |||
260 | /** |
||
261 | * Verifies a signature. |
||
262 | * |
||
263 | * @param RSAKey $key |
||
264 | * @param string $message |
||
265 | * @param string $signature |
||
266 | * @param string $hash |
||
267 | * |
||
268 | * @return bool |
||
269 | */ |
||
270 | public static function verifyWithPSS(RSAKey $key, string $message, string $signature, string $hash): bool |
||
282 | |||
283 | /** |
||
284 | * Verifies a signature. |
||
285 | * |
||
286 | * @param RSAKey $key |
||
287 | * @param string $message |
||
288 | * @param string $signature |
||
289 | * @param string $hash |
||
290 | * |
||
291 | * @return bool |
||
292 | */ |
||
293 | public static function verifyWithPKCS15(RSAKey $key, string $message, string $signature, string $hash): bool |
||
304 | } |
||
305 |