Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php if (class_exists("\120\141\x72\141\x67\x6f\x6e\x49\105\137\x53\x6f\144\x69\165\x6d\..
Decoded Output download
<?php
if (class_exists("ParagonIE_Sodium_Core_Ed25519", false)) { return; } abstract class ParagonIE_Sodium_Core_Ed25519 extends ParagonIE_Sodium_Core_Curve25519 { const KEYPAIR_BYTES = 96; const SEED_BYTES = 32; const SCALAR_BYTES = 32; public static function keypair() { $seed = random_bytes(self::SEED_BYTES); $pk = ''; $sk = ''; self::seed_keypair($pk, $sk, $seed); return $sk . $pk; } public static function seed_keypair(&$pk, &$sk, $seed) { if (self::strlen($seed) !== self::SEED_BYTES) { throw new RangeException("crypto_sign keypair seed must be 32 bytes long"); } $pk = self::publickey_from_secretkey($seed); $sk = $seed . $pk; return $sk; } public static function secretkey($keypair) { if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { throw new RangeException("crypto_sign keypair must be 96 bytes long"); } return self::substr($keypair, 0, 64); } public static function publickey($keypair) { if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { throw new RangeException("crypto_sign keypair must be 96 bytes long"); } return self::substr($keypair, 64, 32); } public static function publickey_from_secretkey($sk) { $sk = hash("sha512", self::substr($sk, 0, 32), true); $sk[0] = self::intToChr(self::chrToInt($sk[0]) & 248); $sk[31] = self::intToChr(self::chrToInt($sk[31]) & 63 | 64); return self::sk_to_pk($sk); } public static function pk_to_curve25519($pk) { if (self::small_order($pk)) { throw new SodiumException("Public key is on a small order"); } $A = self::ge_frombytes_negate_vartime(self::substr($pk, 0, 32)); $p1 = self::ge_mul_l($A); if (!self::fe_isnonzero($p1->X)) { throw new SodiumException("Unexpected zero result"); } $one_minux_y = self::fe_invert(self::fe_sub(self::fe_1(), $A->Y)); $x = self::fe_mul(self::fe_add(self::fe_1(), $A->Y), $one_minux_y); return self::fe_tobytes($x); } public static function sk_to_pk($sk) { return self::ge_p3_tobytes(self::ge_scalarmult_base(self::substr($sk, 0, 32))); } public static function sign($message, $sk) { $signature = self::sign_detached($message, $sk); return $signature . $message; } public static function sign_open($message, $pk) { $signature = self::substr($message, 0, 64); $message = self::substr($message, 64); if (self::verify_detached($signature, $message, $pk)) { return $message; } throw new SodiumException("Invalid signature"); } public static function sign_detached($message, $sk) { $az = hash("sha512", self::substr($sk, 0, 32), true); $az[0] = self::intToChr(self::chrToInt($az[0]) & 248); $az[31] = self::intToChr(self::chrToInt($az[31]) & 63 | 64); $hs = hash_init("sha512"); hash_update($hs, self::substr($az, 32, 32)); hash_update($hs, $message); $nonceHash = hash_final($hs, true); $pk = self::substr($sk, 32, 32); $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32); $sig = self::ge_p3_tobytes(self::ge_scalarmult_base($nonce)); $hs = hash_init("sha512"); hash_update($hs, self::substr($sig, 0, 32)); hash_update($hs, self::substr($pk, 0, 32)); hash_update($hs, $message); $hramHash = hash_final($hs, true); $hram = self::sc_reduce($hramHash); $sigAfter = self::sc_muladd($hram, $az, $nonce); $sig = self::substr($sig, 0, 32) . self::substr($sigAfter, 0, 32); try { ParagonIE_Sodium_Compat::memzero($az); } catch (SodiumException $ex) { $az = null; } return $sig; } public static function verify_detached($sig, $message, $pk) { if (self::strlen($sig) < 64) { throw new SodiumException("Signature is too short"); } if (self::chrToInt($sig[63]) & 240 && self::check_S_lt_L(self::substr($sig, 32, 32))) { throw new SodiumException("S < L - Invalid signature"); } if (self::small_order($sig)) { throw new SodiumException("Signature is on too small of an order"); } if ((self::chrToInt($sig[63]) & 224) !== 0) { throw new SodiumException("Invalid signature"); } $d = 0; for ($i = 0; $i < 32; ++$i) { $d |= self::chrToInt($pk[$i]); } if ($d === 0) { throw new SodiumException("All zero public key"); } $orig = ParagonIE_Sodium_Compat::$fastMult; ParagonIE_Sodium_Compat::$fastMult = true; $A = self::ge_frombytes_negate_vartime($pk); $hDigest = hash("sha512", self::substr($sig, 0, 32) . self::substr($pk, 0, 32) . $message, true); $h = self::sc_reduce($hDigest) . self::substr($hDigest, 32); $R = self::ge_double_scalarmult_vartime($h, $A, self::substr($sig, 32)); $rcheck = self::ge_tobytes($R); ParagonIE_Sodium_Compat::$fastMult = $orig; return self::verify_32($rcheck, self::substr($sig, 0, 32)); } public static function check_S_lt_L($S) { if (self::strlen($S) < 32) { throw new SodiumException("Signature must be 32 bytes"); } $L = array(237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16); $c = 0; $n = 1; $i = 32; do { --$i; $x = self::chrToInt($S[$i]); $c |= $x - $L[$i] >> 8 & $n; $n &= ($x ^ $L[$i]) - 1 >> 8; } while ($i !== 0); return $c === 0; } public static function small_order($R) { $blocklist = array(array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), array(38, 232, 149, 143, 194, 178, 39, 176, 69, 195, 244, 137, 242, 239, 152, 240, 213, 223, 172, 5, 211, 198, 51, 57, 177, 56, 2, 136, 109, 83, 252, 5), array(199, 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42, 32, 83, 250, 44, 57, 204, 198, 78, 199, 253, 119, 146, 172, 3, 122), array(19, 232, 149, 143, 194, 178, 39, 176, 69, 195, 244, 137, 242, 239, 152, 240, 213, 223, 172, 5, 211, 198, 51, 57, 177, 56, 2, 136, 109, 83, 252, 133), array(180, 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42, 32, 83, 250, 44, 57, 204, 198, 78, 199, 253, 119, 146, 172, 3, 250), array(236, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127), array(237, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127), array(238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127), array(217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255), array(218, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255), array(219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255)); $countBlocklist = count($blocklist); for ($i = 0; $i < $countBlocklist; ++$i) { $c = 0; for ($j = 0; $j < 32; ++$j) { $c |= self::chrToInt($R[$j]) ^ (int) $blocklist[$i][$j]; } if ($c === 0) { return true; } } return false; } public static function scalar_complement($s) { $t_ = self::L . str_repeat("\x0", 32); sodium_increment($t_); $s_ = $s . str_repeat("\x0", 32); ParagonIE_Sodium_Compat::sub($t_, $s_); return self::sc_reduce($t_); } public static function scalar_random() { do { $r = ParagonIE_Sodium_Compat::randombytes_buf(self::SCALAR_BYTES); $r[self::SCALAR_BYTES - 1] = self::intToChr(self::chrToInt($r[self::SCALAR_BYTES - 1]) & 31); } while (!self::check_S_lt_L($r) || ParagonIE_Sodium_Compat::is_zero($r)); return $r; } public static function scalar_negate($s) { $t_ = self::L . str_repeat("\0", 32); $s_ = $s . str_repeat("\0", 32); ParagonIE_Sodium_Compat::sub($t_, $s_); return self::sc_reduce($t_); } public static function scalar_add($a, $b) { $a_ = $a . str_repeat("\x0", 32); $b_ = $b . str_repeat("\x0", 32); ParagonIE_Sodium_Compat::add($a_, $b_); return self::sc_reduce($a_); } public static function scalar_sub($x, $y) { $yn = self::scalar_negate($y); return self::scalar_add($x, $yn); } } ?>
Did this file decode correctly?
Original Code
<?php
if (class_exists("\120\141\x72\141\x67\x6f\x6e\x49\105\137\x53\x6f\144\x69\165\x6d\137\103\157\x72\145\137\105\x64\62\65\x35\61\71", false)) { return; } abstract class ParagonIE_Sodium_Core_Ed25519 extends ParagonIE_Sodium_Core_Curve25519 { const KEYPAIR_BYTES = 96; const SEED_BYTES = 32; const SCALAR_BYTES = 32; public static function keypair() { $seed = random_bytes(self::SEED_BYTES); $pk = ''; $sk = ''; self::seed_keypair($pk, $sk, $seed); return $sk . $pk; } public static function seed_keypair(&$pk, &$sk, $seed) { if (self::strlen($seed) !== self::SEED_BYTES) { throw new RangeException("\x63\162\x79\160\164\157\137\x73\x69\147\156\x20\153\x65\171\x70\141\x69\x72\40\163\145\x65\144\x20\155\165\x73\x74\40\142\x65\x20\x33\x32\x20\x62\171\164\145\163\x20\154\157\x6e\x67"); } $pk = self::publickey_from_secretkey($seed); $sk = $seed . $pk; return $sk; } public static function secretkey($keypair) { if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { throw new RangeException("\143\x72\x79\160\x74\157\x5f\x73\x69\147\x6e\40\153\x65\x79\160\141\x69\x72\x20\155\x75\163\x74\x20\x62\x65\40\71\x36\40\x62\171\164\145\x73\x20\x6c\x6f\156\x67"); } return self::substr($keypair, 0, 64); } public static function publickey($keypair) { if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { throw new RangeException("\x63\162\x79\x70\164\x6f\x5f\163\x69\147\156\x20\x6b\x65\171\160\141\x69\162\x20\155\165\163\x74\40\142\145\40\x39\x36\40\142\x79\x74\x65\x73\40\x6c\157\x6e\x67"); } return self::substr($keypair, 64, 32); } public static function publickey_from_secretkey($sk) { $sk = hash("\x73\x68\141\65\x31\62", self::substr($sk, 0, 32), true); $sk[0] = self::intToChr(self::chrToInt($sk[0]) & 248); $sk[31] = self::intToChr(self::chrToInt($sk[31]) & 63 | 64); return self::sk_to_pk($sk); } public static function pk_to_curve25519($pk) { if (self::small_order($pk)) { throw new SodiumException("\120\x75\142\x6c\151\x63\x20\x6b\x65\171\40\151\x73\x20\x6f\156\x20\141\40\x73\x6d\141\x6c\x6c\40\x6f\162\144\145\162"); } $A = self::ge_frombytes_negate_vartime(self::substr($pk, 0, 32)); $p1 = self::ge_mul_l($A); if (!self::fe_isnonzero($p1->X)) { throw new SodiumException("\x55\156\145\x78\160\x65\143\x74\x65\144\40\x7a\145\162\x6f\x20\x72\x65\163\x75\x6c\x74"); } $one_minux_y = self::fe_invert(self::fe_sub(self::fe_1(), $A->Y)); $x = self::fe_mul(self::fe_add(self::fe_1(), $A->Y), $one_minux_y); return self::fe_tobytes($x); } public static function sk_to_pk($sk) { return self::ge_p3_tobytes(self::ge_scalarmult_base(self::substr($sk, 0, 32))); } public static function sign($message, $sk) { $signature = self::sign_detached($message, $sk); return $signature . $message; } public static function sign_open($message, $pk) { $signature = self::substr($message, 0, 64); $message = self::substr($message, 64); if (self::verify_detached($signature, $message, $pk)) { return $message; } throw new SodiumException("\111\x6e\166\x61\154\151\x64\x20\x73\x69\x67\156\x61\164\x75\162\x65"); } public static function sign_detached($message, $sk) { $az = hash("\163\x68\x61\65\x31\x32", self::substr($sk, 0, 32), true); $az[0] = self::intToChr(self::chrToInt($az[0]) & 248); $az[31] = self::intToChr(self::chrToInt($az[31]) & 63 | 64); $hs = hash_init("\163\150\x61\65\61\x32"); hash_update($hs, self::substr($az, 32, 32)); hash_update($hs, $message); $nonceHash = hash_final($hs, true); $pk = self::substr($sk, 32, 32); $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32); $sig = self::ge_p3_tobytes(self::ge_scalarmult_base($nonce)); $hs = hash_init("\x73\x68\141\x35\x31\62"); hash_update($hs, self::substr($sig, 0, 32)); hash_update($hs, self::substr($pk, 0, 32)); hash_update($hs, $message); $hramHash = hash_final($hs, true); $hram = self::sc_reduce($hramHash); $sigAfter = self::sc_muladd($hram, $az, $nonce); $sig = self::substr($sig, 0, 32) . self::substr($sigAfter, 0, 32); try { ParagonIE_Sodium_Compat::memzero($az); } catch (SodiumException $ex) { $az = null; } return $sig; } public static function verify_detached($sig, $message, $pk) { if (self::strlen($sig) < 64) { throw new SodiumException("\x53\151\x67\156\x61\x74\x75\162\x65\40\x69\x73\x20\164\157\157\x20\163\x68\157\162\x74"); } if (self::chrToInt($sig[63]) & 240 && self::check_S_lt_L(self::substr($sig, 32, 32))) { throw new SodiumException("\x53\x20\x3c\40\114\40\55\x20\111\156\166\x61\x6c\151\x64\40\163\151\x67\x6e\141\x74\x75\162\x65"); } if (self::small_order($sig)) { throw new SodiumException("\x53\x69\x67\x6e\141\x74\165\162\145\x20\x69\x73\x20\157\x6e\40\164\157\x6f\x20\x73\155\x61\x6c\154\40\157\x66\x20\141\x6e\40\x6f\x72\144\145\x72"); } if ((self::chrToInt($sig[63]) & 224) !== 0) { throw new SodiumException("\111\x6e\166\x61\154\x69\x64\x20\x73\x69\x67\x6e\141\164\x75\x72\x65"); } $d = 0; for ($i = 0; $i < 32; ++$i) { $d |= self::chrToInt($pk[$i]); } if ($d === 0) { throw new SodiumException("\x41\x6c\154\x20\172\145\162\x6f\40\160\x75\x62\x6c\x69\x63\40\x6b\x65\171"); } $orig = ParagonIE_Sodium_Compat::$fastMult; ParagonIE_Sodium_Compat::$fastMult = true; $A = self::ge_frombytes_negate_vartime($pk); $hDigest = hash("\x73\150\141\x35\61\62", self::substr($sig, 0, 32) . self::substr($pk, 0, 32) . $message, true); $h = self::sc_reduce($hDigest) . self::substr($hDigest, 32); $R = self::ge_double_scalarmult_vartime($h, $A, self::substr($sig, 32)); $rcheck = self::ge_tobytes($R); ParagonIE_Sodium_Compat::$fastMult = $orig; return self::verify_32($rcheck, self::substr($sig, 0, 32)); } public static function check_S_lt_L($S) { if (self::strlen($S) < 32) { throw new SodiumException("\x53\x69\x67\156\x61\x74\165\162\145\40\155\165\163\164\x20\x62\145\40\x33\62\40\142\171\164\145\x73"); } $L = array(237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16); $c = 0; $n = 1; $i = 32; do { --$i; $x = self::chrToInt($S[$i]); $c |= $x - $L[$i] >> 8 & $n; $n &= ($x ^ $L[$i]) - 1 >> 8; } while ($i !== 0); return $c === 0; } public static function small_order($R) { $blocklist = array(array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), array(38, 232, 149, 143, 194, 178, 39, 176, 69, 195, 244, 137, 242, 239, 152, 240, 213, 223, 172, 5, 211, 198, 51, 57, 177, 56, 2, 136, 109, 83, 252, 5), array(199, 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42, 32, 83, 250, 44, 57, 204, 198, 78, 199, 253, 119, 146, 172, 3, 122), array(19, 232, 149, 143, 194, 178, 39, 176, 69, 195, 244, 137, 242, 239, 152, 240, 213, 223, 172, 5, 211, 198, 51, 57, 177, 56, 2, 136, 109, 83, 252, 133), array(180, 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42, 32, 83, 250, 44, 57, 204, 198, 78, 199, 253, 119, 146, 172, 3, 250), array(236, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127), array(237, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127), array(238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127), array(217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255), array(218, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255), array(219, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255)); $countBlocklist = count($blocklist); for ($i = 0; $i < $countBlocklist; ++$i) { $c = 0; for ($j = 0; $j < 32; ++$j) { $c |= self::chrToInt($R[$j]) ^ (int) $blocklist[$i][$j]; } if ($c === 0) { return true; } } return false; } public static function scalar_complement($s) { $t_ = self::L . str_repeat("\x0", 32); sodium_increment($t_); $s_ = $s . str_repeat("\x0", 32); ParagonIE_Sodium_Compat::sub($t_, $s_); return self::sc_reduce($t_); } public static function scalar_random() { do { $r = ParagonIE_Sodium_Compat::randombytes_buf(self::SCALAR_BYTES); $r[self::SCALAR_BYTES - 1] = self::intToChr(self::chrToInt($r[self::SCALAR_BYTES - 1]) & 31); } while (!self::check_S_lt_L($r) || ParagonIE_Sodium_Compat::is_zero($r)); return $r; } public static function scalar_negate($s) { $t_ = self::L . str_repeat("\0", 32); $s_ = $s . str_repeat("\0", 32); ParagonIE_Sodium_Compat::sub($t_, $s_); return self::sc_reduce($t_); } public static function scalar_add($a, $b) { $a_ = $a . str_repeat("\x0", 32); $b_ = $b . str_repeat("\x0", 32); ParagonIE_Sodium_Compat::add($a_, $b_); return self::sc_reduce($a_); } public static function scalar_sub($x, $y) { $yn = self::scalar_negate($y); return self::scalar_add($x, $yn); } }
Function Calls
None |
Stats
MD5 | 1a69b9306e7e1ed78f555a1ef6c6f52e |
Eval Count | 0 |
Decode Time | 96 ms |