PHP-Curve25519 icon indicating copy to clipboard operation
PHP-Curve25519 copied to clipboard

Public Key Generation Error in Windows

Open manusreload opened this issue 6 years ago • 5 comments

Hello,

I try to run this lib in Windows, but the generation of public key does seem to be correct in Windows SO.

Here is the PHPUnit results:

$ ./vendor/bin/phpunit.bat -c phpunit.xml.dist
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

FF....

Time: 749 ms, Memory: 4.00MB

There were 2 failures:

1) Curve25519\Curve25519Test::testOverall
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-3h═╗@Smp@L-_;(
+a
  ╚╗
+╚      ,╚ ╔@ǎ2X        q

C:\Users\mmunoz\proyectos\whatsapp-web-api\vendor\leigh\curve25519\test\Curve25519Test.php:20

2) Curve25519\Curve25519Test::testNaCL
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-       0Tt}ܴ>Z
-:
-&8뤩Nj
+

Here is my PHP version:

$ php -v
PHP 7.2.6 (cli) (built: May 23 2018 20:51:04) ( ZTS MSVC15 (Visual C++ 2017) x86 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

manusreload avatar Dec 26 '18 22:12 manusreload

I think that the issue is related to sqr function at line 93, the Windows systems is always 32bits, and long numbers will be cast to float. I don't know if this operation can be done in whit this memory size.

Related file: https://github.com/lt/PHP-Curve25519/blob/c59f4250ac2770d0864df66ee89707d06196060a/lib/Curve25519.php#L93

manusreload avatar Dec 26 '18 22:12 manusreload

It looks like commit 6adab2df is where I removed 32 bit support. Try reverting to that and see if that fixes it for you.

On Wed, 26 Dec 2018, 22:54 Manu Muñoz <[email protected] wrote:

I think that the issue is related to sqr function at line 93, the Windows systems is always 32bits, and long numbers will be cast to float. I don't know if this operation can be done in whit this memory size.

Related file:

https://github.com/lt/PHP-Curve25519/blob/c59f4250ac2770d0864df66ee89707d06196060a/lib/Curve25519.php#L93

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lt/PHP-Curve25519/issues/7#issuecomment-450037753, or mute the thread https://github.com/notifications/unsubscribe-auth/ABbvWSvGnlUqtpjs8IoGHFo6mJyJD6hTks5u8_4mgaJpZM4ZiI9f .

lt avatar Dec 27 '18 08:12 lt

Hello again!

This is the phpunit output:

$ ./vendor/bin/phpunit -c phpunit.xml.dist
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

F..FF....

Time: 3.01 seconds, Memory: 4.00MB

There were 3 failures:

1) Curve25519Test::testOverall

2) Curve25519Test::testMulModP
Failed asserting that Array &0 (
    0 => 64872
    1 => 64927
    2 => 64964
    3 => 65001
    4 => 65038
    5 => 65075
    6 => 65112
    7 => 65149
    8 => 65186
    9 => 65223
    10 => 65260
    11 => 65297
    12 => 65334
    13 => 65371
    14 => 65408
    15 => 32677
) is identical to Array &0 (
    0 => 1350
    1 => 0
    2 => 0
    3 => 0
    4 => 0
    5 => 0
    6 => 0
    7 => 0
    8 => 0
    9 => 0
    10 => 0
    11 => 0
    12 => 0
    13 => 0
    14 => 0
    15 => 32768
).

C:\Users\mmunoz\proyectos\whatsapp-web-api\vendor\leigh\curve25519\test\Curve25519Test.php:95

3) Curve25519Test::testSqrModP
Failed asserting that Array &0 (
    0 => 64872
    1 => 64927
    2 => 64964
    3 => 65001
    4 => 65038
    5 => 65075
    6 => 65112
    7 => 65149
    8 => 65186
    9 => 65223
    10 => 65260
    11 => 65297
    12 => 65334
    13 => 65371
    14 => 65408
    15 => 32677
) is identical to Array &0 (
    0 => 1350
    1 => 0
    2 => 0
    3 => 0
    4 => 0
    5 => 0
    6 => 0
    7 => 0
    8 => 0
    9 => 0
    10 => 0
    11 => 0
    12 => 0
    13 => 0
    14 => 0
    15 => 32768
).

C:\Users\mmunoz\proyectos\whatsapp-web-api\vendor\leigh\curve25519\test\Curve25519Test.php:114

FAILURES!
Tests: 9, Assertions: 16, Failures: 3.

Any ideas?

manusreload avatar Jan 02 '19 22:01 manusreload

Hello again, I try this class https://gist.github.com/devi/c245de0d2e8f38511f4f and It seems to works fine.

The question now is consider to detect php int size. I noticed that in Windows (PHP 7) PHP_INT_SIZE = 4 but in Unix systems is 8.

I hope this can be helpfull.

manusreload avatar Jan 03 '19 18:01 manusreload

PHP_INT_SIZE is 4 because you are using PHP 32-bit. The first line in the output of php -v contains x86, which says it's PHP 32-bit.

If you were using PHP 64-bit, php -v would return an output similar to the following one.

PHP 7.4.9 (cli) (built: Aug 4 2020 11:52:41) ( ZTS Visual C++ 2017 x64 ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies

(x64 means it's PHP 64-bit.)

In that case, the value of PHP_INT_SIZE would be 8 even on Windows.

avpaderno avatar Sep 04 '20 11:09 avpaderno