changeset 21 | 48c4eec2b7e6 |
parent 18 | be944660c56a |
child 22 | 8c2e4d02f4ef |
20:7b1b88e27a20 | 21:48c4eec2b7e6 |
---|---|
108 } |
108 } |
109 } |
109 } |
110 if (!is_callable('sodium_add')) { |
110 if (!is_callable('sodium_add')) { |
111 /** |
111 /** |
112 * @see ParagonIE_Sodium_Compat::add() |
112 * @see ParagonIE_Sodium_Compat::add() |
113 * @param string $val |
113 * @param string $string1 |
114 * @param string $addv |
114 * @param string $string2 |
115 * @return void |
115 * @return void |
116 * @throws SodiumException |
116 * @throws SodiumException |
117 */ |
117 */ |
118 function sodium_add(&$val, $addv) |
118 function sodium_add(&$string1, $string2) |
119 { |
119 { |
120 ParagonIE_Sodium_Compat::add($val, $addv); |
120 ParagonIE_Sodium_Compat::add($string1, $string2); |
121 } |
121 } |
122 } |
122 } |
123 if (!is_callable('sodium_base642bin')) { |
123 if (!is_callable('sodium_base642bin')) { |
124 /** |
124 /** |
125 * @see ParagonIE_Sodium_Compat::bin2base64() |
125 * @see ParagonIE_Sodium_Compat::bin2base64() |
163 } |
163 } |
164 } |
164 } |
165 if (!is_callable('sodium_compare')) { |
165 if (!is_callable('sodium_compare')) { |
166 /** |
166 /** |
167 * @see ParagonIE_Sodium_Compat::compare() |
167 * @see ParagonIE_Sodium_Compat::compare() |
168 * @param string $a |
168 * @param string $string1 |
169 * @param string $b |
169 * @param string $string2 |
170 * @return int |
170 * @return int |
171 * @throws SodiumException |
171 * @throws SodiumException |
172 * @throws TypeError |
172 * @throws TypeError |
173 */ |
173 */ |
174 function sodium_compare($a, $b) |
174 function sodium_compare($string1, $string2) |
175 { |
175 { |
176 return ParagonIE_Sodium_Compat::compare($a, $b); |
176 return ParagonIE_Sodium_Compat::compare($string1, $string2); |
177 } |
177 } |
178 } |
178 } |
179 if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) { |
179 if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) { |
180 /** |
180 /** |
181 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() |
181 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() |
182 * @param string $message |
182 * @param string $ciphertext |
183 * @param string $assocData |
183 * @param string $additional_data |
184 * @param string $nonce |
184 * @param string $nonce |
185 * @param string $key |
185 * @param string $key |
186 * @return string|bool |
186 * @return string|bool |
187 */ |
187 */ |
188 function sodium_crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) |
188 function sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $additional_data, $nonce, $key) |
189 { |
189 { |
190 try { |
190 try { |
191 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); |
191 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt( |
192 $ciphertext, |
|
193 $additional_data, |
|
194 $nonce, |
|
195 $key |
|
196 ); |
|
197 } catch (Error $ex) { |
|
198 return false; |
|
199 } catch (Exception $ex) { |
|
200 if (($ex instanceof SodiumException) && ($ex->getMessage() === 'AES-256-GCM is not available')) { |
|
201 throw $ex; |
|
202 } |
|
203 return false; |
|
204 } |
|
205 } |
|
206 } |
|
207 if (!is_callable('sodium_crypto_aead_aes256gcm_encrypt')) { |
|
208 /** |
|
209 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() |
|
210 * @param string $message |
|
211 * @param string $additional_data |
|
212 * @param string $nonce |
|
213 * @param string $key |
|
214 * @return string |
|
215 * @throws SodiumException |
|
216 * @throws TypeError |
|
217 */ |
|
218 function sodium_crypto_aead_aes256gcm_encrypt($message, $additional_data, $nonce, $key) |
|
219 { |
|
220 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $additional_data, $nonce, $key); |
|
221 } |
|
222 } |
|
223 if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) { |
|
224 /** |
|
225 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() |
|
226 * @return bool |
|
227 */ |
|
228 function sodium_crypto_aead_aes256gcm_is_available() |
|
229 { |
|
230 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); |
|
231 } |
|
232 } |
|
233 if (!is_callable('sodium_crypto_aead_chacha20poly1305_decrypt')) { |
|
234 /** |
|
235 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() |
|
236 * @param string $ciphertext |
|
237 * @param string $additional_data |
|
238 * @param string $nonce |
|
239 * @param string $key |
|
240 * @return string|bool |
|
241 */ |
|
242 function sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $additional_data, $nonce, $key) |
|
243 { |
|
244 try { |
|
245 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt( |
|
246 $ciphertext, |
|
247 $additional_data, |
|
248 $nonce, |
|
249 $key |
|
250 ); |
|
192 } catch (Error $ex) { |
251 } catch (Error $ex) { |
193 return false; |
252 return false; |
194 } catch (Exception $ex) { |
253 } catch (Exception $ex) { |
195 return false; |
254 return false; |
196 } |
255 } |
197 } |
256 } |
198 } |
257 } |
199 if (!is_callable('sodium_crypto_aead_aes256gcm_encrypt')) { |
258 if (!is_callable('sodium_crypto_aead_chacha20poly1305_encrypt')) { |
200 /** |
259 /** |
201 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() |
260 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() |
202 * @param string $message |
261 * @param string $message |
203 * @param string $assocData |
262 * @param string $additional_data |
204 * @param string $nonce |
263 * @param string $nonce |
205 * @param string $key |
264 * @param string $key |
206 * @return string |
265 * @return string |
207 * @throws SodiumException |
266 * @throws SodiumException |
208 * @throws TypeError |
267 * @throws TypeError |
209 */ |
268 */ |
210 function sodium_crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key) |
269 function sodium_crypto_aead_chacha20poly1305_encrypt($message, $additional_data, $nonce, $key) |
211 { |
270 { |
212 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key); |
271 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt( |
213 } |
272 $message, |
214 } |
273 $additional_data, |
215 if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) { |
274 $nonce, |
216 /** |
275 $key |
217 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() |
276 ); |
218 * @return bool |
277 } |
219 */ |
278 } |
220 function sodium_crypto_aead_aes256gcm_is_available() |
279 if (!is_callable('sodium_crypto_aead_chacha20poly1305_keygen')) { |
221 { |
280 /** |
222 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); |
281 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen() |
223 } |
282 * @return string |
224 } |
283 * @throws Exception |
225 if (!is_callable('sodium_crypto_aead_chacha20poly1305_decrypt')) { |
284 */ |
226 /** |
285 function sodium_crypto_aead_chacha20poly1305_keygen() |
227 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() |
286 { |
228 * @param string $message |
287 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen(); |
229 * @param string $assocData |
288 } |
289 } |
|
290 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_decrypt')) { |
|
291 /** |
|
292 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() |
|
293 * @param string $message |
|
294 * @param string $additional_data |
|
230 * @param string $nonce |
295 * @param string $nonce |
231 * @param string $key |
296 * @param string $key |
232 * @return string|bool |
297 * @return string|bool |
233 */ |
298 */ |
234 function sodium_crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key) |
299 function sodium_crypto_aead_chacha20poly1305_ietf_decrypt($message, $additional_data, $nonce, $key) |
235 { |
300 { |
236 try { |
301 try { |
237 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key); |
302 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt( |
303 $message, |
|
304 $additional_data, |
|
305 $nonce, |
|
306 $key |
|
307 ); |
|
238 } catch (Error $ex) { |
308 } catch (Error $ex) { |
239 return false; |
309 return false; |
240 } catch (Exception $ex) { |
310 } catch (Exception $ex) { |
241 return false; |
311 return false; |
242 } |
312 } |
243 } |
313 } |
244 } |
314 } |
245 if (!is_callable('sodium_crypto_aead_chacha20poly1305_encrypt')) { |
315 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_encrypt')) { |
246 /** |
316 /** |
247 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() |
317 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() |
248 * @param string $message |
318 * @param string $message |
249 * @param string $assocData |
319 * @param string $additional_data |
250 * @param string $nonce |
320 * @param string $nonce |
251 * @param string $key |
321 * @param string $key |
252 * @return string |
322 * @return string |
253 * @throws SodiumException |
323 * @throws SodiumException |
254 * @throws TypeError |
324 * @throws TypeError |
255 */ |
325 */ |
256 function sodium_crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key) |
326 function sodium_crypto_aead_chacha20poly1305_ietf_encrypt($message, $additional_data, $nonce, $key) |
257 { |
327 { |
258 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key); |
328 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt( |
259 } |
329 $message, |
260 } |
330 $additional_data, |
261 if (!is_callable('sodium_crypto_aead_chacha20poly1305_keygen')) { |
331 $nonce, |
262 /** |
332 $key |
263 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen() |
333 ); |
264 * @return string |
334 } |
265 * @throws Exception |
335 } |
266 */ |
336 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_keygen')) { |
267 function sodium_crypto_aead_chacha20poly1305_keygen() |
337 /** |
268 { |
338 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen() |
269 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen(); |
339 * @return string |
270 } |
340 * @throws Exception |
271 } |
341 */ |
272 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_decrypt')) { |
342 function sodium_crypto_aead_chacha20poly1305_ietf_keygen() |
273 /** |
343 { |
274 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() |
344 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen(); |
275 * @param string $message |
345 } |
276 * @param string $assocData |
346 } |
347 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) { |
|
348 /** |
|
349 * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt() |
|
350 * @param string $ciphertext |
|
351 * @param string $additional_data |
|
277 * @param string $nonce |
352 * @param string $nonce |
278 * @param string $key |
353 * @param string $key |
279 * @return string|bool |
354 * @return string|bool |
280 */ |
355 */ |
281 function sodium_crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) |
356 function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $additional_data, $nonce, $key) |
282 { |
357 { |
283 try { |
358 try { |
284 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key); |
359 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt( |
360 $ciphertext, |
|
361 $additional_data, |
|
362 $nonce, |
|
363 $key, |
|
364 true |
|
365 ); |
|
285 } catch (Error $ex) { |
366 } catch (Error $ex) { |
286 return false; |
367 return false; |
287 } catch (Exception $ex) { |
368 } catch (Exception $ex) { |
288 return false; |
369 return false; |
289 } |
370 } |
290 } |
371 } |
291 } |
372 } |
292 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_encrypt')) { |
373 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) { |
293 /** |
374 /** |
294 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() |
375 * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt() |
295 * @param string $message |
376 * @param string $message |
296 * @param string $assocData |
377 * @param string $additional_data |
297 * @param string $nonce |
378 * @param string $nonce |
298 * @param string $key |
379 * @param string $key |
299 * @return string |
380 * @return string |
300 * @throws SodiumException |
381 * @throws SodiumException |
301 * @throws TypeError |
382 * @throws TypeError |
302 */ |
383 */ |
303 function sodium_crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) |
384 function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt( |
304 { |
385 $message, |
305 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key); |
386 $additional_data, |
306 } |
387 $nonce, |
307 } |
388 $key |
308 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_keygen')) { |
389 ) { |
309 /** |
390 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt( |
310 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen() |
391 $message, |
311 * @return string |
392 $additional_data, |
312 * @throws Exception |
393 $nonce, |
313 */ |
394 $key, |
314 function sodium_crypto_aead_chacha20poly1305_ietf_keygen() |
395 true |
315 { |
396 ); |
316 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen(); |
397 } |
317 } |
398 } |
318 } |
399 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_keygen')) { |
319 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) { |
400 /** |
320 /** |
401 * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen() |
321 * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt() |
402 * @return string |
322 * @param string $message |
403 * @throws Exception |
323 * @param string $assocData |
404 */ |
405 function sodium_crypto_aead_xchacha20poly1305_ietf_keygen() |
|
406 { |
|
407 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen(); |
|
408 } |
|
409 } |
|
410 if (!is_callable('sodium_crypto_auth')) { |
|
411 /** |
|
412 * @see ParagonIE_Sodium_Compat::crypto_auth() |
|
413 * @param string $message |
|
414 * @param string $key |
|
415 * @return string |
|
416 * @throws SodiumException |
|
417 * @throws TypeError |
|
418 */ |
|
419 function sodium_crypto_auth($message, $key) |
|
420 { |
|
421 return ParagonIE_Sodium_Compat::crypto_auth($message, $key); |
|
422 } |
|
423 } |
|
424 if (!is_callable('sodium_crypto_auth_keygen')) { |
|
425 /** |
|
426 * @see ParagonIE_Sodium_Compat::crypto_auth_keygen() |
|
427 * @return string |
|
428 * @throws Exception |
|
429 */ |
|
430 function sodium_crypto_auth_keygen() |
|
431 { |
|
432 return ParagonIE_Sodium_Compat::crypto_auth_keygen(); |
|
433 } |
|
434 } |
|
435 if (!is_callable('sodium_crypto_auth_verify')) { |
|
436 /** |
|
437 * @see ParagonIE_Sodium_Compat::crypto_auth_verify() |
|
438 * @param string $mac |
|
439 * @param string $message |
|
440 * @param string $key |
|
441 * @return bool |
|
442 * @throws SodiumException |
|
443 * @throws TypeError |
|
444 */ |
|
445 function sodium_crypto_auth_verify($mac, $message, $key) |
|
446 { |
|
447 return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key); |
|
448 } |
|
449 } |
|
450 if (!is_callable('sodium_crypto_box')) { |
|
451 /** |
|
452 * @see ParagonIE_Sodium_Compat::crypto_box() |
|
453 * @param string $message |
|
324 * @param string $nonce |
454 * @param string $nonce |
325 * @param string $key |
455 * @param string $key_pair |
456 * @return string |
|
457 * @throws SodiumException |
|
458 * @throws TypeError |
|
459 */ |
|
460 function sodium_crypto_box($message, $nonce, $key_pair) |
|
461 { |
|
462 return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $key_pair); |
|
463 } |
|
464 } |
|
465 if (!is_callable('sodium_crypto_box_keypair')) { |
|
466 /** |
|
467 * @see ParagonIE_Sodium_Compat::crypto_box_keypair() |
|
468 * @return string |
|
469 * @throws SodiumException |
|
470 * @throws TypeError |
|
471 */ |
|
472 function sodium_crypto_box_keypair() |
|
473 { |
|
474 return ParagonIE_Sodium_Compat::crypto_box_keypair(); |
|
475 } |
|
476 } |
|
477 if (!is_callable('sodium_crypto_box_keypair_from_secretkey_and_publickey')) { |
|
478 /** |
|
479 * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() |
|
480 * @param string $secret_key |
|
481 * @param string $public_key |
|
482 * @return string |
|
483 * @throws SodiumException |
|
484 * @throws TypeError |
|
485 */ |
|
486 function sodium_crypto_box_keypair_from_secretkey_and_publickey($secret_key, $public_key) |
|
487 { |
|
488 return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($secret_key, $public_key); |
|
489 } |
|
490 } |
|
491 if (!is_callable('sodium_crypto_box_open')) { |
|
492 /** |
|
493 * @see ParagonIE_Sodium_Compat::crypto_box_open() |
|
494 * @param string $ciphertext |
|
495 * @param string $nonce |
|
496 * @param string $key_pair |
|
326 * @return string|bool |
497 * @return string|bool |
327 */ |
498 */ |
328 function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) |
499 function sodium_crypto_box_open($ciphertext, $nonce, $key_pair) |
329 { |
500 { |
330 try { |
501 try { |
331 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key, true); |
502 return ParagonIE_Sodium_Compat::crypto_box_open($ciphertext, $nonce, $key_pair); |
332 } catch (Error $ex) { |
503 } catch (Error $ex) { |
333 return false; |
504 return false; |
334 } catch (Exception $ex) { |
505 } catch (Exception $ex) { |
335 return false; |
506 return false; |
336 } |
507 } |
337 } |
508 } |
338 } |
509 } |
339 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) { |
510 if (!is_callable('sodium_crypto_box_publickey')) { |
340 /** |
511 /** |
341 * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt() |
512 * @see ParagonIE_Sodium_Compat::crypto_box_publickey() |
342 * @param string $message |
513 * @param string $key_pair |
343 * @param string $assocData |
514 * @return string |
344 * @param string $nonce |
515 * @throws SodiumException |
345 * @param string $key |
516 * @throws TypeError |
346 * @return string |
517 */ |
347 * @throws SodiumException |
518 function sodium_crypto_box_publickey($key_pair) |
348 * @throws TypeError |
519 { |
349 */ |
520 return ParagonIE_Sodium_Compat::crypto_box_publickey($key_pair); |
350 function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) |
521 } |
351 { |
522 } |
352 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key, true); |
523 if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) { |
353 } |
524 /** |
354 } |
525 * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() |
355 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_keygen')) { |
526 * @param string $secret_key |
356 /** |
527 * @return string |
357 * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen() |
528 * @throws SodiumException |
358 * @return string |
529 * @throws TypeError |
359 * @throws Exception |
530 */ |
360 */ |
531 function sodium_crypto_box_publickey_from_secretkey($secret_key) |
361 function sodium_crypto_aead_xchacha20poly1305_ietf_keygen() |
532 { |
362 { |
533 return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($secret_key); |
363 return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen(); |
534 } |
364 } |
535 } |
365 } |
536 if (!is_callable('sodium_crypto_box_seal')) { |
366 if (!is_callable('sodium_crypto_auth')) { |
537 /** |
367 /** |
538 * @see ParagonIE_Sodium_Compat::crypto_box_seal() |
368 * @see ParagonIE_Sodium_Compat::crypto_auth() |
539 * @param string $message |
369 * @param string $message |
540 * @param string $public_key |
370 * @param string $key |
541 * @return string |
371 * @return string |
542 * @throws SodiumException |
372 * @throws SodiumException |
543 * @throws TypeError |
373 * @throws TypeError |
544 */ |
374 */ |
545 function sodium_crypto_box_seal($message, $public_key) |
375 function sodium_crypto_auth($message, $key) |
546 { |
376 { |
547 return ParagonIE_Sodium_Compat::crypto_box_seal($message, $public_key); |
377 return ParagonIE_Sodium_Compat::crypto_auth($message, $key); |
548 } |
378 } |
549 } |
379 } |
550 if (!is_callable('sodium_crypto_box_seal_open')) { |
380 if (!is_callable('sodium_crypto_auth_keygen')) { |
551 /** |
381 /** |
552 * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
382 * @see ParagonIE_Sodium_Compat::crypto_auth_keygen() |
553 * @param string $message |
383 * @return string |
554 * @param string $key_pair |
384 * @throws Exception |
|
385 */ |
|
386 function sodium_crypto_auth_keygen() |
|
387 { |
|
388 return ParagonIE_Sodium_Compat::crypto_auth_keygen(); |
|
389 } |
|
390 } |
|
391 if (!is_callable('sodium_crypto_auth_verify')) { |
|
392 /** |
|
393 * @see ParagonIE_Sodium_Compat::crypto_auth_verify() |
|
394 * @param string $mac |
|
395 * @param string $message |
|
396 * @param string $key |
|
397 * @return bool |
|
398 * @throws SodiumException |
|
399 * @throws TypeError |
|
400 */ |
|
401 function sodium_crypto_auth_verify($mac, $message, $key) |
|
402 { |
|
403 return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key); |
|
404 } |
|
405 } |
|
406 if (!is_callable('sodium_crypto_box')) { |
|
407 /** |
|
408 * @see ParagonIE_Sodium_Compat::crypto_box() |
|
409 * @param string $message |
|
410 * @param string $nonce |
|
411 * @param string $kp |
|
412 * @return string |
|
413 * @throws SodiumException |
|
414 * @throws TypeError |
|
415 */ |
|
416 function sodium_crypto_box($message, $nonce, $kp) |
|
417 { |
|
418 return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp); |
|
419 } |
|
420 } |
|
421 if (!is_callable('sodium_crypto_box_keypair')) { |
|
422 /** |
|
423 * @see ParagonIE_Sodium_Compat::crypto_box_keypair() |
|
424 * @return string |
|
425 * @throws SodiumException |
|
426 * @throws TypeError |
|
427 */ |
|
428 function sodium_crypto_box_keypair() |
|
429 { |
|
430 return ParagonIE_Sodium_Compat::crypto_box_keypair(); |
|
431 } |
|
432 } |
|
433 if (!is_callable('sodium_crypto_box_keypair_from_secretkey_and_publickey')) { |
|
434 /** |
|
435 * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() |
|
436 * @param string $sk |
|
437 * @param string $pk |
|
438 * @return string |
|
439 * @throws SodiumException |
|
440 * @throws TypeError |
|
441 */ |
|
442 function sodium_crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) |
|
443 { |
|
444 return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk); |
|
445 } |
|
446 } |
|
447 if (!is_callable('sodium_crypto_box_open')) { |
|
448 /** |
|
449 * @see ParagonIE_Sodium_Compat::crypto_box_open() |
|
450 * @param string $message |
|
451 * @param string $nonce |
|
452 * @param string $kp |
|
453 * @return string|bool |
555 * @return string|bool |
454 */ |
556 * @throws SodiumException |
455 function sodium_crypto_box_open($message, $nonce, $kp) |
557 */ |
558 function sodium_crypto_box_seal_open($message, $key_pair) |
|
456 { |
559 { |
457 try { |
560 try { |
458 return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp); |
561 return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $key_pair); |
459 } catch (Error $ex) { |
|
460 return false; |
|
461 } catch (Exception $ex) { |
|
462 return false; |
|
463 } |
|
464 } |
|
465 } |
|
466 if (!is_callable('sodium_crypto_box_publickey')) { |
|
467 /** |
|
468 * @see ParagonIE_Sodium_Compat::crypto_box_publickey() |
|
469 * @param string $keypair |
|
470 * @return string |
|
471 * @throws SodiumException |
|
472 * @throws TypeError |
|
473 */ |
|
474 function sodium_crypto_box_publickey($keypair) |
|
475 { |
|
476 return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair); |
|
477 } |
|
478 } |
|
479 if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) { |
|
480 /** |
|
481 * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() |
|
482 * @param string $sk |
|
483 * @return string |
|
484 * @throws SodiumException |
|
485 * @throws TypeError |
|
486 */ |
|
487 function sodium_crypto_box_publickey_from_secretkey($sk) |
|
488 { |
|
489 return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk); |
|
490 } |
|
491 } |
|
492 if (!is_callable('sodium_crypto_box_seal')) { |
|
493 /** |
|
494 * @see ParagonIE_Sodium_Compat::crypto_box_seal() |
|
495 * @param string $message |
|
496 * @param string $publicKey |
|
497 * @return string |
|
498 * @throws SodiumException |
|
499 * @throws TypeError |
|
500 */ |
|
501 function sodium_crypto_box_seal($message, $publicKey) |
|
502 { |
|
503 return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey); |
|
504 } |
|
505 } |
|
506 if (!is_callable('sodium_crypto_box_seal_open')) { |
|
507 /** |
|
508 * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
|
509 * @param string $message |
|
510 * @param string $kp |
|
511 * @return string|bool |
|
512 * @throws SodiumException |
|
513 */ |
|
514 function sodium_crypto_box_seal_open($message, $kp) |
|
515 { |
|
516 try { |
|
517 return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp); |
|
518 } catch (SodiumException $ex) { |
562 } catch (SodiumException $ex) { |
519 if ($ex->getMessage() === 'Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.') { |
563 if ($ex->getMessage() === 'Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.') { |
520 throw $ex; |
564 throw $ex; |
521 } |
565 } |
522 return false; |
566 return false; |
524 } |
568 } |
525 } |
569 } |
526 if (!is_callable('sodium_crypto_box_secretkey')) { |
570 if (!is_callable('sodium_crypto_box_secretkey')) { |
527 /** |
571 /** |
528 * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() |
572 * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() |
529 * @param string $keypair |
573 * @param string $key_pair |
530 * @return string |
574 * @return string |
531 * @throws SodiumException |
575 * @throws SodiumException |
532 * @throws TypeError |
576 * @throws TypeError |
533 */ |
577 */ |
534 function sodium_crypto_box_secretkey($keypair) |
578 function sodium_crypto_box_secretkey($key_pair) |
535 { |
579 { |
536 return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair); |
580 return ParagonIE_Sodium_Compat::crypto_box_secretkey($key_pair); |
537 } |
581 } |
538 } |
582 } |
539 if (!is_callable('sodium_crypto_box_seed_keypair')) { |
583 if (!is_callable('sodium_crypto_box_seed_keypair')) { |
540 /** |
584 /** |
541 * @see ParagonIE_Sodium_Compat::crypto_box_seed_keypair() |
585 * @see ParagonIE_Sodium_Compat::crypto_box_seed_keypair() |
552 if (!is_callable('sodium_crypto_generichash')) { |
596 if (!is_callable('sodium_crypto_generichash')) { |
553 /** |
597 /** |
554 * @see ParagonIE_Sodium_Compat::crypto_generichash() |
598 * @see ParagonIE_Sodium_Compat::crypto_generichash() |
555 * @param string $message |
599 * @param string $message |
556 * @param string|null $key |
600 * @param string|null $key |
557 * @param int $outLen |
601 * @param int $length |
558 * @return string |
602 * @return string |
559 * @throws SodiumException |
603 * @throws SodiumException |
560 * @throws TypeError |
604 * @throws TypeError |
561 */ |
605 */ |
562 function sodium_crypto_generichash($message, $key = null, $outLen = 32) |
606 function sodium_crypto_generichash($message, $key = null, $length = 32) |
563 { |
607 { |
564 return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen); |
608 return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $length); |
565 } |
609 } |
566 } |
610 } |
567 if (!is_callable('sodium_crypto_generichash_final')) { |
611 if (!is_callable('sodium_crypto_generichash_final')) { |
568 /** |
612 /** |
569 * @see ParagonIE_Sodium_Compat::crypto_generichash_final() |
613 * @see ParagonIE_Sodium_Compat::crypto_generichash_final() |
570 * @param string|null $ctx |
614 * @param string|null $state |
571 * @param int $outputLength |
615 * @param int $outputLength |
572 * @return string |
616 * @return string |
573 * @throws SodiumException |
617 * @throws SodiumException |
574 * @throws TypeError |
618 * @throws TypeError |
575 */ |
619 */ |
576 function sodium_crypto_generichash_final(&$ctx, $outputLength = 32) |
620 function sodium_crypto_generichash_final(&$state, $outputLength = 32) |
577 { |
621 { |
578 return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength); |
622 return ParagonIE_Sodium_Compat::crypto_generichash_final($state, $outputLength); |
579 } |
623 } |
580 } |
624 } |
581 if (!is_callable('sodium_crypto_generichash_init')) { |
625 if (!is_callable('sodium_crypto_generichash_init')) { |
582 /** |
626 /** |
583 * @see ParagonIE_Sodium_Compat::crypto_generichash_init() |
627 * @see ParagonIE_Sodium_Compat::crypto_generichash_init() |
584 * @param string|null $key |
628 * @param string|null $key |
585 * @param int $outLen |
629 * @param int $length |
586 * @return string |
630 * @return string |
587 * @throws SodiumException |
631 * @throws SodiumException |
588 * @throws TypeError |
632 * @throws TypeError |
589 */ |
633 */ |
590 function sodium_crypto_generichash_init($key = null, $outLen = 32) |
634 function sodium_crypto_generichash_init($key = null, $length = 32) |
591 { |
635 { |
592 return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen); |
636 return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $length); |
593 } |
637 } |
594 } |
638 } |
595 if (!is_callable('sodium_crypto_generichash_keygen')) { |
639 if (!is_callable('sodium_crypto_generichash_keygen')) { |
596 /** |
640 /** |
597 * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen() |
641 * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen() |
604 } |
648 } |
605 } |
649 } |
606 if (!is_callable('sodium_crypto_generichash_update')) { |
650 if (!is_callable('sodium_crypto_generichash_update')) { |
607 /** |
651 /** |
608 * @see ParagonIE_Sodium_Compat::crypto_generichash_update() |
652 * @see ParagonIE_Sodium_Compat::crypto_generichash_update() |
609 * @param string|null $ctx |
653 * @param string|null $state |
610 * @param string $message |
654 * @param string $message |
611 * @return void |
655 * @return void |
612 * @throws SodiumException |
656 * @throws SodiumException |
613 * @throws TypeError |
657 * @throws TypeError |
614 */ |
658 */ |
615 function sodium_crypto_generichash_update(&$ctx, $message = '') |
659 function sodium_crypto_generichash_update(&$state, $message = '') |
616 { |
660 { |
617 ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message); |
661 ParagonIE_Sodium_Compat::crypto_generichash_update($state, $message); |
618 } |
662 } |
619 } |
663 } |
620 if (!is_callable('sodium_crypto_kdf_keygen')) { |
664 if (!is_callable('sodium_crypto_kdf_keygen')) { |
621 /** |
665 /** |
622 * @see ParagonIE_Sodium_Compat::crypto_kdf_keygen() |
666 * @see ParagonIE_Sodium_Compat::crypto_kdf_keygen() |
629 } |
673 } |
630 } |
674 } |
631 if (!is_callable('sodium_crypto_kdf_derive_from_key')) { |
675 if (!is_callable('sodium_crypto_kdf_derive_from_key')) { |
632 /** |
676 /** |
633 * @see ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key() |
677 * @see ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key() |
634 * @param int $subkey_len |
678 * @param int $subkey_length |
635 * @param int $subkey_id |
679 * @param int $subkey_id |
636 * @param string $context |
680 * @param string $context |
637 * @param string $key |
681 * @param string $key |
638 * @return string |
682 * @return string |
639 * @throws Exception |
683 * @throws Exception |
640 */ |
684 */ |
641 function sodium_crypto_kdf_derive_from_key($subkey_len, $subkey_id, $context, $key) |
685 function sodium_crypto_kdf_derive_from_key($subkey_length, $subkey_id, $context, $key) |
642 { |
686 { |
643 return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key( |
687 return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key( |
644 $subkey_len, |
688 $subkey_length, |
645 $subkey_id, |
689 $subkey_id, |
646 $context, |
690 $context, |
647 $key |
691 $key |
648 ); |
692 ); |
649 } |
693 } |
690 return ParagonIE_Sodium_Compat::crypto_kx_keypair(); |
734 return ParagonIE_Sodium_Compat::crypto_kx_keypair(); |
691 } |
735 } |
692 } |
736 } |
693 if (!is_callable('sodium_crypto_kx_client_session_keys')) { |
737 if (!is_callable('sodium_crypto_kx_client_session_keys')) { |
694 /** |
738 /** |
695 * @param string $keypair |
739 * @param string $client_key_pair |
696 * @param string $serverPublicKey |
740 * @param string $server_key |
697 * @return array{0: string, 1: string} |
741 * @return array{0: string, 1: string} |
698 * @throws SodiumException |
742 * @throws SodiumException |
699 */ |
743 */ |
700 function sodium_crypto_kx_client_session_keys($keypair, $serverPublicKey) |
744 function sodium_crypto_kx_client_session_keys($client_key_pair, $server_key) |
701 { |
745 { |
702 return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($keypair, $serverPublicKey); |
746 return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($client_key_pair, $server_key); |
703 } |
747 } |
704 } |
748 } |
705 if (!is_callable('sodium_crypto_kx_server_session_keys')) { |
749 if (!is_callable('sodium_crypto_kx_server_session_keys')) { |
706 /** |
750 /** |
707 * @param string $keypair |
751 * @param string $server_key_pair |
708 * @param string $clientPublicKey |
752 * @param string $client_key |
709 * @return array{0: string, 1: string} |
753 * @return array{0: string, 1: string} |
710 * @throws SodiumException |
754 * @throws SodiumException |
711 */ |
755 */ |
712 function sodium_crypto_kx_server_session_keys($keypair, $clientPublicKey) |
756 function sodium_crypto_kx_server_session_keys($server_key_pair, $client_key) |
713 { |
757 { |
714 return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($keypair, $clientPublicKey); |
758 return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($server_key_pair, $client_key); |
715 } |
759 } |
716 } |
760 } |
717 if (!is_callable('sodium_crypto_kx_secretkey')) { |
761 if (!is_callable('sodium_crypto_kx_secretkey')) { |
718 /** |
762 /** |
719 * @param string $keypair |
763 * @param string $key_pair |
720 * @return string |
764 * @return string |
721 * @throws Exception |
765 * @throws Exception |
722 */ |
766 */ |
723 function sodium_crypto_kx_secretkey($keypair) |
767 function sodium_crypto_kx_secretkey($key_pair) |
724 { |
768 { |
725 return ParagonIE_Sodium_Compat::crypto_kx_secretkey($keypair); |
769 return ParagonIE_Sodium_Compat::crypto_kx_secretkey($key_pair); |
726 } |
770 } |
727 } |
771 } |
728 if (!is_callable('sodium_crypto_kx_publickey')) { |
772 if (!is_callable('sodium_crypto_kx_publickey')) { |
729 /** |
773 /** |
730 * @param string $keypair |
774 * @param string $key_pair |
731 * @return string |
775 * @return string |
732 * @throws Exception |
776 * @throws Exception |
733 */ |
777 */ |
734 function sodium_crypto_kx_publickey($keypair) |
778 function sodium_crypto_kx_publickey($key_pair) |
735 { |
779 { |
736 return ParagonIE_Sodium_Compat::crypto_kx_publickey($keypair); |
780 return ParagonIE_Sodium_Compat::crypto_kx_publickey($key_pair); |
737 } |
781 } |
738 } |
782 } |
739 if (!is_callable('sodium_crypto_pwhash')) { |
783 if (!is_callable('sodium_crypto_pwhash')) { |
740 /** |
784 /** |
741 * @see ParagonIE_Sodium_Compat::crypto_pwhash() |
785 * @see ParagonIE_Sodium_Compat::crypto_pwhash() |
742 * @param int $outlen |
786 * @param int $length |
743 * @param string $passwd |
787 * @param string $passwd |
744 * @param string $salt |
788 * @param string $salt |
745 * @param int $opslimit |
789 * @param int $opslimit |
746 * @param int $memlimit |
790 * @param int $memlimit |
747 * @param int|null $algo |
791 * @param int|null $algo |
748 * @return string |
792 * @return string |
749 * @throws SodiumException |
793 * @throws SodiumException |
750 * @throws TypeError |
794 * @throws TypeError |
751 */ |
795 */ |
752 function sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo = null) |
796 function sodium_crypto_pwhash($length, $passwd, $salt, $opslimit, $memlimit, $algo = null) |
753 { |
797 { |
754 return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo); |
798 return ParagonIE_Sodium_Compat::crypto_pwhash($length, $passwd, $salt, $opslimit, $memlimit, $algo); |
755 } |
799 } |
756 } |
800 } |
757 if (!is_callable('sodium_crypto_pwhash_str')) { |
801 if (!is_callable('sodium_crypto_pwhash_str')) { |
758 /** |
802 /** |
759 * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() |
803 * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() |
799 } |
843 } |
800 } |
844 } |
801 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) { |
845 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) { |
802 /** |
846 /** |
803 * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() |
847 * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() |
804 * @param int $outlen |
848 * @param int $length |
805 * @param string $passwd |
849 * @param string $passwd |
806 * @param string $salt |
850 * @param string $salt |
807 * @param int $opslimit |
851 * @param int $opslimit |
808 * @param int $memlimit |
852 * @param int $memlimit |
809 * @return string |
853 * @return string |
810 * @throws SodiumException |
854 * @throws SodiumException |
811 * @throws TypeError |
855 * @throws TypeError |
812 */ |
856 */ |
813 function sodium_crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit) |
857 function sodium_crypto_pwhash_scryptsalsa208sha256($length, $passwd, $salt, $opslimit, $memlimit) |
814 { |
858 { |
815 return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit); |
859 return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256( |
860 $length, |
|
861 $passwd, |
|
862 $salt, |
|
863 $opslimit, |
|
864 $memlimit |
|
865 ); |
|
816 } |
866 } |
817 } |
867 } |
818 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str')) { |
868 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str')) { |
819 /** |
869 /** |
820 * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() |
870 * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() |
898 } |
948 } |
899 } |
949 } |
900 if (!is_callable('sodium_crypto_secretbox_open')) { |
950 if (!is_callable('sodium_crypto_secretbox_open')) { |
901 /** |
951 /** |
902 * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() |
952 * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() |
903 * @param string $message |
953 * @param string $ciphertext |
904 * @param string $nonce |
954 * @param string $nonce |
905 * @param string $key |
955 * @param string $key |
906 * @return string|bool |
956 * @return string|bool |
907 */ |
957 */ |
908 function sodium_crypto_secretbox_open($message, $nonce, $key) |
958 function sodium_crypto_secretbox_open($ciphertext, $nonce, $key) |
909 { |
959 { |
910 try { |
960 try { |
911 return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key); |
961 return ParagonIE_Sodium_Compat::crypto_secretbox_open($ciphertext, $nonce, $key); |
912 } catch (Error $ex) { |
962 } catch (Error $ex) { |
913 return false; |
963 return false; |
914 } catch (Exception $ex) { |
964 } catch (Exception $ex) { |
915 return false; |
965 return false; |
916 } |
966 } |
928 } |
978 } |
929 } |
979 } |
930 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) { |
980 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) { |
931 /** |
981 /** |
932 * @param string $state |
982 * @param string $state |
933 * @param string $msg |
983 * @param string $message |
934 * @param string $aad |
984 * @param string $additional_data |
935 * @param int $tag |
985 * @param int $tag |
936 * @return string |
986 * @return string |
937 * @throws SodiumException |
987 * @throws SodiumException |
938 */ |
988 */ |
939 function sodium_crypto_secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) |
989 function sodium_crypto_secretstream_xchacha20poly1305_push( |
940 { |
990 &$state, |
941 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push($state, $msg, $aad, $tag); |
991 $message, |
992 $additional_data = '', |
|
993 $tag = 0 |
|
994 ) { |
|
995 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push( |
|
996 $state, |
|
997 $message, |
|
998 $additional_data, |
|
999 $tag |
|
1000 ); |
|
942 } |
1001 } |
943 } |
1002 } |
944 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_pull')) { |
1003 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_pull')) { |
945 /** |
1004 /** |
946 * @param string $header |
1005 * @param string $header |
954 } |
1013 } |
955 } |
1014 } |
956 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) { |
1015 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) { |
957 /** |
1016 /** |
958 * @param string $state |
1017 * @param string $state |
959 * @param string $cipher |
1018 * @param string $ciphertext |
960 * @param string $aad |
1019 * @param string $additional_data |
961 * @return bool|array{0: string, 1: int} |
1020 * @return bool|array{0: string, 1: int} |
962 * @throws SodiumException |
1021 * @throws SodiumException |
963 */ |
1022 */ |
964 function sodium_crypto_secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '') |
1023 function sodium_crypto_secretstream_xchacha20poly1305_pull(&$state, $ciphertext, $additional_data = '') |
965 { |
1024 { |
966 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull($state, $cipher, $aad); |
1025 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull( |
1026 $state, |
|
1027 $ciphertext, |
|
1028 $additional_data |
|
1029 ); |
|
967 } |
1030 } |
968 } |
1031 } |
969 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_rekey')) { |
1032 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_rekey')) { |
970 /** |
1033 /** |
971 * @param string $state |
1034 * @param string $state |
1014 } |
1077 } |
1015 if (!is_callable('sodium_crypto_sign')) { |
1078 if (!is_callable('sodium_crypto_sign')) { |
1016 /** |
1079 /** |
1017 * @see ParagonIE_Sodium_Compat::crypto_sign() |
1080 * @see ParagonIE_Sodium_Compat::crypto_sign() |
1018 * @param string $message |
1081 * @param string $message |
1019 * @param string $sk |
1082 * @param string $secret_key |
1020 * @return string |
1083 * @return string |
1021 * @throws SodiumException |
1084 * @throws SodiumException |
1022 * @throws TypeError |
1085 * @throws TypeError |
1023 */ |
1086 */ |
1024 function sodium_crypto_sign($message, $sk) |
1087 function sodium_crypto_sign($message, $secret_key) |
1025 { |
1088 { |
1026 return ParagonIE_Sodium_Compat::crypto_sign($message, $sk); |
1089 return ParagonIE_Sodium_Compat::crypto_sign($message, $secret_key); |
1027 } |
1090 } |
1028 } |
1091 } |
1029 if (!is_callable('sodium_crypto_sign_detached')) { |
1092 if (!is_callable('sodium_crypto_sign_detached')) { |
1030 /** |
1093 /** |
1031 * @see ParagonIE_Sodium_Compat::crypto_sign_detached() |
1094 * @see ParagonIE_Sodium_Compat::crypto_sign_detached() |
1032 * @param string $message |
1095 * @param string $message |
1033 * @param string $sk |
1096 * @param string $secret_key |
1034 * @return string |
1097 * @return string |
1035 * @throws SodiumException |
1098 * @throws SodiumException |
1036 * @throws TypeError |
1099 * @throws TypeError |
1037 */ |
1100 */ |
1038 function sodium_crypto_sign_detached($message, $sk) |
1101 function sodium_crypto_sign_detached($message, $secret_key) |
1039 { |
1102 { |
1040 return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk); |
1103 return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $secret_key); |
1041 } |
1104 } |
1042 } |
1105 } |
1043 if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) { |
1106 if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) { |
1044 /** |
1107 /** |
1045 * @see ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey() |
1108 * @see ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey() |
1046 * @param string $sk |
1109 * @param string $secret_key |
1047 * @param string $pk |
1110 * @param string $public_key |
1048 * @return string |
1111 * @return string |
1049 * @throws SodiumException |
1112 * @throws SodiumException |
1050 * @throws TypeError |
1113 * @throws TypeError |
1051 */ |
1114 */ |
1052 function sodium_crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk) |
1115 function sodium_crypto_sign_keypair_from_secretkey_and_publickey($secret_key, $public_key) |
1053 { |
1116 { |
1054 return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk); |
1117 return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($secret_key, $public_key); |
1055 } |
1118 } |
1056 } |
1119 } |
1057 if (!is_callable('sodium_crypto_sign_keypair')) { |
1120 if (!is_callable('sodium_crypto_sign_keypair')) { |
1058 /** |
1121 /** |
1059 * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() |
1122 * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() |
1068 } |
1131 } |
1069 if (!is_callable('sodium_crypto_sign_open')) { |
1132 if (!is_callable('sodium_crypto_sign_open')) { |
1070 /** |
1133 /** |
1071 * @see ParagonIE_Sodium_Compat::crypto_sign_open() |
1134 * @see ParagonIE_Sodium_Compat::crypto_sign_open() |
1072 * @param string $signedMessage |
1135 * @param string $signedMessage |
1073 * @param string $pk |
1136 * @param string $public_key |
1074 * @return string|bool |
1137 * @return string|bool |
1075 */ |
1138 */ |
1076 function sodium_crypto_sign_open($signedMessage, $pk) |
1139 function sodium_crypto_sign_open($signedMessage, $public_key) |
1077 { |
1140 { |
1078 try { |
1141 try { |
1079 return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk); |
1142 return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $public_key); |
1080 } catch (Error $ex) { |
1143 } catch (Error $ex) { |
1081 return false; |
1144 return false; |
1082 } catch (Exception $ex) { |
1145 } catch (Exception $ex) { |
1083 return false; |
1146 return false; |
1084 } |
1147 } |
1085 } |
1148 } |
1086 } |
1149 } |
1087 if (!is_callable('sodium_crypto_sign_publickey')) { |
1150 if (!is_callable('sodium_crypto_sign_publickey')) { |
1088 /** |
1151 /** |
1089 * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() |
1152 * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() |
1090 * @param string $keypair |
1153 * @param string $key_pair |
1091 * @return string |
1154 * @return string |
1092 * @throws SodiumException |
1155 * @throws SodiumException |
1093 * @throws TypeError |
1156 * @throws TypeError |
1094 */ |
1157 */ |
1095 function sodium_crypto_sign_publickey($keypair) |
1158 function sodium_crypto_sign_publickey($key_pair) |
1096 { |
1159 { |
1097 return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair); |
1160 return ParagonIE_Sodium_Compat::crypto_sign_publickey($key_pair); |
1098 } |
1161 } |
1099 } |
1162 } |
1100 if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) { |
1163 if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) { |
1101 /** |
1164 /** |
1102 * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() |
1165 * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() |
1103 * @param string $sk |
1166 * @param string $secret_key |
1104 * @return string |
1167 * @return string |
1105 * @throws SodiumException |
1168 * @throws SodiumException |
1106 * @throws TypeError |
1169 * @throws TypeError |
1107 */ |
1170 */ |
1108 function sodium_crypto_sign_publickey_from_secretkey($sk) |
1171 function sodium_crypto_sign_publickey_from_secretkey($secret_key) |
1109 { |
1172 { |
1110 return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk); |
1173 return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($secret_key); |
1111 } |
1174 } |
1112 } |
1175 } |
1113 if (!is_callable('sodium_crypto_sign_secretkey')) { |
1176 if (!is_callable('sodium_crypto_sign_secretkey')) { |
1114 /** |
1177 /** |
1115 * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() |
1178 * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() |
1116 * @param string $keypair |
1179 * @param string $key_pair |
1117 * @return string |
1180 * @return string |
1118 * @throws SodiumException |
1181 * @throws SodiumException |
1119 * @throws TypeError |
1182 * @throws TypeError |
1120 */ |
1183 */ |
1121 function sodium_crypto_sign_secretkey($keypair) |
1184 function sodium_crypto_sign_secretkey($key_pair) |
1122 { |
1185 { |
1123 return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair); |
1186 return ParagonIE_Sodium_Compat::crypto_sign_secretkey($key_pair); |
1124 } |
1187 } |
1125 } |
1188 } |
1126 if (!is_callable('sodium_crypto_sign_seed_keypair')) { |
1189 if (!is_callable('sodium_crypto_sign_seed_keypair')) { |
1127 /** |
1190 /** |
1128 * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() |
1191 * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() |
1139 if (!is_callable('sodium_crypto_sign_verify_detached')) { |
1202 if (!is_callable('sodium_crypto_sign_verify_detached')) { |
1140 /** |
1203 /** |
1141 * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() |
1204 * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() |
1142 * @param string $signature |
1205 * @param string $signature |
1143 * @param string $message |
1206 * @param string $message |
1144 * @param string $pk |
1207 * @param string $public_key |
1145 * @return bool |
1208 * @return bool |
1146 * @throws SodiumException |
1209 * @throws SodiumException |
1147 * @throws TypeError |
1210 * @throws TypeError |
1148 */ |
1211 */ |
1149 function sodium_crypto_sign_verify_detached($signature, $message, $pk) |
1212 function sodium_crypto_sign_verify_detached($signature, $message, $public_key) |
1150 { |
1213 { |
1151 return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk); |
1214 return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $public_key); |
1152 } |
1215 } |
1153 } |
1216 } |
1154 if (!is_callable('sodium_crypto_sign_ed25519_pk_to_curve25519')) { |
1217 if (!is_callable('sodium_crypto_sign_ed25519_pk_to_curve25519')) { |
1155 /** |
1218 /** |
1156 * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() |
1219 * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() |
1157 * @param string $pk |
1220 * @param string $public_key |
1158 * @return string |
1221 * @return string |
1159 * @throws SodiumException |
1222 * @throws SodiumException |
1160 * @throws TypeError |
1223 * @throws TypeError |
1161 */ |
1224 */ |
1162 function sodium_crypto_sign_ed25519_pk_to_curve25519($pk) |
1225 function sodium_crypto_sign_ed25519_pk_to_curve25519($public_key) |
1163 { |
1226 { |
1164 return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk); |
1227 return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($public_key); |
1165 } |
1228 } |
1166 } |
1229 } |
1167 if (!is_callable('sodium_crypto_sign_ed25519_sk_to_curve25519')) { |
1230 if (!is_callable('sodium_crypto_sign_ed25519_sk_to_curve25519')) { |
1168 /** |
1231 /** |
1169 * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() |
1232 * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() |
1170 * @param string $sk |
1233 * @param string $secret_key |
1171 * @return string |
1234 * @return string |
1172 * @throws SodiumException |
1235 * @throws SodiumException |
1173 * @throws TypeError |
1236 * @throws TypeError |
1174 */ |
1237 */ |
1175 function sodium_crypto_sign_ed25519_sk_to_curve25519($sk) |
1238 function sodium_crypto_sign_ed25519_sk_to_curve25519($secret_key) |
1176 { |
1239 { |
1177 return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk); |
1240 return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($secret_key); |
1178 } |
1241 } |
1179 } |
1242 } |
1180 if (!is_callable('sodium_crypto_stream')) { |
1243 if (!is_callable('sodium_crypto_stream')) { |
1181 /** |
1244 /** |
1182 * @see ParagonIE_Sodium_Compat::crypto_stream() |
1245 * @see ParagonIE_Sodium_Compat::crypto_stream() |
1183 * @param int $len |
1246 * @param int $length |
1184 * @param string $nonce |
1247 * @param string $nonce |
1185 * @param string $key |
1248 * @param string $key |
1186 * @return string |
1249 * @return string |
1187 * @throws SodiumException |
1250 * @throws SodiumException |
1188 * @throws TypeError |
1251 * @throws TypeError |
1189 */ |
1252 */ |
1190 function sodium_crypto_stream($len, $nonce, $key) |
1253 function sodium_crypto_stream($length, $nonce, $key) |
1191 { |
1254 { |
1192 return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key); |
1255 return ParagonIE_Sodium_Compat::crypto_stream($length, $nonce, $key); |
1193 } |
1256 } |
1194 } |
1257 } |
1195 if (!is_callable('sodium_crypto_stream_keygen')) { |
1258 if (!is_callable('sodium_crypto_stream_keygen')) { |
1196 /** |
1259 /** |
1197 * @see ParagonIE_Sodium_Compat::crypto_stream_keygen() |
1260 * @see ParagonIE_Sodium_Compat::crypto_stream_keygen() |
1221 require_once dirname(__FILE__) . '/stream-xchacha20.php'; |
1284 require_once dirname(__FILE__) . '/stream-xchacha20.php'; |
1222 if (!is_callable('sodium_hex2bin')) { |
1285 if (!is_callable('sodium_hex2bin')) { |
1223 /** |
1286 /** |
1224 * @see ParagonIE_Sodium_Compat::hex2bin() |
1287 * @see ParagonIE_Sodium_Compat::hex2bin() |
1225 * @param string $string |
1288 * @param string $string |
1226 * @return string |
1289 * @param string $ignore |
1227 * @throws SodiumException |
1290 * @return string |
1228 * @throws TypeError |
1291 * @throws SodiumException |
1229 */ |
1292 * @throws TypeError |
1230 function sodium_hex2bin($string) |
1293 */ |
1231 { |
1294 function sodium_hex2bin($string, $ignore = '') |
1232 return ParagonIE_Sodium_Compat::hex2bin($string); |
1295 { |
1296 return ParagonIE_Sodium_Compat::hex2bin($string, $ignore); |
|
1233 } |
1297 } |
1234 } |
1298 } |
1235 if (!is_callable('sodium_increment')) { |
1299 if (!is_callable('sodium_increment')) { |
1236 /** |
1300 /** |
1237 * @see ParagonIE_Sodium_Compat::increment() |
1301 * @see ParagonIE_Sodium_Compat::increment() |
1276 } |
1340 } |
1277 } |
1341 } |
1278 if (!is_callable('sodium_memcmp')) { |
1342 if (!is_callable('sodium_memcmp')) { |
1279 /** |
1343 /** |
1280 * @see ParagonIE_Sodium_Compat::memcmp() |
1344 * @see ParagonIE_Sodium_Compat::memcmp() |
1281 * @param string $a |
1345 * @param string $string1 |
1282 * @param string $b |
1346 * @param string $string2 |
1283 * @return int |
1347 * @return int |
1284 * @throws SodiumException |
1348 * @throws SodiumException |
1285 * @throws TypeError |
1349 * @throws TypeError |
1286 */ |
1350 */ |
1287 function sodium_memcmp($a, $b) |
1351 function sodium_memcmp($string1, $string2) |
1288 { |
1352 { |
1289 return ParagonIE_Sodium_Compat::memcmp($a, $b); |
1353 return ParagonIE_Sodium_Compat::memcmp($string1, $string2); |
1290 } |
1354 } |
1291 } |
1355 } |
1292 if (!is_callable('sodium_memzero')) { |
1356 if (!is_callable('sodium_memzero')) { |
1293 /** |
1357 /** |
1294 * @see ParagonIE_Sodium_Compat::memzero() |
1358 * @see ParagonIE_Sodium_Compat::memzero() |
1295 * @param string $str |
1359 * @param string $string |
1296 * @return void |
1360 * @return void |
1297 * @throws SodiumException |
1361 * @throws SodiumException |
1298 * @throws TypeError |
1362 * @throws TypeError |
1299 */ |
1363 * |
1300 function sodium_memzero(&$str) |
1364 * @psalm-suppress ReferenceConstraintViolation |
1301 { |
1365 */ |
1302 ParagonIE_Sodium_Compat::memzero($str); |
1366 function sodium_memzero(&$string) |
1367 { |
|
1368 ParagonIE_Sodium_Compat::memzero($string); |
|
1303 } |
1369 } |
1304 } |
1370 } |
1305 if (!is_callable('sodium_pad')) { |
1371 if (!is_callable('sodium_pad')) { |
1306 /** |
1372 /** |
1307 * @see ParagonIE_Sodium_Compat::pad() |
1373 * @see ParagonIE_Sodium_Compat::pad() |
1308 * @param string $unpadded |
1374 * @param string $unpadded |
1309 * @param int $blockSize |
1375 * @param int $block_size |
1310 * @return int |
1376 * @return string |
1311 * @throws SodiumException |
1377 * @throws SodiumException |
1312 * @throws TypeError |
1378 * @throws TypeError |
1313 */ |
1379 */ |
1314 function sodium_pad($unpadded, $blockSize) |
1380 function sodium_pad($unpadded, $block_size) |
1315 { |
1381 { |
1316 return ParagonIE_Sodium_Compat::pad($unpadded, $blockSize, true); |
1382 return ParagonIE_Sodium_Compat::pad($unpadded, $block_size, true); |
1317 } |
1383 } |
1318 } |
1384 } |
1319 if (!is_callable('sodium_unpad')) { |
1385 if (!is_callable('sodium_unpad')) { |
1320 /** |
1386 /** |
1321 * @see ParagonIE_Sodium_Compat::pad() |
1387 * @see ParagonIE_Sodium_Compat::pad() |
1322 * @param string $padded |
1388 * @param string $padded |
1323 * @param int $blockSize |
1389 * @param int $block_size |
1324 * @return int |
1390 * @return string |
1325 * @throws SodiumException |
1391 * @throws SodiumException |
1326 * @throws TypeError |
1392 * @throws TypeError |
1327 */ |
1393 */ |
1328 function sodium_unpad($padded, $blockSize) |
1394 function sodium_unpad($padded, $block_size) |
1329 { |
1395 { |
1330 return ParagonIE_Sodium_Compat::unpad($padded, $blockSize, true); |
1396 return ParagonIE_Sodium_Compat::unpad($padded, $block_size, true); |
1331 } |
1397 } |
1332 } |
1398 } |
1333 if (!is_callable('sodium_randombytes_buf')) { |
1399 if (!is_callable('sodium_randombytes_buf')) { |
1334 /** |
1400 /** |
1335 * @see ParagonIE_Sodium_Compat::randombytes_buf() |
1401 * @see ParagonIE_Sodium_Compat::randombytes_buf() |