31#define PHP_SODIUM_ZSTR_TRUNCATE(zs, len) do { ZSTR_LEN(zs) = (len); } while(0)
35#if (defined(__amd64) || defined(__amd64__) || defined(__x86_64__) || defined(__i386__) || \
36 defined(_M_AMD64) || defined(_M_IX86) || defined(__aarch64__) || defined(_M_ARM64))
53#ifndef crypto_kdf_BYTES_MIN
54# define crypto_kdf_BYTES_MIN 16
55# define crypto_kdf_BYTES_MAX 64
56# define crypto_kdf_CONTEXTBYTES 8
57# define crypto_kdf_KEYBYTES 32
60#ifndef crypto_kx_SEEDBYTES
61# define crypto_kx_SEEDBYTES 32
62# define crypto_kx_SESSIONKEYBYTES 32
63# define crypto_kx_PUBLICKEYBYTES 32
64# define crypto_kx_SECRETKEYBYTES 32
69#ifndef crypto_aead_chacha20poly1305_IETF_KEYBYTES
70# define crypto_aead_chacha20poly1305_IETF_KEYBYTES crypto_aead_chacha20poly1305_KEYBYTES
72#ifndef crypto_aead_chacha20poly1305_IETF_NSECBYTES
73# define crypto_aead_chacha20poly1305_IETF_NSECBYTES crypto_aead_chacha20poly1305_NSECBYTES
75#ifndef crypto_aead_chacha20poly1305_IETF_ABYTES
76# define crypto_aead_chacha20poly1305_IETF_ABYTES crypto_aead_chacha20poly1305_ABYTES
79#if defined(crypto_secretstream_xchacha20poly1305_ABYTES) && SODIUM_LIBRARY_VERSION_MAJOR < 10
80# undef crypto_secretstream_xchacha20poly1305_ABYTES
83#ifndef crypto_pwhash_OPSLIMIT_MIN
84# define crypto_pwhash_OPSLIMIT_MIN crypto_pwhash_OPSLIMIT_INTERACTIVE
86#ifndef crypto_pwhash_MEMLIMIT_MIN
87# define crypto_pwhash_MEMLIMIT_MIN crypto_pwhash_MEMLIMIT_INTERACTIVE
89#ifndef crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN
90# define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE
92#ifndef crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN
93# define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE
120#ifdef COMPILE_DL_SODIUM
125static void sodium_remove_param_values_from_backtrace(
zend_object *obj) {
144 sodium_remove_param_values_from_backtrace(obj);
148static void sodium_separate_string(
zval *
zv) {
159 if (sodium_init() < 0) {
164 sodium_exception_ce->create_object = sodium_exception_create_object;
166#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
172 register_libsodium_symbols(module_number);
198 sodium_remove_param_values_from_backtrace(
EG(
exception));
224 sodium_remove_param_values_from_backtrace(
EG(
exception));
233 sodium_separate_string(val_zv);
248 "zs", &val_zv, &addv, &addv_len) ==
FAILURE) {
249 sodium_remove_param_values_from_backtrace(
EG(
exception));
258 sodium_separate_string(val_zv);
261 if (val_len != addv_len) {
262 zend_argument_error(sodium_exception_ce, 1,
"and argument #2 ($string_2) must have the same length");
278 sodium_remove_param_values_from_backtrace(
EG(
exception));
282 zend_argument_error(sodium_exception_ce, 1,
"and argument #2 ($string_2) must have the same length");
299 sodium_remove_param_values_from_backtrace(
EG(
exception));
302 if (key_len != crypto_shorthash_KEYBYTES) {
303 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SHORTHASH_KEYBYTES bytes long");
306 hash = zend_string_alloc(crypto_shorthash_BYTES, 0);
308 (
unsigned long long) msg_len,
key) != 0) {
309 zend_string_efree(
hash);
323 unsigned char *nonce;
332 sodium_remove_param_values_from_backtrace(
EG(
exception));
335 if (nonce_len != crypto_secretbox_NONCEBYTES) {
336 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SECRETBOX_NONCEBYTES bytes long");
339 if (key_len != crypto_secretbox_KEYBYTES) {
340 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes long");
343 if (
SIZE_MAX - msg_len <= crypto_secretbox_MACBYTES) {
347 ciphertext = zend_string_alloc((
size_t) msg_len + crypto_secretbox_MACBYTES, 0);
348 if (crypto_secretbox_easy((
unsigned char *)
ZSTR_VAL(ciphertext),
349 msg, (
unsigned long long) msg_len,
351 zend_string_efree(ciphertext);
355 ZSTR_VAL(ciphertext)[msg_len + crypto_secretbox_MACBYTES] = 0;
364 unsigned char *ciphertext;
365 unsigned char *nonce;
367 size_t ciphertext_len;
371 &ciphertext, &ciphertext_len,
374 sodium_remove_param_values_from_backtrace(
EG(
exception));
377 if (nonce_len != crypto_secretbox_NONCEBYTES) {
378 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SECRETBOX_NONCEBYTES bytes long");
381 if (key_len != crypto_secretbox_KEYBYTES) {
382 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes long");
385 if (ciphertext_len < crypto_secretbox_MACBYTES) {
388 msg = zend_string_alloc
389 ((
size_t) ciphertext_len - crypto_secretbox_MACBYTES, 0);
390 if (crypto_secretbox_open_easy((
unsigned char *)
ZSTR_VAL(
msg), ciphertext,
391 (
unsigned long long) ciphertext_len,
393 zend_string_efree(
msg);
396 ZSTR_VAL(
msg)[ciphertext_len - crypto_secretbox_MACBYTES] = 0;
406 zend_long hash_len = crypto_generichash_BYTES;
414 sodium_remove_param_values_from_backtrace(
EG(
exception));
417 if (hash_len < crypto_generichash_BYTES_MIN ||
418 hash_len > crypto_generichash_BYTES_MAX) {
423 (key_len < crypto_generichash_KEYBYTES_MIN ||
424 key_len > crypto_generichash_KEYBYTES_MAX)) {
428 hash = zend_string_alloc(hash_len, 0);
429 if (crypto_generichash((
unsigned char *)
ZSTR_VAL(
hash), (
size_t) hash_len,
430 msg, (
unsigned long long) msg_len,
431 key, (
size_t) key_len) != 0) {
432 zend_string_efree(
hash);
443 crypto_generichash_state state_tmp;
446 size_t state_len =
sizeof (crypto_generichash_state);
447 zend_long hash_len = crypto_generichash_BYTES;
453 sodium_remove_param_values_from_backtrace(
EG(
exception));
456 if (hash_len < crypto_generichash_BYTES_MIN ||
457 hash_len > crypto_generichash_BYTES_MAX) {
462 (key_len < crypto_generichash_KEYBYTES_MIN ||
463 key_len > crypto_generichash_KEYBYTES_MAX)) {
467 memset(&state_tmp, 0,
sizeof state_tmp);
468 if (crypto_generichash_init((
void *) &state_tmp,
key, (
size_t) key_len,
469 (
size_t) hash_len) != 0) {
473 state = zend_string_alloc(state_len, 0);
483 crypto_generichash_state state_tmp;
486 unsigned char *
state;
492 sodium_remove_param_values_from_backtrace(
EG(
exception));
500 sodium_separate_string(state_zv);
503 if (state_len !=
sizeof (crypto_generichash_state)) {
508 if (crypto_generichash_update((
void *) &state_tmp,
msg,
509 (
unsigned long long) msg_len) != 0) {
522 crypto_generichash_state state_tmp;
525 unsigned char *
state;
527 zend_long hash_len = crypto_generichash_BYTES;
530 &state_zv, &hash_len) ==
FAILURE) {
531 sodium_remove_param_values_from_backtrace(
EG(
exception));
539 sodium_separate_string(state_zv);
542 if (state_len !=
sizeof (crypto_generichash_state)) {
546 if (hash_len < crypto_generichash_BYTES_MIN ||
547 hash_len > crypto_generichash_BYTES_MAX) {
551 hash = zend_string_alloc(hash_len, 0);
553 if (crypto_generichash_final((
void *) &state_tmp,
555 (
size_t) hash_len) != 0) {
557 zend_string_efree(
hash);
577 keypair_len = crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES;
578 keypair = zend_string_alloc(keypair_len, 0);
579 if (crypto_box_keypair((
unsigned char *)
ZSTR_VAL(keypair) +
580 crypto_box_SECRETKEYBYTES,
581 (
unsigned char *)
ZSTR_VAL(keypair)) != 0) {
582 zend_string_efree(keypair);
599 &seed, &seed_len) ==
FAILURE) {
600 sodium_remove_param_values_from_backtrace(
EG(
exception));
603 if (seed_len != crypto_box_SEEDBYTES) {
604 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_BOX_SEEDBYTES bytes long");
607 keypair_len = crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES;
608 keypair = zend_string_alloc(keypair_len, 0);
609 if (crypto_box_seed_keypair((
unsigned char *)
ZSTR_VAL(keypair) +
610 crypto_box_SECRETKEYBYTES,
611 (
unsigned char *)
ZSTR_VAL(keypair),
613 zend_string_efree(keypair);
628 size_t publickey_len;
629 size_t secretkey_len;
632 &secretkey, &secretkey_len,
633 &publickey, &publickey_len) ==
FAILURE) {
634 sodium_remove_param_values_from_backtrace(
EG(
exception));
637 if (secretkey_len != crypto_box_SECRETKEYBYTES) {
638 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_BOX_SECRETKEYBYTES bytes long");
641 if (publickey_len != crypto_box_PUBLICKEYBYTES) {
642 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_BOX_PUBLICKEYBYTES bytes long");
645 keypair_len = crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES;
646 keypair = zend_string_alloc(keypair_len, 0);
649 crypto_box_PUBLICKEYBYTES);
658 unsigned char *keypair;
662 &keypair, &keypair_len) ==
FAILURE) {
663 sodium_remove_param_values_from_backtrace(
EG(
exception));
667 crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES) {
668 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long");
671 secretkey = zend_string_alloc(crypto_box_SECRETKEYBYTES, 0);
673 ZSTR_VAL(secretkey)[crypto_box_SECRETKEYBYTES] = 0;
681 unsigned char *keypair;
685 &keypair, &keypair_len) ==
FAILURE) {
686 sodium_remove_param_values_from_backtrace(
EG(
exception));
690 crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES) {
691 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long");
694 publickey = zend_string_alloc(crypto_box_PUBLICKEYBYTES, 0);
696 crypto_box_PUBLICKEYBYTES);
697 ZSTR_VAL(publickey)[crypto_box_PUBLICKEYBYTES] = 0;
705 unsigned char *secretkey;
706 size_t secretkey_len;
709 &secretkey, &secretkey_len) ==
FAILURE) {
710 sodium_remove_param_values_from_backtrace(
EG(
exception));
713 if (secretkey_len != crypto_box_SECRETKEYBYTES) {
714 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_BOX_SECRETKEYBYTES bytes long");
717 publickey = zend_string_alloc(crypto_box_PUBLICKEYBYTES, 0);
718 (
void)
sizeof(
int[crypto_scalarmult_BYTES ==
719 crypto_box_PUBLICKEYBYTES ? 1 : -1]);
720 (
void)
sizeof(
int[crypto_scalarmult_SCALARBYTES ==
721 crypto_box_SECRETKEYBYTES ? 1 : -1]);
722 crypto_scalarmult_base((
unsigned char *)
ZSTR_VAL(publickey), secretkey);
723 ZSTR_VAL(publickey)[crypto_box_PUBLICKEYBYTES] = 0;
731 unsigned char *keypair;
733 unsigned char *nonce;
734 unsigned char *publickey;
735 unsigned char *secretkey;
743 &keypair, &keypair_len) ==
FAILURE) {
744 sodium_remove_param_values_from_backtrace(
EG(
exception));
747 if (nonce_len != crypto_box_NONCEBYTES) {
748 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_BOX_NONCEBYTES bytes long");
751 if (keypair_len != crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES) {
752 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long");
756 publickey = keypair + crypto_box_SECRETKEYBYTES;
757 if (
SIZE_MAX - msg_len <= crypto_box_MACBYTES) {
761 ciphertext = zend_string_alloc((
size_t) msg_len + crypto_box_MACBYTES, 0);
762 if (crypto_box_easy((
unsigned char *)
ZSTR_VAL(ciphertext),
msg,
763 (
unsigned long long) msg_len,
764 nonce, publickey, secretkey) != 0) {
765 zend_string_efree(ciphertext);
769 ZSTR_VAL(ciphertext)[msg_len + crypto_box_MACBYTES] = 0;
777 unsigned char *ciphertext;
778 unsigned char *keypair;
779 unsigned char *nonce;
780 unsigned char *publickey;
781 unsigned char *secretkey;
782 size_t ciphertext_len;
787 &ciphertext, &ciphertext_len,
789 &keypair, &keypair_len) ==
FAILURE) {
790 sodium_remove_param_values_from_backtrace(
EG(
exception));
793 if (nonce_len != crypto_box_NONCEBYTES) {
794 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_BOX_NONCEBYTES bytes long");
797 if (keypair_len != crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES) {
798 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long");
802 publickey = keypair + crypto_box_SECRETKEYBYTES;
803 if (ciphertext_len < crypto_box_MACBYTES) {
806 msg = zend_string_alloc((
size_t) ciphertext_len - crypto_box_MACBYTES, 0);
807 if (crypto_box_open_easy((
unsigned char *)
ZSTR_VAL(
msg), ciphertext,
808 (
unsigned long long) ciphertext_len,
809 nonce, publickey, secretkey) != 0) {
810 zend_string_efree(
msg);
813 ZSTR_VAL(
msg)[ciphertext_len - crypto_box_MACBYTES] = 0;
822 unsigned char *publickey;
824 size_t publickey_len;
828 &publickey, &publickey_len) ==
FAILURE) {
829 sodium_remove_param_values_from_backtrace(
EG(
exception));
832 if (publickey_len != crypto_box_PUBLICKEYBYTES) {
833 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_BOX_PUBLICKEYBYTES bytes long");
836 if (
SIZE_MAX - msg_len <= crypto_box_SEALBYTES) {
840 ciphertext = zend_string_alloc((
size_t) msg_len + crypto_box_SEALBYTES, 0);
841 if (crypto_box_seal((
unsigned char *)
ZSTR_VAL(ciphertext),
msg,
842 (
unsigned long long) msg_len, publickey) != 0) {
843 zend_string_efree(ciphertext);
847 ZSTR_VAL(ciphertext)[msg_len + crypto_box_SEALBYTES] = 0;
855 unsigned char *ciphertext;
856 unsigned char *keypair;
857 unsigned char *publickey;
858 unsigned char *secretkey;
859 size_t ciphertext_len;
863 &ciphertext, &ciphertext_len,
864 &keypair, &keypair_len) ==
FAILURE) {
865 sodium_remove_param_values_from_backtrace(
EG(
exception));
868 if (keypair_len != crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES) {
869 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long");
873 publickey = keypair + crypto_box_SECRETKEYBYTES;
874 if (ciphertext_len < crypto_box_SEALBYTES) {
877 msg = zend_string_alloc((
size_t) ciphertext_len - crypto_box_SEALBYTES, 0);
878 if (crypto_box_seal_open((
unsigned char *)
ZSTR_VAL(
msg), ciphertext,
879 (
unsigned long long) ciphertext_len,
880 publickey, secretkey) != 0) {
881 zend_string_efree(
msg);
884 ZSTR_VAL(
msg)[ciphertext_len - crypto_box_SEALBYTES] = 0;
897 keypair_len = crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES;
898 keypair = zend_string_alloc(keypair_len, 0);
899 if (crypto_sign_keypair((
unsigned char *)
ZSTR_VAL(keypair) +
900 crypto_sign_SECRETKEYBYTES,
901 (
unsigned char *)
ZSTR_VAL(keypair)) != 0) {
902 zend_string_efree(keypair);
919 &seed, &seed_len) ==
FAILURE) {
920 sodium_remove_param_values_from_backtrace(
EG(
exception));
923 if (seed_len != crypto_sign_SEEDBYTES) {
924 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_SEEDBYTES bytes long");
927 keypair_len = crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES;
928 keypair = zend_string_alloc(keypair_len, 0);
929 if (crypto_sign_seed_keypair((
unsigned char *)
ZSTR_VAL(keypair) +
930 crypto_sign_SECRETKEYBYTES,
931 (
unsigned char *)
ZSTR_VAL(keypair),
933 zend_string_efree(keypair);
948 size_t publickey_len;
949 size_t secretkey_len;
952 &secretkey, &secretkey_len,
953 &publickey, &publickey_len) ==
FAILURE) {
954 sodium_remove_param_values_from_backtrace(
EG(
exception));
957 if (secretkey_len != crypto_sign_SECRETKEYBYTES) {
958 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes long");
961 if (publickey_len != crypto_sign_PUBLICKEYBYTES) {
962 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes long");
965 keypair_len = crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES;
966 keypair = zend_string_alloc(keypair_len, 0);
969 crypto_sign_PUBLICKEYBYTES);
979 size_t secretkey_len;
982 &secretkey, &secretkey_len) ==
FAILURE) {
983 sodium_remove_param_values_from_backtrace(
EG(
exception));
986 if (secretkey_len != crypto_sign_SECRETKEYBYTES) {
987 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes long");
990 publickey = zend_string_alloc(crypto_sign_PUBLICKEYBYTES, 0);
992 if (crypto_sign_ed25519_sk_to_pk((
unsigned char *)
ZSTR_VAL(publickey),
993 (
const unsigned char *) secretkey) != 0) {
994 zend_string_efree(publickey);
996 "internal error", 0);
999 ZSTR_VAL(publickey)[crypto_sign_PUBLICKEYBYTES] = 0;
1007 unsigned char *keypair;
1011 &keypair, &keypair_len) ==
FAILURE) {
1012 sodium_remove_param_values_from_backtrace(
EG(
exception));
1016 crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES) {
1017 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_KEYPAIRBYTES bytes long");
1020 secretkey = zend_string_alloc(crypto_sign_SECRETKEYBYTES, 0);
1021 memcpy(
ZSTR_VAL(secretkey), keypair, crypto_sign_SECRETKEYBYTES);
1022 ZSTR_VAL(secretkey)[crypto_sign_SECRETKEYBYTES] = 0;
1030 unsigned char *keypair;
1034 &keypair, &keypair_len) ==
FAILURE) {
1035 sodium_remove_param_values_from_backtrace(
EG(
exception));
1039 crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES) {
1040 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_KEYPAIRBYTES bytes long");
1043 publickey = zend_string_alloc(crypto_sign_PUBLICKEYBYTES, 0);
1044 memcpy(
ZSTR_VAL(publickey), keypair + crypto_sign_SECRETKEYBYTES,
1045 crypto_sign_PUBLICKEYBYTES);
1046 ZSTR_VAL(publickey)[crypto_sign_PUBLICKEYBYTES] = 0;
1055 unsigned char *secretkey;
1056 unsigned long long msg_signed_real_len;
1058 size_t msg_signed_len;
1059 size_t secretkey_len;
1063 &secretkey, &secretkey_len) ==
FAILURE) {
1064 sodium_remove_param_values_from_backtrace(
EG(
exception));
1067 if (secretkey_len != crypto_sign_SECRETKEYBYTES) {
1068 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes long");
1071 if (
SIZE_MAX - msg_len <= crypto_sign_BYTES) {
1075 msg_signed_len = msg_len + crypto_sign_BYTES;
1076 msg_signed = zend_string_alloc((
size_t) msg_signed_len, 0);
1077 if (crypto_sign((
unsigned char *)
ZSTR_VAL(msg_signed),
1078 &msg_signed_real_len,
msg,
1079 (
unsigned long long) msg_len, secretkey) != 0) {
1080 zend_string_efree(msg_signed);
1084 if (msg_signed_real_len >=
SIZE_MAX || msg_signed_real_len > msg_signed_len) {
1085 zend_string_efree(msg_signed);
1090 ZSTR_VAL(msg_signed)[msg_signed_real_len] = 0;
1098 unsigned char *msg_signed;
1099 unsigned char *publickey;
1100 unsigned long long msg_real_len;
1102 size_t msg_signed_len;
1103 size_t publickey_len;
1106 &msg_signed, &msg_signed_len,
1107 &publickey, &publickey_len) ==
FAILURE) {
1108 sodium_remove_param_values_from_backtrace(
EG(
exception));
1111 if (publickey_len != crypto_sign_PUBLICKEYBYTES) {
1112 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes long");
1115 msg_len = msg_signed_len;
1120 msg = zend_string_alloc((
size_t) msg_len, 0);
1121 if (crypto_sign_open((
unsigned char *)
ZSTR_VAL(
msg), &msg_real_len,
1122 msg_signed, (
unsigned long long) msg_signed_len,
1124 zend_string_efree(
msg);
1127 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_signed_len) {
1128 zend_string_efree(
msg);
1142 unsigned char *secretkey;
1143 unsigned long long signature_real_len;
1145 size_t secretkey_len;
1149 &secretkey, &secretkey_len) ==
FAILURE) {
1150 sodium_remove_param_values_from_backtrace(
EG(
exception));
1153 if (secretkey_len != crypto_sign_SECRETKEYBYTES) {
1154 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes long");
1157 signature = zend_string_alloc((
size_t) crypto_sign_BYTES, 0);
1159 if (crypto_sign_detached((
unsigned char *)
ZSTR_VAL(signature),
1160 &signature_real_len,
msg,
1161 (
unsigned long long) msg_len, secretkey) != 0) {
1162 zend_string_efree(signature);
1166 if (signature_real_len <= 0U || signature_real_len > crypto_sign_BYTES) {
1167 zend_string_efree(signature);
1172 ZSTR_VAL(signature)[signature_real_len] = 0;
1180 unsigned char *publickey;
1181 unsigned char *signature;
1183 size_t publickey_len;
1184 size_t signature_len;
1187 &signature, &signature_len,
1189 &publickey, &publickey_len) ==
FAILURE) {
1190 sodium_remove_param_values_from_backtrace(
EG(
exception));
1193 if (signature_len != crypto_sign_BYTES) {
1194 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_BYTES bytes long");
1197 if (publickey_len != crypto_sign_PUBLICKEYBYTES) {
1198 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes long");
1201 if (crypto_sign_verify_detached(signature,
1202 msg, (
unsigned long long) msg_len,
1213 unsigned char *nonce;
1222 sodium_remove_param_values_from_backtrace(
EG(
exception));
1225 if (ciphertext_len <= 0 || ciphertext_len >=
SIZE_MAX) {
1229 if (nonce_len != crypto_stream_NONCEBYTES) {
1230 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_STREAM_NONCEBYTES bytes long");
1233 if (key_len != crypto_stream_KEYBYTES) {
1234 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_STREAM_KEYBYTES bytes long");
1237 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
1238 if (crypto_stream((
unsigned char *)
ZSTR_VAL(ciphertext),
1239 (
unsigned long long) ciphertext_len, nonce,
key) != 0) {
1240 zend_string_efree(ciphertext);
1244 ZSTR_VAL(ciphertext)[ciphertext_len] = 0;
1254 unsigned char *nonce;
1255 size_t ciphertext_len;
1264 sodium_remove_param_values_from_backtrace(
EG(
exception));
1267 if (nonce_len != crypto_stream_NONCEBYTES) {
1268 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_STREAM_NONCEBYTES bytes long");
1271 if (key_len != crypto_stream_KEYBYTES) {
1272 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_STREAM_KEYBYTES bytes long");
1275 ciphertext_len = msg_len;
1276 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
1277 if (crypto_stream_xor((
unsigned char *)
ZSTR_VAL(ciphertext),
msg,
1278 (
unsigned long long) msg_len, nonce,
key) != 0) {
1279 zend_string_efree(ciphertext);
1283 ZSTR_VAL(ciphertext)[ciphertext_len] = 0;
1288#ifdef crypto_stream_xchacha20_KEYBYTES
1293 unsigned char *nonce;
1302 sodium_remove_param_values_from_backtrace(
EG(
exception));
1305 if (ciphertext_len <= 0 || ciphertext_len >=
SIZE_MAX) {
1309 if (nonce_len != crypto_stream_xchacha20_NONCEBYTES) {
1310 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES bytes long");
1313 if (key_len != crypto_stream_xchacha20_KEYBYTES) {
1314 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_STREAM_XCHACHA20_KEYBYTES bytes long");
1317 ciphertext = zend_string_checked_alloc((
size_t) ciphertext_len, 0);
1318 if (crypto_stream_xchacha20((
unsigned char *)
ZSTR_VAL(ciphertext),
1319 (
unsigned long long) ciphertext_len, nonce,
key) != 0) {
1320 zend_string_free(ciphertext);
1324 ZSTR_VAL(ciphertext)[ciphertext_len] = 0;
1334 unsigned char *nonce;
1335 size_t ciphertext_len;
1344 sodium_remove_param_values_from_backtrace(
EG(
exception));
1347 if (nonce_len != crypto_stream_xchacha20_NONCEBYTES) {
1348 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES bytes long");
1351 if (key_len != crypto_stream_xchacha20_KEYBYTES) {
1352 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_STREAM_XCHACHA20_KEYBYTES bytes long");
1355 ciphertext_len = msg_len;
1356 ciphertext = zend_string_checked_alloc((
size_t) ciphertext_len, 0);
1357 if (crypto_stream_xchacha20_xor((
unsigned char *)
ZSTR_VAL(ciphertext),
msg,
1358 (
unsigned long long) msg_len, nonce,
key) != 0) {
1359 zend_string_free(ciphertext);
1363 ZSTR_VAL(ciphertext)[ciphertext_len] = 0;
1373 unsigned char *nonce;
1376 size_t ciphertext_len;
1386 sodium_remove_param_values_from_backtrace(
EG(
exception));
1389 if (nonce_len != crypto_stream_xchacha20_NONCEBYTES) {
1390 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES bytes long");
1393 if (key_len != crypto_stream_xchacha20_KEYBYTES) {
1394 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_STREAM_XCHACHA20_KEYBYTES bytes long");
1397 ciphertext_len = msg_len;
1398 ciphertext = zend_string_checked_alloc((
size_t) ciphertext_len, 0);
1399 if (crypto_stream_xchacha20_xor_ic((
unsigned char *)
ZSTR_VAL(ciphertext),
msg,
1400 (
unsigned long long) msg_len, nonce,
1401 (uint64_t) ic,
key) != 0) {
1402 zend_string_free(ciphertext);
1406 ZSTR_VAL(ciphertext)[ciphertext_len] = 0;
1412#ifdef crypto_pwhash_SALTBYTES
1416 unsigned char *salt;
1426 alg = (
zend_long) crypto_pwhash_ALG_DEFAULT;
1429 &passwd, &passwd_len,
1431 &opslimit, &memlimit, &alg) ==
FAILURE) {
1432 sodium_remove_param_values_from_backtrace(
EG(
exception));
1435 if (hash_len <= 0) {
1439 if (hash_len >= 0xffffffff) {
1443 if (passwd_len >= 0xffffffff) {
1447 if (opslimit <= 0) {
1451 if (memlimit <= 0 || memlimit >
SIZE_MAX) {
1455 if (alg != crypto_pwhash_ALG_ARGON2I13
1456# ifdef crypto_pwhash_ALG_ARGON2ID13
1457 && alg != crypto_pwhash_ALG_ARGON2ID13
1459 && alg != crypto_pwhash_ALG_DEFAULT) {
1463 if (passwd_len <= 0) {
1466 if (salt_len != crypto_pwhash_SALTBYTES) {
1467 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_PWHASH_SALTBYTES bytes long");
1477 hash = zend_string_alloc((
size_t) hash_len, 0);
1479# ifdef crypto_pwhash_ALG_ARGON2ID13
1480 if (alg == crypto_pwhash_ALG_ARGON2ID13) {
1481 ret = crypto_pwhash_argon2id
1482 ((
unsigned char *)
ZSTR_VAL(
hash), (
unsigned long long) hash_len,
1483 passwd, (
unsigned long long) passwd_len, salt,
1484 (
unsigned long long) opslimit, (
size_t) memlimit, (
int) alg);
1489 ((
unsigned char *)
ZSTR_VAL(
hash), (
unsigned long long) hash_len,
1490 passwd, (
unsigned long long) passwd_len, salt,
1491 (
unsigned long long) opslimit, (
size_t) memlimit, (
int) alg);
1494 zend_string_efree(
hash);
1513 &passwd, &passwd_len,
1514 &opslimit, &memlimit) ==
FAILURE) {
1515 sodium_remove_param_values_from_backtrace(
EG(
exception));
1518 if (opslimit <= 0) {
1522 if (memlimit <= 0 || memlimit >
SIZE_MAX) {
1526 if (passwd_len >= 0xffffffff) {
1530 if (passwd_len <= 0) {
1539 hash_str = zend_string_alloc(crypto_pwhash_STRBYTES - 1, 0);
1540 if (crypto_pwhash_str
1541 (
ZSTR_VAL(hash_str), passwd, (
unsigned long long) passwd_len,
1542 (
unsigned long long) opslimit, (
size_t) memlimit) != 0) {
1543 zend_string_efree(hash_str);
1547 ZSTR_VAL(hash_str)[crypto_pwhash_STRBYTES - 1] = 0;
1555#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
1561 size_t hash_str_len;
1564 &hash_str, &hash_str_len, &opslimit, &memlimit) ==
FAILURE) {
1567 if (crypto_pwhash_str_needs_rehash(hash_str, opslimit, memlimit) == 0) {
1578 size_t hash_str_len;
1582 &hash_str, &hash_str_len,
1583 &passwd, &passwd_len) ==
FAILURE) {
1584 sodium_remove_param_values_from_backtrace(
EG(
exception));
1587 if (passwd_len >= 0xffffffff) {
1591 if (passwd_len <= 0) {
1594 if (crypto_pwhash_str_verify
1595 (hash_str, passwd, (
unsigned long long) passwd_len) == 0) {
1602#ifdef crypto_pwhash_scryptsalsa208sha256_SALTBYTES
1606 unsigned char *salt;
1616 &passwd, &passwd_len,
1618 &opslimit, &memlimit) ==
FAILURE) {
1619 sodium_remove_param_values_from_backtrace(
EG(
exception));
1622 if (hash_len <= 0 || hash_len >=
SIZE_MAX || hash_len > 0x1fffffffe0ULL) {
1626 if (opslimit <= 0) {
1630 if (memlimit <= 0 || memlimit >
SIZE_MAX) {
1634 if (passwd_len <= 0) {
1637 if (salt_len != crypto_pwhash_scryptsalsa208sha256_SALTBYTES) {
1638 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES bytes long");
1641 if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) {
1642 zend_argument_error(sodium_exception_ce, 4,
"must be greater than or equal to %d", crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE);
1644 if (memlimit < crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) {
1645 zend_argument_error(sodium_exception_ce, 5,
"must be greater than or equal to %d", crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
1647 hash = zend_string_alloc((
size_t) hash_len, 0);
1648 if (crypto_pwhash_scryptsalsa208sha256
1649 ((
unsigned char *)
ZSTR_VAL(
hash), (
unsigned long long) hash_len,
1650 passwd, (
unsigned long long) passwd_len, salt,
1651 (
unsigned long long) opslimit, (
size_t) memlimit) != 0) {
1652 zend_string_efree(
hash);
1670 &passwd, &passwd_len,
1671 &opslimit, &memlimit) ==
FAILURE) {
1672 sodium_remove_param_values_from_backtrace(
EG(
exception));
1675 if (opslimit <= 0) {
1679 if (memlimit <= 0 || memlimit >
SIZE_MAX) {
1683 if (passwd_len <= 0) {
1686 if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) {
1687 zend_argument_error(sodium_exception_ce, 2,
"must be greater than or equal to %d", crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE);
1689 if (memlimit < crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) {
1690 zend_argument_error(sodium_exception_ce, 3,
"must be greater than or equal to %d", crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
1692 hash_str = zend_string_alloc
1693 (crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1, 0);
1694 if (crypto_pwhash_scryptsalsa208sha256_str
1695 (
ZSTR_VAL(hash_str), passwd, (
unsigned long long) passwd_len,
1696 (
unsigned long long) opslimit, (
size_t) memlimit) != 0) {
1697 zend_string_efree(hash_str);
1701 ZSTR_VAL(hash_str)[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1] = 0;
1710 size_t hash_str_len;
1714 &hash_str, &hash_str_len,
1715 &passwd, &passwd_len) ==
FAILURE) {
1716 sodium_remove_param_values_from_backtrace(
EG(
exception));
1719 if (passwd_len <= 0) {
1722 if (hash_str_len != crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1) {
1726 if (crypto_pwhash_scryptsalsa208sha256_str_verify
1727 (hash_str, passwd, (
unsigned long long) passwd_len) == 0) {
1740 RETURN_BOOL(crypto_aead_aes256gcm_is_available());
1752 unsigned char *npub;
1753 unsigned char *secretkey;
1754 unsigned long long ciphertext_real_len;
1756 size_t ciphertext_len;
1759 size_t secretkey_len;
1765 &secretkey, &secretkey_len) ==
FAILURE) {
1766 sodium_remove_param_values_from_backtrace(
EG(
exception));
1769 if (npub_len != crypto_aead_aes256gcm_NPUBBYTES) {
1770 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES bytes long");
1773 if (secretkey_len != crypto_aead_aes256gcm_KEYBYTES) {
1774 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES bytes long");
1777 if (
SIZE_MAX - msg_len <= crypto_aead_aes256gcm_ABYTES) {
1781 if ((
unsigned long long) msg_len > (16ULL * ((1ULL << 32) - 2ULL)) - crypto_aead_aes256gcm_ABYTES) {
1785 ciphertext_len = msg_len + crypto_aead_aes256gcm_ABYTES;
1786 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
1787 if (crypto_aead_aes256gcm_encrypt
1788 ((
unsigned char *)
ZSTR_VAL(ciphertext), &ciphertext_real_len,
msg,
1789 (
unsigned long long) msg_len,
1790 ad, (
unsigned long long) ad_len,
NULL, npub, secretkey) != 0) {
1791 zend_string_efree(ciphertext);
1795 if (ciphertext_real_len <= 0U || ciphertext_real_len >=
SIZE_MAX ||
1796 ciphertext_real_len > ciphertext_len) {
1797 zend_string_efree(ciphertext);
1802 ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
1811 unsigned char *ciphertext;
1812 unsigned char *npub;
1813 unsigned char *secretkey;
1814 unsigned long long msg_real_len;
1816 size_t ciphertext_len;
1819 size_t secretkey_len;
1822 &ciphertext, &ciphertext_len,
1825 &secretkey, &secretkey_len) ==
FAILURE) {
1826 sodium_remove_param_values_from_backtrace(
EG(
exception));
1829 if (npub_len != crypto_aead_aes256gcm_NPUBBYTES) {
1830 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES bytes long");
1833 if (secretkey_len != crypto_aead_aes256gcm_KEYBYTES) {
1834 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES bytes long");
1837 if (ciphertext_len < crypto_aead_aes256gcm_ABYTES) {
1840 if (ciphertext_len - crypto_aead_aes256gcm_ABYTES > 16ULL * ((1ULL << 32) - 2ULL)) {
1844 msg_len = ciphertext_len;
1849 msg = zend_string_alloc((
size_t) msg_len, 0);
1850 if (crypto_aead_aes256gcm_decrypt
1852 ciphertext, (
unsigned long long) ciphertext_len,
1853 ad, (
unsigned long long) ad_len, npub, secretkey) != 0) {
1854 zend_string_efree(
msg);
1857 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_len) {
1858 zend_string_efree(
msg);
1869#ifdef crypto_aead_aegis128l_KEYBYTES
1875 unsigned char *npub;
1876 unsigned char *secretkey;
1877 unsigned long long ciphertext_real_len;
1879 size_t ciphertext_len;
1882 size_t secretkey_len;
1888 &secretkey, &secretkey_len) ==
FAILURE) {
1889 sodium_remove_param_values_from_backtrace(
EG(
exception));
1892 if (npub_len != crypto_aead_aegis128l_NPUBBYTES) {
1893 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_AEGIS128L_NPUBBYTES bytes long");
1896 if (secretkey_len != crypto_aead_aegis128l_KEYBYTES) {
1897 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES bytes long");
1900 if (
SIZE_MAX - msg_len <= crypto_aead_aegis128l_ABYTES) {
1904 ciphertext_len = msg_len + crypto_aead_aegis128l_ABYTES;
1905 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
1906 if (crypto_aead_aegis128l_encrypt
1907 ((
unsigned char *)
ZSTR_VAL(ciphertext), &ciphertext_real_len,
msg,
1908 (
unsigned long long) msg_len,
1909 ad, (
unsigned long long) ad_len,
NULL, npub, secretkey) != 0) {
1910 zend_string_efree(ciphertext);
1914 if (ciphertext_real_len <= 0U || ciphertext_real_len >=
SIZE_MAX ||
1915 ciphertext_real_len > ciphertext_len) {
1916 zend_string_efree(ciphertext);
1921 ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
1930 unsigned char *ciphertext;
1931 unsigned char *npub;
1932 unsigned char *secretkey;
1933 unsigned long long msg_real_len;
1935 size_t ciphertext_len;
1938 size_t secretkey_len;
1941 &ciphertext, &ciphertext_len,
1944 &secretkey, &secretkey_len) ==
FAILURE) {
1945 sodium_remove_param_values_from_backtrace(
EG(
exception));
1948 if (npub_len != crypto_aead_aegis128l_NPUBBYTES) {
1949 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_AEGIS128L_NPUBBYTES bytes long");
1952 if (secretkey_len != crypto_aead_aegis128l_KEYBYTES) {
1953 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES bytes long");
1956 if (ciphertext_len < crypto_aead_aegis128l_ABYTES) {
1959 msg_len = ciphertext_len;
1964 msg = zend_string_alloc((
size_t) msg_len, 0);
1965 if (crypto_aead_aegis128l_decrypt
1967 ciphertext, (
unsigned long long) ciphertext_len,
1968 ad, (
unsigned long long) ad_len, npub, secretkey) != 0) {
1969 zend_string_efree(
msg);
1972 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_len) {
1973 zend_string_efree(
msg);
1984#ifdef crypto_aead_aegis256_KEYBYTES
1990 unsigned char *npub;
1991 unsigned char *secretkey;
1992 unsigned long long ciphertext_real_len;
1994 size_t ciphertext_len;
1997 size_t secretkey_len;
2003 &secretkey, &secretkey_len) ==
FAILURE) {
2004 sodium_remove_param_values_from_backtrace(
EG(
exception));
2007 if (npub_len != crypto_aead_aegis256_NPUBBYTES) {
2008 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_AEGIS256_NPUBBYTES bytes long");
2011 if (secretkey_len != crypto_aead_aegis256_KEYBYTES) {
2012 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_AEGIS256_KEYBYTES bytes long");
2015 if (
SIZE_MAX - msg_len <= crypto_aead_aegis256_ABYTES) {
2019 ciphertext_len = msg_len + crypto_aead_aegis256_ABYTES;
2020 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
2021 if (crypto_aead_aegis256_encrypt
2022 ((
unsigned char *)
ZSTR_VAL(ciphertext), &ciphertext_real_len,
msg,
2023 (
unsigned long long) msg_len,
2024 ad, (
unsigned long long) ad_len,
NULL, npub, secretkey) != 0) {
2025 zend_string_efree(ciphertext);
2029 if (ciphertext_real_len <= 0U || ciphertext_real_len >=
SIZE_MAX ||
2030 ciphertext_real_len > ciphertext_len) {
2031 zend_string_efree(ciphertext);
2036 ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
2045 unsigned char *ciphertext;
2046 unsigned char *npub;
2047 unsigned char *secretkey;
2048 unsigned long long msg_real_len;
2050 size_t ciphertext_len;
2053 size_t secretkey_len;
2056 &ciphertext, &ciphertext_len,
2059 &secretkey, &secretkey_len) ==
FAILURE) {
2060 sodium_remove_param_values_from_backtrace(
EG(
exception));
2063 if (npub_len != crypto_aead_aegis256_NPUBBYTES) {
2064 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_AEGIS256_NPUBBYTES bytes long");
2067 if (secretkey_len != crypto_aead_aegis256_KEYBYTES) {
2068 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_AEGIS256_KEYBYTES bytes long");
2071 if (ciphertext_len < crypto_aead_aegis256_ABYTES) {
2074 msg_len = ciphertext_len;
2079 msg = zend_string_alloc((
size_t) msg_len, 0);
2080 if (crypto_aead_aegis256_decrypt
2082 ciphertext, (
unsigned long long) ciphertext_len,
2083 ad, (
unsigned long long) ad_len, npub, secretkey) != 0) {
2084 zend_string_efree(
msg);
2087 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_len) {
2088 zend_string_efree(
msg);
2104 unsigned char *npub;
2105 unsigned char *secretkey;
2106 unsigned long long ciphertext_real_len;
2108 size_t ciphertext_len;
2111 size_t secretkey_len;
2117 &secretkey, &secretkey_len) ==
FAILURE) {
2118 sodium_remove_param_values_from_backtrace(
EG(
exception));
2121 if (npub_len != crypto_aead_chacha20poly1305_NPUBBYTES) {
2122 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES bytes long");
2125 if (secretkey_len != crypto_aead_chacha20poly1305_KEYBYTES) {
2126 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES bytes long");
2129 if (
SIZE_MAX - msg_len <= crypto_aead_chacha20poly1305_ABYTES) {
2133 ciphertext_len = msg_len + crypto_aead_chacha20poly1305_ABYTES;
2134 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
2135 if (crypto_aead_chacha20poly1305_encrypt
2136 ((
unsigned char *)
ZSTR_VAL(ciphertext), &ciphertext_real_len,
msg,
2137 (
unsigned long long) msg_len,
2138 ad, (
unsigned long long) ad_len,
NULL, npub, secretkey) != 0) {
2139 zend_string_efree(ciphertext);
2143 if (ciphertext_real_len <= 0U || ciphertext_real_len >=
SIZE_MAX ||
2144 ciphertext_real_len > ciphertext_len) {
2145 zend_string_efree(ciphertext);
2150 ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
2159 unsigned char *ciphertext;
2160 unsigned char *npub;
2161 unsigned char *secretkey;
2162 unsigned long long msg_real_len;
2164 size_t ciphertext_len;
2167 size_t secretkey_len;
2170 &ciphertext, &ciphertext_len,
2173 &secretkey, &secretkey_len) ==
FAILURE) {
2174 sodium_remove_param_values_from_backtrace(
EG(
exception));
2177 if (npub_len != crypto_aead_chacha20poly1305_NPUBBYTES) {
2178 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES bytes long");
2181 if (secretkey_len != crypto_aead_chacha20poly1305_KEYBYTES) {
2182 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES bytes long");
2185 if (ciphertext_len < crypto_aead_chacha20poly1305_ABYTES) {
2188 msg_len = ciphertext_len;
2193 msg = zend_string_alloc((
size_t) msg_len, 0);
2194 if (crypto_aead_chacha20poly1305_decrypt
2196 ciphertext, (
unsigned long long) ciphertext_len,
2197 ad, (
unsigned long long) ad_len, npub, secretkey) != 0) {
2198 zend_string_efree(
msg);
2201 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_len) {
2202 zend_string_efree(
msg);
2217 unsigned char *npub;
2218 unsigned char *secretkey;
2219 unsigned long long ciphertext_real_len;
2221 size_t ciphertext_len;
2224 size_t secretkey_len;
2230 &secretkey, &secretkey_len) ==
FAILURE) {
2231 sodium_remove_param_values_from_backtrace(
EG(
exception));
2234 if (npub_len != crypto_aead_chacha20poly1305_IETF_NPUBBYTES) {
2235 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES bytes long");
2239 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES bytes long");
2246 if ((
unsigned long long) msg_len > 64ULL * (1ULL << 32) - 64ULL) {
2251 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
2252 if (crypto_aead_chacha20poly1305_ietf_encrypt
2253 ((
unsigned char *)
ZSTR_VAL(ciphertext), &ciphertext_real_len,
msg,
2254 (
unsigned long long) msg_len,
2255 ad, (
unsigned long long) ad_len,
NULL, npub, secretkey) != 0) {
2256 zend_string_efree(ciphertext);
2260 if (ciphertext_real_len <= 0U || ciphertext_real_len >=
SIZE_MAX ||
2261 ciphertext_real_len > ciphertext_len) {
2262 zend_string_efree(ciphertext);
2267 ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
2276 unsigned char *ciphertext;
2277 unsigned char *npub;
2278 unsigned char *secretkey;
2279 unsigned long long msg_real_len;
2281 size_t ciphertext_len;
2284 size_t secretkey_len;
2287 &ciphertext, &ciphertext_len,
2290 &secretkey, &secretkey_len) ==
FAILURE) {
2291 sodium_remove_param_values_from_backtrace(
EG(
exception));
2294 if (npub_len != crypto_aead_chacha20poly1305_IETF_NPUBBYTES) {
2295 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES bytes long");
2299 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES bytes long");
2302 msg_len = ciphertext_len;
2310 if ((
unsigned long long) ciphertext_len -
2315 msg = zend_string_alloc((
size_t) msg_len, 0);
2316 if (crypto_aead_chacha20poly1305_ietf_decrypt
2318 ciphertext, (
unsigned long long) ciphertext_len,
2319 ad, (
unsigned long long) ad_len, npub, secretkey) != 0) {
2320 zend_string_efree(
msg);
2323 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_len) {
2324 zend_string_efree(
msg);
2334#ifdef crypto_aead_xchacha20poly1305_IETF_NPUBBYTES
2340 unsigned char *npub;
2341 unsigned char *secretkey;
2342 unsigned long long ciphertext_real_len;
2344 size_t ciphertext_len;
2347 size_t secretkey_len;
2353 &secretkey, &secretkey_len) ==
FAILURE) {
2354 sodium_remove_param_values_from_backtrace(
EG(
exception));
2357 if (npub_len != crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) {
2358 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES bytes long");
2361 if (secretkey_len != crypto_aead_xchacha20poly1305_IETF_KEYBYTES) {
2362 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES bytes long");
2365 if (
SIZE_MAX - msg_len <= crypto_aead_xchacha20poly1305_IETF_ABYTES) {
2369 ciphertext_len = msg_len + crypto_aead_xchacha20poly1305_IETF_ABYTES;
2370 ciphertext = zend_string_alloc((
size_t) ciphertext_len, 0);
2371 if (crypto_aead_xchacha20poly1305_ietf_encrypt
2372 ((
unsigned char *)
ZSTR_VAL(ciphertext), &ciphertext_real_len,
msg,
2373 (
unsigned long long) msg_len,
2374 ad, (
unsigned long long) ad_len,
NULL, npub, secretkey) != 0) {
2375 zend_string_efree(ciphertext);
2379 if (ciphertext_real_len <= 0U || ciphertext_real_len >=
SIZE_MAX ||
2380 ciphertext_real_len > ciphertext_len) {
2381 zend_string_efree(ciphertext);
2386 ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
2395 unsigned char *ciphertext;
2396 unsigned char *npub;
2397 unsigned char *secretkey;
2398 unsigned long long msg_real_len;
2400 size_t ciphertext_len;
2403 size_t secretkey_len;
2406 &ciphertext, &ciphertext_len,
2409 &secretkey, &secretkey_len) ==
FAILURE) {
2410 sodium_remove_param_values_from_backtrace(
EG(
exception));
2413 if (npub_len != crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) {
2414 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES bytes long");
2417 if (secretkey_len != crypto_aead_xchacha20poly1305_IETF_KEYBYTES) {
2418 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES bytes long");
2421 if (ciphertext_len < crypto_aead_xchacha20poly1305_IETF_ABYTES) {
2424 msg_len = ciphertext_len;
2425 if (msg_len - crypto_aead_xchacha20poly1305_IETF_ABYTES >=
SIZE_MAX) {
2429 if ((
unsigned long long) ciphertext_len -
2430 crypto_aead_xchacha20poly1305_IETF_ABYTES > 64ULL * (1ULL << 32) - 64ULL) {
2434 msg = zend_string_alloc((
size_t) msg_len, 0);
2435 if (crypto_aead_xchacha20poly1305_ietf_decrypt
2437 ciphertext, (
unsigned long long) ciphertext_len,
2438 ad, (
unsigned long long) ad_len, npub, secretkey) != 0) {
2439 zend_string_efree(
msg);
2442 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_len) {
2443 zend_string_efree(
msg);
2463 sodium_remove_param_values_from_backtrace(
EG(
exception));
2470 hex_len = bin_len * 2U;
2471 hex = zend_string_alloc((
size_t) hex_len, 0);
2483 char *ignore =
NULL;
2484 size_t bin_real_len;
2487 size_t ignore_len = 0;
2491 &ignore, &ignore_len) ==
FAILURE) {
2492 sodium_remove_param_values_from_backtrace(
EG(
exception));
2495 bin_len = hex_len / 2;
2496 bin = zend_string_alloc(bin_len, 0);
2498 ignore, &bin_real_len, &
end) != 0 ||
2499 end != hex + hex_len) {
2500 zend_string_efree(bin);
2504 if (bin_real_len >=
SIZE_MAX || bin_real_len > bin_len) {
2505 zend_string_efree(bin);
2515#ifdef sodium_base64_VARIANT_ORIGINAL
2526 sodium_remove_param_values_from_backtrace(
EG(
exception));
2529 if ((((
unsigned int)
variant) & ~ 0x6U) != 0x1U) {
2533 if (bin_len >=
SIZE_MAX / 4U * 3U - 3U - 1U) {
2537 b64_len = sodium_base64_ENCODED_LEN(bin_len,
variant);
2538 b64 = zend_string_alloc((
size_t) b64_len - 1U, 0);
2549 char *ignore =
NULL;
2551 size_t bin_real_len;
2554 size_t ignore_len = 0;
2558 &ignore, &ignore_len) ==
FAILURE) {
2559 sodium_remove_param_values_from_backtrace(
EG(
exception));
2562 if ((((
unsigned int)
variant) & ~ 0x6U) != 0x1U) {
2566 bin_len = b64_len / 4U * 3U + 2U;
2567 bin = zend_string_alloc(bin_len, 0);
2570 ignore, &bin_real_len, &
end, (
int)
variant) != 0 ||
2571 end != b64 + b64_len) {
2572 zend_string_efree(bin);
2576 if (bin_real_len >=
SIZE_MAX || bin_real_len > bin_len) {
2577 zend_string_efree(bin);
2598 sodium_remove_param_values_from_backtrace(
EG(
exception));
2601 if (n_len != crypto_scalarmult_SCALARBYTES) {
2602 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SCALARMULT_SCALARBYTES bytes long");
2605 if (p_len != crypto_scalarmult_BYTES) {
2606 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SCALARMULT_SCALARBYTES bytes long");
2609 q = zend_string_alloc(crypto_scalarmult_BYTES, 0);
2610 if (crypto_scalarmult((
unsigned char *)
ZSTR_VAL(q),
n,
p) != 0) {
2611 zend_string_efree(q);
2615 ZSTR_VAL(q)[crypto_scalarmult_BYTES] = 0;
2620#ifdef crypto_core_ristretto255_HASHBYTES
2631 sodium_remove_param_values_from_backtrace(
EG(
exception));
2634 if (n_len != crypto_scalarmult_ristretto255_SCALARBYTES) {
2636 "must be SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES bytes long");
2639 if (p_len != crypto_scalarmult_ristretto255_BYTES) {
2641 "must be SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_BYTES bytes long");
2644 q = zend_string_alloc(crypto_scalarmult_ristretto255_BYTES, 0);
2645 if (crypto_scalarmult_ristretto255((
unsigned char *)
ZSTR_VAL(q),
n,
p) != 0) {
2646 zend_string_efree(q);
2650 ZSTR_VAL(q)[crypto_scalarmult_ristretto255_BYTES] = 0;
2663 sodium_remove_param_values_from_backtrace(
EG(
exception));
2666 if (n_len != crypto_scalarmult_ristretto255_SCALARBYTES) {
2668 "must be SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES bytes long");
2671 q = zend_string_alloc(crypto_scalarmult_ristretto255_BYTES, 0);
2672 if (crypto_scalarmult_ristretto255_base((
unsigned char *)
ZSTR_VAL(q),
n) != 0) {
2673 zend_string_efree(q);
2677 ZSTR_VAL(q)[crypto_scalarmult_BYTES] = 0;
2687 unsigned char *seed;
2692 &seed, &seed_len) ==
FAILURE) {
2693 sodium_remove_param_values_from_backtrace(
EG(
exception));
2697 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_KX_SEEDBYTES bytes long");
2703 sk = (
unsigned char *)
ZSTR_VAL(keypair);
2707 if (crypto_scalarmult_base(pk, sk) != 0) {
2708 zend_string_efree(keypair);
2726 sk = (
unsigned char *)
ZSTR_VAL(keypair);
2729 if (crypto_scalarmult_base(pk, sk) != 0) {
2730 zend_string_efree(keypair);
2741 unsigned char *keypair;
2745 &keypair, &keypair_len) ==
FAILURE) {
2746 sodium_remove_param_values_from_backtrace(
EG(
exception));
2751 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes long");
2764 unsigned char *keypair;
2768 &keypair, &keypair_len) ==
FAILURE) {
2769 sodium_remove_param_values_from_backtrace(
EG(
exception));
2774 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes long");
2787 crypto_generichash_state h;
2788 unsigned char q[crypto_scalarmult_BYTES];
2789 unsigned char *keypair;
2790 unsigned char *client_sk;
2791 unsigned char *client_pk;
2792 unsigned char *server_pk;
2795 size_t server_pk_len;
2798 &keypair, &keypair_len,
2799 &server_pk, &server_pk_len) ==
FAILURE) {
2800 sodium_remove_param_values_from_backtrace(
EG(
exception));
2804 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes long");
2808 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes long");
2811 client_sk = &keypair[0];
2815 if (crypto_scalarmult(q, client_sk, server_pk) != 0) {
2820 crypto_generichash_update(&h, q,
sizeof q);
2828 (
const char *) session_keys,
2837 crypto_generichash_state h;
2838 unsigned char q[crypto_scalarmult_BYTES];
2839 unsigned char *keypair;
2840 unsigned char *server_sk;
2841 unsigned char *server_pk;
2842 unsigned char *client_pk;
2845 size_t client_pk_len;
2848 &keypair, &keypair_len,
2849 &client_pk, &client_pk_len) ==
FAILURE) {
2850 sodium_remove_param_values_from_backtrace(
EG(
exception));
2854 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes long");
2858 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes long");
2861 server_sk = &keypair[0];
2865 if (crypto_scalarmult(q, server_sk, client_pk) != 0) {
2870 crypto_generichash_update(&h, q,
sizeof q);
2881 (
const char *) session_keys,
2896 sodium_remove_param_values_from_backtrace(
EG(
exception));
2899 if (key_len != crypto_auth_KEYBYTES) {
2900 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_AUTH_KEYBYTES bytes long");
2903 mac = zend_string_alloc(crypto_auth_BYTES, 0);
2904 if (crypto_auth((
unsigned char *)
ZSTR_VAL(mac),
2905 (
const unsigned char *)
msg, msg_len,
2906 (
const unsigned char *)
key) != 0) {
2907 zend_string_efree(mac);
2911 ZSTR_VAL(mac)[crypto_auth_BYTES] = 0;
2929 sodium_remove_param_values_from_backtrace(
EG(
exception));
2932 if (key_len != crypto_auth_KEYBYTES) {
2933 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_AUTH_KEYBYTES bytes long");
2936 if (mac_len != crypto_auth_BYTES) {
2937 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_AUTH_BYTES bytes long");
2940 if (crypto_auth_verify((
const unsigned char *) mac,
2941 (
const unsigned char *)
msg, msg_len,
2942 (
const unsigned char *)
key) != 0) {
2952 size_t eddsakey_len;
2955 &eddsakey, &eddsakey_len) ==
FAILURE) {
2956 sodium_remove_param_values_from_backtrace(
EG(
exception));
2959 if (eddsakey_len != crypto_sign_SECRETKEYBYTES) {
2960 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes long");
2963 ecdhkey = zend_string_alloc(crypto_box_SECRETKEYBYTES, 0);
2965 if (crypto_sign_ed25519_sk_to_curve25519((
unsigned char *)
ZSTR_VAL(ecdhkey),
2966 (
const unsigned char *) eddsakey) != 0) {
2967 zend_string_efree(ecdhkey);
2971 ZSTR_VAL(ecdhkey)[crypto_box_SECRETKEYBYTES] = 0;
2980 size_t eddsakey_len;
2983 &eddsakey, &eddsakey_len) ==
FAILURE) {
2984 sodium_remove_param_values_from_backtrace(
EG(
exception));
2987 if (eddsakey_len != crypto_sign_PUBLICKEYBYTES) {
2988 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes long");
2991 ecdhkey = zend_string_alloc(crypto_sign_PUBLICKEYBYTES, 0);
2993 if (crypto_sign_ed25519_pk_to_curve25519((
unsigned char *)
ZSTR_VAL(ecdhkey),
2994 (
const unsigned char *) eddsakey) != 0) {
2995 zend_string_efree(ecdhkey);
2999 ZSTR_VAL(ecdhkey)[crypto_box_PUBLICKEYBYTES] = 0;
3014 sodium_remove_param_values_from_backtrace(
EG(
exception));
3018 zend_argument_error(sodium_exception_ce, 1,
"and argument #2 ($string_2) must have the same length");
3022 (
const unsigned char *) buf2, (
size_t) len1));
3029 unsigned char key[crypto_aead_aes256gcm_KEYBYTES];
3034 randombytes_buf(
key,
sizeof key);
3039#ifdef crypto_aead_aegis128l_KEYBYTES
3042 unsigned char key[crypto_aead_aegis128l_KEYBYTES];
3047 crypto_aead_aegis128l_keygen(
key);
3052#ifdef crypto_aead_aegis256_KEYBYTES
3055 unsigned char key[crypto_aead_aegis256_KEYBYTES];
3060 crypto_aead_aegis256_keygen(
key);
3067 unsigned char key[crypto_aead_chacha20poly1305_KEYBYTES];
3072 randombytes_buf(
key,
sizeof key);
3083 randombytes_buf(
key,
sizeof key);
3087#ifdef crypto_aead_xchacha20poly1305_IETF_NPUBBYTES
3090 unsigned char key[crypto_aead_xchacha20poly1305_IETF_KEYBYTES];
3095 randombytes_buf(
key,
sizeof key);
3102 unsigned char key[crypto_auth_KEYBYTES];
3107 randombytes_buf(
key,
sizeof key);
3113 unsigned char key[crypto_generichash_KEYBYTES];
3118 randombytes_buf(
key,
sizeof key);
3129 randombytes_buf(
key,
sizeof key);
3135 unsigned char key[crypto_secretbox_KEYBYTES];
3140 randombytes_buf(
key,
sizeof key);
3146 unsigned char key[crypto_shorthash_KEYBYTES];
3151 randombytes_buf(
key,
sizeof key);
3157 unsigned char key[crypto_stream_KEYBYTES];
3162 randombytes_buf(
key,
sizeof key);
3165#ifdef crypto_stream_xchacha20_KEYBYTES
3168 unsigned char key[crypto_stream_xchacha20_KEYBYTES];
3173 randombytes_buf(
key,
sizeof key);
3180 unsigned char ctx_padded[crypto_generichash_blake2b_PERSONALBYTES];
3181#ifndef crypto_kdf_PRIMITIVE
3182 unsigned char salt[crypto_generichash_blake2b_SALTBYTES];
3197 sodium_remove_param_values_from_backtrace(
EG(
exception));
3201 zend_argument_error(sodium_exception_ce, 1,
"must be greater than or equal to SODIUM_CRYPTO_KDF_BYTES_MIN");
3205 zend_argument_error(sodium_exception_ce, 1,
"must be less than or equal to SODIUM_CRYPTO_KDF_BYTES_MAX");
3208 if (subkey_id < 0) {
3213 zend_argument_error(sodium_exception_ce, 3,
"must be SODIUM_CRYPTO_KDF_CONTEXTBYTES bytes long");
3217 zend_argument_error(sodium_exception_ce, 4,
"must be SODIUM_CRYPTO_KDF_BYTES_MIN bytes long");
3222 subkey = zend_string_alloc((
size_t) subkey_len, 0);
3223#ifdef crypto_kdf_PRIMITIVE
3224 crypto_kdf_derive_from_key((
unsigned char *)
ZSTR_VAL(subkey),
3225 (
size_t) subkey_len, (uint64_t) subkey_id,
3226 ctx, (
const unsigned char *)
key);
3228 salt[0] = (
unsigned char) (((uint64_t) subkey_id) );
3229 salt[1] = (
unsigned char) (((uint64_t) subkey_id) >> 8);
3230 salt[2] = (
unsigned char) (((uint64_t) subkey_id) >> 16);
3231 salt[3] = (
unsigned char) (((uint64_t) subkey_id) >> 24);
3232 salt[4] = (
unsigned char) (((uint64_t) subkey_id) >> 32);
3233 salt[5] = (
unsigned char) (((uint64_t) subkey_id) >> 40);
3234 salt[6] = (
unsigned char) (((uint64_t) subkey_id) >> 48);
3235 salt[7] = (
unsigned char) (((uint64_t) subkey_id) >> 56);
3236 memset(salt + 8, 0, (
sizeof salt) - 8);
3237 crypto_generichash_blake2b_salt_personal((
unsigned char *)
ZSTR_VAL(subkey),
3238 (
size_t) subkey_len,
3240 (
const unsigned char *)
key,
3256 size_t unpadded_len;
3261 &unpadded, &unpadded_len, &blocksize) ==
FAILURE) {
3262 sodium_remove_param_values_from_backtrace(
EG(
exception));
3265 if (blocksize <= 0) {
3273 xpadlen = blocksize - 1U;
3274 if ((blocksize & (blocksize - 1U)) == 0
U) {
3275 xpadlen -= unpadded_len & ((size_t) blocksize - 1U);
3277 xpadlen -= unpadded_len % (size_t) blocksize;
3279 if ((
size_t)
SIZE_MAX - unpadded_len <= xpadlen) {
3283 xpadded_len = unpadded_len + xpadlen;
3284 padded = zend_string_alloc(xpadded_len + 1U, 0);
3285 if (unpadded_len > 0) {
3289 for (
j = 0
U;
j <= xpadded_len;
j++) {
3292 st = (size_t) (~(((( (((uint64_t) k) >> 48) | (((uint64_t) k) >> 32) |
3293 (k >> 16) | k) & 0xffff) - 1U) >> 16)) & 1U;
3297#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
3299 (
size_t) blocksize, xpadded_len + 1U) != 0) {
3300 zend_string_efree(padded);
3307 volatile unsigned char mask;
3308 unsigned char barrier_mask;
3312 for (i = 0; i < blocksize; i++) {
3313 barrier_mask = (
unsigned char)
3314 (((i ^ xpadlen) - 1U) >> ((
sizeof(
size_t) - 1U) * CHAR_BIT));
3315 tail[-i] = (
tail[-i] & mask) | (0x80 & barrier_mask);
3316 mask |= barrier_mask;
3320 ZSTR_VAL(padded)[xpadded_len + 1U] = 0;
3330 size_t unpadded_len;
3335 &padded, &padded_len, &blocksize) ==
FAILURE) {
3336 sodium_remove_param_values_from_backtrace(
EG(
exception));
3339 if (blocksize <= 0) {
3347 if (padded_len < blocksize) {
3348 zend_argument_error(sodium_exception_ce, 1,
"must be at least as long as the block size");
3352#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
3354 padded_len, (
size_t) blocksize);
3358 unsigned char acc = 0
U;
3360 unsigned char valid = 0
U;
3361 volatile size_t pad_len = 0
U;
3365 tail = &padded[padded_len - 1U];
3367 for (i = 0
U; i < (size_t) blocksize; i++) {
3370 (( (acc - 1U) & (pad_len - 1U) & ((c ^ 0x80) - 1U) ) >> 8) & 1U;
3372 pad_len |= i & (1U + ~is_barrier);
3373 valid |= (
unsigned char) is_barrier;
3375 unpadded_len = padded_len - 1U - pad_len;
3376 ret = (int) (valid - 1U);
3383 unpadded = zend_string_init(padded, padded_len, 0);
3385 ZSTR_VAL(unpadded)[unpadded_len] = 0;
3389#ifdef crypto_secretstream_xchacha20poly1305_ABYTES
3392 unsigned char key[crypto_secretstream_xchacha20poly1305_KEYBYTES];
3397 randombytes_buf(
key,
sizeof key);
3403 crypto_secretstream_xchacha20poly1305_state
state;
3404 unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES];
3410 sodium_remove_param_values_from_backtrace(
EG(
exception));
3413 if (key_len != crypto_secretstream_xchacha20poly1305_KEYBYTES) {
3414 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES bytes long");
3417 if (crypto_secretstream_xchacha20poly1305_init_push(&
state,
3431 unsigned char *ad =
NULL;
3433 unsigned char *
state;
3434 unsigned long long c_real_len;
3435 zend_long tag = crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;
3436 size_t ad_len = (size_t) 0
U;
3443 &
msg, &msg_len, &ad, &ad_len, &tag) ==
FAILURE) {
3444 sodium_remove_param_values_from_backtrace(
EG(
exception));
3452 sodium_separate_string(state_zv);
3455 if (state_len !=
sizeof (crypto_secretstream_xchacha20poly1305_state)) {
3459 if (msg_len > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX ||
3460 msg_len >
SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES) {
3461 zend_argument_error(sodium_exception_ce, 2,
"must be at most SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX bytes long");
3464 if (tag < 0 || tag > 255) {
3468 c_len = msg_len + crypto_secretstream_xchacha20poly1305_ABYTES;
3469 c = zend_string_alloc((
size_t) c_len, 0);
3470 if (crypto_secretstream_xchacha20poly1305_push
3471 ((
void *)
state, (
unsigned char *)
ZSTR_VAL(c), &c_real_len,
3472 msg, (
unsigned long long) msg_len, ad, (
unsigned long long) ad_len,
3473 (
unsigned char) tag) != 0) {
3474 zend_string_efree(c);
3478 if (c_real_len <= 0U || c_real_len >=
SIZE_MAX || c_real_len > c_len) {
3479 zend_string_efree(c);
3491 crypto_secretstream_xchacha20poly1305_state
state;
3500 sodium_remove_param_values_from_backtrace(
EG(
exception));
3503 if (header_len != crypto_secretstream_xchacha20poly1305_HEADERBYTES) {
3504 zend_argument_error(sodium_exception_ce, 1,
"must be SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES bytes long");
3507 if (key_len != crypto_secretstream_xchacha20poly1305_KEYBYTES) {
3508 zend_argument_error(sodium_exception_ce, 2,
"must be SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES bytes long");
3511 if (crypto_secretstream_xchacha20poly1305_init_pull(&
state,
3523 unsigned char *ad =
NULL;
3525 unsigned char *
state;
3526 unsigned long long msg_real_len;
3527 size_t ad_len = (size_t) 0
U;
3535 &c, &c_len, &ad, &ad_len) ==
FAILURE) {
3536 sodium_remove_param_values_from_backtrace(
EG(
exception));
3544 sodium_separate_string(state_zv);
3547 if (state_len !=
sizeof (crypto_secretstream_xchacha20poly1305_state)) {
3551 if (c_len < crypto_secretstream_xchacha20poly1305_ABYTES) {
3554 msg_len = c_len - crypto_secretstream_xchacha20poly1305_ABYTES;
3555 msg = zend_string_alloc((
size_t) msg_len, 0);
3556 if (crypto_secretstream_xchacha20poly1305_pull
3558 c, (
unsigned long long) c_len, ad, (
unsigned long long) ad_len) != 0) {
3559 zend_string_efree(
msg);
3562 if (msg_real_len >=
SIZE_MAX || msg_real_len > msg_len) {
3563 zend_string_efree(
msg);
3577 unsigned char *
state;
3581 sodium_remove_param_values_from_backtrace(
EG(
exception));
3589 sodium_separate_string(state_zv);
3592 if (state_len !=
sizeof (crypto_secretstream_xchacha20poly1305_state)) {
3596 crypto_secretstream_xchacha20poly1305_rekey((
void *)
state);
3600#ifdef crypto_core_ristretto255_HASHBYTES
3610 &
p, &p_len, &q, &q_len) ==
FAILURE) {
3611 sodium_remove_param_values_from_backtrace(
EG(
exception));
3614 if (p_len != crypto_core_ristretto255_BYTES) {
3616 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES bytes long");
3619 if (q_len != crypto_core_ristretto255_BYTES) {
3621 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES bytes long");
3624 r = zend_string_alloc(crypto_core_ristretto255_BYTES, 0);
3625 if (crypto_core_ristretto255_add((
unsigned char *)
ZSTR_VAL(r),
p, q) != 0) {
3626 zend_string_efree(r);
3630 ZSTR_VAL(r)[crypto_core_ristretto255_BYTES] = 0;
3642 sodium_remove_param_values_from_backtrace(
EG(
exception));
3645 if (s_len != crypto_core_ristretto255_HASHBYTES) {
3647 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_HASHBYTES bytes long");
3650 r = zend_string_alloc(crypto_core_ristretto255_SCALARBYTES, 0);
3651 if (crypto_core_ristretto255_from_hash((
unsigned char *)
ZSTR_VAL(r),
s) != 0) {
3652 zend_string_efree(r);
3656 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3667 sodium_remove_param_values_from_backtrace(
EG(
exception));
3670 if (s_len != crypto_core_ristretto255_BYTES) {
3672 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES bytes long");
3675 RETURN_BOOL(crypto_core_ristretto255_is_valid_point(
s));
3685 r = zend_string_alloc(crypto_core_ristretto255_BYTES, 0);
3686 crypto_core_ristretto255_random((
unsigned char *)
ZSTR_VAL(r));
3687 ZSTR_VAL(r)[crypto_core_ristretto255_BYTES] = 0;
3700 &
p, &p_len, &q, &q_len) ==
FAILURE) {
3701 sodium_remove_param_values_from_backtrace(
EG(
exception));
3704 if (p_len != crypto_core_ristretto255_SCALARBYTES) {
3706 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3709 if (q_len != crypto_core_ristretto255_SCALARBYTES) {
3711 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3714 r = zend_string_alloc(crypto_core_ristretto255_BYTES, 0);
3715 crypto_core_ristretto255_scalar_add((
unsigned char *)
ZSTR_VAL(r),
p, q);
3716 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3728 sodium_remove_param_values_from_backtrace(
EG(
exception));
3731 if (s_len != crypto_core_ristretto255_SCALARBYTES) {
3733 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3736 r = zend_string_alloc(crypto_core_ristretto255_SCALARBYTES, 0);
3737 crypto_core_ristretto255_scalar_complement((
unsigned char *)
ZSTR_VAL(r),
s);
3738 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3750 sodium_remove_param_values_from_backtrace(
EG(
exception));
3753 if (s_len != crypto_core_ristretto255_SCALARBYTES) {
3755 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3758 r = zend_string_alloc(crypto_core_ristretto255_SCALARBYTES, 0);
3759 if (crypto_core_ristretto255_scalar_invert((
unsigned char *)
ZSTR_VAL(r),
s) != 0) {
3760 zend_string_efree(r);
3764 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3777 &x, &x_len, &y, &y_len) ==
FAILURE) {
3778 sodium_remove_param_values_from_backtrace(
EG(
exception));
3781 if (x_len != crypto_core_ristretto255_SCALARBYTES) {
3783 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3786 if (y_len != crypto_core_ristretto255_SCALARBYTES) {
3788 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3791 r = zend_string_alloc(crypto_core_ristretto255_BYTES, 0);
3792 crypto_core_ristretto255_scalar_mul((
unsigned char *)
ZSTR_VAL(r), x, y);
3793 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3805 sodium_remove_param_values_from_backtrace(
EG(
exception));
3808 if (s_len != crypto_core_ristretto255_SCALARBYTES) {
3810 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3813 r = zend_string_alloc(crypto_core_ristretto255_SCALARBYTES, 0);
3814 crypto_core_ristretto255_scalar_negate((
unsigned char *)
ZSTR_VAL(r),
s);
3815 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3826 r = zend_string_alloc(crypto_core_ristretto255_SCALARBYTES, 0);
3827 crypto_core_ristretto255_scalar_random((
unsigned char *)
ZSTR_VAL(r));
3828 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3840 sodium_remove_param_values_from_backtrace(
EG(
exception));
3843 if (s_len != crypto_core_ristretto255_NONREDUCEDSCALARBYTES) {
3845 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES bytes long");
3848 r = zend_string_alloc(crypto_core_ristretto255_SCALARBYTES, 0);
3849 crypto_core_ristretto255_scalar_reduce((
unsigned char *)
ZSTR_VAL(r),
s);
3850 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3863 &
p, &p_len, &q, &q_len) ==
FAILURE) {
3864 sodium_remove_param_values_from_backtrace(
EG(
exception));
3867 if (p_len != crypto_core_ristretto255_SCALARBYTES) {
3869 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3872 if (q_len != crypto_core_ristretto255_SCALARBYTES) {
3874 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES bytes long");
3877 r = zend_string_alloc(crypto_core_ristretto255_BYTES, 0);
3878 crypto_core_ristretto255_scalar_sub((
unsigned char *)
ZSTR_VAL(r),
p, q);
3879 ZSTR_VAL(r)[crypto_core_ristretto255_SCALARBYTES] = 0;
3892 &
p, &p_len, &q, &q_len) ==
FAILURE) {
3893 sodium_remove_param_values_from_backtrace(
EG(
exception));
3896 if (p_len != crypto_core_ristretto255_BYTES) {
3898 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES bytes long");
3901 if (q_len != crypto_core_ristretto255_BYTES) {
3903 "must be SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES bytes long");
3906 r = zend_string_alloc(crypto_core_ristretto255_BYTES, 0);
3907 if (crypto_core_ristretto255_sub((
unsigned char *)
ZSTR_VAL(r),
p, q) != 0) {
3908 zend_string_efree(r);
3912 ZSTR_VAL(r)[crypto_core_ristretto255_BYTES] = 0;
copy(string $from, string $to, $context=null)
header(string $header, bool $replace=true, int $response_code=0)
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
hash(string $algo, string $data, bool $binary=false, array $options=[])
#define crypto_kx_PUBLICKEYBYTES
#define crypto_pwhash_OPSLIMIT_MIN
#define crypto_kdf_CONTEXTBYTES
#define crypto_kdf_BYTES_MAX
#define crypto_kdf_KEYBYTES
#define crypto_kx_SESSIONKEYBYTES
#define crypto_pwhash_MEMLIMIT_MIN
zend_module_entry sodium_module_entry
#define crypto_kx_SEEDBYTES
#define crypto_kdf_BYTES_MIN
#define PHP_SODIUM_ZSTR_TRUNCATE(zs, len)
#define crypto_aead_chacha20poly1305_IETF_KEYBYTES
#define crypto_aead_chacha20poly1305_IETF_ABYTES
#define crypto_kx_SECRETKEYBYTES
sodium_base642bin(#[\SensitiveParameter] string $string, int $id, string $ignore="")
sodium_crypto_sign_publickey(#[\SensitiveParameter] string $key_pair)
sodium_crypto_box_keypair()
sodium_crypto_core_ristretto255_scalar_complement(string $s)
sodium_crypto_aead_chacha20poly1305_ietf_decrypt(string $ciphertext, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_sign_secretkey(#[\SensitiveParameter] string $key_pair)
sodium_crypto_auth_keygen()
sodium_crypto_aead_chacha20poly1305_ietf_keygen()
sodium_crypto_stream_keygen()
sodium_crypto_aead_aes256gcm_encrypt(#[\SensitiveParameter] string $message, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_increment(string &$string)
sodium_crypto_core_ristretto255_is_valid_point(string $s)
sodium_crypto_sign_keypair()
sodium_crypto_aead_chacha20poly1305_decrypt(string $ciphertext, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_generichash_keygen()
sodium_crypto_core_ristretto255_scalar_random()
sodium_crypto_sign_publickey_from_secretkey(#[\SensitiveParameter] string $secret_key)
sodium_add(string &$string1, string $string2)
sodium_crypto_core_ristretto255_from_hash(string $s)
sodium_crypto_auth_verify(string $mac, string $message, #[\SensitiveParameter] string $key)
sodium_crypto_generichash(string $message, #[\SensitiveParameter] string $key="", int $length=SODIUM_CRYPTO_GENERICHASH_BYTES)
sodium_crypto_core_ristretto255_scalar_sub(string $x, string $y)
sodium_crypto_pwhash_str_verify(string $hash, #[\SensitiveParameter] string $password)
sodium_crypto_kx_secretkey(#[\SensitiveParameter] string $key_pair)
sodium_crypto_generichash_update(string &$state, string $message)
sodium_crypto_aead_aes256gcm_decrypt(string $ciphertext, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_secretstream_xchacha20poly1305_init_push(#[\SensitiveParameter] string $key)
sodium_bin2hex(#[\SensitiveParameter] string $string)
sodium_crypto_generichash_init(#[\SensitiveParameter] string $key="", int $length=SODIUM_CRYPTO_GENERICHASH_BYTES)
sodium_crypto_secretbox_keygen()
sodium_crypto_box_publickey(#[\SensitiveParameter] string $key_pair)
sodium_crypto_sign_ed25519_sk_to_curve25519(#[\SensitiveParameter] string $secret_key)
sodium_crypto_core_ristretto255_random()
sodium_crypto_sign_detached(string $message, #[\SensitiveParameter] string $secret_key)
sodium_crypto_aead_aegis256_encrypt(#[\SensitiveParameter] string $message, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_aead_aegis256_decrypt(string $ciphertext, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_secretstream_xchacha20poly1305_pull(string &$state, string $ciphertext, string $additional_data="")
sodium_crypto_sign_open(string $signed_message, string $public_key)
sodium_crypto_aead_chacha20poly1305_encrypt(#[\SensitiveParameter] string $message, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_kx_seed_keypair(#[\SensitiveParameter] string $seed)
sodium_hex2bin(#[\SensitiveParameter] string $string, string $ignore="")
sodium_crypto_scalarmult_ristretto255(string $n, string $p)
sodium_crypto_pwhash(int $length, #[\SensitiveParameter] string $password, string $salt, int $opslimit, int $memlimit, int $algo=SODIUM_CRYPTO_PWHASH_ALG_DEFAULT)
sodium_compare(#[\SensitiveParameter] string $string1, #[\SensitiveParameter] string $string2)
sodium_crypto_kx_client_session_keys(#[\SensitiveParameter] string $client_key_pair, string $server_key)
sodium_crypto_aead_aegis128l_decrypt(string $ciphertext, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_kx_server_session_keys(#[\SensitiveParameter] string $server_key_pair, string $client_key)
sodium_crypto_secretbox(#[\SensitiveParameter] string $message, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_aead_chacha20poly1305_ietf_encrypt(#[\SensitiveParameter] string $message, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_stream_xor(#[\SensitiveParameter] string $message, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_secretstream_xchacha20poly1305_push(string &$state, #[\SensitiveParameter] string $message, string $additional_data="", int $tag=SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE)
sodium_crypto_core_ristretto255_scalar_mul(string $x, string $y)
sodium_crypto_box_secretkey(#[\SensitiveParameter] string $key_pair)
sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(#[\SensitiveParameter] string $message, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_core_ristretto255_add(string $p, string $q)
sodium_crypto_aead_aes256gcm_is_available()
sodium_crypto_aead_aes256gcm_keygen()
sodium_crypto_box_publickey_from_secretkey(#[\SensitiveParameter] string $secret_key)
sodium_crypto_aead_aegis256_keygen()
sodium_crypto_pwhash_str(#[\SensitiveParameter] string $password, int $opslimit, int $memlimit)
sodium_unpad(#[\SensitiveParameter] string $string, int $block_size)
sodium_crypto_core_ristretto255_scalar_add(string $x, string $y)
sodium_crypto_stream(int $length, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_kx_keypair()
sodium_crypto_core_ristretto255_scalar_negate(string $s)
sodium_crypto_box_keypair_from_secretkey_and_publickey(#[\SensitiveParameter] string $secret_key, string $public_key)
sodium_bin2base64(#[\SensitiveParameter] string $string, int $id)
sodium_crypto_box_open(string $ciphertext, string $nonce, #[\SensitiveParameter] string $key_pair)
sodium_crypto_aead_xchacha20poly1305_ietf_keygen()
sodium_crypto_core_ristretto255_scalar_reduce(string $s)
sodium_crypto_sign_keypair_from_secretkey_and_publickey(#[\SensitiveParameter] string $secret_key, string $public_key)
sodium_crypto_aead_aegis128l_encrypt(#[\SensitiveParameter] string $message, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_shorthash_keygen()
sodium_pad(#[\SensitiveParameter] string $string, int $block_size)
sodium_crypto_scalarmult_ristretto255_base(string $n)
sodium_crypto_aead_aegis128l_keygen()
sodium_crypto_box_seal(#[\SensitiveParameter] string $message, string $public_key)
sodium_crypto_kx_publickey(#[\SensitiveParameter] string $key_pair)
sodium_crypto_kdf_keygen()
sodium_crypto_stream_xchacha20_keygen()
sodium_crypto_core_ristretto255_sub(string $p, string $q)
sodium_crypto_sign_verify_detached(string $signature, string $message, string $public_key)
sodium_crypto_sign(string $message, #[\SensitiveParameter] string $secret_key)
sodium_crypto_aead_chacha20poly1305_keygen()
sodium_crypto_sign_ed25519_pk_to_curve25519(string $public_key)
sodium_crypto_box_seal_open(string $ciphertext, #[\SensitiveParameter] string $key_pair)
sodium_crypto_pwhash_str_needs_rehash(string $password, int $opslimit, int $memlimit)
sodium_crypto_box(#[\SensitiveParameter] string $message, string $nonce, #[\SensitiveParameter] string $key_pair)
sodium_crypto_pwhash_scryptsalsa208sha256(int $length, #[\SensitiveParameter] string $password, string $salt, int $opslimit, int $memlimit)
sodium_crypto_shorthash(string $message, #[\SensitiveParameter] string $key)
sodium_crypto_stream_xchacha20_xor_ic(#[\SensitiveParameter] string $message, string $nonce, int $counter,#[\SensitiveParameter] string $key)
sodium_crypto_stream_xchacha20_xor(#[\SensitiveParameter] string $message, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(string $ciphertext, string $additional_data, string $nonce, #[\SensitiveParameter] string $key)
sodium_memzero(#[\SensitiveParameter] string &$string)
sodium_crypto_secretbox_open(string $ciphertext, string $nonce, #[\SensitiveParameter] string $key)
sodium_memcmp(#[\SensitiveParameter] string $string1, #[\SensitiveParameter] string $string2)
sodium_crypto_auth(string $message, #[\SensitiveParameter] string $key)
sodium_crypto_kdf_derive_from_key(int $subkey_length, int $subkey_id, string $context, #[\SensitiveParameter] string $key)
sodium_crypto_stream_xchacha20(int $length, string $nonce, #[\SensitiveParameter] string $key)
sodium_crypto_core_ristretto255_scalar_invert(string $s)
sodium_crypto_box_seed_keypair(#[\SensitiveParameter] string $seed)
sodium_crypto_scalarmult(string $n, string $p)
sodium_crypto_generichash_final(string &$state, int $length=SODIUM_CRYPTO_GENERICHASH_BYTES)
sodium_crypto_secretstream_xchacha20poly1305_keygen()
sodium_crypto_pwhash_scryptsalsa208sha256_str_verify(string $hash, #[\SensitiveParameter] string $password)
sodium_crypto_secretstream_xchacha20poly1305_init_pull(string $header, #[\SensitiveParameter] string $key)
sodium_crypto_sign_seed_keypair(#[\SensitiveParameter] string $seed)
sodium_crypto_secretstream_xchacha20poly1305_rekey(string &$state)
sodium_crypto_pwhash_scryptsalsa208sha256_str(#[\SensitiveParameter] string $password, int $opslimit, int $memlimit)
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
unsigned const char * end
#define PHP_SODIUM_VERSION
struct php_pcntl_pending_signal * tail
unsigned char key[REFLECTION_KEY_LEN]
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format,...)
ZEND_API ZEND_COLD void zend_error(int type, const char *format,...)
ZEND_API zval * zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv)
ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length)
ZEND_API zend_result add_next_index_long(zval *arg, zend_long n)
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format,...)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API zend_result add_next_index_str(zval *arg, zend_string *str)
#define RETURN_STRINGL(s, l)
#define ZEND_GET_MODULE(name)
#define zend_parse_parameters_none()
#define RETURN_NEW_STR(s)
#define ZEND_MM_ALIGNED_SIZE(size)
ZEND_API zend_class_entry * zend_ce_exception
ZEND_API ZEND_COLD zend_object * zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code)
ZEND_API zend_class_entry * zend_get_exception_base(zend_object *object)
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
ZEND_API zval *ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key)
#define ZEND_HASH_FOREACH_END()
#define ZVAL_EMPTY_ARRAY(z)
#define ZEND_HASH_FOREACH_VAL(ht, _val)
struct _zend_string zend_string
#define INIT_FUNC_ARGS_PASSTHRU
struct _zend_module_dep zend_module_dep
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES
#define ZEND_MOD_REQUIRED(name)
#define STANDARD_MODULE_HEADER_EX
ZEND_API void ZEND_FASTCALL convert_to_null(zval *op)
#define zend_always_inline
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define _ZSTR_STRUCT_SIZE(len)
#define Z_STRVAL_P(zval_p)
#define Z_ARRVAL_P(zval_p)
#define Z_REFCOUNTED_P(zval_p)
#define Z_STRLEN_P(zval_p)
#define Z_TRY_DELREF_P(pz)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)