3v4l.org

run code in 300+ PHP versions simultaneously
<?php //bk2020 cc0 // SipHash-2-4 // Aumasson and Bernstein 2012, https://131002.net/siphash/ // https://github.com/jedisct1/libsodium/tree/master/src/libsodium/crypto_shorthash // https://github.com/php/php-src/tree/master/ext/sodium/libsodium.c#L472 function bytes_as_hex(&$str, $len=null) { if( !$len ) { $len = strlen($str); } // zero-based array index for unpack, kennwhite 2005: // https://www.php.net/manual/en/function.unpack.php#45188 $arrhead = array_merge( unpack('C*', substr($str,0,$len)) ); return array_reduce( $arrhead, function($a,$b) { return ($b>15) ? $a.dechex($b) : $a.'0'.dechex($b); }, '' ); } $SIPHASH = null; if( function_exists('\sodium_crypto_shorthash') ) { $SIPHASH = 'sodium_crypto_shorthash'; } else if( function_exists('\Sodium\crypto_shorthash') ) { $SIPHASH = '\Sodium\crypto_shorthash'; } else { die('Unable to test SipHash-2-4 using sodium_crypto_shorthash'); } $SIPKEY = '1234567890abcdef'; // 16-byte key for SipHash-2-4 echo '# ', $SIPHASH, PHP_EOL; for ($i = 0; $i < 256; ++$i) { $hsh = $SIPHASH( bin2hex(chr(($i & 0x3F) | 0x80)), $SIPKEY ); echo $i, "\t", bytes_as_hex($hsh,8), PHP_EOL; }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.32, 8.0.1 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
# sodium_crypto_shorthash 0 03eb0a923e19929b 1 bed23cb472fceff7 2 841b56b5fe1dac66 3 05764a0a91b2d65e 4 6dad6018703eb9f4 5 c0524217cc5c4d07 6 225ccb2b4aa950cc 7 ecd3a5d9b55f9433 8 caeab7b8ca752eb1 9 c63da53c4d336a82 10 8ac6ee3bbe24b187 11 a628bc715011269b 12 407a014f279ce4bb 13 0e0a35c85b6723be 14 20cac6af34f25174 15 3f1ed5968319a8d4 16 5acd651749829c8f 17 3fa96e11c7decf58 18 ea4b310354c0b717 19 d63c7fd29757e2da 20 7d2c4a79ab51148d 21 6ca236df36aabde8 22 0b684dc0f9b0e1d8 23 fac562a12834ee2a 24 7e1a8460ffd0c14f 25 459ab3fee07af1c4 26 2fe3faff6d98fb9c 27 cbf9d49bbbba1cee 28 01ab98f366b16d3a 29 9ea6a8f678460335 30 c49fbe6376df813d 31 760c125c770ab31f 32 633dca1c0176b956 33 739f319c39cfa4ba 34 648cfcbf24b99b43 35 ae43342363cdce48 36 2a3362ed26590ffc 37 2b95d2a14d796289 38 a2f20574df0595f9 39 30408e2844cfdad1 40 6233e6665feb4ebc 41 83ed286e7c34e070 42 84c0e85a83b0511e 43 478684eeb2969be0 44 b63357c1eb973a0e 45 acc9750bfb67546a 46 18446562d36dde0b 47 fa30a35ce7d209d0 48 96311dad2fdf305d 49 0cea9a503c7d82d7 50 115729b1dc372dd9 51 d41eec713d499aa2 52 1235a54832061615 53 ecb13165a84cf0bf 54 1aac07bc56db92b3 55 d69538e1ac5211e5 56 97d98f29c1dd8af5 57 37bce240202afe90 58 8c2f70cfa9208df5 59 f44e89ced4fa47cd 60 dc21bcc64575c608 61 8735657c1ef4d0ae 62 0f292c409a12a679 63 f551f5c086589bcc 64 03eb0a923e19929b 65 bed23cb472fceff7 66 841b56b5fe1dac66 67 05764a0a91b2d65e 68 6dad6018703eb9f4 69 c0524217cc5c4d07 70 225ccb2b4aa950cc 71 ecd3a5d9b55f9433 72 caeab7b8ca752eb1 73 c63da53c4d336a82 74 8ac6ee3bbe24b187 75 a628bc715011269b 76 407a014f279ce4bb 77 0e0a35c85b6723be 78 20cac6af34f25174 79 3f1ed5968319a8d4 80 5acd651749829c8f 81 3fa96e11c7decf58 82 ea4b310354c0b717 83 d63c7fd29757e2da 84 7d2c4a79ab51148d 85 6ca236df36aabde8 86 0b684dc0f9b0e1d8 87 fac562a12834ee2a 88 7e1a8460ffd0c14f 89 459ab3fee07af1c4 90 2fe3faff6d98fb9c 91 cbf9d49bbbba1cee 92 01ab98f366b16d3a 93 9ea6a8f678460335 94 c49fbe6376df813d 95 760c125c770ab31f 96 633dca1c0176b956 97 739f319c39cfa4ba 98 648cfcbf24b99b43 99 ae43342363cdce48 100 2a3362ed26590ffc 101 2b95d2a14d796289 102 a2f20574df0595f9 103 30408e2844cfdad1 104 6233e6665feb4ebc 105 83ed286e7c34e070 106 84c0e85a83b0511e 107 478684eeb2969be0 108 b63357c1eb973a0e 109 acc9750bfb67546a 110 18446562d36dde0b 111 fa30a35ce7d209d0 112 96311dad2fdf305d 113 0cea9a503c7d82d7 114 115729b1dc372dd9 115 d41eec713d499aa2 116 1235a54832061615 117 ecb13165a84cf0bf 118 1aac07bc56db92b3 119 d69538e1ac5211e5 120 97d98f29c1dd8af5 121 37bce240202afe90 122 8c2f70cfa9208df5 123 f44e89ced4fa47cd 124 dc21bcc64575c608 125 8735657c1ef4d0ae 126 0f292c409a12a679 127 f551f5c086589bcc 128 03eb0a923e19929b 129 bed23cb472fceff7 130 841b56b5fe1dac66 131 05764a0a91b2d65e 132 6dad6018703eb9f4 133 c0524217cc5c4d07 134 225ccb2b4aa950cc 135 ecd3a5d9b55f9433 136 caeab7b8ca752eb1 137 c63da53c4d336a82 138 8ac6ee3bbe24b187 139 a628bc715011269b 140 407a014f279ce4bb 141 0e0a35c85b6723be 142 20cac6af34f25174 143 3f1ed5968319a8d4 144 5acd651749829c8f 145 3fa96e11c7decf58 146 ea4b310354c0b717 147 d63c7fd29757e2da 148 7d2c4a79ab51148d 149 6ca236df36aabde8 150 0b684dc0f9b0e1d8 151 fac562a12834ee2a 152 7e1a8460ffd0c14f 153 459ab3fee07af1c4 154 2fe3faff6d98fb9c 155 cbf9d49bbbba1cee 156 01ab98f366b16d3a 157 9ea6a8f678460335 158 c49fbe6376df813d 159 760c125c770ab31f 160 633dca1c0176b956 161 739f319c39cfa4ba 162 648cfcbf24b99b43 163 ae43342363cdce48 164 2a3362ed26590ffc 165 2b95d2a14d796289 166 a2f20574df0595f9 167 30408e2844cfdad1 168 6233e6665feb4ebc 169 83ed286e7c34e070 170 84c0e85a83b0511e 171 478684eeb2969be0 172 b63357c1eb973a0e 173 acc9750bfb67546a 174 18446562d36dde0b 175 fa30a35ce7d209d0 176 96311dad2fdf305d 177 0cea9a503c7d82d7 178 115729b1dc372dd9 179 d41eec713d499aa2 180 1235a54832061615 181 ecb13165a84cf0bf 182 1aac07bc56db92b3 183 d69538e1ac5211e5 184 97d98f29c1dd8af5 185 37bce240202afe90 186 8c2f70cfa9208df5 187 f44e89ced4fa47cd 188 dc21bcc64575c608 189 8735657c1ef4d0ae 190 0f292c409a12a679 191 f551f5c086589bcc 192 03eb0a923e19929b 193 bed23cb472fceff7 194 841b56b5fe1dac66 195 05764a0a91b2d65e 196 6dad6018703eb9f4 197 c0524217cc5c4d07 198 225ccb2b4aa950cc 199 ecd3a5d9b55f9433 200 caeab7b8ca752eb1 201 c63da53c4d336a82 202 8ac6ee3bbe24b187 203 a628bc715011269b 204 407a014f279ce4bb 205 0e0a35c85b6723be 206 20cac6af34f25174 207 3f1ed5968319a8d4 208 5acd651749829c8f 209 3fa96e11c7decf58 210 ea4b310354c0b717 211 d63c7fd29757e2da 212 7d2c4a79ab51148d 213 6ca236df36aabde8 214 0b684dc0f9b0e1d8 215 fac562a12834ee2a 216 7e1a8460ffd0c14f 217 459ab3fee07af1c4 218 2fe3faff6d98fb9c 219 cbf9d49bbbba1cee 220 01ab98f366b16d3a 221 9ea6a8f678460335 222 c49fbe6376df813d 223 760c125c770ab31f 224 633dca1c0176b956 225 739f319c39cfa4ba 226 648cfcbf24b99b43 227 ae43342363cdce48 228 2a3362ed26590ffc 229 2b95d2a14d796289 230 a2f20574df0595f9 231 30408e2844cfdad1 232 6233e6665feb4ebc 233 83ed286e7c34e070 234 84c0e85a83b0511e 235 478684eeb2969be0 236 b63357c1eb973a0e 237 acc9750bfb67546a 238 18446562d36dde0b 239 fa30a35ce7d209d0 240 96311dad2fdf305d 241 0cea9a503c7d82d7 242 115729b1dc372dd9 243 d41eec713d499aa2 244 1235a54832061615 245 ecb13165a84cf0bf 246 1aac07bc56db92b3 247 d69538e1ac5211e5 248 97d98f29c1dd8af5 249 37bce240202afe90 250 8c2f70cfa9208df5 251 f44e89ced4fa47cd 252 dc21bcc64575c608 253 8735657c1ef4d0ae 254 0f292c409a12a679 255 f551f5c086589bcc
Output for 7.4.33, 8.0.0
Unable to test SipHash-2-4 using sodium_crypto_shorthash

preferences:
198.1 ms | 401 KiB | 177 Q