web-push-php icon indicating copy to clipboard operation
web-push-php copied to clipboard

Use OpenSSL/libsodium binding for shared secret computation (when possible)

Open Minishlink opened this issue 6 years ago • 3 comments

Follow-up of #5.

Thanks to #147, we generate the encryption keys with OpenSSL, when possible.

We're still using PHP to compute the shared secret though. It's not yet possible (to my knowledge) to do it with OpenSSL or libsodium, but if it becomes possible, please comment on this issue or (better) send a PR to fix it.

Minishlink avatar Mar 17 '18 10:03 Minishlink

Hi,

This will be really difficult to achieve ; I’ve just seen this closed question. The problem is that without any optimized scalar multiplication over NIST curves (from OpenSSL or libSodium), the shared secret computation will remain slow.

Spomky avatar Nov 11 '18 20:11 Spomky

Hi,

I've seen that in php 7.3 there is a new openssl_pkey_derive function that creates shared secret for ECDH. Can it be useful for the shared secret computation ?

ozgurhangisi avatar Dec 07 '18 08:12 ozgurhangisi

Hi @ozgurhangisi,

Sorry for the very late reply. I confirm that the key agreement computation on PHP 7.3 will use the new openssl_pkey_derive function.

This will be available in few days.

The first tests I ran showed that this operation is approx 50 to 80 times faster than the pure php method. So stay tuned!

Edit:

  • PHP7.3+: 1,471.122μs
  • PHP7.1/7.2: 84,756.735μs

=> 57x faster

Spomky avatar Apr 22 '19 15:04 Spomky

@Minishlink Can be closed. Was fixed by #289

Rotzbua avatar Feb 06 '24 18:02 Rotzbua