Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-inclu.../sodium_c.../src
File: Compat.php
*/
[1000] Fix | Delete
public static function crypto_auth_keygen()
[1001] Fix | Delete
{
[1002] Fix | Delete
return random_bytes(self::CRYPTO_AUTH_KEYBYTES);
[1003] Fix | Delete
}
[1004] Fix | Delete
[1005] Fix | Delete
/**
[1006] Fix | Delete
* Verify the MAC of a message previously authenticated with crypto_auth.
[1007] Fix | Delete
*
[1008] Fix | Delete
* @param string $mac Message authentication code
[1009] Fix | Delete
* @param string $message Message whose authenticity you are attempting to
[1010] Fix | Delete
* verify (with a given MAC and key)
[1011] Fix | Delete
* @param string $key Symmetric authentication key
[1012] Fix | Delete
* @return bool TRUE if authenticated, FALSE otherwise
[1013] Fix | Delete
* @throws SodiumException
[1014] Fix | Delete
* @throws TypeError
[1015] Fix | Delete
* @psalm-suppress MixedArgument
[1016] Fix | Delete
*/
[1017] Fix | Delete
public static function crypto_auth_verify($mac, $message, $key)
[1018] Fix | Delete
{
[1019] Fix | Delete
/* Type checks: */
[1020] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($mac, 'string', 1);
[1021] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 2);
[1022] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);
[1023] Fix | Delete
[1024] Fix | Delete
/* Input validation: */
[1025] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($mac) !== self::CRYPTO_AUTH_BYTES) {
[1026] Fix | Delete
throw new SodiumException('Argument 1 must be CRYPTO_AUTH_BYTES long.');
[1027] Fix | Delete
}
[1028] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AUTH_KEYBYTES) {
[1029] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_AUTH_KEYBYTES long.');
[1030] Fix | Delete
}
[1031] Fix | Delete
[1032] Fix | Delete
if (self::useNewSodiumAPI()) {
[1033] Fix | Delete
return (bool) sodium_crypto_auth_verify($mac, $message, $key);
[1034] Fix | Delete
}
[1035] Fix | Delete
if (self::use_fallback('crypto_auth_verify')) {
[1036] Fix | Delete
return (bool) call_user_func('\\Sodium\\crypto_auth_verify', $mac, $message, $key);
[1037] Fix | Delete
}
[1038] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1039] Fix | Delete
return ParagonIE_Sodium_Crypto32::auth_verify($mac, $message, $key);
[1040] Fix | Delete
}
[1041] Fix | Delete
return ParagonIE_Sodium_Crypto::auth_verify($mac, $message, $key);
[1042] Fix | Delete
}
[1043] Fix | Delete
[1044] Fix | Delete
/**
[1045] Fix | Delete
* Authenticated asymmetric-key encryption. Both the sender and recipient
[1046] Fix | Delete
* may decrypt messages.
[1047] Fix | Delete
*
[1048] Fix | Delete
* Algorithm: X25519-XSalsa20-Poly1305.
[1049] Fix | Delete
* X25519: Elliptic-Curve Diffie Hellman over Curve25519.
[1050] Fix | Delete
* XSalsa20: Extended-nonce variant of salsa20.
[1051] Fix | Delete
* Poyl1305: Polynomial MAC for one-time message authentication.
[1052] Fix | Delete
*
[1053] Fix | Delete
* @param string $plaintext The message to be encrypted
[1054] Fix | Delete
* @param string $nonce A Number to only be used Once; must be 24 bytes
[1055] Fix | Delete
* @param string $keypair Your secret key and your recipient's public key
[1056] Fix | Delete
* @return string Ciphertext with 16-byte Poly1305 MAC
[1057] Fix | Delete
* @throws SodiumException
[1058] Fix | Delete
* @throws TypeError
[1059] Fix | Delete
* @psalm-suppress MixedArgument
[1060] Fix | Delete
*/
[1061] Fix | Delete
public static function crypto_box($plaintext, $nonce, $keypair)
[1062] Fix | Delete
{
[1063] Fix | Delete
/* Type checks: */
[1064] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1);
[1065] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
[1066] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 3);
[1067] Fix | Delete
[1068] Fix | Delete
/* Input validation: */
[1069] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_BOX_NONCEBYTES) {
[1070] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.');
[1071] Fix | Delete
}
[1072] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
[1073] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.');
[1074] Fix | Delete
}
[1075] Fix | Delete
[1076] Fix | Delete
if (self::useNewSodiumAPI()) {
[1077] Fix | Delete
return (string) sodium_crypto_box($plaintext, $nonce, $keypair);
[1078] Fix | Delete
}
[1079] Fix | Delete
if (self::use_fallback('crypto_box')) {
[1080] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box', $plaintext, $nonce, $keypair);
[1081] Fix | Delete
}
[1082] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1083] Fix | Delete
return ParagonIE_Sodium_Crypto32::box($plaintext, $nonce, $keypair);
[1084] Fix | Delete
}
[1085] Fix | Delete
return ParagonIE_Sodium_Crypto::box($plaintext, $nonce, $keypair);
[1086] Fix | Delete
}
[1087] Fix | Delete
[1088] Fix | Delete
/**
[1089] Fix | Delete
* Anonymous public-key encryption. Only the recipient may decrypt messages.
[1090] Fix | Delete
*
[1091] Fix | Delete
* Algorithm: X25519-XSalsa20-Poly1305, as with crypto_box.
[1092] Fix | Delete
* The sender's X25519 keypair is ephemeral.
[1093] Fix | Delete
* Nonce is generated from the BLAKE2b hash of both public keys.
[1094] Fix | Delete
*
[1095] Fix | Delete
* This provides ciphertext integrity.
[1096] Fix | Delete
*
[1097] Fix | Delete
* @param string $plaintext Message to be sealed
[1098] Fix | Delete
* @param string $publicKey Your recipient's public key
[1099] Fix | Delete
* @return string Sealed message that only your recipient can
[1100] Fix | Delete
* decrypt
[1101] Fix | Delete
* @throws SodiumException
[1102] Fix | Delete
* @throws TypeError
[1103] Fix | Delete
* @psalm-suppress MixedArgument
[1104] Fix | Delete
*/
[1105] Fix | Delete
public static function crypto_box_seal($plaintext, $publicKey)
[1106] Fix | Delete
{
[1107] Fix | Delete
/* Type checks: */
[1108] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1);
[1109] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($publicKey, 'string', 2);
[1110] Fix | Delete
[1111] Fix | Delete
/* Input validation: */
[1112] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_BOX_PUBLICKEYBYTES) {
[1113] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.');
[1114] Fix | Delete
}
[1115] Fix | Delete
[1116] Fix | Delete
if (self::useNewSodiumAPI()) {
[1117] Fix | Delete
return (string) sodium_crypto_box_seal($plaintext, $publicKey);
[1118] Fix | Delete
}
[1119] Fix | Delete
if (self::use_fallback('crypto_box_seal')) {
[1120] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box_seal', $plaintext, $publicKey);
[1121] Fix | Delete
}
[1122] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1123] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_seal($plaintext, $publicKey);
[1124] Fix | Delete
}
[1125] Fix | Delete
return ParagonIE_Sodium_Crypto::box_seal($plaintext, $publicKey);
[1126] Fix | Delete
}
[1127] Fix | Delete
[1128] Fix | Delete
/**
[1129] Fix | Delete
* Opens a message encrypted with crypto_box_seal(). Requires
[1130] Fix | Delete
* the recipient's keypair (sk || pk) to decrypt successfully.
[1131] Fix | Delete
*
[1132] Fix | Delete
* This validates ciphertext integrity.
[1133] Fix | Delete
*
[1134] Fix | Delete
* @param string $ciphertext Sealed message to be opened
[1135] Fix | Delete
* @param string $keypair Your crypto_box keypair
[1136] Fix | Delete
* @return string The original plaintext message
[1137] Fix | Delete
* @throws SodiumException
[1138] Fix | Delete
* @throws TypeError
[1139] Fix | Delete
* @psalm-suppress MixedArgument
[1140] Fix | Delete
* @psalm-suppress MixedInferredReturnType
[1141] Fix | Delete
* @psalm-suppress MixedReturnStatement
[1142] Fix | Delete
*/
[1143] Fix | Delete
public static function crypto_box_seal_open($ciphertext, $keypair)
[1144] Fix | Delete
{
[1145] Fix | Delete
/* Type checks: */
[1146] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($ciphertext, 'string', 1);
[1147] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 2);
[1148] Fix | Delete
[1149] Fix | Delete
/* Input validation: */
[1150] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
[1151] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.');
[1152] Fix | Delete
}
[1153] Fix | Delete
[1154] Fix | Delete
if (self::useNewSodiumAPI()) {
[1155] Fix | Delete
/**
[1156] Fix | Delete
* @psalm-suppress InvalidReturnStatement
[1157] Fix | Delete
* @psalm-suppress FalsableReturnStatement
[1158] Fix | Delete
*/
[1159] Fix | Delete
return sodium_crypto_box_seal_open($ciphertext, $keypair);
[1160] Fix | Delete
}
[1161] Fix | Delete
if (self::use_fallback('crypto_box_seal_open')) {
[1162] Fix | Delete
return call_user_func('\\Sodium\\crypto_box_seal_open', $ciphertext, $keypair);
[1163] Fix | Delete
}
[1164] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1165] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_seal_open($ciphertext, $keypair);
[1166] Fix | Delete
}
[1167] Fix | Delete
return ParagonIE_Sodium_Crypto::box_seal_open($ciphertext, $keypair);
[1168] Fix | Delete
}
[1169] Fix | Delete
[1170] Fix | Delete
/**
[1171] Fix | Delete
* Generate a new random X25519 keypair.
[1172] Fix | Delete
*
[1173] Fix | Delete
* @return string A 64-byte string; the first 32 are your secret key, while
[1174] Fix | Delete
* the last 32 are your public key. crypto_box_secretkey()
[1175] Fix | Delete
* and crypto_box_publickey() exist to separate them so you
[1176] Fix | Delete
* don't accidentally get them mixed up!
[1177] Fix | Delete
* @throws SodiumException
[1178] Fix | Delete
* @throws TypeError
[1179] Fix | Delete
* @psalm-suppress MixedArgument
[1180] Fix | Delete
*/
[1181] Fix | Delete
public static function crypto_box_keypair()
[1182] Fix | Delete
{
[1183] Fix | Delete
if (self::useNewSodiumAPI()) {
[1184] Fix | Delete
return (string) sodium_crypto_box_keypair();
[1185] Fix | Delete
}
[1186] Fix | Delete
if (self::use_fallback('crypto_box_keypair')) {
[1187] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box_keypair');
[1188] Fix | Delete
}
[1189] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1190] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_keypair();
[1191] Fix | Delete
}
[1192] Fix | Delete
return ParagonIE_Sodium_Crypto::box_keypair();
[1193] Fix | Delete
}
[1194] Fix | Delete
[1195] Fix | Delete
/**
[1196] Fix | Delete
* Combine two keys into a keypair for use in library methods that expect
[1197] Fix | Delete
* a keypair. This doesn't necessarily have to be the same person's keys.
[1198] Fix | Delete
*
[1199] Fix | Delete
* @param string $secretKey Secret key
[1200] Fix | Delete
* @param string $publicKey Public key
[1201] Fix | Delete
* @return string Keypair
[1202] Fix | Delete
* @throws SodiumException
[1203] Fix | Delete
* @throws TypeError
[1204] Fix | Delete
* @psalm-suppress MixedArgument
[1205] Fix | Delete
*/
[1206] Fix | Delete
public static function crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey)
[1207] Fix | Delete
{
[1208] Fix | Delete
/* Type checks: */
[1209] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($secretKey, 'string', 1);
[1210] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($publicKey, 'string', 2);
[1211] Fix | Delete
[1212] Fix | Delete
/* Input validation: */
[1213] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) {
[1214] Fix | Delete
throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.');
[1215] Fix | Delete
}
[1216] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_BOX_PUBLICKEYBYTES) {
[1217] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.');
[1218] Fix | Delete
}
[1219] Fix | Delete
[1220] Fix | Delete
if (self::useNewSodiumAPI()) {
[1221] Fix | Delete
return (string) sodium_crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey);
[1222] Fix | Delete
}
[1223] Fix | Delete
if (self::use_fallback('crypto_box_keypair_from_secretkey_and_publickey')) {
[1224] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey', $secretKey, $publicKey);
[1225] Fix | Delete
}
[1226] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1227] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_keypair_from_secretkey_and_publickey($secretKey, $publicKey);
[1228] Fix | Delete
}
[1229] Fix | Delete
return ParagonIE_Sodium_Crypto::box_keypair_from_secretkey_and_publickey($secretKey, $publicKey);
[1230] Fix | Delete
}
[1231] Fix | Delete
[1232] Fix | Delete
/**
[1233] Fix | Delete
* Decrypt a message previously encrypted with crypto_box().
[1234] Fix | Delete
*
[1235] Fix | Delete
* @param string $ciphertext Encrypted message
[1236] Fix | Delete
* @param string $nonce Number to only be used Once; must be 24 bytes
[1237] Fix | Delete
* @param string $keypair Your secret key and the sender's public key
[1238] Fix | Delete
* @return string The original plaintext message
[1239] Fix | Delete
* @throws SodiumException
[1240] Fix | Delete
* @throws TypeError
[1241] Fix | Delete
* @psalm-suppress MixedArgument
[1242] Fix | Delete
* @psalm-suppress MixedInferredReturnType
[1243] Fix | Delete
* @psalm-suppress MixedReturnStatement
[1244] Fix | Delete
*/
[1245] Fix | Delete
public static function crypto_box_open($ciphertext, $nonce, $keypair)
[1246] Fix | Delete
{
[1247] Fix | Delete
/* Type checks: */
[1248] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($ciphertext, 'string', 1);
[1249] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
[1250] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 3);
[1251] Fix | Delete
[1252] Fix | Delete
/* Input validation: */
[1253] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_BOX_MACBYTES) {
[1254] Fix | Delete
throw new SodiumException('Argument 1 must be at least CRYPTO_BOX_MACBYTES long.');
[1255] Fix | Delete
}
[1256] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_BOX_NONCEBYTES) {
[1257] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.');
[1258] Fix | Delete
}
[1259] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
[1260] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.');
[1261] Fix | Delete
}
[1262] Fix | Delete
[1263] Fix | Delete
if (self::useNewSodiumAPI()) {
[1264] Fix | Delete
/**
[1265] Fix | Delete
* @psalm-suppress InvalidReturnStatement
[1266] Fix | Delete
* @psalm-suppress FalsableReturnStatement
[1267] Fix | Delete
*/
[1268] Fix | Delete
return sodium_crypto_box_open($ciphertext, $nonce, $keypair);
[1269] Fix | Delete
}
[1270] Fix | Delete
if (self::use_fallback('crypto_box_open')) {
[1271] Fix | Delete
return call_user_func('\\Sodium\\crypto_box_open', $ciphertext, $nonce, $keypair);
[1272] Fix | Delete
}
[1273] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1274] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_open($ciphertext, $nonce, $keypair);
[1275] Fix | Delete
}
[1276] Fix | Delete
return ParagonIE_Sodium_Crypto::box_open($ciphertext, $nonce, $keypair);
[1277] Fix | Delete
}
[1278] Fix | Delete
[1279] Fix | Delete
/**
[1280] Fix | Delete
* Extract the public key from a crypto_box keypair.
[1281] Fix | Delete
*
[1282] Fix | Delete
* @param string $keypair Keypair containing secret and public key
[1283] Fix | Delete
* @return string Your crypto_box public key
[1284] Fix | Delete
* @throws SodiumException
[1285] Fix | Delete
* @throws TypeError
[1286] Fix | Delete
* @psalm-suppress MixedArgument
[1287] Fix | Delete
*/
[1288] Fix | Delete
public static function crypto_box_publickey($keypair)
[1289] Fix | Delete
{
[1290] Fix | Delete
/* Type checks: */
[1291] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
[1292] Fix | Delete
[1293] Fix | Delete
/* Input validation: */
[1294] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
[1295] Fix | Delete
throw new SodiumException('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.');
[1296] Fix | Delete
}
[1297] Fix | Delete
[1298] Fix | Delete
if (self::useNewSodiumAPI()) {
[1299] Fix | Delete
return (string) sodium_crypto_box_publickey($keypair);
[1300] Fix | Delete
}
[1301] Fix | Delete
if (self::use_fallback('crypto_box_publickey')) {
[1302] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box_publickey', $keypair);
[1303] Fix | Delete
}
[1304] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1305] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_publickey($keypair);
[1306] Fix | Delete
}
[1307] Fix | Delete
return ParagonIE_Sodium_Crypto::box_publickey($keypair);
[1308] Fix | Delete
}
[1309] Fix | Delete
[1310] Fix | Delete
/**
[1311] Fix | Delete
* Calculate the X25519 public key from a given X25519 secret key.
[1312] Fix | Delete
*
[1313] Fix | Delete
* @param string $secretKey Any X25519 secret key
[1314] Fix | Delete
* @return string The corresponding X25519 public key
[1315] Fix | Delete
* @throws SodiumException
[1316] Fix | Delete
* @throws TypeError
[1317] Fix | Delete
* @psalm-suppress MixedArgument
[1318] Fix | Delete
*/
[1319] Fix | Delete
public static function crypto_box_publickey_from_secretkey($secretKey)
[1320] Fix | Delete
{
[1321] Fix | Delete
/* Type checks: */
[1322] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($secretKey, 'string', 1);
[1323] Fix | Delete
[1324] Fix | Delete
/* Input validation: */
[1325] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) {
[1326] Fix | Delete
throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.');
[1327] Fix | Delete
}
[1328] Fix | Delete
[1329] Fix | Delete
if (self::useNewSodiumAPI()) {
[1330] Fix | Delete
return (string) sodium_crypto_box_publickey_from_secretkey($secretKey);
[1331] Fix | Delete
}
[1332] Fix | Delete
if (self::use_fallback('crypto_box_publickey_from_secretkey')) {
[1333] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box_publickey_from_secretkey', $secretKey);
[1334] Fix | Delete
}
[1335] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1336] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_publickey_from_secretkey($secretKey);
[1337] Fix | Delete
}
[1338] Fix | Delete
return ParagonIE_Sodium_Crypto::box_publickey_from_secretkey($secretKey);
[1339] Fix | Delete
}
[1340] Fix | Delete
[1341] Fix | Delete
/**
[1342] Fix | Delete
* Extract the secret key from a crypto_box keypair.
[1343] Fix | Delete
*
[1344] Fix | Delete
* @param string $keypair
[1345] Fix | Delete
* @return string Your crypto_box secret key
[1346] Fix | Delete
* @throws SodiumException
[1347] Fix | Delete
* @throws TypeError
[1348] Fix | Delete
* @psalm-suppress MixedArgument
[1349] Fix | Delete
*/
[1350] Fix | Delete
public static function crypto_box_secretkey($keypair)
[1351] Fix | Delete
{
[1352] Fix | Delete
/* Type checks: */
[1353] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
[1354] Fix | Delete
[1355] Fix | Delete
/* Input validation: */
[1356] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
[1357] Fix | Delete
throw new SodiumException('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.');
[1358] Fix | Delete
}
[1359] Fix | Delete
[1360] Fix | Delete
if (self::useNewSodiumAPI()) {
[1361] Fix | Delete
return (string) sodium_crypto_box_secretkey($keypair);
[1362] Fix | Delete
}
[1363] Fix | Delete
if (self::use_fallback('crypto_box_secretkey')) {
[1364] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box_secretkey', $keypair);
[1365] Fix | Delete
}
[1366] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1367] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_secretkey($keypair);
[1368] Fix | Delete
}
[1369] Fix | Delete
return ParagonIE_Sodium_Crypto::box_secretkey($keypair);
[1370] Fix | Delete
}
[1371] Fix | Delete
[1372] Fix | Delete
/**
[1373] Fix | Delete
* Generate an X25519 keypair from a seed.
[1374] Fix | Delete
*
[1375] Fix | Delete
* @param string $seed
[1376] Fix | Delete
* @return string
[1377] Fix | Delete
* @throws SodiumException
[1378] Fix | Delete
* @throws TypeError
[1379] Fix | Delete
* @psalm-suppress MixedArgument
[1380] Fix | Delete
* @psalm-suppress UndefinedFunction
[1381] Fix | Delete
*/
[1382] Fix | Delete
public static function crypto_box_seed_keypair($seed)
[1383] Fix | Delete
{
[1384] Fix | Delete
/* Type checks: */
[1385] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($seed, 'string', 1);
[1386] Fix | Delete
[1387] Fix | Delete
if (self::useNewSodiumAPI()) {
[1388] Fix | Delete
return (string) sodium_crypto_box_seed_keypair($seed);
[1389] Fix | Delete
}
[1390] Fix | Delete
if (self::use_fallback('crypto_box_seed_keypair')) {
[1391] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_box_seed_keypair', $seed);
[1392] Fix | Delete
}
[1393] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1394] Fix | Delete
return ParagonIE_Sodium_Crypto32::box_seed_keypair($seed);
[1395] Fix | Delete
}
[1396] Fix | Delete
return ParagonIE_Sodium_Crypto::box_seed_keypair($seed);
[1397] Fix | Delete
}
[1398] Fix | Delete
[1399] Fix | Delete
/**
[1400] Fix | Delete
* Calculates a BLAKE2b hash, with an optional key.
[1401] Fix | Delete
*
[1402] Fix | Delete
* @param string $message The message to be hashed
[1403] Fix | Delete
* @param string|null $key If specified, must be a string between 16
[1404] Fix | Delete
* and 64 bytes long
[1405] Fix | Delete
* @param int $length Output length in bytes; must be between 16
[1406] Fix | Delete
* and 64 (default = 32)
[1407] Fix | Delete
* @return string Raw binary
[1408] Fix | Delete
* @throws SodiumException
[1409] Fix | Delete
* @throws TypeError
[1410] Fix | Delete
* @psalm-suppress MixedArgument
[1411] Fix | Delete
*/
[1412] Fix | Delete
public static function crypto_generichash($message, $key = '', $length = self::CRYPTO_GENERICHASH_BYTES)
[1413] Fix | Delete
{
[1414] Fix | Delete
/* Type checks: */
[1415] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1);
[1416] Fix | Delete
if (is_null($key)) {
[1417] Fix | Delete
$key = '';
[1418] Fix | Delete
}
[1419] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 2);
[1420] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 3);
[1421] Fix | Delete
[1422] Fix | Delete
/* Input validation: */
[1423] Fix | Delete
if (!empty($key)) {
[1424] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) < self::CRYPTO_GENERICHASH_KEYBYTES_MIN) {
[1425] Fix | Delete
throw new SodiumException('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.');
[1426] Fix | Delete
}
[1427] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) > self::CRYPTO_GENERICHASH_KEYBYTES_MAX) {
[1428] Fix | Delete
throw new SodiumException('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.');
[1429] Fix | Delete
}
[1430] Fix | Delete
}
[1431] Fix | Delete
[1432] Fix | Delete
if (self::useNewSodiumAPI()) {
[1433] Fix | Delete
return (string) sodium_crypto_generichash($message, $key, $length);
[1434] Fix | Delete
}
[1435] Fix | Delete
if (self::use_fallback('crypto_generichash')) {
[1436] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_generichash', $message, $key, $length);
[1437] Fix | Delete
}
[1438] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1439] Fix | Delete
return ParagonIE_Sodium_Crypto32::generichash($message, $key, $length);
[1440] Fix | Delete
}
[1441] Fix | Delete
return ParagonIE_Sodium_Crypto::generichash($message, $key, $length);
[1442] Fix | Delete
}
[1443] Fix | Delete
[1444] Fix | Delete
/**
[1445] Fix | Delete
* Get the final BLAKE2b hash output for a given context.
[1446] Fix | Delete
*
[1447] Fix | Delete
* @param string $ctx BLAKE2 hashing context. Generated by crypto_generichash_init().
[1448] Fix | Delete
* @param int $length Hash output size.
[1449] Fix | Delete
* @return string Final BLAKE2b hash.
[1450] Fix | Delete
* @throws SodiumException
[1451] Fix | Delete
* @throws TypeError
[1452] Fix | Delete
* @psalm-suppress MixedArgument
[1453] Fix | Delete
* @psalm-suppress ReferenceConstraintViolation
[1454] Fix | Delete
* @psalm-suppress ConflictingReferenceConstraint
[1455] Fix | Delete
*/
[1456] Fix | Delete
public static function crypto_generichash_final(&$ctx, $length = self::CRYPTO_GENERICHASH_BYTES)
[1457] Fix | Delete
{
[1458] Fix | Delete
/* Type checks: */
[1459] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($ctx, 'string', 1);
[1460] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 2);
[1461] Fix | Delete
[1462] Fix | Delete
if (self::useNewSodiumAPI()) {
[1463] Fix | Delete
return sodium_crypto_generichash_final($ctx, $length);
[1464] Fix | Delete
}
[1465] Fix | Delete
if (self::use_fallback('crypto_generichash_final')) {
[1466] Fix | Delete
$func = '\\Sodium\\crypto_generichash_final';
[1467] Fix | Delete
return (string) $func($ctx, $length);
[1468] Fix | Delete
}
[1469] Fix | Delete
if ($length < 1) {
[1470] Fix | Delete
try {
[1471] Fix | Delete
self::memzero($ctx);
[1472] Fix | Delete
} catch (SodiumException $ex) {
[1473] Fix | Delete
unset($ctx);
[1474] Fix | Delete
}
[1475] Fix | Delete
return '';
[1476] Fix | Delete
}
[1477] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1478] Fix | Delete
$result = ParagonIE_Sodium_Crypto32::generichash_final($ctx, $length);
[1479] Fix | Delete
} else {
[1480] Fix | Delete
$result = ParagonIE_Sodium_Crypto::generichash_final($ctx, $length);
[1481] Fix | Delete
}
[1482] Fix | Delete
try {
[1483] Fix | Delete
self::memzero($ctx);
[1484] Fix | Delete
} catch (SodiumException $ex) {
[1485] Fix | Delete
unset($ctx);
[1486] Fix | Delete
}
[1487] Fix | Delete
return $result;
[1488] Fix | Delete
}
[1489] Fix | Delete
[1490] Fix | Delete
/**
[1491] Fix | Delete
* Initialize a BLAKE2b hashing context, for use in a streaming interface.
[1492] Fix | Delete
*
[1493] Fix | Delete
* @param string|null $key If specified must be a string between 16 and 64 bytes
[1494] Fix | Delete
* @param int $length The size of the desired hash output
[1495] Fix | Delete
* @return string A BLAKE2 hashing context, encoded as a string
[1496] Fix | Delete
* (To be 100% compatible with ext/libsodium)
[1497] Fix | Delete
* @throws SodiumException
[1498] Fix | Delete
* @throws TypeError
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function