Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
Did you try this: https://github.com/nikic/buffer ?? But I don't think your code does the same thing between PHP and JS. If you count the number of times your `F` gets called, php does it 4mill times and JS does it 16mill times. Also, bit operations SHOULD be faster in PHP than in JS (php stores int and js stores floats last time i checked), BUT if you pass a large array by reference to a method/function, and you change it, then it will copy that array... so it will be slow. I see that in JS you do: ``` for (var i = 1; i < 16; i += 2) { x[1] ^= F(S, x8, 0) ^ P[i]; x[0] ^= F(S, x8, 4) ^ P[i+1]; } ``` But in PHP you use x[1] to calculate x[0] ``` for ($i = 1; $i < 16; $i += 2) { $x[1] ^= F($x[0]) ^ $p[$i]; $x[0] ^= F($x[1]) ^ $p[$i + 1]; } ``` So i'm pretty sure your not actually doing the same math here. In the past, I have used this implementation for reference for the blowfish algorithm (javascript to php communication) https://github.com/themattharris/PHP-Blowfish/blob/master/blowfish.php It may give you some ideas. (tried to look it up, but my brain is not into bit operations right now lol)
I was trying to port https://github.com/TritonDataCenter/node-bcrypt-pbkdf from JS to PHP but my port is significantly slower than the JS code and it's not clear to me what, if anything, I can do to speed it up.
Did you try this: https://github.com/nikic/buffer ?? But I don't think your code does the same thing between PHP and JS. If you count the number of times your `F` gets called, php does it 4mill times and JS does it 16mill times. Also, bit operations SHOULD be faster in PHP than in JS (php stores int and js stores floats last time i checked), BUT if you pass a large array by reference to a method/function, and you change it, then it will copy that array... so it will be slow. I see that in JS you do: ``` for (var i = 1; i < 16; i += 2) { x[1] ^= F(S, x8, 0) ^ P[i]; x[0] ^= F(S, x8, 4) ^ P[i+1]; } ``` But in PHP you use x[1] to calculate x[0] ``` for ($i = 1; $i < 16; $i += 2) { $x[1] ^= F($x[0]) ^ $p[$i]; $x[0] ^= F($x[1]) ^ $p[$i + 1]; } ``` So i'm pretty sure your not actually doing the same math here. In the past, I have used this implementation for reference for the blowfish algorithm (javascript to php communication) https://github.com/themattharris/PHP-Blowfish/blob/master/blowfish.php It may give you some ideas. (tried to look it up, but my brain is not into bit operations right now lol)