Compare commits

...

1878 Commits

Author SHA1 Message Date
terrafrost 37bfb273be Merge branch '3.0' 2024-05-13 23:27:47 -05:00
CommanderRoot 415073594a Allow paragonie/constant_time_encoding version 3 2024-05-13 23:15:45 -05:00
terrafrost f5d02126e1 Merge branch '3.0' 2024-05-10 20:55:05 -05:00
terrafrost 81ba8f72c3 Merge branch '2.0' into 3.0 2024-05-10 20:44:54 -05:00
terrafrost df9e8b328a Merge branch '1.0' into 2.0 2024-05-10 20:44:34 -05:00
Jakub Trmota 3b0fb1c05f Agent: reset supported_private_key_algorithms for every key 2024-05-10 20:38:46 -05:00
terrafrost 550dcb3e13 Merge branch '3.0' 2024-05-01 15:15:49 -05:00
terrafrost 2689c727e7 BigInteger: EvalBarrett / Barrett could sometimes slow to a crawl 2024-05-01 15:12:04 -05:00
terrafrost f7ec6a584b Merge branch '3.0' 2024-04-13 17:52:04 -05:00
terrafrost f7f9831bec Merge branch '2.0' into 3.0 2024-04-13 17:51:45 -05:00
terrafrost 08bd1beb12 Merge branch '1.0' into 2.0 2024-04-13 17:51:15 -05:00
terrafrost cd4d0ba47c Crypt/Base: update docblock comment 2024-04-13 17:50:36 -05:00
terrafrost 630b589f80 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2024-04-10 08:44:40 -05:00
terrafrost 1d9a6bf8b0 Merge branch '3.0' 2024-04-10 04:46:02 -05:00
terrafrost 901a79f0ec Keys/OpenSSH: clean up exception messages 2024-04-10 04:43:30 -05:00
terrafrost d2c96631ac
Merge pull request #1988 from Ayesh/php84/nullability
[PHP 8.4] Fixes for implicit nullability deprecation
2024-03-17 01:17:20 -05:00
Ayesh Karunaratne 6931c96422
[PHP 8.4] Fixes for implicit nullability deprecation
Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations.

See:
 - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types)
 - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated)
2024-03-16 02:33:11 +07:00
terrafrost 7a10423218 Merge branch '3.0' 2024-03-02 20:15:11 -06:00
terrafrost cfa2013d0f CHANGELOG: 3.0.37 release 2024-03-02 20:14:58 -06:00
terrafrost 9a89226a33 Merge branch '3.0' 2024-02-28 22:40:33 -06:00
terrafrost c20dd784f0 SSH2: don't set stream timeout if timeout is 0 2024-02-28 22:40:13 -06:00
terrafrost f5a6d02217 Merge branch '3.0' 2024-02-26 07:55:13 -06:00
terrafrost 792314e851 SSH2: openChannel -> open_channel
makes openChannel snake case like close_channel already is. this is
not a BC break as openChannel is protected
2024-02-26 07:52:24 -06:00
terrafrost be012e5578 SSH2: fix bad merge 2024-02-26 00:27:32 -06:00
terrafrost 2b3bf719cc Merge branch '3.0' 2024-02-25 23:20:04 -06:00
terrafrost c2fb513616 Merge branch '3.0-isconnected-tweak' into 3.0 2024-02-25 23:13:14 -06:00
terrafrost b837466794 Merge branch '2.0' into 3.0 2024-02-25 23:12:56 -06:00
terrafrost b7d7d90ee7 Merge branch '1.0' into 2.0 2024-02-25 22:55:38 -06:00
terrafrost 86990d518f CHANGELOG: add 1.0.23 release 2024-02-25 22:44:00 -06:00
terrafrost b55fdb54b0 BigInteger: dev-master updates 2024-02-24 14:33:20 -06:00
terrafrost 8351a813cc Merge branch '3.0' 2024-02-24 14:28:35 -06:00
terrafrost e77f95186f Merge branch '2.0' into 3.0 2024-02-24 14:28:23 -06:00
terrafrost f333669742 Merge branch '3.0' 2024-02-24 14:27:26 -06:00
terrafrost a922309855 BigInteger: optimize getLength() 2024-02-24 14:26:29 -06:00
terrafrost 939f96c4e2 Merge branch '1.0' into 2.0 2024-02-24 14:16:44 -06:00
terrafrost c55b75199e BigInteger: fix getLength() 2024-02-24 14:15:49 -06:00
terrafrost c114503b5d Merge branch '2.0' into 3.0 2024-02-24 13:41:01 -06:00
terrafrost 2870c8fab3 BigInteger: phpseclib 2.0 updates 2024-02-24 13:29:02 -06:00
terrafrost 0777e700b9 Tests: updates for phpseclib 2.0 2024-02-24 13:26:33 -06:00
terrafrost 63711d50e2 Merge branch '1.0' into 2.0 2024-02-24 13:25:48 -06:00
terrafrost baba459ca1 Tests: phpseclib 3.0 updates 2024-02-24 13:23:49 -06:00
terrafrost 0192fcc4aa Merge branch '2.0' into 3.0 2024-02-24 13:23:11 -06:00
terrafrost e67c9dd555 Tests: phpseclib 2.0 updates 2024-02-24 13:16:21 -06:00
terrafrost 072ab45681 Merge branch '1.0' into 2.0 2024-02-24 13:15:33 -06:00
terrafrost e32531001b ASN1: limit OID length 2024-02-24 13:07:01 -06:00
terrafrost 1143630279 Merge branch '3.0' 2024-02-24 12:23:41 -06:00
terrafrost e17409a3e3 Tests: add unit test for EC pub key with excessively large integer 2024-02-24 08:42:27 -06:00
terrafrost 0358eb163c Merge branch '2.0' into 3.0 2024-02-24 08:38:47 -06:00
terrafrost 2124f399b4 BigInteger: rm visibility modifiers from static variables
the non static variables don't have privacy modifiers so idk that
the static ones ought to either. phpseclib 3.0 uses privacy
modifiers but not the 2.0 branch
2024-02-23 21:55:47 -06:00
terrafrost e46ef4cdf7 Merge branch '1.0' into 2.0 2024-02-23 19:15:25 -06:00
terrafrost ad5dbdf212 BigInteger: put guardrails on isPrime() and randomPrime() 2024-02-23 08:57:22 -06:00
terrafrost 978d081fe5 Merge branch '3.0' 2024-02-20 09:02:21 -06:00
terrafrost d12403e997 Merge branch '2.0' into 3.0 2024-02-20 09:00:09 -06:00
terrafrost ef9718e40a Merge branch '1.0' into 2.0 2024-02-20 09:00:04 -06:00
terrafrost d430fb9d8d BACKERS: add anna filina - thanks! 2024-02-20 08:59:58 -06:00
terrafrost d27429a236 SSH2: tweaks to isConnected() 2024-02-20 08:53:22 -06:00
terrafrost 4427f40112 Merge branch '3.0' 2024-02-07 22:44:27 -06:00
terrafrost 8f3a66547a Merge branch '2.0' into 3.0 2024-02-07 22:43:03 -06:00
terrafrost 34ab00b27d Merge branch '1.0' into 2.0 2024-02-07 22:42:46 -06:00
terrafrost a69364def9 SSH2/SFTP: tweak docblock comments for getLastError() / etc 2024-02-07 22:42:24 -06:00
terrafrost e47383e23e Tests: fix bad merge 2024-02-07 21:29:42 -06:00
terrafrost 414b0b0d3b Merge branch '3.0' 2024-02-07 21:17:27 -06:00
terrafrost 89f0d3c952 Tests: data providers need to be static 2024-02-07 21:15:15 -06:00
terrafrost b0c0a82ae7 Merge branch '2.0' into 3.0 2024-02-07 20:14:32 -06:00
terrafrost bcc04abb94 Merge branch '2.0-stream-set-timeout' into 2.0 2024-02-07 20:14:25 -06:00
terrafrost c948a9a407 SSH2: set stream timeout before calling stream_get_contents 2024-02-07 20:09:26 -06:00
terrafrost 57971458fa Merge branch '2.0' into 3.0 2024-02-06 19:42:18 -06:00
terrafrost 2fb6f317d6 SSH2: set stream timeout before calling stream_get_contents 2024-02-06 19:42:08 -06:00
terrafrost 27d1ccc688 Merge branch '3.0' 2024-01-24 07:43:44 -06:00
terrafrost 6a6c22234a EC: when using openssl to do signing use unencrypted key 2024-01-24 07:42:28 -06:00
terrafrost 5833f00bb5 Merge branch '3.0' 2024-01-24 07:40:56 -06:00
terrafrost 6b34da463c SFTP: size() isn't a method.. 2024-01-12 15:44:58 -06:00
terrafrost 48e3b3c264 Merge branch '3.0' 2024-01-12 11:00:02 -06:00
terrafrost 978a5d9dc0 SFTP: fix possible E_NOTICE with put() 2024-01-12 10:58:38 -06:00
terrafrost 8516c99f9e Merge branch '3.0' 2023-12-28 20:00:10 -06:00
terrafrost 4b1827beab Merge branch '2.0' into 3.0 2023-12-28 19:59:53 -06:00
terrafrost cc2d773b7d Merge branch '3.0' 2023-12-28 07:55:37 -06:00
terrafrost 80bc33b741 Merge branch '2.0' into 3.0 2023-12-28 07:54:49 -06:00
terrafrost 20f8c3101b Merge branch '3.0' 2023-12-27 00:55:41 -06:00
terrafrost 4bdfec9c23 Crypt/AsymmetricKey: loading hidden custom key plugins didn't work 2023-12-27 00:47:36 -06:00
terrafrost 05414ffee8 Merge branch '3.0' 2023-12-18 22:55:29 -06:00
terrafrost d2cd758ecb Merge branch '2.0' into 3.0 2023-12-18 22:55:17 -06:00
terrafrost 0a70605d79 Merge branch '3.0' 2023-12-16 11:17:01 -06:00
terrafrost f0194cf639 AsymmetricKey: toString('Raw') returns an array - not a string 2023-12-16 11:12:31 -06:00
terrafrost bae3b79ae0 Merge branch '3.0' 2023-12-08 21:38:55 -06:00
terrafrost 0548866d42 Merge branch '2.0' into 3.0 2023-12-08 21:38:40 -06:00
terrafrost 4da3ee3867 Merge branch '3.0' 2023-12-03 09:50:17 -06:00
terrafrost d962fd6796 Merge branch '2.0' into 3.0 2023-12-03 09:50:10 -06:00
terrafrost ea50144e42 Merge branch '3.0' 2023-12-02 16:42:19 -06:00
terrafrost 9c0a004d01 SSH2: CS adjustment 2023-12-02 16:42:09 -06:00
terrafrost 99c7aa63b0 Merge branch '3.0' 2023-12-02 16:32:35 -06:00
terrafrost 4d62a8ad16 Merge branch '2.0' into 3.0 2023-12-02 16:31:37 -06:00
terrafrost c204a5ccb4 Merge branch '3.0' 2023-11-27 05:14:03 -06:00
terrafrost 56c79f16a6 CHANGELOG: add 3.0.34 release 2023-11-27 05:13:31 -06:00
terrafrost f62b5f832e Merge branch '3.0' 2023-11-24 06:01:54 -06:00
terrafrost 1513383a8c BigInteger/Engines/PHP: Windows JIT impl issue has been resolved 2023-11-24 06:01:28 -06:00
terrafrost e600b49c54 Merge branch '3.0' 2023-11-23 05:35:29 -06:00
terrafrost f71cc096db
Merge pull request #1962 from LordSimal/3.0
fix syntax error
2023-11-23 05:34:54 -06:00
Kevin Pfeifer ad968b2f69 fix syntax error 2023-11-23 10:05:17 +01:00
terrafrost 11bde49f67 Merge branch '3.0' 2023-11-22 18:09:07 -06:00
terrafrost 8ecd156ce1 SSH2: reset more internal variables when connection is reset 2023-11-22 18:08:38 -06:00
terrafrost c6f25ccde3 Merge branch '3.0' 2023-11-22 12:45:05 -06:00
terrafrost be05f4ef1f Merge branch '2.0' into 3.0 2023-11-22 12:44:52 -06:00
terrafrost d88db1afea Merge branch '3.0' 2023-11-22 08:21:55 -06:00
terrafrost 7b893c5cb4 Merge branch '2.0' into 3.0 2023-11-22 08:18:49 -06:00
terrafrost 77b00c3169 CS adjustment 2023-11-22 05:12:24 -06:00
terrafrost cf1be6a3d3 Merge branch '3.0' 2023-11-22 04:51:42 -06:00
terrafrost 7cc1814f9d Merge branch '2.0' into 3.0 2023-11-22 04:44:23 -06:00
terrafrost cf18ffca5c Merge branch '3.0' 2023-11-21 19:44:30 -06:00
terrafrost eafbc8a1a0 CS adjustment 2023-11-21 19:44:19 -06:00
terrafrost 7294cf963e CS adjustment 2023-11-21 19:21:14 -06:00
terrafrost f6801388a8 Merge branch '3.0' 2023-11-21 19:11:59 -06:00
terrafrost 964d78101a Math/BinaryField: fix for excessively large degrees 2023-11-21 19:10:46 -06:00
terrafrost 7ca852e5e7 CS adjustment 2023-11-19 09:57:28 -06:00
terrafrost 7336c9c49f Merge branch '3.0' 2023-11-19 09:56:08 -06:00
terrafrost 9bfd136259 PKCS8: PBES2 / DES encrypted keys didn't work 2023-11-19 09:51:15 -06:00
terrafrost 820ec76610 add unit test for PKCS8 RSA keys with DES encryption 2023-11-19 09:41:38 -06:00
terrafrost c9f4345812 CS adjustment 2023-11-12 09:10:15 -06:00
terrafrost 194b5af961 Merge branch '3.0' 2023-11-12 09:09:13 -06:00
terrafrost c21db263b0 PKCS8: RC2 encrypted keys didn't work 2023-11-12 09:02:35 -06:00
terrafrost 80e82babe9 add unit test for PKCS8 RSA keys with RC2 / MD5 encryption 2023-11-12 08:50:59 -06:00
terrafrost 6f4559f2f3 Merge branch '3.0' 2023-11-04 16:15:50 -05:00
terrafrost 3ecde6bf6a SSH2: don't use AES GCM for TurboFTP Server 2023-11-04 16:13:09 -05:00
terrafrost ec6338ecd2 another CS adjustment after merger 2023-11-01 20:51:12 -05:00
terrafrost afeffdea3c Merge branch '3.0' 2023-11-01 20:50:22 -05:00
terrafrost b19dd5ec7b CS adjustments 2023-11-01 20:44:31 -05:00
terrafrost 5b27f8f26e CS adjustments 2023-11-01 20:30:35 -05:00
terrafrost 8714be625b Merge branch '3.0' 2023-11-01 20:23:50 -05:00
terrafrost ecd2512a32 Tests: don't do echo in unit tests 2023-11-01 20:23:28 -05:00
terrafrost 70a6271d21 Merge branch '3.0' 2023-11-01 19:48:46 -05:00
terrafrost 90e3b38a29 Merge branch 'ieee' into 3.0 2023-11-01 19:48:32 -05:00
terrafrost cd4c30e6d0 add test for prime field with prime numbers 2023-11-01 19:43:29 -05:00
terrafrost 0086be8af1 EC/Signature/Format: add new IEEE format 2023-11-01 19:19:07 -05:00
terrafrost 93417928cc Merge branch '3.0' 2023-10-31 09:51:13 -05:00
terrafrost ce753669bc PrimeField: fix error with squareRoot method 2023-10-31 08:47:58 -05:00
terrafrost b0e223e89b Merge branch '3.0' 2023-10-21 09:00:57 -05:00
terrafrost 33fa69b251 CHANGELOG: add 3.0.33 release 2023-10-21 09:00:39 -05:00
terrafrost fb3f51b9f7 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2023-10-21 07:49:01 -05:00
terrafrost 55fd1afc87 Merge branch '3.0' 2023-10-21 07:22:18 -05:00
terrafrost 46602823cc CS adjustment 2023-10-21 07:21:42 -05:00
terrafrost 9a79a4ffe0 Merge branch '3.0' 2023-10-20 23:23:02 -05:00
MarkLittlewood eb04913463 access $disconnect_reasons using self instead of static 2023-10-18 15:25:41 +01:00
terrafrost f403ff98d3
Merge pull request #1950 from sergiy-petrov/sergiy-petrov-patch-1
Test against php 8.3
2023-10-07 18:32:54 -05:00
terrafrost 967210fb46 CS adjustment 2023-10-07 18:25:46 -05:00
terrafrost ac7c622b96 Merge branch '3.0' 2023-10-07 17:42:15 -05:00
terrafrost 1bfc9a3e44 Merge branch '2.0' into 3.0 2023-10-07 17:40:39 -05:00
Serhii Petrov 2306be7dad
Test against php 8.3 2023-10-05 21:41:27 +03:00
terrafrost fa53d11807 more CS adjustments 2023-09-25 11:22:02 -05:00
terrafrost cb3aff1332 Merge branch '3.0' 2023-09-25 10:57:01 -05:00
terrafrost c5b4d08669 Merge branch '2.0' into 3.0 2023-09-25 10:56:47 -05:00
terrafrost de18d2d81b CS adjustment that i don't agree with 2023-09-25 09:25:59 -05:00
terrafrost 839fd018d8 Merge branch '3.0' 2023-09-25 07:04:36 -05:00
terrafrost 4777b59ce9
Merge pull request #1942 from danog/move_jit_check
Move JIT check to BigInteger
2023-09-25 06:44:51 -05:00
Daniil Gentili 7b9ab171ce
Refactor 2023-09-22 10:07:03 +02:00
terrafrost 259bd9f1e8 Merge branch '3.0' 2023-09-21 15:17:59 -05:00
terrafrost eb456ee319 Tests/AES: rm test from 3.0 branch as 3.0 is super strict with size 2023-09-21 15:17:30 -05:00
terrafrost 1b954b7852 Merge branch '2.0' into 3.0 2023-09-21 15:16:45 -05:00
terrafrost 10e57d6a5e Merge branch '3.0' 2023-09-21 15:10:50 -05:00
terrafrost d25f03be9a Merge branch '2.0' into 3.0 2023-09-21 15:10:42 -05:00
Daniil Gentili e113bb35e7
Move JIT check to BigInteger 2023-09-20 14:36:32 +02:00
terrafrost e840f7a601 Merge branch '3.0' 2023-09-18 12:22:16 -05:00
terrafrost 866cc78fbd CHANGELOG: add 3.0.23 release 2023-09-18 12:22:01 -05:00
terrafrost 4f8fcedd94 Merge branch '3.0' 2023-09-18 12:20:11 -05:00
terrafrost 4db5893fe5
Merge pull request #1940 from pafernandez-oesia/patch-1
Fix Undefined index jit notice
2023-09-18 12:19:32 -05:00
pafernandez-oesia 105edcad00
Fix Undefined index jit notice
If "jit" is not defined in $status array, it generates an "Undefined index: jit" notice.
2023-09-18 16:44:41 +02:00
terrafrost 7639b8a8b1 Merge branch '3.0' 2023-09-16 06:49:50 -05:00
terrafrost b6bd1c5f79 Merge branch '2.0' into 3.0 2023-09-16 06:49:37 -05:00
terrafrost 4fe9f069ee Merge branch '3.0' 2023-09-06 09:14:59 -05:00
terrafrost 38097913bd Merge branch '2.0' into 3.0 2023-09-06 09:14:52 -05:00
terrafrost 0893147281 Merge branch '3.0' 2023-08-31 09:30:23 -05:00
terrafrost 615d6cfc7c BigInteger: fix more PHP32-bit errors 2023-08-31 09:28:16 -05:00
terrafrost e7379980b4 Tests/SFTP: previously last method was void, causing error 2023-08-28 09:06:38 -05:00
terrafrost c160a020db Merge branch '3.0' 2023-08-28 08:51:17 -05:00
terrafrost aeac69b846 Merge branch '2.0' into 3.0 2023-08-28 08:51:10 -05:00
terrafrost 36441a68e9 Merge branch '3.0' 2023-08-27 23:12:02 -05:00
terrafrost fac92403d0 Bootstrap: fix for when opcache ext is enabled but opcache.enable=0 2023-08-27 23:11:25 -05:00
terrafrost 3f7e74e41e Merge branch '3.0' 2023-08-24 20:22:42 -05:00
terrafrost f7e80e44c9 Merge branch '2.0' into 3.0 2023-08-24 20:22:16 -05:00
terrafrost fc746cddfe Merge branch '3.0' 2023-08-10 22:33:44 -05:00
terrafrost c5e9d51e51 CS adjustment 2023-08-10 22:33:35 -05:00
terrafrost 34c05b9dbf Merge branch '3.0' 2023-08-10 22:23:16 -05:00
terrafrost 0f9d6577ad Bootstrap: JIT on Windows breaks certain phpseclib operations 2023-08-10 22:15:59 -05:00
terrafrost 5babbd028c Merge branch '3.0' 2023-07-26 22:00:22 -05:00
terrafrost 426de8d5bf Tests: tweak unit test 2023-07-26 21:54:02 -05:00
terrafrost 25a06f0071 Math/PrimeField: fix for when garbage collection has wiped data 2023-07-26 21:34:39 -05:00
terrafrost 69325956ce Tests: add test for garbage collected primefield 2023-07-26 21:23:08 -05:00
terrafrost a7cfd2440a Merge branch '3.0' 2023-07-25 20:37:18 -05:00
terrafrost f01892a9db BigInteger: use GMP if it's available 2023-07-25 20:32:42 -05:00
terrafrost 90dc3cf6cb Merge branch '3.0' 2023-07-19 19:33:44 -05:00
terrafrost 718503af33 Merge branch 'phpstan' into 3.0 2023-07-19 19:28:21 -05:00
terrafrost 4833d99a30 Merge branch '3.0' 2023-07-09 10:35:26 -05:00
terrafrost 75c1d37671 Merge branch '2.0' into 3.0 2023-07-09 10:35:20 -05:00
terrafrost e810eaff60 Merge branch '3.0' 2023-07-09 10:25:14 -05:00
terrafrost 4580645d3f CHANGELOG: add 3.0.21 release 2023-07-09 10:24:48 -05:00
terrafrost c558f2ee6a Merge branch '2.0' into 3.0 2023-07-09 10:23:13 -05:00
terrafrost 749cacea58 Merge branch '3.0' 2023-07-09 09:53:26 -05:00
terrafrost 0740d58136 BigInteger: do PHP64 w/ OpenSSL before BCMath w/ OpenSSL 2023-07-09 08:51:55 -05:00
terrafrost 249d17f921 BigInteger: BCMath w/o OpenSSL should never be reached 2023-07-09 00:37:53 -05:00
terrafrost cf13741fbb i can't figure this unit test out 2023-07-09 00:31:08 -05:00
terrafrost e7af70d1dd Merge branch '3.0' 2023-07-08 13:28:41 -05:00
terrafrost 37c6f5255c BigInteger: update engine preferences 2023-07-08 13:27:16 -05:00
terrafrost 6ee1f8c45b Merge branch '3.0' 2023-07-05 07:30:46 -05:00
terrafrost 4013d260e0 Merge branch '2.0' into 3.0 2023-07-05 07:30:39 -05:00
terrafrost fc4d9dd480 AsymmetricKey: phpstan tweak 2023-07-02 17:43:35 -05:00
terrafrost 5a02ce27ac CS adjustment 2023-07-02 12:45:16 -05:00
terrafrost a31fd00e5a Merge branch '3.0' 2023-07-02 12:33:20 -05:00
terrafrost 5a7569cd13 SSH2: attempt at fixing stream_select(): unable to select [4] 2023-07-02 12:32:01 -05:00
terrafrost 2d33d7b0dc Merge branch '3.0' 2023-07-02 11:56:58 -05:00
terrafrost 3334a3243c Merge branch '2.0' into 3.0 2023-07-02 11:55:51 -05:00
terrafrost 65693db644 Merge branch '3.0' 2023-07-02 11:29:03 -05:00
terrafrost 9197b3ad3e ASN1: CS adjustment 2023-07-02 11:22:02 -05:00
terrafrost 9341e090c5 Merge branch '2.0' into 3.0 2023-07-02 11:18:17 -05:00
terrafrost 656a46ae12 Merge branch '3.0' 2023-06-25 10:03:23 -05:00
terrafrost bc8e0ed636 BigInteger: speed up powMod() method 2023-06-25 10:03:16 -05:00
terrafrost feee19276b Merge branch '3.0' 2023-06-13 03:42:32 -05:00
terrafrost 862b9662a2 Merge branch '2.0' into 3.0 2023-06-13 03:42:25 -05:00
terrafrost 89548c3976 Merge branch '3.0' 2023-06-13 03:03:29 -05:00
terrafrost afbee9a7d1 Merge branch '2.0' into 3.0 2023-06-13 03:03:22 -05:00
terrafrost 233fe88b75 Merge branch '3.0' 2023-06-13 01:30:57 -05:00
terrafrost 543a1da811 Merge branch '2.0' into 3.0 2023-06-13 01:30:34 -05:00
terrafrost e2de06655b Merge branch '3.0' 2023-06-12 17:29:25 -05:00
terrafrost f29c2958b6 Merge branch '2.0' into 3.0 2023-06-12 17:16:22 -05:00
terrafrost 6833fc79a6 Merge branch '3.0' 2023-06-04 16:39:59 -05:00
terrafrost 4f113bc96c SFTP: CS adjustment 2023-06-04 16:39:44 -05:00
terrafrost 252cc6af33 Merge branch '3.0' 2023-06-04 16:38:23 -05:00
terrafrost dff24146af CS adjustment 2023-06-04 16:33:58 -05:00
terrafrost 0d5617cbe1 Merge branch '3.0' 2023-06-04 16:31:02 -05:00
terrafrost 2a6f8082b0 Merge branch '2.0' into 3.0 2023-06-04 16:24:54 -05:00
terrafrost 9d2e353a04 Merge branch '3.0' 2023-06-04 16:08:09 -05:00
Tobias 3c349e122b feat(ADMINISTRATION-1): added ev subjects 2023-06-04 16:00:15 -05:00
terrafrost ff26e22563 CS adjustments 2023-06-04 11:26:34 -05:00
terrafrost 501c96c48c Merge branch '3.0' 2023-06-04 10:51:36 -05:00
terrafrost b8f8f0b7db SFTP: add optional $recursive parameter to filesize() 2023-06-04 10:50:26 -05:00
terrafrost e6dd9f6492 Merge branch '3.0' 2023-06-02 10:25:13 -05:00
terrafrost f418be845b RSA: setting sig padding broke enc padding and vice versa 2023-06-02 10:14:58 -05:00
terrafrost d856416026 Merge branch '3.0' 2023-05-27 19:30:15 -05:00
Léon Melis 841267aafa X509::getChain() should always return array of X509 objects
Due to an early exit optimization, X509::getChain() could return currentCert as an array, instead of X509
2023-05-27 19:15:15 -05:00
terrafrost 1b1c073d1e Merge branch '3.0' 2023-05-18 08:24:02 -05:00
terrafrost 2097656b4a
Merge pull request #1912 from thomascorthals/3.0
SFTP typehint fixes
2023-05-18 08:17:52 -05:00
thomascorthals c71c217fd5 SFTP typehint fixes 2023-05-15 11:15:49 +02:00
terrafrost 32cefb32f8 Merge branch '3.0' 2023-05-10 04:39:34 -05:00
terrafrost 8d0c1a10c7
Merge pull request #1905 from terrafrost/master-openchannel
(master branch) SSH/SFTP: create new openChannel() method to eliminate dupe code
2023-05-10 04:39:06 -05:00
terrafrost b25206e92b
Merge pull request #1904 from terrafrost/3.0-openchannel
(3.0 branch) SSH/SFTP: create new openChannel() method to eliminate dupe code
2023-05-10 04:38:51 -05:00
terrafrost 8d7cb3a8e3 Merge branch '3.0' 2023-05-10 04:37:10 -05:00
terrafrost 58c2b3a16c Merge branch '2.0' into 3.0 2023-05-10 04:37:03 -05:00
terrafrost e6f86e1770 Merge branch '3.0-openchannel' into master-openchannel 2023-05-07 11:35:24 -05:00
terrafrost 3dd7779939 SSH2: rm redundant isAuthenticated() call 2023-05-07 11:24:33 -05:00
terrafrost 89d8e6ecbb SFTP: rm redundant code 2023-05-07 11:07:38 -05:00
terrafrost f664ccb521 SSH2: make exceptions more useful for read() / write() 2023-05-07 11:07:07 -05:00
terrafrost 128d5496b5 Merge branch '3.0' 2023-05-05 07:38:24 -05:00
terrafrost 961034f4c2 SymmetricKey: fix typehint 2023-05-05 07:36:29 -05:00
terrafrost 928b5870b2 Merge branch '3.0' 2023-04-21 15:39:47 -05:00
terrafrost 79b6f96870 SSH2: CS adjustment 2023-04-21 15:39:01 -05:00
terrafrost 21db83aeb7
Merge pull request #1909 from browner12/AB-fputs-failure-message
(3.0 branch) update exception message
2023-04-21 15:33:04 -05:00
Andrew Brown d4263e854d update exception message
`fputs()` can return `int|false`.  if it fails and `$sent` is `false`, then our exception message looks a little confusing:

> Only  of XXX bytes were sent

This change updates the message to be more descriptive if the `fputs()` fails.
2023-04-18 15:16:18 -05:00
terrafrost 52c85c9935 Merge branch '3.0-openchannel' into master-openchannel 2023-04-15 08:31:37 -05:00
terrafrost 06f45881f9 Tests/SSH2: add more expansive unit test 2023-04-15 08:07:18 -05:00
terrafrost 184a984e97 SSH2: updates to openchannel refactoring 2023-04-14 18:01:20 -05:00
terrafrost 34feefef3d Merge branch '3.0' 2023-04-12 20:58:10 -05:00
terrafrost 8b67d0ac32 Merge branch '2.0' into 3.0 2023-04-12 20:56:23 -05:00
terrafrost 7d4fa71e9c Merge branch '3.0' 2023-04-10 01:28:25 -05:00
terrafrost 72bd9d99d9 Merge branch 'fixPhpdoc' into 3.0 2023-04-10 01:25:51 -05:00
terrafrost 9a0afb1ae1 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2023-04-09 10:34:30 -05:00
terrafrost 4255b050e3 Merge branch '3.0' 2023-04-09 10:34:05 -05:00
terrafrost 2d1216ba29 Merge branch '2.0' into 3.0 2023-04-09 10:33:57 -05:00
terrafrost 1644e8ce34
Merge pull request #1903 from alexander-schranz/patch-1
Fix PHP-CS PrimeFieldTest
2023-03-31 03:47:58 -05:00
terrafrost fd5054bf95 Tests: CS adjustments 2023-03-31 03:43:58 -05:00
terrafrost 55578577c5 Merge branch '3.0-openchannel' into master-openchannel 2023-03-30 20:52:26 -05:00
terrafrost 5fb084b04c SSH2: if the server doesn't support multiple channels error out 2023-03-29 04:05:41 -05:00
Alexander Schranz 41a5f2c21e
Fix PHP-CS PrimeFieldTest 2023-03-28 11:44:05 +02:00
Vincent Langlet 39bc067417 Fix phpdoc 2023-03-28 09:54:46 +02:00
terrafrost cecabb1fea SSH/SFTP: create new openChannel() method to eliminate dupe code 2023-03-27 17:46:46 -05:00
terrafrost e250e6e2f4 Merge branch '3.0' 2023-03-23 13:06:33 -05:00
terrafrost b799abd1a0 SSH/SFTP: make message numbers / packet types static as well 2023-03-23 13:04:07 -05:00
terrafrost 9705cbbc26 SSH/SFTP: make define_array static 2023-03-23 12:23:43 -05:00
terrafrost 5a208267d6
Merge pull request #1898 from rposky/master
SSH2: Better support for multiple interactive channels & expose shell functions: 3.0 Backport Master Merge
2023-03-23 12:17:26 -05:00
terrafrost 0f8bc61538
Merge pull request #1897 from rposky/3.0
SSH2: Better support for multiple interactive channels & expose shell functions: 3.0 Backport
2023-03-23 12:16:56 -05:00
Robert 53fe071bd2 Merge branch '3.0' 2023-03-16 11:01:21 -05:00
Robert 7ec36fb5d5 Exposed publically open shell method as well as methods to query interactive channel open statuses.
Removed in_request_pty_exec and in_subsystem flags, and removed uses of MASK_SHELL in bitmap, replacing with open channel status queries.
Adding channel argument to read, write, and reset allowing callers to select among multiple open interactive channels.
Adding interactive channel identifier interface as sanctioned path for users to obtain channels ids instead of using channel constants.
Deprecating get_interactive_channel helper and documenting its "legacy" behavior in read, write, and reset doc blocks.
Removing disconnect on timeout in channel close for lack of clarity around timeout origin.
Check for open channel prior to closing in stopSubsystem and reset.
2023-03-16 10:18:03 -05:00
terrafrost 5761a0ba46 Merge branch '3.0' 2023-03-14 21:44:41 -05:00
Steven Hetland abbc1ab7c7 ASN1: 3.0 decodeBER() was optimized to remove duplicate work.
decodeBER() now runs twice as fast.
2023-03-14 21:43:29 -05:00
terrafrost b49396a370 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2023-03-06 06:48:07 -06:00
terrafrost cb49bd3fb2 Merge branch '3.0' 2023-03-06 06:47:18 -06:00
terrafrost 5ab7f86739 Merge branch '2.0' into 3.0 2023-03-06 06:46:54 -06:00
terrafrost 45c9910a1e
Merge pull request #1892 from alexislefebvre/patch-1
README: link on CI badge leads to the results
2023-03-06 06:06:20 -06:00
Alexis Lefebvre 2e7da76e9a
README: link on CI badge leads to the results 2023-03-06 11:37:33 +01:00
terrafrost f3db3de295 Merge branch '3.0' 2023-03-05 11:13:22 -06:00
terrafrost cc181005cf CHANGELOG: add 3.0.19 release 2023-03-05 11:13:09 -06:00
terrafrost b9e27cd910 Merge branch '3.0' 2023-03-05 11:09:48 -06:00
terrafrost cee5587120 add unit test for primefield infinite loop 2023-03-05 11:04:55 -06:00
terrafrost b03e953b6c fix bad merge 2023-03-05 10:21:32 -06:00
terrafrost e9596cef8c Merge branch '3.0' 2023-03-05 10:11:53 -06:00
terrafrost 0f6e1c2218 PKCS8: fix public private checks for human readable keys 2023-03-05 10:01:22 -06:00
terrafrost 96e49a5e51 Merge branch '3.0' 2023-03-05 07:06:44 -06:00
terrafrost aff0e68f54 Merge branch '2.0' into 3.0 2023-03-05 07:04:39 -06:00
terrafrost 79dead6a5e CS adjustments 2023-03-05 00:09:02 -06:00
terrafrost 60358cefb1 Merge branch '3.0' 2023-03-04 23:31:30 -06:00
terrafrost cf69b29427 Crypt/PKCS8: rm duplicate code and improve detection of public keys 2023-03-04 23:25:36 -06:00
terrafrost b9996fda00 Tests/EC: add unit test for naked PKCS8 public key 2023-03-04 22:14:46 -06:00
terrafrost 617b096223 Merge branch '3.0' 2023-03-04 21:01:15 -06:00
terrafrost 9a356ba200 Merge branch 'rposky' 2023-03-04 21:00:14 -06:00
terrafrost 71b9b64203 CS adjustments 2023-03-04 20:47:49 -06:00
terrafrost ea0a2375d2 Merge branch '3.0' 2023-03-03 14:55:02 -06:00
Simon Podlipsky 530f8ab210 feat: add return types to few jsonSerialize() 2023-03-03 14:54:56 -06:00
terrafrost f8d2ff5ae4 CS adjustments 2023-03-03 14:42:42 -06:00
terrafrost db622e4b18 Revert "Tests: void return types weren't introduced until PHP 7.1"
This reverts commit 13833af749.
2023-03-03 14:40:37 -06:00
terrafrost e2fc09311e Merge branch '3.0' 2023-03-03 14:40:24 -06:00
terrafrost 13833af749 Tests: void return types weren't introduced until PHP 7.1 2023-03-03 14:39:25 -06:00
terrafrost a8e90331c1 Merge branch '3.0' 2023-03-03 14:23:11 -06:00
Simon Podlipsky c053b895c8 style: add newline at end of BigInteger.php file 2023-03-03 14:23:02 -06:00
terrafrost c918d60b20 SymmetricKey: rm safe_intval 2023-03-03 14:06:25 -06:00
terrafrost f519a54e7a Merge branch '3.0' 2023-03-03 12:54:14 -06:00
terrafrost fbe79b0855 Merge branch '2.0' into 3.0 2023-03-03 09:30:48 -06:00
terrafrost 922cfd8dea Merge branch '3.0' 2023-03-02 04:52:55 -06:00
Simon Podlipsky b946c6eed9 style: run csfixer 2023-03-02 04:52:25 -06:00
terrafrost e77c881b54 Merge branch '3.0' 2023-03-02 03:49:40 -06:00
terrafrost 6298d1cd55 PrimeField: prevent infinite loop with composite primefields 2023-03-02 03:25:08 -06:00
Robert d012d6cd03 Adding getter for timeout to SSH2 2023-02-28 12:52:01 -06:00
terrafrost 6d7f0def17 Merge branch '3.0' 2023-02-11 22:28:21 -06:00
terrafrost 3b6030d887 Merge branch '2.0' into 3.0 2023-02-11 22:28:10 -06:00
terrafrost 72f66aa06e fix bad merge 2023-02-11 22:08:27 -06:00
terrafrost 5d51328dd5 Merge branch '3.0' 2023-02-11 20:57:49 -06:00
terrafrost d3e72bd1fc Merge branch '2.0-github-actions' into 3.0 2023-02-11 20:40:52 -06:00
terrafrost f4340220ad Composer: use latest version of ParaTest 2023-02-06 02:52:43 -06:00
terrafrost 07605e9ce8 Tests: master branch uses ParaTest vs PHPUnit 2023-02-06 01:55:22 -06:00
terrafrost ca2c9588ea Merge branch '3.0' 2023-02-05 23:47:08 -06:00
terrafrost 2487192558 AsymmetricKey: error out on unsupported operations 2023-02-05 17:44:51 -06:00
terrafrost 508eaa7197 Tests: PHPUnit 10 updates 2023-02-05 17:33:16 -06:00
terrafrost c342af1f80 Merge branch '3.0' 2023-01-17 07:56:16 -06:00
terrafrost fa9bf44ed6 Merge branch '2.0' into 3.0 2023-01-17 07:56:10 -06:00
terrafrost 00f5057e1b Merge branch '3.0' 2023-01-06 14:57:48 -06:00
Kevin van Hulst 3ad3693d31 fix "Creating default object from empty value" error 2023-01-06 14:57:05 -06:00
terrafrost 446fa28e5e Merge branch '3.0' 2022-12-23 10:46:53 -06:00
terrafrost f81d9ea09a Merge branch '2.0' into 3.0 2022-12-23 10:46:46 -06:00
terrafrost 21afff89ca Merge branch '3.0' 2022-12-23 10:34:02 -06:00
terrafrost 86e12663fd Merge branch '2.0' into 3.0 2022-12-23 10:28:11 -06:00
terrafrost 8219a6e2a8 Merge branch '3.0' 2022-12-17 12:26:56 -06:00
terrafrost f28693d38b fix another issue arrising from merge 2022-12-17 12:26:50 -06:00
terrafrost b8d416e010 Merge branch '3.0' 2022-12-17 12:00:18 -06:00
terrafrost 974a30d4d9 fix bad merge 2022-12-17 11:48:28 -06:00
terrafrost 5335dbde3e Merge branch '2.0' into 3.0 2022-12-17 11:25:26 -06:00
terrafrost c9cfa9ea3a GitHub Actions: add PHP 8.2 2022-12-17 09:49:00 -06:00
terrafrost 6672496b66 Merge branch '3.0' 2022-12-17 08:57:43 -06:00
Simon Podlipsky 97ea650dba fix: drop use of "self" in callable as it's deprecated since php 8.2 2022-12-17 08:49:29 -06:00
terrafrost 649b4f1713 Merge branch '3.0' 2022-12-16 22:54:07 -06:00
terrafrost 90a1765106 Merge branch '2.0' into 3.0 2022-12-16 22:53:49 -06:00
terrafrost 51e6b3a921 Merge branch '3.0' 2022-12-11 09:15:44 -06:00
Alex e7e7103955 build: harden ci.yml permissions
Signed-off-by: Alex <aleksandrosansan@gmail.com>
2022-12-11 09:15:38 -06:00
terrafrost d02d77ad56 Merge branch '3.0' 2022-12-11 09:01:36 -06:00
terrafrost 1a201dd131 Merge branch '2.0' into 3.0 2022-12-11 08:59:36 -06:00
terrafrost 762e786ec9 SymmetricKey: more CS updates 2022-12-07 08:39:01 -06:00
terrafrost e1541eb109 Merge branch '3.0' 2022-12-07 08:38:28 -06:00
terrafrost 8568af7f9b SymmetricKey: CS updates 2022-12-07 08:38:06 -06:00
terrafrost d186a9d20d Merge branch '2.0' into 3.0 2022-12-07 08:37:25 -06:00
terrafrost 0c728ff2bc SSH/Agent: add proper type hinting to constructor 2022-11-29 06:31:29 -06:00
terrafrost efd5bf281a SSH/Agent: use PHP8's new str_contains function 2022-11-29 06:24:32 -06:00
terrafrost 768d2be8f8 Merge branch '3.0' 2022-11-29 06:10:31 -06:00
terrafrost 68aa48de66 X509: CS adjustment 2022-11-29 06:09:31 -06:00
terrafrost 637444d0ab Merge branch '3.0' 2022-11-29 05:48:31 -06:00
terrafrost 6ee646a480 Merge branch '2.0' into 3.0 2022-11-29 05:47:40 -06:00
terrafrost 18b70376a6 Merge branch '3.0' 2022-11-28 08:44:13 -06:00
terrafrost 228e19f058 Merge branch '2.0' into 3.0 2022-11-28 08:44:02 -06:00
terrafrost d4bfbec520 Merge branch '3.0' 2022-11-27 22:48:23 -06:00
terrafrost b216a4cf07 ASN1: 3.0 already has $location defined 2022-11-27 22:47:20 -06:00
terrafrost d979777a60 Merge branch '2.0' into 3.0 2022-11-27 22:45:55 -06:00
terrafrost 5afc5f77b9 Merge branch '3.0' 2022-11-27 12:18:17 -06:00
terrafrost bf804e6feb DSA/PuTTY: ssh-dsa should be ssh-dss 2022-11-27 12:18:09 -06:00
terrafrost ad11cf3c6b Merge branch '3.0' 2022-10-27 23:07:45 -05:00
terrafrost 08c27ae48a Merge branch '2.0' into 3.0 2022-10-27 23:07:38 -05:00
terrafrost df66aafbe9 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2022-10-24 05:52:31 -05:00
terrafrost 2d76153787 Merge branch '3.0' 2022-10-24 05:52:08 -05:00
terrafrost dbc2307d5c Merge branch '1.0' into 3.0 2022-10-24 05:51:50 -05:00
terrafrost 99c7797d53
Merge pull request #1855 from jack-worman/Remove_bootstrap
Remove bootstrap.php and use latest php version in ci
2022-10-21 21:18:40 -05:00
Jack Worman bd529351e8 Use lastest php version in ci 2022-10-20 17:57:21 -05:00
Jack Worman 7b557d46c5 Remove bootstrap.php 2022-10-20 17:57:21 -05:00
terrafrost e798c6052e
Merge pull request #1853 from jack-worman/Paratest
Paratest
2022-10-18 17:59:32 -05:00
Jack Worman 2c40186711 Paratest 2022-10-16 09:55:20 -05:00
terrafrost caecbdc03d
Merge pull request #1852 from jack-worman/Property_typehint_in_shh2_v2
Property typehint in ssh2
2022-10-11 10:44:38 -05:00
Jack Worman fe4bdc0410 Property_typehint_in_ssh2 2022-10-07 08:39:21 -05:00
terrafrost 0fc733a262 Tests/SFTP: CS adjustments 2022-10-04 22:04:40 -05:00
terrafrost 0a50932285 SFTP: CS adjustments 2022-10-04 21:32:14 -05:00
terrafrost b2ca37b990 Merge branch '3.0' 2022-10-04 21:31:51 -05:00
terrafrost a10a3b8e5b Merge branch '2.0' into 3.0 2022-10-04 21:02:49 -05:00
terrafrost d39777128a
Merge pull request #1835 from jack-worman/Throw_phpseclib_exceptions_v4
Throw \phpseclib3\Exception\ExceptionInterface exceptions
2022-09-26 08:46:07 -05:00
Jack Worman 985b3c4f7c Throw \phpseclib3\Exception\ExceptionInterface exceptions 2022-09-26 07:41:32 -05:00
terrafrost 2b937b413a Merge branch '2.0' 2022-09-23 23:17:54 -05:00
terrafrost 4f53331c98 SSH2: rm if condition that can't ever be true in 3.0+ 2022-09-23 23:03:11 -05:00
terrafrost 19fe966933 CS adjustment 2022-09-23 22:46:02 -05:00
terrafrost c1f284d6b8 Merge branch '3.0' 2022-09-23 22:43:52 -05:00
terrafrost f0a146eaa1 X509: make it so PKCS1 X509 certs can create PSS sigs 2022-09-23 22:33:30 -05:00
terrafrost df21050d03 Tests/X509: add test for PSS signed CRL signed by PKCS1 X509 2022-09-23 18:48:55 -05:00
terrafrost 8c53a80405 Merge branch '3.0' 2022-09-23 16:15:43 -05:00
terrafrost 9158033ddb CS adjustment 2022-09-23 15:23:25 -05:00
terrafrost b54eeb8e35 X509: make it so CRLs, CSRs and SPKACs can support PSS keys 2022-09-23 15:03:37 -05:00
terrafrost ea5a4c3c62 Tests/X509: add unit test for CRL creation with PSS keys 2022-09-23 15:02:44 -05:00
terrafrost c1377159a2 Random: don't do >= 8.1 check 2022-09-15 00:01:15 -05:00
terrafrost 5a6f433ee8 Merge branch '3.0' 2022-09-15 00:00:23 -05:00
terrafrost a1862b1817 fix bad merge 2022-09-15 00:00:14 -05:00
terrafrost 535fa6c777 Merge branch '3.0' 2022-09-14 23:47:17 -05:00
terrafrost ead5790c80 CS adjustment 2022-09-14 23:45:04 -05:00
terrafrost 65493ae3be Merge branch '2.0' into 3.0 2022-09-14 12:50:32 -05:00
terrafrost 0b497cdbe3 Merge branch '3.0' 2022-09-05 13:03:28 -05:00
terrafrost 7181378909 CHANGELOG: add 3.0.16 release 2022-09-05 13:03:08 -05:00
terrafrost 10fe792938 Merge branch '3.0' 2022-09-05 12:51:44 -05:00
terrafrost 59e34b1cd3 SSH2: fix type hinting for keyboard_interactive_helper 2022-09-05 12:50:38 -05:00
terrafrost 0065e80ad9 Merge branch '3.0' 2022-09-02 12:05:15 -05:00
terrafrost c96e250238 Merge branch '2.0' into 3.0 2022-09-02 12:05:08 -05:00
terrafrost d921246e46 Merge branch '2.0' into 3.0 2022-09-02 12:03:58 -05:00
terrafrost 7faeeef866 Merge branch '3.0' 2022-08-28 11:07:55 -05:00
terrafrost b3593f1ce5 Merge branch '2.0' into 3.0 2022-08-28 11:07:47 -05:00
terrafrost 26b2b3f473 CS adjustment 2022-08-27 08:34:15 -05:00
terrafrost 41dbac7a9e Merge branch '3.0' 2022-08-27 08:33:39 -05:00
terrafrost 2026b0c0db Hash: fix PHP 8.2 error
see https://github.com/php/php-src/issues/8924
2022-08-27 08:33:17 -05:00
terrafrost e2a20a6ad9 fix bad merge 2022-08-27 07:33:21 -05:00
terrafrost 2f3555a9b4 Merge branch '3.0' 2022-08-27 06:16:19 -05:00
terrafrost c5a9ee5234 fix deprecated implicit float to int on 32-bit PHP 8.1 2022-08-27 05:53:55 -05:00
terrafrost 584e84d7b8 Merge branch '3.0' 2022-08-23 21:38:06 -05:00
terrafrost 1762ad4d9e CS adjustments 2022-08-23 21:37:53 -05:00
terrafrost 62f7c8aa10 CS tweaks 2022-08-23 21:26:31 -05:00
terrafrost feb5fad15d Merge branch '3.0' 2022-08-23 20:59:06 -05:00
terrafrost 0b9b0074c9 backport more dynamic property fixes 2022-08-23 20:01:11 -05:00
terrafrost 1e5fae186e Merge branch '3.0' 2022-08-21 21:47:25 -05:00
terrafrost b1aef24a86 EC: eliminate dynamic property from Ed25519/448 handling 2022-08-21 21:38:30 -05:00
terrafrost a4dba26ec5 CS adjustments 2022-08-21 13:30:27 -05:00
terrafrost 71fa541c9a Merge branch 'jworman' 2022-08-20 23:19:34 -05:00
terrafrost b64952680e Merge branch '3.0' 2022-08-20 17:38:19 -05:00
terrafrost 0b3c6e27fc add JSON Web Key (JWK) support 2022-08-20 17:38:12 -05:00
terrafrost a01c3915ce Merge branch '3.0' 2022-08-20 06:19:24 -05:00
terrafrost 13b241e3e9 use libsodium's hex (en|de)coding if available 2022-08-19 22:49:26 -05:00
terrafrost 3c73d61e7e Merge branch '3.0' 2022-08-19 09:22:57 -05:00
terrafrost e5396968c5 use libsodium's base64 decoding if available 2022-08-19 09:11:46 -05:00
Jack Worman 16ade5d634 Quality tool fixes 2022-08-18 08:25:29 -05:00
Jack Worman a8f30f516a Throw exception instead of triggering error, and added base exception interface 2022-08-18 08:10:12 -05:00
Jack Worman 3f3de53503 Use loop for encrypting $p 2022-08-18 08:10:12 -05:00
Jack Worman 6958ba1627 php-cs-fixer @PHP81Migration rule set 2022-08-18 08:10:12 -05:00
Jack Worman c74ad399e6 Update composer.json homepage 2022-08-18 08:10:12 -05:00
Jack Worman 80f2d7f521 php-cs-fixer - php 7.4 rules 2022-08-18 08:10:08 -05:00
Jack Worman f199a0cfe9 Update authors - jack worman 2022-08-18 08:08:31 -05:00
terrafrost 0e4e513900 Merge branch '3.0' 2022-08-17 00:08:21 -05:00
terrafrost ea94a73380 Merge branch '2.0' into 3.0 2022-08-17 00:08:15 -05:00
terrafrost 9e7efc914d fix bad merge 2022-08-16 19:38:23 -05:00
terrafrost fd6e53719c Merge branch '3.0' 2022-08-16 19:32:51 -05:00
terrafrost e78edac015 Merge branch '3.0-logging-enhancements' into 3.0 2022-08-16 19:19:40 -05:00
terrafrost 54055bba44 Merge branch '3.0' 2022-08-13 22:45:47 -05:00
terrafrost 9f03f6ea01
Merge pull request #1828 from walkonthemarz/3.0
Revert back the commit https://github.com/phpseclib/phpseclib/commit/
2022-08-13 22:43:52 -05:00
terrafrost 32e85c2145 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2022-08-13 16:52:58 -05:00
terrafrost 1d04f9b1d4 Merge branch 'callmejon' 2022-08-13 09:05:30 -05:00
terrafrost f928536632 EC: make secret field in savePrivateKey optional 2022-08-12 13:12:16 -05:00
walkonthemarz 871f37087d Revert back the commit 85205bf6d5 2022-08-12 16:42:11 +08:00
Jonny Fonsato 5c8966334e
removed initialization where not needed 2022-08-02 11:50:12 +02:00
Jonny Fonsato 05cdd09f52
add --ignore-platform-req=php for fix test error 2022-08-02 11:06:37 +02:00
terrafrost 259f44207a
Merge pull request #1824 from jack-worman/Php_7.3
Php 7.3 php-cs-fixer rule and composer.json scripts
2022-07-31 23:43:07 -05:00
terrafrost 652e84934d
Merge pull request #1823 from jack-worman/Re-add_old_x
Re-add_old_x
2022-07-31 23:27:51 -05:00
terrafrost 92984a318f Merge branch '3.0' 2022-07-31 19:35:05 -05:00
terrafrost 7fbd6d5fef Merge branch '2.0' into 3.0 2022-07-31 19:34:49 -05:00
terrafrost 2e549e3aa1 Merge branch '3.0' 2022-07-31 17:28:30 -05:00
terrafrost 826d8d6670 make it so OpenSSH encrypted keys can be created 2022-07-31 17:14:20 -05:00
terrafrost e95febd5aa rm safe_intval 2022-07-31 16:03:41 -05:00
terrafrost 65f405916b Merge branch 'bcrypt3' into bcrypt4 2022-07-31 10:46:08 -05:00
terrafrost e54624c085 CS adjustments 2022-07-31 09:31:41 -05:00
terrafrost 08f4ec8f56 Merge branch 'bcrypt3' into bcrypt4 2022-07-31 09:14:36 -05:00
terrafrost 4b0af1fa92 Merge branch 'bcrypt2' into bcrypt3 2022-07-31 09:14:22 -05:00
terrafrost 3691aefd2b CS adjustments 2022-07-31 08:48:04 -05:00
terrafrost 69d3f8548a Merge branch 'bcrypt3' 2022-07-30 19:49:05 -05:00
terrafrost 1e10a6ab7a fix bad merge 2022-07-30 18:51:45 -05:00
terrafrost 450a961785 Merge branch 'bcrypt2' into bcrypt3 2022-07-30 18:07:26 -05:00
Jonny Fonsato dd86bd9fbd
change secret position after rebase 2022-07-28 16:56:00 +02:00
Jonny Fonsato 5411695c0b
changed as mentioned by Terrafrost 2022-07-28 16:38:51 +02:00
Jonny Fonsato a3ce8392fd
I have upgraded to php 8.2 with the tests running successfully 2022-07-28 16:30:54 +02:00
terrafrost b0e034ff9d Merge branch '3.0' 2022-07-23 09:41:56 -05:00
terrafrost 33b8a299b5 SymmetricKey: CS update 2022-07-23 09:39:33 -05:00
terrafrost 0ab44df4ce Merge branch '3.0' 2022-07-23 09:35:02 -05:00
terrafrost cd5a38ef3b Merge branch '2.0' into 3.0 2022-07-23 09:32:44 -05:00
Jack Worman bddf9297ca Added some convenient scripts to composer.json 2022-07-22 21:58:10 -05:00
Jack Worman 510a93a50a Php 7.3
- Update php requirement to >=7.3
- Add php-cs-fixer rule: @PHP73Migration
2022-07-22 21:45:53 -05:00
Jack Worman 5f4c89b688 Re-add_old_x 2022-07-22 21:16:51 -05:00
terrafrost a699dadb03 tweak comments 2022-07-22 19:16:04 -05:00
terrafrost a95abeb4c4 Merge remote-tracking branch 'jworman/Php_7.1' 2022-07-22 18:29:53 -05:00
terrafrost 7795ad0969 Merge branch '3.0' 2022-07-16 23:49:51 -05:00
terrafrost 2d11f6e820 Merge branch '2.0' into 3.0 2022-07-16 23:49:46 -05:00
terrafrost 5e524c3f21 Merge branch '3.0' 2022-07-16 09:16:37 -05:00
terrafrost 114f8c8f77 backport more changes from master 2022-07-16 09:03:17 -05:00
terrafrost 57031bdf9a Merge branch '3.0' 2022-07-15 15:32:05 -05:00
Anthony Ryan dd9146e259 Fix return type comment on Crypt/RSA::createKey()
Function returns a Crypt/RSA/PrivateKey and updating
the PHPDoc for it will help with static analysis.
2022-07-15 15:30:47 -05:00
terrafrost 35be18b292 Merge branch '3.0' 2022-07-15 12:29:19 -05:00
terrafrost c73b9f0884 RSA/XML: rm redundant check 2022-07-15 12:28:56 -05:00
terrafrost 167fa7d382 Merge branch '3.0' 2022-07-15 09:56:00 -05:00
terrafrost 89944c813c Composer: phpseclib 3 uses DOM vs XML 2022-07-15 09:55:12 -05:00
terrafrost 243ec71f6f Merge branch '2.0' into 3.0 2022-07-15 09:54:58 -05:00
terrafrost a9c3f10de4 Merge branch '3.0' 2022-07-15 09:18:37 -05:00
terrafrost feced404bb EC/PKCS8: OpenSSL didn't like phpseclib formed Ed25519 public keys 2022-07-15 09:18:15 -05:00
terrafrost 7aa6c08a85 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2022-07-14 23:16:14 -05:00
terrafrost 4914e91a33 Merge branch '3.0' 2022-07-14 23:05:51 -05:00
terrafrost 1692298efd Merge branch '2.0' into 3.0 2022-07-14 23:05:42 -05:00
terrafrost 22e2fdbca6 Merge branch '2.0' into 3.0 2022-07-13 09:14:05 -05:00
terrafrost 68323d8f11 Merge branch '1.0' into 2.0 2022-07-13 09:07:31 -05:00
Jack Worman 7154fd98d2 Php 7.1 2022-07-08 21:42:28 -05:00
Jack Worman e210166f43 Php 7.1 Upgrade 2022-07-08 08:37:58 -05:00
terrafrost 477b98d43d SSH2 / SFTP: unify logging and add a new mode - LOG_SIMPLE_REALTIME 2022-07-06 21:22:03 -05:00
terrafrost 0b5bca65c7
Merge pull request #1800 from jack-worman/Upgrade_to_Php_7.0
Upgrade to PHP 7.0
2022-07-03 09:22:34 -05:00
Jack Worman b2beedbf9a 3rd round of comments 2022-07-03 07:54:11 -05:00
Jack Worman 81ffdbc4ef Merge branch 'master' into Upgrade_to_Php_7.0
# Conflicts:
#	phpseclib/Crypt/EC/BaseCurves/Prime.php
#	phpseclib/Crypt/EC/Formats/Keys/XML.php
#	phpseclib/Crypt/RSA/PrivateKey.php
#	phpseclib/File/ANSI.php
#	phpseclib/File/ASN1.php
#	phpseclib/File/X509.php
#	phpseclib/Net/SFTP.php
#	phpseclib/Net/SFTP/Stream.php
#	phpseclib/Net/SSH2.php
#	phpseclib/System/SSH/Agent.php
#	phpseclib/System/SSH/Agent/Identity.php
#	tests/Unit/Math/BigInteger/TestCase.php
2022-07-03 07:48:16 -05:00
Jack Worman 8a2b94fb24 3rd round of comments 2022-07-03 07:33:45 -05:00
terrafrost 30e845ff1a Merge branch '3.0' 2022-07-02 21:50:18 -05:00
terrafrost 1fd995abdf Merge branch '3.0-type-hinting-backport' into 3.0 2022-07-02 21:49:55 -05:00
terrafrost 250f1a5b51 more backporting 2022-07-02 21:49:45 -05:00
Jack Worman 86ef8ef262 2nd round of comments 2022-07-02 16:47:49 -05:00
Jack Worman beafe2a8a1 1st round of comments 2022-07-02 16:26:17 -05:00
Jack Worman 97902d4bd3 Upgrade to PHP 7.0 2022-07-02 16:26:15 -05:00
terrafrost d124f95ea3 Merge branch '3.0' 2022-06-26 17:21:55 -05:00
terrafrost 9e77203746 Tests/BigInteger: make unit test do == vs === 2022-06-26 17:16:17 -05:00
terrafrost d22639841a Merge branch '3.0' 2022-06-26 17:08:07 -05:00
terrafrost 0b3cc98084 BigInteger: fix behavior on 32-bit PHP installs 2022-06-26 17:07:45 -05:00
terrafrost 7a87270b0c Merge branch '3.0' 2022-06-22 08:32:50 -05:00
terrafrost 22ee5597d3 Merge branch '2.0' into 3.0 2022-06-22 08:19:35 -05:00
terrafrost 8c65ab41d1 Merge branch '3.0' 2022-06-22 08:02:23 -05:00
terrafrost 8e2461dbaa Merge branch '2.0' into 3.0 2022-06-22 08:02:16 -05:00
terrafrost 5f137d60ec Tests/ASN1Test: update tests to work with decodeBER returning null 2022-06-22 07:57:03 -05:00
terrafrost 9141c92236 RSA/PublicKey: rm bad type hint 2022-06-22 07:18:36 -05:00
terrafrost 298c50cde3 Merge branch '3.0' 2022-06-21 08:18:20 -05:00
terrafrost 7de44b745d X509: backport fix for dnsName to 3.0 branch from master 2022-06-21 08:17:59 -05:00
Jack Worman 8245775679
Merge pull request #1806 from vadym-ovechkin/master
Prevent static call to non-static method error
2022-06-21 07:57:58 -05:00
Vadym Ovechkin cee667126c
Prevent static call to non-static method error (#1805) 2022-06-20 21:27:10 +03:00
terrafrost 9a1d16fe97 ASN1: make it so that null is returned if the BER can't be decoded 2022-06-18 22:51:31 -05:00
terrafrost e0adfa1712 backport select type hinting changes from master branch 2022-06-18 17:42:01 -05:00
terrafrost 545b43cd70 Merge branch '3.0' 2022-06-16 17:57:28 -05:00
terrafrost f24691dc55 Merge branch '2.0' into 3.0 2022-06-16 09:37:40 -05:00
terrafrost c4f6f602e5 SFTP: update for the master branch 2022-06-14 05:47:51 -05:00
terrafrost a84f5ddc49 Merge branch '3.0' 2022-06-14 05:47:13 -05:00
terrafrost 623bb39f1c SFTP: update for 3.0 branch
in 1.0 / 2.0 _get_channel_packet could return false even when the
channel status was NET_SSH2_MSG_CHANNEL_DATA. in 3.0 it can't.
where 1.0 / 2.0 returned false 3.0 now throws exceptions
2022-06-14 05:43:31 -05:00
terrafrost d85417c6ec Merge branch '2.0' into 3.0 2022-06-14 05:42:25 -05:00
terrafrost dcf9656a42 Merge branch '3.0' 2022-06-14 03:58:42 -05:00
terrafrost 9c45309d0e SSH2: CS adjustment 2022-06-14 03:58:31 -05:00
terrafrost 0ca4393a2a Merge branch '3.0' 2022-06-14 00:03:20 -05:00
terrafrost fbf6027a43 Merge branch '2.0' into 3.0 2022-06-14 00:03:13 -05:00
terrafrost 0c52d387c0 Merge branch '3.0' 2022-06-03 08:21:17 -05:00
terrafrost be5847751b Merge branch '2.0' into 3.0 2022-06-03 08:21:07 -05:00
terrafrost 62c36daa67 Merge branch '3.0' 2022-05-13 15:04:33 -05:00
terrafrost 4076ff685a
Merge pull request #1794 from Slamdunk/patch-1
SFTP::get can also return true
2022-05-13 15:04:12 -05:00
terrafrost 7e7af4ff28 Merge branch '3.0' 2022-05-13 14:57:23 -05:00
terrafrost 66fa9fa40c Merge branch '2.0' into 3.0 2022-05-13 14:57:10 -05:00
Filippo Tessarotto 8b13462ee8
SFTP::get can also return true 2022-05-11 11:53:42 +02:00
terrafrost 2b36a0fcd7 Merge branch '3.0' 2022-05-10 23:16:48 -05:00
terrafrost 2e963c0002 Tests/BigInteger: fix 8.2 deprecation errors 2022-05-10 23:08:46 -05:00
terrafrost 0446caf2f6 Merge branch '3.0' 2022-05-10 22:14:16 -05:00
terrafrost 43c59198b8 Merge branch '2.0' into 3.0 2022-05-10 22:14:10 -05:00
terrafrost c11618f005 Merge branch '3.0' 2022-05-06 16:25:37 -05:00
terrafrost 15ad047415 replace git.io links 2022-05-06 16:25:22 -05:00
terrafrost 51f863f289 Merge branch '3.0' 2022-05-06 14:27:24 -05:00
terrafrost 715bb9ff97 SFTP: CS adjustment 2022-05-06 14:26:57 -05:00
terrafrost 571e16af38 Merge branch '2.0' into 3.0 2022-05-06 14:26:30 -05:00
terrafrost 21993760ad Merge branch '3.0' 2022-05-04 07:09:00 -05:00
terrafrost 3ce5d6f8c7 ASN1\Maps: CS adjustments 2022-05-04 07:03:47 -05:00
Jack Worman 8855351cbb Remove_@access 2022-05-04 01:35:56 -05:00
terrafrost f21681bee8 Merge branch '3.0' 2022-05-04 01:19:12 -05:00
terrafrost a965060d81 SSH2: make login method return false under rare situation 2022-05-04 01:18:33 -05:00
terrafrost bff58b0d5b Merge branch '3.0' 2022-04-26 09:13:34 -05:00
terrafrost 2b5ecd3315 Merge branch '2.0' into 3.0 2022-04-26 09:03:59 -05:00
terrafrost b4e20843c8 Merge branch '3.0' 2022-04-22 18:50:55 -05:00
Jack Worman 746e9eef57 Clean Up Tests 2022-04-22 18:41:59 -05:00
terrafrost f57f5debe0 Merge branch '3.0' 2022-04-14 11:50:40 -05:00
terrafrost e700ac7561 SFTP: fix enableDatePreservation bug w.r.t. mtime 2022-04-14 11:48:49 -05:00
terrafrost 369c98616d Merge branch '3.0' 2022-04-10 09:33:14 -05:00
terrafrost 4979cf71f2 Merge branch '2.0' into 3.0 2022-04-10 09:33:07 -05:00
terrafrost 6d2356b546 Merge branch '3.0' 2022-04-04 00:15:54 -05:00
terrafrost 2f0b7af658 Merge branch '2.0' into 3.0 2022-04-04 00:15:45 -05:00
terrafrost 726264bafa Merge branch '3.0' 2022-03-20 13:52:26 -05:00
terrafrost 9a1e1caa90 EC / DSA: useBestEngine() needs to be called in getEngine() 2022-03-20 13:52:00 -05:00
terrafrost ed0f7cc9f6 Merge branch '3.0' 2022-03-20 11:30:52 -05:00
terrafrost 301aad4764 RSA: conditionally call useBestEngine() when getEngine() is called 2022-03-20 11:30:24 -05:00
terrafrost 19502c5070 Merge branch '3.0' 2022-03-18 12:47:49 -05:00
terrafrost eb971aaaac BigInteger: fix deprecation notice 2022-03-18 12:47:40 -05:00
terrafrost a85498bb04 Merge branch '3.0' 2022-03-18 11:24:39 -05:00
terrafrost 2a3951538b Merge branch '2.0' into 3.0 2022-03-18 11:24:32 -05:00
terrafrost 3e073a59e0 Merge branch '3.0' 2022-03-15 18:56:04 -05:00
Jack Worman 0a69972571 Clean Up Tests 2022-03-15 18:49:38 -05:00
terrafrost 57ad98e8bb Merge branch '3.0' 2022-03-12 21:15:36 -06:00
terrafrost 887cf97185 fix pslam error 2022-03-11 19:14:07 -06:00
terrafrost f04a4e6fda fix error in PHP EvalBarrett Engine: 2022-03-11 18:38:01 -06:00
terrafrost 26d8f7a250 make it so BigIntegers can be JSON serialized 2022-03-10 20:26:46 -06:00
terrafrost 815aa23b39 BigInteger/Engines/BCMath: bcmod got a third param in PHP 7.2.0
the third parameter also isn't set in any other bcmod call and
isn't needed for bccomp anyway as
bccomp('0.000', '0') == bccomp('0', '0')
2022-03-10 05:24:30 -06:00
terrafrost 42853f2805 rm appveyor.yml 2022-03-09 00:46:46 -06:00
terrafrost 2f57517bad BigInteger/Engines/PHP: trim 0's when a precision is being used 2022-03-08 23:37:29 -06:00
terrafrost 1c35df08dc Merge branch '3.0' 2022-03-08 20:53:33 -06:00
terrafrost 824b232b47 BigInteger: add precision to __debugInfo 2022-03-08 20:53:18 -06:00
terrafrost b722a4f002 Merge branch '3.0' 2022-03-08 08:53:21 -06:00
Jack Worman 46758107de GitHub actions 2022-03-08 06:08:01 -06:00
terrafrost 963fd7368f Merge branch '3.0' 2022-03-03 17:49:36 -06:00
terrafrost 04e46cf656 CS adjustment 2022-03-03 17:44:41 -06:00
Jack Worman 9e321981a2 Psalm coverage for phpseclib3\Math\
Revert accidental change
2022-03-03 17:40:20 -06:00
Jack Worman 6bad45c016 Psalm coverage for phpseclib3\Math\ 2022-03-03 17:37:26 -06:00
Jack Worman b6f93a4a21 Psalm coverage for phpseclib3\Math\
Psalm coverage for phpseclib3\Math\
2022-03-03 17:36:10 -06:00
Jack Worman 6f2db49696 Psalm coverage for phpseclib3\Math\
Psalm coverage for phpseclib3\Math\
2022-03-03 17:20:24 -06:00
terrafrost 95aec3267d CS tweaks (Ssh -> SSH, Sftp -> SFTP) 2022-02-27 02:17:25 -06:00
terrafrost 6a6e80ba8f Merge branch '3.0' 2022-02-27 01:40:25 -06:00
Jack Worman 574953061a PSR4 for tests and added fall-through for switches
PSR4 for tests and added fall-through for switches
2022-02-27 01:26:31 -06:00
terrafrost 120cdfb6e3 Merge branch '3.0' 2022-02-27 00:37:14 -06:00
terrafrost 5f60f96487 File/ASN1/Maps: CS adjustments
these are mostly backported from PR#1754. the only modified files
from that PR are:

- RSAPrivateKey
- OtherPrimeInfo
2022-02-27 00:36:32 -06:00
terrafrost 004aec954f Merge branch '3.0' 2022-02-19 18:08:40 -06:00
terrafrost f2e9dd993d ChaCha20: ignore coding standards 2022-02-19 17:33:15 -06:00
terrafrost a0d06e5e81 CS adjustments 2022-02-19 17:19:08 -06:00
Jack Worman ea9f6540f3 PSR12 fixes
PSR12 fixes
2022-02-19 17:06:13 -06:00
terrafrost 87be41b0ee Merge branch '3.0' 2022-02-18 01:52:28 -06:00
terrafrost 566d74b991 Merge branch '2.0' into 3.0 2022-02-18 01:47:58 -06:00
terrafrost c56d8525ef Strings: increment_str should return incremented value 2022-02-17 23:45:07 -06:00
terrafrost 28019bb8f8 Merge branch '3.0' 2022-02-17 23:07:24 -06:00
terrafrost b510af1cb5 Merge branch '2.0' into 3.0 2022-02-17 23:07:16 -06:00
terrafrost 8d07631d81 Merge branch '3.0' 2022-02-17 22:27:58 -06:00
terrafrost 97eea332c5 PuTTY: add support for saving PuTTY v3 keys 2022-02-17 22:24:46 -06:00
terrafrost 7cbd239124 Merge branch '3.0' 2022-02-17 08:22:56 -06:00
terrafrost 9f6af761b0 Merge branch '2.0' into 3.0 2022-02-17 08:19:47 -06:00
terrafrost b58f7dc4ac Merge branch '3.0' 2022-02-14 23:25:28 -06:00
terrafrost 27f578797d XML Key loading tweaks 2022-02-14 23:20:29 -06:00
terrafrost e2f9d10660 Merge branch '3.0' 2022-02-14 21:19:59 -06:00
terrafrost 7d3dbccd72 DH/PKCS8: encryption options couldn't be set for PKCS8 private keys 2022-02-14 21:19:29 -06:00
terrafrost 5bc572e2ce EC/PKCS8: OpenSSL didn't like phpseclib formed Ed25519 private keys
Tested with openssl pkey -in private.pem -pubout -text on
OpenSSL 1.1.1f 31 Mar 2020
2022-02-14 21:15:36 -06:00
terrafrost c1da7c5e8a Merge branch '3.0' 2022-02-14 20:14:14 -06:00
terrafrost f1dec13c38 PKCS8: the parent class shouldn't be directly called 2022-02-14 20:09:33 -06:00
terrafrost c233a385cc Merge branch '3.0' 2022-02-14 19:34:16 -06:00
terrafrost dc488f967f PKCS8: fix private key creation 2022-02-14 19:27:47 -06:00
terrafrost f5858a6a1d Tests/RSA: add test for changing PKCS8 encryption parameters 2022-02-14 19:25:13 -06:00
terrafrost ffbddd8152 Merge branch '3.0' 2022-02-14 17:59:57 -06:00
terrafrost 91a674a781 RSA/PrivateKey: add comment to explain things 2022-02-14 17:59:41 -06:00
terrafrost 1d652e4a25 Merge branch '3.0' 2022-02-14 17:53:34 -06:00
terrafrost 3460c70e3a Merge branch '2.0' into 3.0 2022-02-14 17:53:25 -06:00
terrafrost 37566b7b73 Merge branch '3.0' 2022-02-14 17:44:14 -06:00
terrafrost 86c0007078 SFTP: backport fix from master 2022-02-14 17:42:49 -06:00
terrafrost b5a3b05574 Merge branch '2.0' 2022-02-14 17:35:58 -06:00
terrafrost 247d23f40e X509: code cleanup 2022-02-14 17:32:20 -06:00
Jack Worman b96fc26dbc Psalm coverage to everywhere except phpseclib/Crypt/, phpseclib/Math/ and tests/
Revert "Removed remaining tabs"

This reverts commit 31c077d6b1.

Revert "Whitespace php-cs-fixer.php rules added"

This reverts commit 25e336614d.

Addressing comments
2022-02-14 17:30:41 -06:00
terrafrost b2b5e54afe Merge branch '3.0' 2022-02-08 20:37:20 -06:00
terrafrost f96f3505a8 Hash: add support for keccak256 2022-02-08 20:34:17 -06:00
terrafrost 30eeb49583 Merge branch '3.0' 2022-02-04 10:39:04 -06:00
terrafrost 60edff77e6 EC: CS adjustment 2022-02-04 10:38:47 -06:00
terrafrost dbe7daff1d
Merge pull request #1752 from Slamdunk/ec_sign_without_password
EC: decipher private key to generate signature
2022-02-04 10:36:23 -06:00
terrafrost b3f14dee37 SSH2: move KEXDH_INIT / KEXDH_REPLY to MessageType 2022-02-04 08:56:52 -06:00
Filippo Tessarotto e884929175
EC: decipher private key to generate signature 2022-02-04 10:15:39 +01:00
Jack Worman b352bd602d Changed casing 2022-02-03 19:09:41 -06:00
Jack Worman fa53c147a5 Aliases PacketType 2022-02-03 12:50:50 -06:00
Jack Worman dcf3528c8d Renamed constants classes 2022-02-03 12:49:50 -06:00
Jack Worman 61f2bc1c06 Remove Dynamic Constants
Remove Dynamic Constants
2022-02-02 19:43:32 -06:00
terrafrost cc65aa3b0e Merge branch '3.0' 2022-02-01 21:21:16 -06:00
terrafrost 56973d40db SSH2: stop using more dynamic properties in SymmetricKey 2022-02-01 21:17:10 -06:00
Jack Worman f900045772 updated contribution steps
updated contribution steps
2022-02-01 20:46:16 -06:00
Jack Worman 9b1c218664 psalm ci
psalm-ci

psalm-ci

psalm-ci
2022-02-01 20:45:53 -06:00
Jack Worman ef66d9f7dd php-cs-fixer ci
php-cs-fixer ci
2022-02-01 20:29:48 -06:00
terrafrost dc5a5fafb6 Merge branch '3.0' 2022-02-01 07:01:26 -06:00
terrafrost ea3bee985c Merge branch '2.0' into 3.0 2022-02-01 07:01:19 -06:00
terrafrost 60dd91a03b Merge branch '3.0' 2022-02-01 06:34:01 -06:00
terrafrost d925e66677 Merge branch '1.0' into 3.0 2022-02-01 06:33:46 -06:00
Jack Worman 5916c2bff8 Fixed risky tests 2022-01-31 09:53:36 -06:00
terrafrost 3f05c5ce3a Merge branch '3.0' 2022-01-30 10:26:57 -06:00
terrafrost 112ed0225f Merge branch '2.0' into 3.0 2022-01-30 10:26:49 -06:00
terrafrost bcaec1620c Merge branch '3.0' 2022-01-30 02:50:15 -06:00
terrafrost 1443ab7936 Merge branch '2.0' into 3.0 2022-01-30 02:50:05 -06:00
terrafrost 41bca090c2 Merge branch '3.0' 2022-01-30 01:59:16 -06:00
terrafrost 3f2a5aa4cd SSH2: stop using dynamic properties in Hash 2022-01-30 01:52:31 -06:00
terrafrost 215fd61d12 SSHi2: stop using dynamic properties in SymmetricKey 2022-01-30 01:36:02 -06:00
terrafrost 48259b20b3 Merge branch '3.0' 2022-01-30 01:19:37 -06:00
Jack Worman 0a9fc99dc8 Un-qualifying global functions
Un-qualifying global functions
2022-01-30 01:19:16 -06:00
Jack Worman e3b71763ae Fixed psalm level 6 errors in phpseclib/Net/ 2022-01-30 01:18:53 -06:00
terrafrost ab5e7858d8 Merge branch '3.0' 2022-01-29 15:04:34 -06:00
terrafrost 57661764c5 Merge branch '2.0' into 3.0 2022-01-29 15:04:27 -06:00
terrafrost d6a068e5f3 Merge branch '3.0' 2022-01-29 11:38:28 -06:00
terrafrost 3d70b5ece8 SSH2: rm debug code 2022-01-29 11:38:19 -06:00
terrafrost 57771503aa Merge branch '3.0' 2022-01-29 11:35:55 -06:00
terrafrost de4220c461 SSH2: CS adjustments 2022-01-29 11:35:38 -06:00
terrafrost 08790c520d Merge branch '3.0' 2022-01-29 09:44:36 -06:00
terrafrost 56ed69fbe7 fix bad merge 2022-01-29 09:15:01 -06:00
terrafrost 1017120fa9 Merge branch '2.0' into 3.0 2022-01-28 15:10:07 -06:00
terrafrost fea0b235fe Merge branch '3.0' 2022-01-28 00:55:12 -06:00
terrafrost e6afe3e25f Merge branch '2.0' into 3.0 2022-01-28 00:54:53 -06:00
terrafrost 2961a0c0d6 Merge branch '3.0' 2022-01-27 18:26:31 -06:00
terrafrost a748bf5bef SSH2: one more tweak to RSA signature verificatio 2022-01-27 18:26:08 -06:00
terrafrost ebc0701f8a Merge branch '2.0' 2022-01-27 05:51:44 -06:00
terrafrost decbde4f5d SSH2: rsa-sha2-256 and rsa-sha2-512 sigs weren't verifying 2022-01-27 05:51:06 -06:00
terrafrost a88b7e546e Merge branch '3.0' 2022-01-23 11:00:48 -06:00
Jack Worman 7c000843ab Corrected many @return annotations in phpseclib/Net
Corrected many @return annotations in phpseclib/Net
2022-01-23 11:00:41 -06:00
terrafrost 254f44888d Merge branch '3.0' 2022-01-15 20:19:45 -06:00
terrafrost 88e39a1d4b Merge branch '2.0' into 3.0 2022-01-15 20:19:38 -06:00
terrafrost c0b60b80ab Merge branch '2.0' 2022-01-14 18:32:48 -06:00
terrafrost 602760c5d8 SSH2: CS change for 3.0 branch 2022-01-14 18:32:23 -06:00
terrafrost d359543fe7 Merge branch '2.0' into 3.0 2022-01-14 18:31:48 -06:00
terrafrost ffd2522941 Merge branch '3.0' 2022-01-08 19:53:20 -06:00
terrafrost ddfb217855 Merge branch '1.0' into 3.0 2022-01-08 19:51:35 -06:00
terrafrost c4b4264008 Merge branch '3.0' 2022-01-08 16:49:57 -06:00
terrafrost 796270a254 Tests: update for 3.0 branch 2022-01-08 16:49:43 -06:00
terrafrost 2aa8072410 Merge branch '1.0' into 3.0 2022-01-08 16:49:00 -06:00
terrafrost 08c279de73 Merge branch '3.0' 2021-12-28 00:28:25 -06:00
terrafrost 438241b6c2 Merge branch '1.0' into 3.0 2021-12-28 00:27:33 -06:00
terrafrost 50e6998b4a Merge branch '3.0' 2021-12-26 10:46:59 -06:00
terrafrost 0a71243b91 Merge branch '1.0' into 3.0 2021-12-26 02:28:45 -06:00
terrafrost d58c82afc2 Merge branch '2.0' 2021-12-26 00:41:00 -06:00
terrafrost cc6edd81a6 Strings: misc tweaks 2021-12-26 00:40:43 -06:00
terrafrost 380430cb29 Merge branch '3.0' 2021-12-15 07:29:12 -06:00
terrafrost df918f6af9 Merge branch '2.0' into 3.0 2021-12-15 07:28:38 -06:00
terrafrost 1272e9fd3c
Merge pull request #1724 from michaelKaefer/master
Remove define() from SSH2 and use class constants instead (master branch)
2021-12-15 05:56:47 -06:00
terrafrost e0d8b9454a
Merge pull request #1723 from michaelKaefer/3.0
Remove define() from SSH2 and use class constants instead (3.0 branch)
2021-12-15 05:56:29 -06:00
Michael Käfer bcec175691 Remove define() from SSH2 and use class constants instead (3.0 branch) 2021-12-14 16:43:57 +01:00
Michael Käfer d71522d8aa Remove define() from SSH2 and use class constants instead (3.0 branch) 2021-12-14 16:34:41 +01:00
terrafrost 713fa95292 Merge branch '3.0' 2021-12-11 10:26:14 -06:00
terrafrost 13881b09d4 Travis: add PHP 8.1 support
See https://bugs.php.net/75474#1509646645 for more info on the static
change
2021-12-11 10:19:39 -06:00
terrafrost 013de5ad16 Merge branch '3.0' 2021-12-10 07:32:50 -06:00
terrafrost 8a0e6c05e7 Salsa20: fix PHP 5.6 error
The following demonstrates the error:

function demo(&$x)
{
  $x = 5;
}

$x = $y = [10];
demo(...$y);
echo $x[0];

That outputs 5 in PHP 5.6 and 10 in later PHP versions
2021-12-10 07:30:26 -06:00
terrafrost e75604733b ... 2021-12-08 19:08:35 -06:00
terrafrost 13e8ebf67d ... 2021-12-08 19:05:51 -06:00
terrafrost b6375e5a4e Travis: add PHP 8.1 2021-12-08 07:51:06 -06:00
terrafrost 76e4d1e78c Merge branch '3.0' 2021-12-07 22:21:08 -06:00
terrafrost 072a56b2f9 SSH2: allow for stringable objects 2021-12-07 22:20:55 -06:00
terrafrost 7cabdc0748 Merge branch '3.0' 2021-12-07 22:13:23 -06:00
terrafrost 20b9abf589 SSH2: show a more helpful error message when logging in with pubkey 2021-12-07 22:10:29 -06:00
terrafrost be731e9ae7 Merge branch '3.0' 2021-12-07 21:59:52 -06:00
terrafrost 6a935bb57b Merge branch '2.0' into 3.0 2021-12-07 21:59:47 -06:00
terrafrost 9c44f493ce Merge branch '3.0' 2021-12-04 22:59:34 -06:00
terrafrost 8c137a19e4 Tests/Salsa20: use stream[0..63] instead of xor-digest 2021-12-04 22:44:20 -06:00
terrafrost 4141799c02 Tests: fix issues with Salsa20 / ChaCha20 unit tests 2021-12-04 18:43:12 -06:00
terrafrost 35d8974ac1 Tests: ChaCha20 and Salsa20 unit tests weren't being ran 2021-12-04 16:27:52 -06:00
terrafrost 1b0d423245 Merge branch '2.0' 2021-12-04 16:05:40 -06:00
thephilosoft aa88c5621b fix: fix syntax errors in ChaCha20 and Salsa20 tests 2021-12-04 15:42:25 -06:00
terrafrost 4671b10d14 Merge branch '3.0' 2021-12-04 15:11:34 -06:00
terrafrost 2bcb643660 Merge branch '2.0' into 3.0 2021-12-04 15:10:52 -06:00
terrafrost f3cd784b9b Merge branch '3.0' 2021-11-29 07:25:29 -06:00
terrafrost dc3e7bda71 Tests/SFTP: PHP 8.1 error message changed 2021-11-29 07:23:49 -06:00
terrafrost a233605081 Merge branch '3.0' 2021-11-28 17:46:13 -06:00
terrafrost 89bfb45bd8 CHANGELOG: fix bad merge 2021-11-28 17:46:03 -06:00
terrafrost 3542fd5c4d Merge branch '3.0' 2021-11-28 17:31:53 -06:00
terrafrost bf17f54058 Merge branch '2.0' into 3.0 2021-11-28 17:31:46 -06:00
terrafrost f39e797bb2 Merge branch '3.0' 2021-11-28 11:35:25 -06:00
terrafrost 1bd5b40ee1 SymmetricKey: add getMode() 2021-11-28 11:27:52 -06:00
terrafrost 2d67d19d2b Merge branch '3.0' 2021-11-22 08:14:46 -06:00
terrafrost a85c2f0d6e RSA: rm unused privateKey variable 2021-11-22 08:13:55 -06:00
terrafrost 90fdcaedcf Merge branch '3.0' 2021-11-21 21:28:25 -06:00
terrafrost 84295e2fc2 RSA/Keys/Raw: add support for private keys 2021-11-21 21:22:34 -06:00
terrafrost 1f9b6c52d6 Merge branch '3.0' 2021-11-21 10:37:47 -06:00
terrafrost ea0e71977e Tests/EC: add a test showing phpseclib's immunity to an EC vuln 2021-11-21 10:34:15 -06:00
terrafrost 8beb966f9e Merge branch '3.0' 2021-11-21 09:59:25 -06:00
terrafrost d20bf291a1 Merge branch '3.0' of https://github.com/phpseclib/phpseclib into 3.0 2021-11-21 09:59:07 -06:00
terrafrost 35dc9059bd Merge branch '3.0' 2021-11-21 09:58:48 -06:00
terrafrost c4b571a588 EC: error out when scalar is out of range 2021-11-21 09:55:04 -06:00
terrafrost a4b280de10 Merge branch '3.0' 2021-11-17 09:25:11 -06:00
terrafrost 24c26e63e9 Merge branch '2.0' into 3.0 2021-11-17 09:25:04 -06:00
terrafrost 8b08fbfe63 Merge branch '3.0' 2021-11-14 00:57:40 -06:00
terrafrost 053910784e CS adjustments 2021-11-14 00:53:03 -06:00
terrafrost 4eb9cbd0c8 EC/Keys/PKCS8: publicKey parameter should be optional 2021-11-14 00:52:37 -06:00
terrafrost f86ecf6674 Merge branch '3.0' 2021-11-11 19:51:47 -06:00
terrafrost 014b3a95a1 Merge branch '2.0' into 3.0 2021-11-11 19:51:26 -06:00
terrafrost bb8dc9d4aa Merge branch '3.0' 2021-11-11 19:40:16 -06:00
terrafrost 779e11e496 SSH2: use exceptions rather than user_error 2021-11-11 19:39:49 -06:00
terrafrost 15263f0c9c Merge branch '1.0' into 3.0 2021-11-11 19:38:52 -06:00
terrafrost b15e21d3fc Merge branch '3.0' 2021-11-10 19:46:26 -06:00
terrafrost 0b7db9ebd6 Merge branch '1.0' into 3.0 2021-11-10 19:46:19 -06:00
terrafrost 213fa40c94 Merge branch '3.0' 2021-11-08 06:45:02 -06:00
terrafrost 17e79d9341 Merge branch '2.0' into 3.0 2021-11-08 06:44:55 -06:00
terrafrost 7c16f6d1fe Merge branch '3.0' 2021-11-03 22:32:48 -05:00
terrafrost a0405d4816 Merge branch '2.0' into 3.0 2021-11-03 22:28:16 -05:00
terrafrost 5909f55757 Merge branch '3.0' 2021-10-30 18:16:37 -05:00
terrafrost 878526d7c9 SSH2: CS adjustments 2021-10-30 18:16:23 -05:00
terrafrost 13b9663ac6 Merge branch '1.0' into 3.0 2021-10-30 18:15:28 -05:00
terrafrost a5d9ba3e0f Merge branch '3.0' 2021-10-26 22:02:08 -05:00
terrafrost 6e794226a3 Merge branch '2.0' into 3.0 2021-10-26 22:01:46 -05:00
terrafrost b5653538e2 Merge branch '2.0' 2021-10-26 20:51:24 -05:00
terrafrost 7a739d75fe Merge branch '2.0' into 3.0 2021-10-26 20:48:46 -05:00
terrafrost 17fb1331ed Merge branch '3.0' 2021-10-13 22:00:40 -05:00
terrafrost 01cdf396b2 Merge branch '2.0' into 3.0 2021-10-13 22:00:32 -05:00
terrafrost 3945c15b43 Merge branch '3.0' 2021-10-13 19:58:37 -05:00
Christopher Davis 24150b26f6 Don't Use Array Unpackage for Status Code -> Error
the `status_codes` property is an array with integer keys and string
values, but the `$error` value in `SFTP::logError` was trying to be unpacked
from an array.

Seems to come from cee3f3cd4a, but even at
that commit the `status_codes` data structure was still an array.

This bug is only present in 3.X, 2.X release didn't unpack here:
a684f12065/phpseclib/Net/SFTP.php (L829)
2021-10-13 19:58:27 -05:00
terrafrost b7b8d755fa Merge branch '3.0' 2021-10-12 20:37:42 -05:00
terrafrost 2ec8356121 Merge branch '2.0' into 3.0 2021-10-12 20:37:34 -05:00
terrafrost efa5b8a066 Merge branch '3.0' 2021-10-11 09:18:27 -05:00
terrafrost a2c30f9d33 Merge branch '2.0' into 3.0 2021-10-11 09:15:37 -05:00
terrafrost 5cfa2137ab Merge branch '3.0' 2021-10-09 13:35:16 -05:00
terrafrost 2564032e6f Merge branch '2.0' into 3.0 2021-10-09 13:32:07 -05:00
terrafrost 4c9b067b63 Merge branch '3.0' 2021-10-09 13:27:46 -05:00
terrafrost b3e39538b8 Merge branch '2.0' into 3.0 2021-10-09 13:27:40 -05:00
terrafrost 8545a78223 Merge branch '2.0' 2021-10-09 13:01:45 -05:00
terrafrost 644af71b6c SSH2: readd public for 3.0 branch 2021-10-09 13:00:30 -05:00
terrafrost 025b8beb8f Merge branch '2.0' into 3.0 2021-10-09 13:00:03 -05:00
terrafrost 4ee4ef76f6 Merge branch '3.0' 2021-10-09 08:32:22 -05:00
terrafrost 844a8d2c3a Merge branch '2.0' into 3.0 2021-10-09 08:28:37 -05:00
terrafrost d9a73a410b Merge branch '3.0' 2021-10-09 07:51:23 -05:00
terrafrost cd80f98788 Merge branch '2.0' into 3.0 2021-10-09 07:51:17 -05:00
terrafrost 0a73af1337 Merge branch '3.0' 2021-09-28 20:56:57 -05:00
terrafrost b192ec0d12 Merge branch '2.0' into 3.0 2021-09-28 20:56:36 -05:00
terrafrost d8ea63dbdb
Merge pull request #1697 from terrafrost/sftpv456-3.0
add SFTP v4/5/6 support to phpseclib v3
2021-09-28 20:39:40 -05:00
terrafrost 0e6f4247f2 Merge branch '1.0' 2021-09-28 09:00:11 -05:00
terrafrost 13b5ad9593 Merge branch '1.0' into 3.0 2021-09-28 09:00:00 -05:00
terrafrost defd5d23b1 fix bad merge 2021-09-18 10:35:21 -05:00
terrafrost 0dbbeb39ce Merge branch 'sftpv455-2.0' into sftpv456-3.0 2021-09-16 16:24:11 -05:00
terrafrost 615dc51dec Merge branch '3.0' 2021-08-24 20:27:47 -05:00
terrafrost 1b90375231 Merge branch '2.0' into 3.0 2021-08-24 20:24:50 -05:00
terrafrost 9db03e1536 Merge branch '2.0' into 3.0 2021-08-24 20:20:20 -05:00
terrafrost 31141fee09 Merge branch '3.0' 2021-08-15 23:24:52 -05:00
terrafrost 62fcc5a94a Merge branch '2.0' into 3.0 2021-08-15 23:24:45 -05:00
terrafrost e5e21c114f BigInteger: code cleanup
generateCustomReduction() is called by slidingWindow() and
createRecurringModuloFunction(). i suspect this code was an early
attempt to implement what'd later become createRecurringModuloFunction()
2021-08-14 18:15:14 -05:00
terrafrost d274ef8d48 Merge branch '3.0' 2021-08-14 13:26:59 -05:00
Claude Pache 291eec0ce5 PublicKeyLoader: make all methods static 2021-08-14 12:03:43 -05:00
terrafrost 12864bd9f6 AsymmetricKey: make more methods static 2021-08-14 12:03:23 -05:00
terrafrost 5bb28dd86b Merge branch '3.0' 2021-07-28 21:21:07 -05:00
terrafrost a19c6ab7e6 Merge branch '1.0' into 3.0 2021-07-28 21:00:24 -05:00
terrafrost 92b0261c0c Merge branch '3.0' 2021-07-22 09:23:42 -05:00
terrafrost 5e290492d1 Serializable is being deprecated in PHP 8.1 2021-07-22 09:19:15 -05:00
terrafrost 046707d23c Merge branch '3.0' 2021-07-10 13:24:59 -05:00
terrafrost 05539a72be PrimeField: plug memory leaks 2021-07-10 13:24:33 -05:00
terrafrost c8959ded2c Merge branch '3.0' 2021-07-05 08:36:07 -05:00
terrafrost 8186db7533 SFTP: get_channel_packet throws exceptions in 3.0 2021-07-05 08:35:39 -05:00
terrafrost 926d3545a2 Merge branch '2.0' into 3.0 2021-07-05 08:34:36 -05:00
terrafrost ed50aa2725 Merge branch '3.0' 2021-06-24 21:48:30 -05:00
terrafrost 927f8062a7 Merge branch '2.0' into 3.0 2021-06-24 21:45:57 -05:00
terrafrost 1ffb7ab88f Merge branch '3.0' 2021-06-23 22:09:50 -05:00
terrafrost 5f3281a6d5 Tests/X509/CSR: cast implicit bools to explicit bools 2021-06-23 22:05:00 -05:00
terrafrost f0736a8828 X509: getPublicKey() didn't return correct RSA key type 2021-06-23 22:00:36 -05:00
terrafrost a8a13ae7c9 Tests/X509/CSR: getPublicKey() didn't handle PKCS1 / PSS correctly 2021-06-23 21:53:48 -05:00
terrafrost ad26fafa66 Merge branch '3.0' 2021-06-19 11:30:17 -05:00
terrafrost fceb5b47da SFTP: CS adjustments 2021-06-19 11:30:03 -05:00
terrafrost 946dedb3e9 Merge branch '3.0' 2021-06-19 11:22:26 -05:00
terrafrost 418035c404 SSH2: use weakreference when available to stop memory leak 2021-06-19 11:17:23 -05:00
terrafrost 20b3360191 Merge branch '3.0' 2021-06-19 10:15:12 -05:00
terrafrost e3df33183c SSH2: use weakreference when available to stop memory leak 2021-06-19 10:14:45 -05:00
terrafrost 6ba0aef278 Merge branch '3.0' 2021-06-16 08:43:55 -05:00
ahoareau f1c4164687 fix exception thrown because of undefined constant with php7.4 2021-06-16 08:43:35 -05:00
terrafrost 0bca60f6b9 Merge branch '3.0' 2021-06-16 08:12:46 -05:00
terrafrost 9b1f8a260a SSH2: NET_SSH2_CHANNEL_KEEP_ALIVE -> self::CHANNEL_KEEP_ALIVE 2021-06-16 08:12:09 -05:00
terrafrost d789306e5c Merge branch '3.0' 2021-06-16 01:40:56 -05:00
terrafrost a5fcb44e28 AsymmetricKey: make methods static 2021-06-16 01:40:27 -05:00
terrafrost 683b465fd7 Merge branch '3.0' 2021-06-15 07:29:13 -05:00
terrafrost b32ffb64b8 Merge branch '2.0' into 3.0 2021-06-15 07:29:03 -05:00
terrafrost f051153024 Merge branch '3.0' 2021-06-14 01:55:14 -05:00
terrafrost a127a51338 Merge branch '2.0' into 3.0 2021-06-14 01:54:45 -05:00
terrafrost fbf5503b21 Merge branch '2.0' into 3.0 2021-06-14 01:53:51 -05:00
terrafrost c029eb9a73 Merge branch '3.0' 2021-06-12 08:05:12 -05:00
terrafrost 07423805ac Merge branch '2.0' into 3.0 2021-06-12 07:58:20 -05:00
terrafrost b77ebf2bd2 Merge branch '3.0' 2021-06-02 22:59:34 -05:00
terrafrost d1666cac50 SFTP: CS adjustments 2021-06-02 22:59:11 -05:00
terrafrost b6988f8ced Merge branch '3.0' 2021-06-01 21:07:14 -05:00
terrafrost 6d4f436da1 X509: add unit tests 2021-06-01 21:01:48 -05:00
terrafrost d7c96ebfb2 ASN1: change how default values are processed for ints and enums 2021-06-01 20:00:40 -05:00
terrafrost 25be1ed285 Merge branch '3.0' 2021-05-23 10:39:31 -05:00
terrafrost d0a18020f3 Merge branch '2.0' into 3.0 2021-05-23 10:39:25 -05:00
terrafrost 5cc95a591d Merge branch '3.0' 2021-05-22 10:23:48 -05:00
terrafrost cfe8a24011 PrivateKey: tweak interface 2021-05-22 10:18:11 -05:00
terrafrost 84f07cc9cb X509: signing with pw protected PSS keys yielded errors 2021-05-22 10:10:09 -05:00
terrafrost e7de3c1ca9 Merge branch '3.0' 2021-05-21 16:37:10 -05:00
terrafrost c98b163e76 SSH2: rm unneeded false checks (for which exceptions are now used) 2021-05-21 16:36:53 -05:00
terrafrost 4b2bdfa408 Merge branch '2.0' into 3.0 2021-05-18 22:02:48 -05:00
terrafrost ab64bc3a63 Merge branch '3.0' 2021-05-15 22:41:27 -05:00
terrafrost c1c233e907 Merge branch '2.0' into 3.0 2021-05-15 22:28:36 -05:00
terrafrost c46150651f Merge branch '3.0' 2021-05-14 12:56:23 -05:00
terrafrost 574382e06a Merge branch '2.0' into 3.0 2021-05-14 12:56:16 -05:00
terrafrost e8c1cd9f65 Merge branch '3.0' 2021-05-11 20:49:27 -05:00
terrafrost 748e889513 Merge branch '3.0-channel-closure' into 3.0 2021-05-11 20:29:41 -05:00
terrafrost 81ffb62c20 Merge branch '2.0' into 3.0-channel-closure 2021-05-11 20:28:46 -05:00
terrafrost 0448d3b07b Merge branch '3.0' 2021-05-09 08:00:25 -05:00
terrafrost b3b54e8c6b Merge branch '2.0' into 3.0 2021-05-09 08:00:02 -05:00
terrafrost 05828a8759 SFTP: reopen channel on channel closure 2021-05-09 01:07:09 -05:00
terrafrost 46e1fca2b7 Merge branch '3.0' 2021-05-02 08:51:49 -05:00
terrafrost bd0e217793 Merge branch '2.0' into 3.0 2021-05-02 08:44:27 -05:00
nickyb b53f54d953 Implemented auth_methods_to_continue property and getter. 2021-05-02 08:44:02 -05:00
terrafrost 78d0c55953 Merge branch '3.0' 2021-04-26 09:08:02 -05:00
Kyle 0f77cf3a59 Allow string for BigInteger
In real life BigInteger are used to store number too big to be `int` so `string` is actually the natural type to use
2021-04-26 09:07:55 -05:00
terrafrost 95d4b95001 Merge branch '3.0' 2021-04-20 16:21:19 -05:00
terrafrost cf39b89276 CHANGELOG: add 3.0.8 release 2021-04-20 16:21:05 -05:00
terrafrost 1642985976 Merge branch '3.0' 2021-04-20 16:12:40 -05:00
terrafrost 7d3b0a2182 X509: tweaks to mapOutExtensions 2021-04-20 16:01:45 -05:00
Kyle c596078d7a Create tbsCertificate/extensions if missing
Fix #1642
Create tbsCertificate/extensions if missing when extensions values are proceeded
2021-04-20 15:59:46 -05:00
terrafrost cdbc0308c3 Merge branch '3.0' 2021-04-18 22:21:25 -05:00
terrafrost d9615a6fb9 AsymetrticKey: add getComment() method 2021-04-18 22:20:48 -05:00
terrafrost 545b5db5c8 Merge branch '3.0' 2021-04-18 10:32:47 -05:00
terrafrost 701881d3de X509: add replace parameter to setExtensionValue 2021-04-18 10:00:26 -05:00
terrafrost 4b24efb042 Merge branch '3.0' 2021-04-17 08:32:05 -05:00
terrafrost 0d9d1eedb1 Tests/EC: now that Parallels isn't running these plugins linger 2021-04-17 08:18:11 -05:00
terrafrost 5fccc4cada fix bad merge 2021-04-17 07:36:50 -05:00
terrafrost b44a59091a Merge branch '2.0' into 3.0 2021-04-17 06:53:11 -05:00
terrafrost 721fd70a6b Merge branch '2.0' into 3.0 2021-04-17 06:18:10 -05:00
terrafrost 5536318563 Merge branch '3.0' 2021-04-16 18:51:14 -05:00
terrafrost 07f728546b X509: apparently list() works differently in 5.6 than in 7.0+ 2021-04-16 09:06:52 -05:00
terrafrost acc2657511 X509: symmetric array destructuring requires PHP 7.1+ 2021-04-15 21:24:35 -05:00
Bastien Miclo 0dabb0c090 Allow to specify extension value as critical 2021-04-15 21:21:48 -05:00
terrafrost b25118c6aa Merge branch '3.0' 2021-04-15 21:03:20 -05:00
Kyle 8123521307 Don't filter basicConstraints on unique values
array_unique check values which is not relevant for basicConstraints where `true == "foo"` so prevent to specify any other constraint (like pathlen)
2021-04-15 21:03:08 -05:00
terrafrost a3f8999eac Merge branch '3.0' 2021-04-14 05:33:02 -05:00
terrafrost 03e9060cbb cipher_name_openssl_ecb shouldn't be static because of AES 2021-04-14 05:24:03 -05:00
terrafrost cd89d1766b Merge branch '3.0' 2021-04-13 08:06:02 -05:00
terrafrost 5b6024b409 CS adjustment 2021-04-13 08:05:55 -05:00
terrafrost a9aa3b117d Merge branch '3.0' 2021-04-12 08:23:56 -05:00
terrafrost 11cc31d99a Merge branch '3.0' of https://github.com/terrafrost/phpseclib into 3.0 2021-04-12 06:17:41 -05:00
terrafrost 4e1093fc22 CS adjustments 2021-04-12 06:17:04 -05:00
terrafrost b7eaee4977 don't load plugins whose filename start with a . 2021-04-09 10:55:50 -05:00
terrafrost 7e38313802 Merge branch '3.0' 2021-04-06 09:00:18 -05:00
terrafrost d369510df0 Merge branch '2.0' into 3.0 2021-04-06 09:00:11 -05:00
terrafrost 1ed024c5a3 Merge branch '3.0' 2021-04-06 08:43:27 -05:00
terrafrost 9dbcbd1562 Merge branch '2.0' into 3.0 2021-04-06 08:43:20 -05:00
terrafrost e436022c89 Merge branch 'moosa-2.0' into moosa-3.0 2021-04-03 18:21:04 -05:00
terrafrost 2a5c801f30 Merge branch 'moosa-2.0' into moosa-3.0 2021-04-03 17:56:17 -05:00
terrafrost f61cce9c83 RSA: misc fixes for "without NULL" PKCS1 signature validation 2021-04-03 17:50:28 -05:00
terrafrost a60f569126 Merge branch 'moosa-2.0' into moosa-3.0 2021-04-03 17:13:46 -05:00
terrafrost ae15ac69d0 Merge branch 'moosa-2.0' into moosa-3.0 2021-04-03 17:12:38 -05:00
terrafrost 0fc7c81c66 fix bad merge 2021-04-03 13:48:40 -05:00
terrafrost 104a57badd Merge branch 'moosa-2.0' into moosa-3.0 2021-04-03 13:28:23 -05:00
terrafrost 42fc46e9a9 RSA: make sure that parameters is null for relaxed PKCS1 signatures 2021-04-03 11:33:49 -05:00
terrafrost c6a22faf60 Merge branch 'moosa-2.0' into moosa-3.0 2021-04-03 11:11:50 -05:00
terrafrost c06f322426 Merge branch 'moosa-2.0' into moosa-3.0 2021-04-02 13:48:20 -05:00
terrafrost 801070db1a Merge branch 'moosa-2.0' into moosa-3.0 2021-04-02 11:09:57 -05:00
terrafrost 1e0fe567b2 Merge branch '3.0' 2021-04-02 10:29:14 -05:00
terrafrost ed52a587e8 ASN1: CS adjustment 2021-04-02 10:29:04 -05:00
terrafrost 62c69d8372 Merge branch '3.0' 2021-04-02 10:28:04 -05:00
terrafrost 86184fb7b9 Merge branch 'nexans-2.0' into nexans-3.0 2021-03-30 22:44:35 -05:00
terrafrost 5cb4e29555 Merge branch 'nexans-2.0' into nexans-3.0 2021-03-30 22:41:43 -05:00
terrafrost 111852d7c0 Merge branch 'nexans-1.0' into nexans-2.0 2021-03-30 22:41:03 -05:00
terrafrost b18714c248 ... 2021-03-30 22:39:46 -05:00
terrafrost f0f8d80073 SSH2: use type boolean for want reply instead of character 2021-03-29 08:15:16 -05:00
terrafrost dfb71b4fc7 Merge branch '2.0' into 3.0 2021-03-27 10:33:46 -05:00
terrafrost fecdb6b1aa Merge branch '1.0' into 2.0 2021-03-27 10:03:23 -05:00
terrafrost 098cb69039 SSH2: don't close channel on unexpected response to channel request 2021-03-27 10:01:37 -05:00
terrafrost 57cb1984c1 Merge branch '3.0' 2021-03-20 06:31:07 -05:00
terrafrost 57b6942962 Merge branch '2.0' into 3.0 2021-03-20 06:30:39 -05:00
terrafrost 78364b0127 ... 2021-03-20 06:09:38 -05:00
terrafrost 8f31e59efa ... 2021-03-20 06:00:23 -05:00
terrafrost 54b18b4547 Merge branch '2.0' into 3.0 2021-03-20 00:46:53 -05:00
terrafrost 2b1e5e40e2 Merge branch '3.0' 2021-03-16 21:19:29 -05:00
terrafrost 624f514e88 SSH2: add setTerminal() method 2021-03-16 21:18:56 -05:00
terrafrost 45d07d336f Merge branch '3.0' 2021-03-16 06:55:44 -05:00
terrafrost d74340a41c more CS adjustments 2021-03-16 06:55:20 -05:00
terrafrost 6ade44a687 Merge branch '3.0' 2021-03-16 06:18:29 -05:00
terrafrost cd5e5126ca SFTP: CS adjustment 2021-03-16 06:18:19 -05:00
terrafrost e2328a9477 Merge branch '3.0' 2021-03-13 08:24:12 -06:00
terrafrost a8018c1922 CHANGELOG: add 3.0.6 release 2021-03-13 08:24:01 -06:00
terrafrost 7b1b13edd5 Merge branch '3.0' 2021-03-10 07:58:51 -06:00
Ernest Lebedev 906a5fafab Added some PHPDoc fixes according to use cases from the docs (https://phpseclib.com/docs/sftp) to satisfy PHPStan 2021-03-10 07:58:31 -06:00
terrafrost d8f7b0ef2b Merge branch '3.0' 2021-03-08 23:04:34 -06:00
terrafrost 70bc5d01f0 Merge branch '2.0' into 3.0 2021-03-08 23:04:28 -06:00
terrafrost f2733c54bc Merge branch '3.0' 2021-02-26 09:21:57 -06:00
terrafrost eb2d0b3099 Merge branch '2.0' into 3.0 2021-02-26 09:21:38 -06:00
terrafrost ae44cb5d8a Merge branch '3.0' 2021-02-23 05:29:10 -06:00
terrafrost eeabad1ed3 SFTP: mkdir on streams didn't work 2021-02-23 05:14:25 -06:00
terrafrost 425993a61b Merge branch '3.0' 2021-02-22 09:06:55 -06:00
terrafrost 8a459caada Merge branch '2.0' into 3.0 2021-02-22 09:06:46 -06:00
terrafrost 6e0b98c847 Merge branch '3.0' 2021-02-21 19:19:30 -06:00
terrafrost a8f5d9db55 Merge branch '2.0' into 3.0 2021-02-21 18:57:40 -06:00
terrafrost 613dd50591 Merge branch '3.0' 2021-02-12 10:18:28 -06:00
terrafrost 7c751ea006 CHANGELOG: add 3.0.5 release 2021-02-12 10:18:16 -06:00
terrafrost 74a19f554c Merge branch '3.0' 2021-02-12 10:15:28 -06:00
terrafrost 8a028a001c CHANGELOG: add 3.0.4 release 2021-02-12 10:15:17 -06:00
terrafrost 76869c6d8f Merge branch '3.0' 2021-02-12 07:48:49 -06:00
terrafrost 55f23334cd loadPublic -> loadPublicKey; loadPrivate -> loadPrivateKey 2021-02-12 07:48:12 -06:00
terrafrost 8809c6a2b6 Merge branch '3.0' 2021-02-10 08:27:26 -06:00
terrafrost 052cb7d762 X509: add getCurrentCert method (since $currentCert is now private) 2021-02-10 08:26:58 -06:00
terrafrost 99fb313234 Merge branch '3.0' 2021-02-09 04:05:16 -06:00
terrafrost 3bddf4d962 PublicKeyLoader: add loadPublic, loadPrivate and loadParameters 2021-02-08 23:44:24 -06:00
terrafrost 505b673e19 Merge branch '3.0' 2021-02-04 01:06:39 -06:00
terrafrost a18b86ae26 add mode to all block cipher examples 2021-02-04 01:06:14 -06:00
terrafrost 71c96ce3d1 Merge branch '3.0' 2021-02-03 20:56:16 -06:00
terrafrost 8797d76009 Merge branch '2.0' into 3.0 2021-02-03 20:02:29 -06:00
terrafrost 1e42ae8138 Merge branch '3.0' 2021-02-02 20:39:16 -06:00
terrafrost d096769654 Rijndael: calling setIV() after setBlockLength() can result in err 2021-02-02 20:21:56 -06:00
terrafrost b296d4a88b Merge branch '3.0' 2021-01-28 10:09:16 -06:00
terrafrost e9f79655db RSA: use OpenSSL for generating private keys 2021-01-28 09:49:15 -06:00
terrafrost 7c8868a632 Merge branch '3.0' 2021-01-26 23:34:26 -06:00
terrafrost b49203d5b9 BigInteger: big speedups for when OpenSSL is used 2021-01-26 23:13:40 -06:00
terrafrost 85a844bab1 RSA: CS adjustments 2021-01-26 22:58:45 -06:00
terrafrost 03e3db6ed2 Merge branch '3.0' 2021-01-25 13:12:21 -06:00
terrafrost 845a2275e8 X509: CS adjustments 2021-01-25 13:02:05 -06:00
terrafrost bdb6c08c35 misc docblock adjustments 2021-01-25 12:36:02 -06:00
terrafrost 1795b5df6a SSH/Agent: EC keys didn't work with agent 2021-01-25 12:21:14 -06:00
terrafrost 3d4767301c X509: fix niche issue with computeKeyIdentifier 2021-01-25 12:17:36 -06:00
terrafrost 5d49c5409c Merge branch '3.0' 2021-01-19 08:26:59 -06:00
Tomáš Procházka e8b4e4d4df Allow newer versions of paragonie/random_compat
Allows to use version of paragonie/random_compat which is NOOP for PHP 7.0 or newer.
2021-01-19 08:26:31 -06:00
terrafrost 4ab3eee13d Merge branch '3.0' 2021-01-16 11:35:34 -06:00
terrafrost 97a5a270e4 CHANGELOG: add 3.0.3 release 2021-01-16 11:35:19 -06:00
terrafrost ee66bcfbb3 Merge branch '3.0' 2021-01-16 10:41:45 -06:00
terrafrost c203a4425e Merge branch '2.0' into 3.0 2021-01-16 10:41:30 -06:00
terrafrost 14dfaafcb3 Merge branch '3.0' 2021-01-16 10:33:56 -06:00
terrafrost cdbb1236a7 Merge branch '2.0' into 3.0 2021-01-16 10:33:39 -06:00
Jan Slabon 131459996b Added support for absent parameters field in PSS keys
See [here](https://tools.ietf.org/html/rfc4055#section-3.1) for details.
2021-01-16 10:24:55 -06:00
terrafrost c1b70c21cb RSA: the salt length isn't saved for new keys 2021-01-16 09:59:45 -06:00
terrafrost 6c142a35d3 Merge branch '3.0' 2021-01-15 21:59:28 -06:00
terrafrost 3e32d5a853
Merge pull request #1573 from kylekatarnls/feature/allow-to-use-extensions
Allow to extend X509 extensions
2021-01-15 21:57:07 -06:00
Bastien Miclo 57476bf304
Cleanup import 2021-01-14 16:18:07 +01:00
Bastien Miclo e69049be5e
Add getRegisteredExtension() 2021-01-14 16:15:55 +01:00
terrafrost dfb12d5331 Merge branch '3.0' 2021-01-14 08:49:05 -06:00
terrafrost 5f8ca76d0f RSA: the salt length, if not specified, is the length of the hash 2021-01-14 08:11:53 -06:00
terrafrost 9f5b6ea953 Merge branch '3.0' 2021-01-14 03:11:12 -06:00
terrafrost 06cd62ae55 Merge branch 'rsa-exceptions' into 3.0 2021-01-14 03:10:59 -06:00
terrafrost bfb49c06e8 RSA: throw exceptions instead of returning false 2021-01-13 12:08:23 -06:00
terrafrost 523372cb7f Merge branch '3.0' 2021-01-13 01:21:38 -06:00
terrafrost 9b24cc87d0 Merge branch 'ssh-auth-alteration-2.0' into ssh-auth-alteration-3.0 2021-01-12 23:23:26 -06:00
terrafrost b3bff1eb2c Merge branch '3.0' 2021-01-12 11:12:51 -06:00
Simon Podlipsky b82766486a Fix imports in PublicKeyLoader 2021-01-12 11:12:31 -06:00
terrafrost fcf691124e
Merge pull request #1578 from kylekatarnls/fix/end-as-date-time
Allow to pass end date as DateTime
2021-01-12 10:31:24 -06:00
terrafrost ee74b22c01
Merge pull request #1575 from kylekatarnls/fix/phpdoc
Fix encodeDER() PHPDoc
2021-01-12 10:28:33 -06:00
terrafrost 6470c492c5
Merge pull request #1574 from kylekatarnls/fix/unit-test-windows-compatibility
Allow tests to pass even on Windows with git core.autocrlf on
2021-01-12 10:27:40 -06:00
terrafrost d812384c2d Merge branch '3.0' 2021-01-08 19:20:17 -06:00
terrafrost 05d934c89f RSA: improve identification of public / private PKCS1 / PKCS8 keys 2021-01-08 09:01:31 -06:00
terrafrost 9a1c87fbcc Merge branch '3.0' 2021-01-07 20:36:33 -06:00
terrafrost 010ca94cb4 Merge branch '2.0' into 3.0 2021-01-07 20:36:27 -06:00
terrafrost f4a93d71c1 Merge branch '3.0' 2021-01-07 20:24:37 -06:00
terrafrost d9b8341e9c Merge branch '2.0' into 3.0 2021-01-07 20:24:15 -06:00
terrafrost d365f1f1d5 Merge branch '3.0' 2021-01-07 19:36:15 -06:00
terrafrost e14e9e92ca EC: use the correct case up front 2021-01-07 19:35:34 -06:00
Bastien Miclo cce21f077f
Allow to pass end date as DateTime 2021-01-07 22:05:17 +01:00
Bastien Miclo 619253cdfb
Allow tests to pass even on Windows with git core.autocrlf on 2021-01-07 00:00:26 +01:00
Bastien Miclo 0be984fd80
Fix encodeDER() PHPDoc 2021-01-06 23:57:47 +01:00
Bastien Miclo 3d35690a0a
Allow to extend X509 extensions 2021-01-06 23:25:23 +01:00
terrafrost bef6b2159c Merge branch '3.0' 2020-12-30 09:08:16 -06:00
terrafrost 7b7d254a6c rm docblock templates 2020-12-30 09:08:05 -06:00
terrafrost 3bff661c00 Merge branch '3.0' 2020-12-30 06:08:16 -06:00
David Prévot 5fd81cff55 ChaCha20 testsuite: tfix (missing quote) 2020-12-30 06:08:09 -06:00
terrafrost 6e7aacaa56 Merge branch '3.0' 2020-12-30 05:36:44 -06:00
Tobias Nyholm aa638b1c75 Added changelog for 3.0.2 2020-12-30 05:36:37 -06:00
terrafrost ac2770e359 Merge branch '3.0' 2020-12-30 05:25:11 -06:00
terrafrost b14caee559 Merge branch '2.0' into 3.0 2020-12-30 05:25:02 -06:00
terrafrost 1ee5c3971d Merge branch '3.0' 2020-12-30 05:23:39 -06:00
terrafrost f8d9aa8c49
Merge pull request #1550 from remicollet/patch-1
Simplify test
2020-12-30 05:23:14 -06:00
terrafrost 4926098440 Merge branch '3.0' 2020-12-30 05:21:13 -06:00
terrafrost a19b5b4ca8 update how @internal phpdoc attributes are used 2020-12-30 05:05:54 -06:00
terrafrost a2b390d725 Merge branch '3.0' 2020-12-23 10:41:04 -06:00
terrafrost 7a9418e4e0 SSH2: suppress errors on stream_select calls 2020-12-23 10:39:00 -06:00
terrafrost 44a4dfb7ac Merge branch '3.0' 2020-12-23 10:27:20 -06:00
terrafrost 19afa6300a CHANGELOG: add note about namespace change 2020-12-23 10:27:03 -06:00
terrafrost 1e44f1fc8d Merge branch '3.0' 2020-12-23 08:17:43 -06:00
Bastien Miclo ba89cdbf0f Support DateTimeImmutable 2020-12-23 08:16:22 -06:00
terrafrost f77930aa83 Merge branch '3.0' 2020-12-23 07:49:30 -06:00
Bastien Miclo 224abbc1f9 Show array-failure in load() method 2020-12-23 07:49:08 -06:00
terrafrost 18ae08bfdf Merge branch '3.0' 2020-12-23 07:06:53 -06:00
terrafrost 02fa3b142e EC/PKCS1: throw exception when trying to load non-strings 2020-12-23 07:06:04 -06:00
terrafrost 9e2b8b2375 Merge branch '3.0' 2020-12-19 01:52:47 -06:00
terrafrost 094bcbdd97 CHANGELOG: add 3.0.1 release 2020-12-19 01:52:34 -06:00
terrafrost e5efc6e24f Merge branch '3.0' 2020-12-19 01:14:13 -06:00
terrafrost 5e1c890ac6 Tests: fix bad unit test 2020-12-19 01:14:06 -06:00
terrafrost 6ff6bc9433 Merge branch '3.0' 2020-12-19 01:12:25 -06:00
terrafrost f5d7c06264 Merge branch '2.0' into 3.0 2020-12-19 01:12:16 -06:00
terrafrost 1d75d080f1 Merge branch '3.0' 2020-12-19 01:02:39 -06:00
terrafrost 31c5e50902 SFTP: change where stat cache is being cleared for uploads 2020-12-19 01:02:06 -06:00
terrafrost 9637e25bf7 add unit test for resuming uploads 2020-12-18 21:34:21 -06:00
terrafrost df22fa0487 add unit test for stream_select addition 2020-12-18 21:29:09 -06:00
terrafrost c1a9c5e6da Merge branch '3.0' 2020-12-18 17:32:25 -06:00
terrafrost 08478feee7 SFTP: resuming uploads didn't work 2020-12-18 17:31:55 -06:00
terrafrost 4d3e5ccf6d Merge branch '3.0' 2020-12-18 16:19:25 -06:00
terrafrost 20852adf78 SSH2/Stream: stream_select needs to be able to access $fsock 2020-12-18 16:12:14 -06:00
terrafrost a77a56648e Merge branch '3.0' 2020-12-17 08:54:21 -06:00
terrafrost 203a4eb10a Merge branch '2.0' into 3.0 2020-12-17 08:54:14 -06:00
terrafrost 5fcb2d4e34 Merge branch '3.0' 2020-12-17 08:14:20 -06:00
terrafrost 99e8d7b822 PKCS8: fix E_WARNING 2020-12-17 08:13:56 -06:00
Remi Collet 9ae6c8fd3a
Simplify test 2020-12-17 08:48:04 +01:00
terrafrost 2e3e8b13b8 Merge branch '3.0' 2020-12-17 00:11:17 -06:00
terrafrost fe62c85e02 CHANGELOG: add 3.0.0 entry 2020-12-17 00:10:28 -06:00
terrafrost b28b9472c8 Merge branch '2.0' into 3.0 2020-12-16 23:59:48 -06:00
terrafrost d1c8c6dba1 Merge branch 'keepalive-master' 2020-12-16 23:15:16 -06:00
terrafrost caa287b181 Merge branch 'keepalive-3.0' into keepalive-master 2020-12-16 09:13:28 -06:00
terrafrost 47e1ce60b3 SSH2: syntax error 2020-12-16 09:13:05 -06:00
terrafrost 0144a86e25 Merge branch 'keepalive-2.0' into keepalive-3.0 2020-12-16 09:12:45 -06:00
terrafrost 7a3bffdf99 Merge branch 'keepalive-3.0' into keepalive-master 2020-12-16 08:37:01 -06:00
terrafrost 32bfbcd7d2 Merge branch 'keepalive-2.0' into keepalive-3.0 2020-12-16 08:36:43 -06:00
terrafrost 1f5d87212b Merge branch 'keepalive-3.0' into keepalive-master 2020-12-15 23:53:16 -06:00
terrafrost 0ddcff753f Merge branch 'keepalive-2.0' into keepalive-3.0 2020-12-15 23:52:53 -06:00
terrafrost 20cec076ea Merge branch 'keepalive-3.0' into keepalive-master 2020-12-15 08:53:57 -06:00
terrafrost a4af48c7a6 Merge branch 'keepalive-2.0' into keepalive-3.0 2020-12-15 08:52:43 -06:00
terrafrost e4dc5bd55a Merge branch '3.0' 2020-12-13 09:49:09 -06:00
terrafrost eb4e02debe PHPUnit 4 is redundant for phpseclib 3.0 2020-12-13 09:09:14 -06:00
terrafrost 727d337c1d Merge branch '3.0' 2020-12-13 02:24:20 -06:00
terrafrost a2a5bf1003 Merge branch '2.0' into 3.0 2020-12-13 02:24:02 -06:00
terrafrost c5d9534ada fix bad merge 2020-12-13 00:57:30 -06:00
terrafrost c25dff2ef0 Merge branch '2.0-class-rename' into 3.0-class-rename 2020-12-12 22:26:03 -06:00
terrafrost 1a30cd862f ... 2020-12-12 20:13:42 -06:00
terrafrost 7237c0f803 fix bad merge 2020-12-12 19:34:38 -06:00
terrafrost e4bf7b111a Merge branch '2.0' into 3.0 2020-12-12 19:22:36 -06:00
terrafrost af30bca1d0 Merge branch '3.0' 2020-12-07 08:40:38 -06:00
terrafrost c08683402e Merge branch '2.0' into 3.0 2020-12-07 08:04:12 -06:00
terrafrost ecafd8612d Merge branch '3.0' 2020-11-26 21:09:26 -06:00
terrafrost afca3030c0 Merge branch '2.0' into 3.0 2020-11-26 21:09:21 -06:00
terrafrost 6e2960e304 Merge branch '3.0' 2020-11-26 19:11:40 -06:00
terrafrost b310f694ef Merge branch '2.0' into 3.0 2020-11-26 19:10:48 -06:00
terrafrost fefac4ba66 README: make travis-ci.com run for master branch instead of 3.0 2020-11-21 12:17:36 -06:00
terrafrost aae9131bec Merge branch '3.0' 2020-11-21 12:16:56 -06:00
terrafrost a609b9fcf5 Merge branch '2.0' into 3.0 2020-11-21 12:11:38 -06:00
terrafrost 77ed1d6a01 Merge branch '3.0' 2020-11-21 10:51:45 -06:00
terrafrost e69b79eba7 Merge branch 'codelts' into 3.0 2020-11-21 10:51:30 -06:00
terrafrost 7eca0af4f2 Merge branch '3.0' 2020-11-02 19:54:43 -06:00
terrafrost dd5e7742ea Merge branch '2.0' into 3.0 2020-11-02 19:54:32 -06:00
terrafrost 5492361206 Merge branch '3.0' 2020-11-01 09:31:28 -06:00
terrafrost 7e337c9bd7 Merge branch '2.0' into 3.0 2020-11-01 09:31:17 -06:00
terrafrost e220455d27 Merge branch '3.0' 2020-10-30 05:57:46 -05:00
terrafrost 336fe5c8f8 Merge branch '2.0' into 3.0 2020-10-29 21:46:30 -05:00
terrafrost 92eb7b670f Merge branch '3.0' 2020-09-19 08:55:40 -05:00
terrafrost 5983df848c EC: add support for PKCS1 private keys with separate parameters 2020-09-19 08:36:09 -05:00
William Desportes 5711e7fbe4
Fix phpdoc issues reported by Doctum 2020-09-12 10:14:54 +02:00
terrafrost 07ae7972e9 Merge branch '3.0' 2020-09-11 21:23:49 -05:00
William Desportes 480af6b980
Merge branch '2.0' into 3.0 2020-09-09 10:46:22 +02:00
terrafrost 272b6b2cfb Merge branch '3.0' 2020-09-07 23:24:55 -05:00
terrafrost c6d51fc87e Merge branch '2.0' into 3.0 2020-09-07 23:24:49 -05:00
terrafrost e026c54e41 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2020-08-31 05:17:47 -05:00
terrafrost 95ffb5caa0 Merge branch '3.0' of https://github.com/phpseclib/phpseclib into 3.0 2020-08-31 05:16:55 -05:00
terrafrost 14d546c002 Merge branch '3.0' 2020-08-30 08:22:26 -05:00
terrafrost fc4a1b0083 Merge branch '2.0' into 3.0 2020-08-30 08:22:20 -05:00
Andreas Fischer 4e90b2e82f Merge branch '3.0'
* 3.0:
  Remove api from build target
2020-08-21 19:35:49 +02:00
Andreas Fischer fe00f1667e Merge branch '2.0' into 3.0
* 2.0:
  Remove api from build target
2020-08-21 19:35:49 +02:00
Andreas Fischer 51143184c1 Merge branch '3.0'
* 3.0:
  Move Doctum config files to phpseclib/api-docs
2020-08-21 18:20:59 +02:00
Andreas Fischer 2285601cf3 Merge branch '2.0' into 3.0
* 2.0:
  Move Doctum config files to phpseclib/api-docs
2020-08-21 18:20:24 +02:00
terrafrost b83bbd6742 Merge branch '3.0' 2020-08-17 07:30:52 -05:00
terrafrost dcc85b795d Merge branch '2.0' into 3.0 2020-08-17 07:30:46 -05:00
terrafrost c4a7e40ebe Merge branch '3.0' 2020-08-09 11:01:08 -05:00
terrafrost 8f62b798ef Merge branch '2.0' into 3.0 2020-08-09 11:00:57 -05:00
terrafrost 75632c19f0 Merge branch '3.0' 2020-08-01 04:08:14 -05:00
terrafrost f6e85053e1 Merge branch '2.0' into 3.0 2020-08-01 04:08:06 -05:00
terrafrost 1a76e62a41 Merge branch '3.0' 2020-08-01 02:31:42 -05:00
Liam Dennehy a7fc232c63 getaddrinfo error message seems to be unstable, add tolerance to test 2020-08-01 02:28:56 -05:00
terrafrost 15937ea13b Merge branch '3.0' 2020-07-31 21:36:00 -05:00
terrafrost 92a67a03aa Merge branch '2.0' into 3.0 2020-07-31 21:27:38 -05:00
terrafrost 68ef6e95f2 Merge branch '3.0' 2020-07-31 04:11:54 -05:00
terrafrost 5fbdb8b582 Merge branch '2.0' into 3.0 2020-07-31 04:11:26 -05:00
terrafrost 096251d645 Merge branch '3.0' 2020-07-30 23:20:20 -05:00
terrafrost abe8f6aab8 Merge branch '2.0' into 3.0 2020-07-30 22:59:13 -05:00
terrafrost 3e9a474a22 Merge branch '3.0' 2020-07-19 22:40:56 -05:00
terrafrost 478672607c PKCS8: fix E_NOTICE 2020-07-19 22:40:42 -05:00
terrafrost 901c055a15 Merge branch '3.0' 2020-07-17 07:55:33 -05:00
terrafrost 8af870963a Merge branch '2.0' into 3.0 2020-07-17 07:55:11 -05:00
terrafrost dc6ccb2ad5 Merge branch '3.0' 2020-07-08 08:49:10 -05:00
terrafrost e2fa9f3925 Revert "..."
This reverts commit 827607575a.
2020-07-08 08:48:48 -05:00
terrafrost fc43eea049 Merge branch '3.0' 2020-07-08 04:13:34 -05:00
terrafrost 6e4f6dab1b Merge branch '2.0' into 3.0 2020-07-08 04:13:28 -05:00
terrafrost b483f13748 Merge branch '3.0' 2020-07-07 23:47:56 -05:00
terrafrost 9e81c7e257 Merge branch '2.0' into 3.0 2020-07-07 23:47:47 -05:00
terrafrost fe5980e22d Merge branch '3.0' 2020-07-07 23:35:28 -05:00
terrafrost 30eed17c2f Merge branch '2.0' into 3.0 2020-07-07 23:35:22 -05:00
terrafrost 827607575a ... 2020-07-03 13:31:37 -05:00
terrafrost dad0c699cd Merge branch '3.0' 2020-06-02 08:53:59 -05:00
terrafrost 844d7ab539 X509: getPublicKey() didn't work for SPKAC 2020-06-02 08:51:04 -05:00
terrafrost b4224cf613 Merge branch '3.0' 2020-05-31 12:22:51 -05:00
terrafrost 97ab584c63 Merge branch '2.0' into 3.0 2020-05-31 12:22:45 -05:00
terrafrost 8c8863eca5 Merge branch '3.0' 2020-05-31 10:07:11 -05:00
terrafrost c2ab2a4884 X509: publicKey wasn't being loaded for CSRs / SPKACs 2020-05-31 02:11:44 -05:00
terrafrost 005630ccee Merge branch '3.0' 2020-05-31 01:55:48 -05:00
terrafrost 0bda2b4573 Merge branch '2.0' into 3.0 2020-05-29 08:36:26 -05:00
terrafrost 49afc58e04 Merge branch '3.0' 2020-05-16 14:01:29 -05:00
terrafrost 32acf235e8 SymmetricKey: rm unused line 2020-05-16 13:19:24 -05:00
terrafrost 392fc92ff1 Merge branch '3.0' 2020-05-15 21:36:52 -05:00
terrafrost a82dc8e009 SymmetricKey: ECB doesn't use an IV either 2020-05-15 07:53:14 -05:00
terrafrost 6c855e709d Merge branch '3.0' 2020-05-13 06:07:49 -05:00
terrafrost f780640ecf move more common elements to StreamCipher class 2020-05-12 22:03:06 -05:00
terrafrost 8de9ebeddd Merge branch '3.0' 2020-05-12 08:47:48 -05:00
terrafrost 995bf77315 SSH2: rm format_log_helper method 2020-05-12 08:35:45 -05:00
terrafrost dcd6b7cbbd Merge branch '3.0' 2020-05-12 08:32:46 -05:00
terrafrost cc45f18cb8 stream ciphers don't use IVs 2020-05-12 08:15:49 -05:00
terrafrost ad971b976b Merge branch '3.0' 2020-05-12 07:01:09 -05:00
terrafrost ce6d28789a ChaCha20: rm unused 'use' statement 2020-05-12 07:00:38 -05:00
terrafrost 06e1ee6cb3 Merge branch '3.0' 2020-05-10 23:52:37 -05:00
terrafrost 85d55164a6 Merge branch '2.0' into 3.0 2020-05-10 23:52:28 -05:00
terrafrost 21e0d29a7b Merge branch '3.0' 2020-05-10 10:27:08 -05:00
terrafrost 3bce91c2cb Merge branch '2.0' into 3.0 2020-05-10 10:27:00 -05:00
terrafrost b3688c244c Merge branch '3.0' 2020-05-01 21:36:12 -05:00
terrafrost 4af7ca4c09 Merge branch '2.0' into 3.0 2020-05-01 21:36:02 -05:00
terrafrost 5035e2b7e2 Merge branch '3.0' 2020-04-28 22:08:15 -05:00
terrafrost 65de0f6225 Merge branch '2.0' into 3.0 2020-04-28 22:08:07 -05:00
terrafrost 08fc9615e3 Merge branch '3.0' 2020-04-19 15:39:51 -05:00
terrafrost 0b231cc53b RSA: rm ENCRYPTION_PKCS15_COMPAT mode 2020-04-19 15:10:38 -05:00
terrafrost 8724c077e4 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2020-04-19 09:20:09 -05:00
terrafrost b48181e4e3 Merge branch '3.0' 2020-04-19 09:19:47 -05:00
terrafrost 881fbd78ee Hash: add __toString() method 2020-04-19 09:19:27 -05:00
terrafrost fdbf1179a2 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2020-04-18 11:12:50 -05:00
terrafrost e20b742eb0 Merge branch '3.0' 2020-04-18 10:45:51 -05:00
terrafrost 10ce0b9b21 PuTTY: comments weren't settable via toString() method 2020-04-18 10:44:15 -05:00
terrafrost 92d0cd837e PKCS8: add extractEncryptionAlgorithm() method 2020-04-17 22:51:03 -05:00
terrafrost 0f8486cc87 allow strinable objects to be loaded instead of just strings 2020-04-13 07:58:00 -05:00
terrafrost bc3374a2c1 Merge branch '3.0' 2020-04-08 06:16:10 -05:00
terrafrost 94d3403ed3 getLoadedFormat() threw exception for loadFormat()-loaded keys 2020-04-08 06:15:46 -05:00
terrafrost e56f60ff3c Merge branch '3.0' 2020-04-08 05:29:50 -05:00
terrafrost 327a13d133 $key->getLoadedFormat didn't work on EC / DSA keys 2020-04-08 05:07:47 -05:00
terrafrost dbefc9aec6 Merge branch '3.0' 2020-04-05 15:05:03 -05:00
terrafrost ceff4cfbbc rm call_user_func() calls 2020-04-05 15:04:22 -05:00
terrafrost d37dffdb81 SSH: use an anonymous function for logging callback 2020-04-05 10:29:57 -05:00
terrafrost 0d623aa83d Merge branch '3.0' 2020-04-04 18:23:30 -05:00
terrafrost b787c33f3f Merge branch '2.0' into 3.0 2020-04-04 18:22:59 -05:00
terrafrost 3be9465b72 Merge branch '3.0' 2020-04-04 13:09:36 -05:00
terrafrost 3a6be79821 Merge branch '2.0' into 3.0 2020-04-04 12:25:35 -05:00
terrafrost 91e84a24c2 SFTP: optimize call to parent login method for 2.0 branch 2020-04-04 12:20:36 -05:00
terrafrost 3f01740787 Merge branch '1.0' into 2.0 2020-04-04 12:18:34 -05:00
terrafrost 5218532739 SFTP: make it so extending SFTP doesn't cause a segfault 2020-04-04 12:17:55 -05:00
terrafrost 0ad0cd1e2a Merge branch '3.0' 2020-04-03 07:35:40 -05:00
terrafrost 76f80bb0c4 Merge branch '2.0' into 3.0 2020-04-03 07:35:32 -05:00
terrafrost 5ea7be57da Merge branch '3.0' 2020-03-30 07:50:05 -05:00
terrafrost 542bb6cca1 Merge branch '2.0' into 3.0 2020-03-30 07:36:43 -05:00
terrafrost 61398e0fbf Merge branch '3.0' 2020-03-30 00:42:08 -05:00
terrafrost fc87edce6e PKCS8: throw an exception when no ASN1 maps can be used 2020-03-30 00:19:45 -05:00
terrafrost 5d5ed4a449 RSA: fix for RSA PKCS1 public keys masquerading as public keys 2020-03-29 23:31:13 -05:00
terrafrost 7b5356bf86 RSA: add unit test for public key masquerading as private key 2020-03-29 23:12:52 -05:00
terrafrost 688cc2ddf3 Merge branch '3.0' 2020-03-12 23:15:56 -05:00
terrafrost fa4ab86913 Merge branch '2.0' into 3.0 2020-03-12 23:15:48 -05:00
terrafrost 6cfa4a7ef2 Merge branch '3.0' 2020-03-12 08:27:48 -05:00
terrafrost 1004bf5ac1 Merge branch '2.0' into 3.0 2020-03-12 08:27:42 -05:00
terrafrost 90842f90fa Merge branch '3.0' 2020-03-09 20:07:58 -05:00
terrafrost ef04a176dd Merge branch '2.0' into 3.0 2020-03-09 20:02:17 -05:00
terrafrost 4375d13574 Merge branch '3.0' 2020-03-07 22:22:07 -06:00
terrafrost c47ffe187a Merge branch 'master-speed-up-uploads' 2020-03-07 22:22:03 -06:00
terrafrost 2ba26e5490 Merge branch '2.0' into 3.0 2020-03-07 22:21:51 -06:00
terrafrost 0a6f457d14 Merge branch '3.0-speed-up-uploads' into 3.0 2020-03-07 22:21:48 -06:00
terrafrost f15f8d7d17 Merge branch '3.0' 2020-03-07 21:36:30 -06:00
terrafrost b1a1fb5a08 Merge branch '2.0' into 3.0 2020-03-07 21:36:06 -06:00
terrafrost a9a8f69bc5 Merge branch '3.0' 2020-03-07 21:19:36 -06:00
terrafrost ddd5a08c5f SSH2: update identifier to 3.0 2020-03-07 21:19:00 -06:00
terrafrost 6e55470431 Merge branch '2.0' into 3.0 2020-03-02 10:57:07 -06:00
terrafrost 0b5eeac6a4 Merge branch '3.0-speed-up-uploads' into master-speed-up-uploads 2020-02-25 20:45:46 -06:00
terrafrost 053e856a47 Merge branch '2.0-speed-up-uploads' into 3.0-speed-up-uploads 2020-02-25 20:45:18 -06:00
terrafrost 0915176a3e Merge branch '3.0' 2020-02-25 00:09:19 -06:00
terrafrost 8c8e805c73 Merge branch '2.0' into 3.0 2020-02-25 00:00:25 -06:00
terrafrost f1661a7dc2 Merge branch '3.0' 2020-02-24 19:57:11 -06:00
terrafrost 59a7b1166b SSH2: use RFC8332 auth even if host key algo isn't RSA 2020-02-24 19:43:32 -06:00
terrafrost 056cc32868 Merge branch '3.0' 2020-02-24 18:18:11 -06:00
terrafrost ee10846cac SSH2: more consistent exception handling 2020-02-24 18:16:31 -06:00
terrafrost a1362f8bbc Merge branch '3.0' 2020-02-22 22:31:08 -06:00
terrafrost e8da444bb7 SFTP/Stream: expand private key support to more than just RSA 2020-02-22 22:21:19 -06:00
terrafrost 548a94ff9e Merge branch '3.0' 2020-02-22 17:44:05 -06:00
terrafrost cb75dd33bf Merge branch '2.0' into 3.0 2020-02-22 17:43:55 -06:00
terrafrost c1d2ebf770 Merge branch '3.0' 2020-02-11 23:25:13 -06:00
terrafrost 8dac275a03 SFTP: rm size() (we already have filesize()) 2020-02-11 23:25:04 -06:00
terrafrost 8088db319a Merge branch '3.0' 2020-02-11 06:42:15 -06:00
terrafrost b95120c808 SFTP: change visibility of sortOptions for phpseclib2_compat 2020-02-11 06:29:21 -06:00
terrafrost 562371a0ec Merge branch '3.0' 2020-02-10 21:26:55 -06:00
terrafrost f8685c0577 SFTP: _get_sftp_packet() -> get_sftp_packet() 2020-02-10 21:09:22 -06:00
terrafrost f44d39fb19 SFTP: rm permissions attribute 2020-02-10 21:05:00 -06:00
terrafrost 123b2e9af4 Merge branch '3.0' 2020-02-04 06:16:09 -06:00
terrafrost bbf80c878d rm SSH1 2020-02-04 06:15:55 -06:00
terrafrost 5f5fcda72d Merge branch '3.0' 2020-02-04 06:15:21 -06:00
terrafrost 9f09f482ba Merge branch '2.0' into 3.0 2020-02-04 06:15:12 -06:00
terrafrost 11ece32b3f Merge branch '3.0' 2020-02-03 05:39:02 -06:00
terrafrost cacd08a768 Agent/Identity: ECDSA -> EC 2020-02-03 00:56:37 -06:00
terrafrost 7387d79a4f Merge branch '2.0' into 3.0 2020-02-01 22:50:28 -06:00
terrafrost e1e5750f1f Merge branch '3.0' 2020-01-19 08:06:38 -06:00
terrafrost d0856357ea SSH2: don't adjust ssh-ed25519 signatures 2020-01-19 08:05:55 -06:00
terrafrost c5db54de7d Merge branch '3.0' 2020-01-19 02:26:40 -06:00
terrafrost db85a95af2 Tests/RSA: add unit test for exceptions 2020-01-19 02:17:43 -06:00
terrafrost 3c6a741a31 Merge branch '3.0' 2020-01-19 02:10:39 -06:00
terrafrost 2b28c3814b Keys/PuTTY: better support RFC4716 keys 2020-01-19 02:09:39 -06:00
terrafrost abb4fc8bc8 Merge branch '3.0' 2020-01-18 23:08:35 -06:00
terrafrost 14c09f8527 throw exceptions for all private formats not supporting encryption 2020-01-18 22:53:35 -06:00
terrafrost 1dd7278ee1 Merge branch '3.0' 2020-01-18 22:51:41 -06:00
terrafrost 0afd386114 RSA: PuTTY public keys couldn't be saved 2020-01-18 22:12:00 -06:00
terrafrost b65bad4a1d Tests/RSA: add unit test for PuTTY public keys 2020-01-18 21:58:48 -06:00
terrafrost d8dabdf7bc Merge branch '3.0' 2020-01-18 18:53:31 -06:00
terrafrost bed8be26d7 Keys/OpenSSH: throw an exception if you try to encrypt 2020-01-18 18:53:09 -06:00
terrafrost cab9f1e2bc Merge branch '3.0' 2020-01-18 17:57:44 -06:00
terrafrost 0e1dff2be7 RSA: fix MSBLOB encoding error 2020-01-18 17:47:24 -06:00
terrafrost a485e85ba5 Tests/RSA: add additional assert for MSBLOBs 2020-01-18 17:31:34 -06:00
terrafrost e3efc1cf51 Tests/RSA: add additional assert for MSBLOBs 2020-01-18 17:31:10 -06:00
terrafrost 112a210f4d Merge branch '3.0' 2020-01-17 06:39:14 -06:00
terrafrost 6470d1c80e SSH2: @stream_select -> stream_select 2020-01-17 06:38:54 -06:00
terrafrost cb87d1885b
Merge pull request #1444 from tomsommer/patch-2
Remove error suppression from stream_select()
2020-01-17 06:37:44 -06:00
terrafrost 3efafb14b9 Merge branch '3.0' 2020-01-17 06:07:14 -06:00
terrafrost 1da139e0b8 Merge branch '2.0' into 3.0 2020-01-17 06:07:06 -06:00
terrafrost f1772cbf7a ... 2020-01-17 05:42:29 -06:00
terrafrost 0a1c10386a ... 2020-01-17 05:10:12 -06:00
terrafrost b4bff90106 Merge branch '2.0' into 3.0 2020-01-17 04:09:49 -06:00
Tom Sommer 40bd4192fc
Update SSH2.php 2020-01-17 09:41:45 +01:00
terrafrost e0bc38794e Merge branch '3.0' 2020-01-17 02:14:02 -06:00
terrafrost e55ea2e10b Merge branch '2.0' into 3.0 2020-01-17 02:13:51 -06:00
terrafrost 123e44bc8f Merge branch '2.0' 2020-01-17 02:13:44 -06:00
Tom Sommer e2841212cb
Remove error suppression from stream_select()
Suppressing errors from stream_select() makes debugging timeouts extremely hard.
2020-01-10 11:58:36 +01:00
terrafrost 61ffe1a147 SSH2: fix rare key exchange issue 2020-01-07 00:20:47 -06:00
terrafrost 3ba5902046 RSA / X509: misc fixes (mostly related to PSS) 2020-01-04 16:26:55 -06:00
terrafrost 299f7b554d X509: fix bitwise mask for PSS / PKCS1 RSA mode checking 2020-01-03 08:45:16 -06:00
terrafrost c4e07725aa EC: don't call loadCurveByParams if params is null 2020-01-02 05:43:27 -06:00
terrafrost a7b1d031bb visibility changes for phpseclib2_compat 2019-12-30 22:19:07 -06:00
terrafrost be221d8b23 Merge branch '2.0' into 3.0 2019-12-25 17:49:03 -06:00
terrafrost 15c8cc6810 update unit test to account for newly added null byte 2019-12-17 22:01:42 -06:00
terrafrost 0c8b6961e3 EC: fix PKCS8 Ed25519 private keys 2019-12-17 07:56:16 -06:00
terrafrost fd8389f365 add unit test for phpseclib created PKCS8 Ed25519 private keys 2019-12-17 07:55:36 -06:00
terrafrost 320189d94e Merge branch '3.0' 2019-12-08 21:46:37 -06:00
terrafrost 0dd1048553 Merge branch '2.0' into 3.0 2019-12-08 21:44:49 -06:00
Graham Campbell 3f9780f7c5
Updated Travis Config 2019-12-08 13:09:57 +00:00
terrafrost 7e72d923ce Merge branch '3.0' 2019-12-07 18:57:28 -06:00
terrafrost d35f987cb4
Merge pull request #1437 from terrafrost/phpseclib3
rename phpseclib/phpseclib to phpseclib/phpseclib3 for 3.0 branch
2019-12-07 18:55:49 -06:00
terrafrost f1d04b23db Merge branch '3.0' into phpseclib3 2019-11-23 01:55:36 -06:00
terrafrost d587dd5e1f Merge branch '3.0' 2019-11-23 01:53:45 -06:00
terrafrost ea27295c8f SSH2: ssh-ed25519 keys didn't work 2019-11-23 00:58:12 -06:00
terrafrost 653dbd7f94 rename phpseclib/phpseclib to phpseclib/phpseclib3 for 3.0 branch 2019-11-21 19:38:03 -06:00
terrafrost c43a99daf1 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2019-11-17 06:24:17 -06:00
terrafrost 9737b617fb Merge branch '3.0' 2019-11-13 23:48:29 -06:00
terrafrost 4f7992a9ca Merge branch '2.0' into 3.0 2019-11-13 23:48:20 -06:00
terrafrost 33a8224636 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2019-11-02 21:51:51 -05:00
terrafrost c65733b5bb Merge branch '3.0' 2019-11-02 12:44:44 -05:00
terrafrost 8ad4743364 Merge branch '2.0' into 3.0 2019-11-02 12:44:34 -05:00
terrafrost cb8cc30337
add github as a sponsorship source 2019-10-20 21:23:37 -05:00
terrafrost 0054e7b43b Merge branch '3.0' 2019-10-20 14:01:28 -05:00
terrafrost 2a0c1b6e59 Merge branch '2.0' into 3.0 2019-10-20 14:01:13 -05:00
terrafrost 66650f0659 Merge branch '3.0' 2019-10-20 13:45:38 -05:00
terrafrost e7e563d0ce Merge branch '2.0' into 3.0 2019-10-20 13:45:06 -05:00
terrafrost 34c78baf4c Merge branch '3.0' 2019-10-10 00:00:39 -05:00
terrafrost f36b4686c9 SSH2: fix E_NOTICE for diffie-hellman key exchange 2019-10-09 23:59:32 -05:00
terrafrost 01340054a5 Merge branch '3.0' 2019-10-05 19:57:04 -05:00
terrafrost 7cbeb7df48 Merge branch '2.0' into 3.0 2019-10-05 19:56:57 -05:00
terrafrost 5ff9e7b48b Merge branch '3.0' 2019-09-28 13:05:50 -05:00
terrafrost bd534c9271 Merge branch '2.0' into 3.0 2019-09-28 13:05:42 -05:00
terrafrost 62770de289 Merge branch '3.0' 2019-09-28 08:34:30 -05:00
terrafrost ce4722ade0 Merge branch '2.0' into 3.0 2019-09-28 08:34:18 -05:00
terrafrost 070ed06d1e Merge branch '3.0' 2019-09-24 22:21:26 -05:00
terrafrost 72fe2540ab readd visibility for 3.0 branch 2019-09-24 22:21:07 -05:00
terrafrost 52203748de Merge branch '2.0' into 3.0 2019-09-24 22:20:39 -05:00
terrafrost 4ee40bf58e Merge branch '3.0' 2019-09-22 10:39:36 -05:00
terrafrost 470c79056b Merge branch '2.0' into 3.0 2019-09-22 10:39:23 -05:00
terrafrost 53e4418a95 Merge branch '3.0' 2019-09-18 08:51:18 -05:00
terrafrost 666cde2b11 Merge branch '2.0' into 3.0 2019-09-18 08:46:54 -05:00
terrafrost 497900643f Merge branch '3.0' 2019-09-18 08:26:32 -05:00
terrafrost c14557ec8b SSH2: fix typo in exception 2019-09-18 08:26:07 -05:00
Vladmir Gaydamaka 05bf34860d Added test SFTPWrongServerTest 2019-09-18 07:54:01 -05:00
terrafrost f1e2b6e7ef SSH2: fix typo in exception 2019-09-16 23:31:46 -05:00
terrafrost 2fee8e22c1 Merge branch '2.0' into 3.0 2019-09-16 23:12:19 -05:00
terrafrost 67a83ca7c8 Merge branch '2.0' into 3.0 2019-09-16 22:41:42 -05:00
terrafrost 3af5d3b530 Merge branch '2.0' into 3.0 2019-09-16 20:08:58 -05:00
terrafrost 45d787a578
Merge pull request #1403 from terrafrost/hmac-additions
add new HMAC algorithms
2019-09-16 07:41:54 -05:00
terrafrost 853649320b Merge branch '2.0' 2019-09-15 18:24:00 -05:00
terrafrost 0c06e24ac5 Merge branch '2.0' 2019-09-15 17:48:59 -05:00
terrafrost 677a15c122 Merge branch '2.0' 2019-09-15 17:31:53 -05:00
terrafrost 6f8ba6c614 SSH2: tweaks to Exceptions 2019-09-11 07:55:29 -05:00
terrafrost e52697abac SSH2: no authentication didn't work 2019-09-11 06:36:03 -05:00
terrafrost a06a166db6 SSH2: move $this->send_seq_no++ 2019-09-10 23:43:09 -05:00
terrafrost eab705fbb5 SSH2: typo 2019-09-10 23:41:52 -05:00
terrafrost 7aaf46c8ac SSH2: make array_intersect_first static 2019-09-10 23:14:29 -05:00
terrafrost 2774e55ab2 SSH2: eliminate some code re-use involving key exchanges for MACs 2019-09-10 23:01:26 -05:00
terrafrost af3b0d8c2f Merge branch '2.0' 2019-09-10 20:10:03 -05:00
terrafrost 69a11136ae SSH2: ping tweaks 2019-09-10 19:52:35 -05:00
terrafrost 71aa8165fa Merge branch '2.0' 2019-09-10 18:13:12 -05:00
terrafrost 71ced69714 SSH2: add support for EtM 2019-09-09 01:18:33 -05:00
terrafrost 580eb94fd3 SSH2: add umac-64 / umac-128 support 2019-09-08 11:23:29 -05:00
terrafrost e1621ab2f6 Merge branch '2.0' 2019-09-07 20:21:25 -05:00
terrafrost 8a03e90d95 SSH2: update private key auth example 2019-09-07 17:06:51 -05:00
terrafrost 8608463d61 Hash: add support for UMACs 2019-09-07 14:46:55 -05:00
terrafrost eddbdcc66c don't re-generate Eval mode stuff when only IV has changed 2019-09-06 05:37:13 -05:00
terrafrost 23ffa6452e revisions to gocom's code changes 2019-08-28 07:16:24 -05:00
Jukka Svahn 488433e10f Fix mode mapping order and param type 2019-08-24 02:06:45 +03:00
terrafrost b89c488f43 SFTP: unpack() -> unpackSSH2() 2019-08-22 05:01:33 -05:00
terrafrost d51b72abbf
Merge pull request #1390 from terrafrost/diffie-hellman
add a new diffie-hellman key exchange class
2019-08-13 23:07:34 -05:00
terrafrost 422523cf43 EC: make libsodium an insvisible key format 2019-08-09 09:19:01 -05:00
terrafrost 68f3d7d8af add support for Curve448 2019-08-08 22:38:42 -05:00
terrafrost 7cf5facae7 DH: add Curve25519 unit test based off of RFC7748 test vectors 2019-08-08 08:00:37 -05:00
terrafrost 66efabda53 SSH2: update libsodium check 2019-08-07 23:29:33 -05:00
terrafrost 6c1befa7cb X509: select function accessibility changes 2019-08-07 22:57:40 -05:00
terrafrost f04d69a3eb Merge branch 'master' into diffie-hellman 2019-08-07 08:09:36 -05:00
terrafrost 1e7453b585 add a new diffie-hellman key exchange class 2019-08-06 22:10:56 -05:00
terrafrost dfde088d4c visiblity adjustments for PHP 7.4 2019-08-03 16:42:40 -05:00
terrafrost 8088c499b0 Merge branch '2.0' 2019-08-03 11:41:51 -05:00
terrafrost 5a0a7c4dcd Merge branch 'master' of https://github.com/terrafrost/phpseclib 2019-08-03 09:12:08 -05:00
terrafrost cef6916d71 Merge branch '2.0' 2019-08-03 09:11:45 -05:00
terrafrost 0832fb2fd6 Merge branch '2.0' 2019-08-03 07:28:14 -05:00
terrafrost 2286c834bd Merge branch '2.0' 2019-08-02 23:41:40 -05:00
terrafrost de8903d2f2 Merge branch '2.0' 2019-07-30 21:06:22 -05:00
terrafrost e1f265e613 Merge branch '2.0' 2019-07-15 00:22:30 -05:00
terrafrost eb36430ff1 another update to .travis.yml 2019-07-14 12:02:10 -05:00
terrafrost a9d796f1cd Merge branch 'update-auto-channel-close-master' 2019-07-14 11:26:52 -05:00
terrafrost d448dba5a1 Travis: allow failures on 7.4snapshot 2019-07-14 10:52:24 -05:00
terrafrost 353ad158b4 Merge branch 'update-auto-channel-close-2.0' into update-auto-channel-close-master 2019-07-12 07:55:31 -05:00
terrafrost 560e6d2fb1 Merge branch 'update-auto-channel-close-2.0' into update-auto-channel-close-master 2019-07-12 07:39:59 -05:00
terrafrost b6e5b81a26
FUNDING.yml: another update 2019-07-09 08:18:28 -05:00
terrafrost d9b42c1617
update FUNDING.yml 2019-07-04 21:34:07 -05:00
terrafrost e743d900b4
FUNDING: update for tidelift 2019-07-02 07:31:12 -05:00
terrafrost 53c249a9b5
FUNDING: i am not yet approved as a GitHub Sponsor 2019-07-02 07:29:56 -05:00
terrafrost 338eb2e4d3
create FUNDING.yml 2019-07-02 07:26:30 -05:00
terrafrost 113f8dec08 Merge branch '2.0' 2019-07-02 07:12:24 -05:00
terrafrost da5df07948 Merge branch '2.0' 2019-07-02 06:43:51 -05:00
terrafrost cb1e6b285c for private key's, load works but loadFormat would be better 2019-06-28 09:30:46 -05:00
terrafrost eb659a5544 set password in load methods for each pubkey instead of in loader 2019-06-28 08:58:20 -05:00
terrafrost 5573187f3d rm $type parameter from AsymmetricKey::load and add loadFormat() 2019-06-28 08:51:12 -05:00
terrafrost 289ae55f9f rename ECDSA -> EC 2019-06-27 23:15:25 -05:00
terrafrost 0abce39e39 move $enableBlinding property from AsymmetricKey to RSA 2019-06-27 00:30:55 -05:00
terrafrost 25dab4b5ae move traits to Traits subfolder 2019-06-26 00:42:02 -05:00
terrafrost 7012e72488 mv Keys/ and Signature/ to Formats/* 2019-06-25 07:52:45 -05:00
terrafrost d7abfaadbc X509: rm $signatureAlgorithm parameter from signature methods 2019-06-24 18:24:14 -05:00
terrafrost 640e3788f4 Merge branch '2.0' 2019-06-23 11:33:59 -05:00
terrafrost 9b3fa8d8a7 Merge branch '2.0' 2019-06-23 11:17:59 -05:00
terrafrost 33ed294b76 Merge branch '2.0' 2019-06-23 11:14:17 -05:00
terrafrost a7c9e7a4d6 Merge branch '2.0' 2019-06-23 11:08:42 -05:00
terrafrost 50ea988570 Merge branch '2.0' 2019-06-23 10:42:06 -05:00
terrafrost 84b852933e Merge branch '2.0' 2019-06-19 22:36:18 -05:00
terrafrost 305d1b94f3 Merge branch '2.0' 2019-06-16 15:31:53 -05:00
terrafrost e71f203742 Merge branch 'master-callback' 2019-06-16 15:31:39 -05:00
terrafrost aa8a30cd81 Merge branch '2.0' 2019-06-16 11:04:31 -05:00
terrafrost 0e449e8b17 X509: add support for id-RSASSA-PSS 2019-06-15 10:46:34 -05:00
terrafrost 39eda40ed7 Merge branch '2.0' 2019-06-13 01:16:37 -05:00
terrafrost 8e0651308c SSH2: _close_channel -> close_channel 2019-06-12 22:08:48 -05:00
terrafrost 988d37e479 Merge branch '2.0' 2019-06-12 22:07:49 -05:00
terrafrost cee1151f9b Merge branch '2.0' 2019-06-10 00:10:54 -05:00
terrafrost c5a9a66d69 DSA: pass password parameter correctly to OpenSSH::load 2019-06-08 23:18:21 -05:00
terrafrost 327f555b7c add expanded support for OpenSSH private keys 2019-06-08 22:04:54 -05:00
terrafrost 88b6337a3f RSA: fix issue with PKCS1 encryption 2019-06-08 18:58:24 -05:00
terrafrost a431a1959a ECDSA: make it so toString() can setspecified / named curve use 2019-06-03 20:33:01 -05:00
terrafrost 557676edd9 use array type hint 2019-06-02 10:26:26 -05:00
terrafrost 30320f5a91 Merge branch '2.0-callback' into master-callback 2019-06-02 08:22:26 -05:00
terrafrost 8e03f5bfb2 RSA: make it so PSS keys can be saved 2019-06-01 19:35:17 -05:00
terrafrost 5b89ff4177 Merge branch 'rsa-pss' 2019-06-01 16:07:48 -05:00
terrafrost b226c3d882 add second $options parameter to toString method for public keys 2019-06-01 15:53:35 -05:00
terrafrost 8017c74429 RSA: add preliminary support for RSA-PSS keys 2019-05-29 00:32:53 -05:00
terrafrost 79f925e43c SFTP: replace user_error() with Exceptions 2019-05-28 08:52:53 -05:00
terrafrost 72b4bf74d2 SFTP: use microtime(true) 2019-05-28 08:50:22 -05:00
terrafrost 93c0880ca8 SSH2: make $timeout protected 2019-05-28 08:50:03 -05:00
terrafrost a773ae80bd Merge branch '2.0' 2019-05-28 08:47:59 -05:00
terrafrost 89e41233e0 fix bad merge 2019-05-26 22:56:20 -05:00
terrafrost 337b41f865 Merge branch 'master' into immutable-keys 2019-05-26 22:51:40 -05:00
terrafrost 52248669cd Merge branch '2.0' 2019-05-26 15:40:13 -05:00
terrafrost 10f79a86af BigInteger: fix for BigInteger('-0') 2019-05-26 15:35:28 -05:00
terrafrost 50d6c8aafd Tests/BigInteger: test for new BigInteger('-0') 2019-05-26 15:21:27 -05:00
terrafrost 1e3f1d3a38 Merge branch '2.0' 2019-05-26 12:17:51 -05:00
terrafrost 63f8276693 Merge branch '2.0' 2019-05-26 11:43:14 -05:00
terrafrost 7c270b9db3 Merge branch '2.0' 2019-05-26 10:29:34 -05:00
terrafrost 64542e699f BigInteger: GMP engine didn't always return 1 or -1 2019-05-24 21:45:59 -05:00
terrafrost c839297065 Tests/BigInteger: GMP engine didn't always return 1 or -1 2019-05-24 08:25:52 -05:00
terrafrost d02f96e180 System/Agent: non-SSH2 signatures aren't *currently* supported 2019-05-23 08:57:46 -05:00
terrafrost 7c7d500d80 System/Agent: add support for DSA / ECDSA keys 2019-05-23 08:35:36 -05:00
terrafrost 85e2bd4811 SSH2: get binary output from OpenSSH key handler 2019-05-21 09:10:18 -05:00
terrafrost e06f733528 ECDSA: add missing class variables for deterministic ECDSA 2019-05-21 00:03:21 -05:00
terrafrost 7d3b5a0c79 Tests/X509: add new tests to test DSA / ECDSA certs 2019-05-20 23:38:54 -05:00
terrafrost cc32cd2e95 make RSA / DSA / ECDSA immutable and add support to SSH2 / X509 2019-05-19 15:35:29 -05:00
terrafrost b09bc1883e Merge branch 'oid-revamp-2.0' 2019-05-02 07:28:27 -05:00
terrafrost 00b6eaf507 ECDSA/Keys/PKCS8: correctly convert private keys to public 2019-04-29 21:45:17 -05:00
terrafrost 227d9c45ef Merge branch '2.0' 2019-04-11 21:56:27 -05:00
terrafrost e0cbd3fe78 Tests/BigInteger: update unit test 2019-04-10 08:24:24 -05:00
terrafrost 75f51fc8cc BigInteger: make the bitwise methods better handle negative numbers 2019-04-10 06:53:00 -05:00
terrafrost 31c10f39e5 BigInteger/GMP: negative base-256 numbers didn't load correctly 2019-04-09 20:42:18 -05:00
terrafrost 114dc17f5b BigInteger: toBits(true) wasn't working correctly 2019-04-08 08:02:48 -05:00
terrafrost 0e874f1d21 SSH/Agent: use Strings::packSSH2() / Strings::unpackSSH2() 2019-04-06 13:34:33 -05:00
terrafrost cee3f3cd4a SFTP: use Strings::packSSH2() / Strings::unpackSSH2() 2019-04-03 22:09:15 -05:00
terrafrost 0001b81950 SSH2: use Strings::packSSH2() / Strings::unpackSSH2() 2019-04-02 00:09:19 -05:00
terrafrost f2226184ee rm Common/Functions/Objects.php 2019-03-31 16:28:21 -05:00
terrafrost d329814f55 SSH2: send_binary_packet() now always throws exceptions on error 2019-03-31 00:33:57 -05:00
terrafrost 1780bee619 SSH2: add support for elliptic curve hostkeys 2019-03-30 13:35:16 -05:00
terrafrost c9d4a89267 rm SSH1 2019-03-29 21:51:26 -05:00
terrafrost 72209ffd65 add setPreferredAlgorithms() and getServerAlgorithms() 2019-03-29 18:44:31 -05:00
terrafrost 0cff98b19e SSH2: make it so preferred algorithm depends on available engines 2019-03-28 22:15:04 -05:00
terrafrost e629271f7d SSH2: add getMethodsNegotiated() method 2019-03-28 18:53:26 -05:00
terrafrost b5abee639d
Merge pull request #1354 from terrafrost/chacha20
add Salsa20 / ChaCha20 / Poly1305 support
2019-03-28 13:55:32 -05:00
terrafrost aa4c6e686a Merge branch 'master' into chacha20 2019-03-26 08:36:07 -05:00
terrafrost 16abd15089 SSH2: micro-optimization for AES-GCM 2019-03-23 21:41:52 -05:00
terrafrost 70f5eb4bf7 SSH2: Rijndael -> AES (for consistency) 2019-03-23 20:53:20 -05:00
terrafrost 213516128a Crypt: $use_inline_crypt is no longer used 2019-03-23 20:50:10 -05:00
terrafrost 34e065fec8 Merge branch '2.0' 2019-03-23 20:22:34 -05:00
terrafrost 539fc1a9b0 SSH2: CS adjustments 2019-03-23 19:20:06 -05:00
terrafrost 7d41903846 Merge branch '2.0' 2019-03-23 19:18:31 -05:00
terrafrost 494d20efc8 add Salsa20 / ChaCha20 stream ciphers 2019-03-22 15:45:36 -05:00
terrafrost 8ce392f218 SFTP: nlist() didn't return empty directories - now it does
I view this as a BC breaking change so atm do not plan on
backporting it to 1.0/2.0. eg. now, all subdirectories have . and
.. as "files" whereas before they didn't
2019-03-16 09:41:06 -05:00
terrafrost 47280b4e44 Merge branch '2.0' 2019-03-10 11:53:57 -05:00
terrafrost 09fdd60931 Merge branch '2.0' 2019-03-09 18:43:35 -06:00
terrafrost 8a58f3fcd5 Merge branch '2.0' 2019-03-09 17:25:42 -06:00
terrafrost 37df27a4af Merge branch '2.0' 2019-03-08 08:02:54 -06:00
terrafrost 4a920c3690 RSA: fix bad merge 2019-03-08 08:02:20 -06:00
terrafrost 604954cd09 Merge branch '2.0' 2019-03-04 08:16:25 -06:00
terrafrost 496fcd18cd Merge branch '2.0' 2019-03-03 18:42:47 -06:00
terrafrost 2ddcc1f88a Travis: allow failures on nightly 2019-02-24 22:10:37 -06:00
terrafrost adc9a5d189 Merge branch '2.0' 2019-02-24 21:37:43 -06:00
terrafrost ef0518a84a Merge branch '2.0' 2019-02-10 17:24:06 -06:00
terrafrost bf7b1630ea Merge branch 'master' of https://github.com/phpseclib/phpseclib 2019-02-06 06:27:14 -06:00
terrafrost ee742d4edb Merge branch '2.0' 2019-02-05 23:31:20 -06:00
terrafrost 41c76d6e0e SCP: replace user_error with exception 2019-01-27 17:10:06 -06:00
terrafrost 0f3cbce359 Merge branch '2.0' 2019-01-27 17:04:49 -06:00
terrafrost 9e8afe2d78 Merge branch '2.0' 2019-01-27 13:37:47 -06:00
terrafrost 590c92b2a1 Merge branch '2.0' 2019-01-20 09:39:44 -06:00
terrafrost c03753e3c7 Merge branch '2.0' 2019-01-20 09:17:57 -06:00
terrafrost ea3c8dbd9a Merge branch '2.0' 2019-01-16 21:17:18 -06:00
terrafrost 3f6eb2012a Merge branch '2.0' 2019-01-15 23:50:33 -06:00
terrafrost 44a56b8a1f BinaryField: fix issue with negate 2019-01-07 08:06:10 -06:00
terrafrost c53ca28b25 BinaryField: CS adjustment 2019-01-07 06:42:00 -06:00
terrafrost de63198197 PrimeField: docblock cleanup 2019-01-07 06:34:00 -06:00
terrafrost 4ae33f9bde BinaryField: speed up multiplication for GCM and smaller curves 2019-01-07 06:33:11 -06:00
terrafrost 835b1207fa SSH2: replace "$this->object !== false" with "$this->object" 2018-12-31 14:14:43 -06:00
terrafrost 17e6938fba updates to Exceptions 2018-12-31 09:55:32 -06:00
terrafrost c6f9807633 SymmetricKey: don't define self::$gcmField unless we're in GCM mode 2018-12-30 10:14:51 -06:00
terrafrost f98e0afc76 AES: move GCM code to Rijndael 2018-12-30 02:15:06 -06:00
terrafrost 5abb16dc6d SymmetricKey: simplify mode setup 2018-12-30 01:30:21 -06:00
terrafrost a8d07e3dcb SymmetricKey: make $cipher_name_openssl_ecb static 2018-12-29 23:21:18 -06:00
terrafrost 49be6e5529 Hash: rm function_exists calls for hash extension functions 2018-12-29 23:09:33 -06:00
terrafrost e2256f4267 Hash: fix grammer error 2018-12-29 23:05:20 -06:00
terrafrost 97d41fd3aa SSH2: make bad_algorithm_candidate method static 2018-12-29 20:54:18 -06:00
terrafrost 5126937d40 Rijndael: replace block size switch with a single variadic function 2018-12-29 19:35:05 -06:00
terrafrost cef647f9a9
Merge pull request #1330 from terrafrost/gcm
add support for Galois/Counter Mode (GCM)
2018-12-29 19:33:58 -06:00
terrafrost 01c92a59f8 add support for Galois/Counter Mode (GCM) 2018-12-27 08:31:35 -06:00
terrafrost a30cfff79c Merge branch 'master' of https://github.com/phpseclib/phpseclib 2018-12-16 19:04:43 -06:00
terrafrost 3dbc50c667 Merge branch 'post-ecdsa' 2018-12-16 19:03:44 -06:00
terrafrost d37969a345
Merge pull request #1322 from terrafrost/ecdsa
add ECDSA / EdDSA support
2018-12-16 17:46:28 -06:00
terrafrost b76a67dfb4 Merge branch '2.0' 2018-12-16 11:45:37 -06:00
terrafrost 8e977b4e59 ECDSA: CS adjustments to curves 2018-12-03 03:47:46 -06:00
terrafrost 7fb7e6ce52 Twofish: make tables static 2018-12-02 14:28:14 -06:00
terrafrost e758878580 RC2: make pitable / invpitable tables static 2018-12-02 14:13:08 -06:00
terrafrost b278bc7e7e DES: make sboxes static 2018-12-02 13:59:42 -06:00
terrafrost 4679cb7bf7 Blowfish: make sboxes static 2018-12-02 12:42:53 -06:00
terrafrost 9bcd851e97 Blowfish: CS adjustments (" -> ') 2018-12-02 12:21:56 -06:00
terrafrost 5bcb298af7 SymmetricKey: throw an exception when en/de-crypting w/o a key 2018-12-02 12:01:56 -06:00
terrafrost 50f9e1a71a Tests/AES: add unit test for encrypting without a key 2018-12-02 11:58:07 -06:00
terrafrost 479fa4ce3d BigInteger: add getEngine() static method 2018-12-02 10:58:07 -06:00
terrafrost b4ef9a1cae BigInteger: random() would error out if a BigInteger wasn't defined 2018-12-02 10:41:24 -06:00
terrafrost 3ecc62912d throw exceptions when signing / verification is attempted w/o a key 2018-12-02 07:17:17 -06:00
terrafrost 8b2ef543ab Merge branch '2.0' 2018-12-01 23:14:37 -06:00
terrafrost ab49ab9dca Merge branch '2.0' 2018-12-01 22:47:04 -06:00
terrafrost 2c1994805b ECDSA: make it so hash can't be changed for Ed25519 / Ed448 2018-11-29 10:05:28 -06:00
terrafrost d234297819 Tests/ECDSA: test to make sure that k is not re-used 2018-11-24 22:13:40 -06:00
terrafrost 3c4fbe131f Tests/ECDSA: make tests work on PHP 5.6 (by skipping some tests) 2018-11-24 08:32:14 -06:00
terrafrost 669ba5224f SSH2: rm debug code 2018-11-23 00:50:56 -06:00
terrafrost e006f5b326 Merge branch '2.0' 2018-11-22 21:55:51 -06:00
terrafrost e1961c598d Merge branch '2.0' 2018-11-22 13:33:35 -06:00
terrafrost 3423c74f9a Merge branch 'master' of https://github.com/phpseclib/phpseclib 2018-11-20 08:29:11 -06:00
terrafrost 9ccfaff7ba expand on eval() explanation 2018-11-20 08:26:17 -06:00
terrafrost 92f0ee0464 Merge branch '2.0' 2018-11-20 07:52:04 -06:00
terrafrost 0398f7a815 add ECDSA / EdDSA support 2018-11-19 12:39:21 -06:00
Andreas Fischer ba91fbcd1c Merge branch '2.0'
* 2.0:
  fix order of user_error() and bitmap reset
  fix order of user_error() and bitmap reset
2018-11-11 16:25:15 +01:00
terrafrost 451949a5f3 Merge branch '2.0' 2018-11-04 00:46:10 -05:00
terrafrost 11e33eecc5 Merge branch '2.0' 2018-10-27 17:44:01 -05:00
terrafrost faa073ff2a Merge branch '2.0' 2018-10-13 08:22:38 -05:00
terrafrost 405ed06e8a Merge branch '2.0' 2018-10-13 08:18:47 -05:00
terrafrost 3119bb98e3 Merge branch '1.0' into 2.0 2018-10-13 08:15:46 -05:00
terrafrost 39d3ffbeb1 Hash: use hash method for sha3 when available 2018-10-13 07:48:47 -05:00
terrafrost 3df87e8632 Merge branch '2.0' 2018-10-13 00:50:48 -05:00
terrafrost a1513eb02f Merge branch '2.0' 2018-10-12 22:44:14 -05:00
terrafrost 2fdeb47dc1
Merge pull request #1300 from Slamdunk/patch-1
Explain the kraken
2018-10-09 22:45:04 -05:00
Filippo Tessarotto 19f706003e
Explain the kraken 2018-10-09 08:35:56 +02:00
terrafrost 016b252bbb Merge branch '2.0' 2018-10-08 07:36:04 -05:00
terrafrost edc51aac63 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2018-10-06 14:17:30 -05:00
terrafrost 8705f4b31e SSH2: update ping method to work with exceptions 2018-10-06 11:41:15 -05:00
terrafrost c1493a8063 Merge branch '2.0' 2018-10-06 08:02:59 -05:00
terrafrost 422533c978 Merge branch '2.0' 2018-10-05 23:01:03 -05:00
terrafrost 44c2003d4b
Merge pull request #1295 from grongor/fix-wrong-method-name
Fix invalid method name + usages in comments
2018-09-17 00:45:19 -05:00
terrafrost 4bc53f1251 Merge branch '2.0' 2018-09-17 00:29:24 -05:00
Jakub Chábek bee5fd70d8 Fix invalid method name + usages in comments 2018-09-10 17:20:48 +02:00
terrafrost 640fb24ab3 Merge branch '2.0' 2018-09-08 14:42:26 -05:00
terrafrost 086afadf1b Merge branch '2.0' 2018-08-20 21:42:00 -05:00
terrafrost 6021e74a79 Merge branch '2.0-dsas' 2018-08-18 15:04:51 -05:00
terrafrost 6973285758 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2018-08-11 23:56:15 -05:00
terrafrost 7740d9c0c0 Hash: add sha3 support 2018-08-11 23:55:41 -05:00
terrafrost f434acc167
Merge pull request #1284 from simPod/fix-types
Fix return type for Read()
2018-07-24 15:51:33 -05:00
Simon Podlipsky d598204874
Fix return type for Read() 2018-07-22 14:17:15 +03:00
terrafrost 790b9cb22c Merge branch '2.0' 2018-07-16 00:57:08 -05:00
terrafrost 383e4e73a7 Merge branch '2.0' 2018-05-27 11:34:32 -05:00
terrafrost ffb21d7622 SSH/Agent: fix bad merge 2018-05-27 11:27:19 -05:00
terrafrost 03f9a4dc7e Merge branch '2.0' 2018-05-27 10:54:36 -05:00
terrafrost 0b2eb54a29 Merge branch '2.0' 2018-05-27 09:55:45 -05:00
terrafrost 8da15ab19b Merge branch '2.0' 2018-05-19 07:48:42 -05:00
terrafrost 4b6a26acda
Merge pull request #1269 from henk23/patch-1
Fix composer require syntax in readme
2018-05-10 10:29:10 -05:00
henk23 cc6131a329
Fix composer require syntax in readme
According to https://getcomposer.org/doc/03-cli.md#require
2018-05-10 15:51:30 +02:00
terrafrost 78eb98311f Merge branch '2.0' 2018-04-29 16:56:35 -05:00
terrafrost 03d59d73c0 Merge branch '2.0' 2018-04-15 11:55:13 -05:00
terrafrost 28b26b50df Merge branch '2.0' 2018-04-15 10:31:12 -05:00
terrafrost 66aa5aec5c Merge branch '2.0' 2018-04-10 19:00:13 -05:00
terrafrost ab270d1602 Merge branch '2.0' 2018-04-10 00:19:49 -05:00
terrafrost a3081aa7f8 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2018-04-03 20:30:27 -05:00
terrafrost 011f6ad200 BigInteger/PHP: make sure that zero is represented uniformly 2018-04-03 20:23:47 -05:00
terrafrost d4b0e00d14 Tests/BigInteger: make sure that zero is represented uniformly 2018-04-03 20:19:14 -05:00
terrafrost e7d96c7aeb Merge branch '2.0' 2018-03-27 11:07:58 -05:00
terrafrost 8b830700cf Merge branch 'master' of https://github.com/phpseclib/phpseclib 2018-03-27 11:04:25 -05:00
terrafrost 898b14aa05 Merge branch '2.0' 2018-03-27 11:01:45 -05:00
terrafrost 12bd06210c
Merge pull request #1250 from luzpaz/misc-typos
Misc. trivial typos
2018-03-03 15:41:58 -06:00
terrafrost e9bff8a4de X509: cs updates 2018-03-03 13:57:23 -06:00
terrafrost 1ee4167a03 Merge branch '2.0' 2018-03-03 13:44:36 -06:00
terrafrost 6c4a108a92 Merge branch 'authority-info-access-2.0' into authority-info-access-master 2018-03-03 08:09:26 -06:00
luz.paz 380517ef00 Misc. trivial typos
Found via `codespell -q 3`
2018-03-03 07:07:14 -05:00
terrafrost 908dbf341f Merge branch 'master' of https://github.com/phpseclib/phpseclib 2018-02-23 21:41:14 -06:00
terrafrost 2a6f5f825a Asymmetric: fix for phar's
Inspired by 4e367c9631
2018-02-23 21:15:33 -06:00
terrafrost ef0c0ee0a7
Merge pull request #1242 from andreybolonin/patch-1
add php nightly tests
2018-02-21 15:45:11 -06:00
terrafrost b9cd84108c AES: fix issue preventing ECB mode from decrypting 2018-02-21 08:26:52 -06:00
terrafrost 2440be341d Tests/AES: add test for ECB mode 2018-02-21 08:20:29 -06:00
terrafrost 596d122a76 X509: code cleanup 2018-02-20 10:12:50 -06:00
terrafrost 1669e24269 Merge branch '2.0' 2018-02-18 22:29:37 -06:00
terrafrost 55384afdac RSA: make it so you can't sign w/ public key, decrypt w/ private 2018-02-18 16:03:06 -06:00
terrafrost 63b6df29a8 Merge branch '2.0' 2018-02-07 21:24:51 -06:00
terrafrost 7ed7ff2277 README: rm merge conflict code 2018-01-30 00:45:27 -06:00
terrafrost 489627f803 Merge branch '2.0' 2018-01-30 00:40:20 -06:00
terrafrost 44ac8f3996 Merge branch '2.0' 2018-01-22 07:26:57 -06:00
terrafrost 739d826a16 Tests/X509: update for master branch 2018-01-21 13:01:24 -06:00
terrafrost fe71957c37 Merge branch '2.0' 2018-01-21 13:01:06 -06:00
Andrey Bolonin 838e8f69c5
add php nightly tests 2018-01-17 14:04:35 +02:00
terrafrost 59faa1d253 Merge branch '2.0' 2018-01-01 13:09:18 -06:00
terrafrost 3c96ca9fd1 Merge branch '2.0-channel-request-updates' into master-channel-request-updates 2017-12-25 19:12:57 -06:00
terrafrost 56a644faa8 replace user_error with exceptions in a few more places 2017-12-23 14:32:22 -06:00
terrafrost 0571ab0e0c Merge branch 'master' of https://github.com/phpseclib/phpseclib 2017-12-23 14:21:47 -06:00
terrafrost 239a32ff06
Merge pull request #1222 from rrran/extract_func_phpdoc
Add PhpDoc @var for extract() functions
2017-12-23 14:18:28 -06:00
Sokolovskyy Roman b8d826f04f Trying to fix unit tests 2017-12-21 10:17:30 +01:00
Sokolovskyy Roman 62ee1a5747 Multiline phpdoc for extract to one liner 2017-12-21 10:14:53 +01:00
terrafrost 020fc97a1e Merge branch '2.0' 2017-12-19 07:46:16 -06:00
terrafrost c8dae32334 Merge branch '2.0' 2017-12-18 06:52:04 -06:00
terrafrost 19a46748a2 Merge branch '2.0' 2017-12-17 16:25:30 -06:00
terrafrost ce8ad063c7 Merge branch '2.0' 2017-12-14 23:52:18 -06:00
terrafrost eefcf9c941 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2017-12-14 22:49:47 -06:00
terrafrost a5ed1acbae Merge branch '2.0' 2017-12-14 06:34:43 -06:00
Andreas Fischer 3d07f7ef39 Merge pull request #1227 from carusogabriel/refactoring-tests
Refactoring tests

* carusogabriel/refactoring-tests:
  Refactoring tests
2017-12-12 22:36:30 +01:00
terrafrost 4f9e92b380 Merge branch '2.0' 2017-12-09 18:59:25 -06:00
Gabriel Caruso 8eb7f3a798 Refactoring tests 2017-12-07 18:08:19 -02:00
terrafrost a96add4526 DSA/Signature/SSH2: fix infrequent error with too short sigs 2017-12-05 00:08:56 -06:00
terrafrost 0074539429 Merge branch 'array_to_short_syntax' 2017-12-04 23:03:35 -06:00
Sokolovskyy Roman c705e7d9c6 Add PhpDoc @var for extract() functions 2017-12-04 11:11:43 +01:00
terrafrost 4bd11c6229 Merge branch 'master-travis-exp' 2017-12-03 23:00:40 -06:00
terrafrost defe0514a9 Random: CS adjustment 2017-12-03 22:42:58 -06:00
terrafrost f0b1439639 Merge branch '2.0-travis-exp' into master-travis-exp 2017-12-03 22:41:02 -06:00
terrafrost 15863ff588 Merge branch '2.0-travis-exp' into master-travis-exp 2017-12-03 22:38:03 -06:00
terrafrost b1aa278fe6 Merge branch '2.0' 2017-11-30 07:12:47 -06:00
terrafrost d572cd40b3 Merge branch '2.0' 2017-11-29 05:31:09 -06:00
terrafrost 0a58b73037 Merge branch '2.0' 2017-11-29 00:38:20 -06:00
terrafrost a6acafa36c Merge branch 'master' of https://github.com/phpseclib/phpseclib 2017-11-29 00:14:58 -06:00
Sokolovskyy Roman 966ee7f170 Long array() to short [] syntax 2017-11-27 09:30:14 +01:00
terrafrost 675822df96 Merge branch 'master-is-prime' 2017-11-23 10:25:43 -06:00
terrafrost 2314b638c7
Merge pull request #1212 from rrran/func_get_args_to_tripple_dots
Get rid of func_get_args()
2017-11-23 10:02:59 -06:00
terrafrost e2e719ee29 Merge branch '2.0' 2017-11-23 09:37:26 -06:00
terrafrost 88b34382f9 Merge branch '2.0-is-prime' 2017-11-22 19:52:49 -06:00
Sokolovskyy Roman ee8f5e9769 Get rid of func_get_args() 2017-11-21 09:36:28 +01:00
terrafrost 3065d24b0d
$this->_string_shift -> Strings::shift 2017-11-13 09:27:11 -06:00
terrafrost e91da39098 Merge branch '2.0' 2017-11-11 23:16:23 -06:00
terrafrost 17f5292dfb Merge branch 'master' of https://github.com/phpseclib/phpseclib 2017-11-11 16:39:05 -06:00
terrafrost c66b31e698 Merge branch '2.0' 2017-11-11 16:13:48 -06:00
terrafrost d90e9d1b7a
Merge pull request #1204 from comsolit/feature/show-answer-not-understood
Unveil received value in unexpected value exceptions (SFTP)
2017-11-05 15:16:40 -06:00
terrafrost ec579bd9ed revisions to rrran's PHPDoc changes 2017-11-05 14:35:27 -06:00
terrafrost 10828543ce Merge remote-tracking branch 'rrran/Fixes3' 2017-11-05 13:16:03 -06:00
terrafrost 5f3c49cbcc Merge remote-tracking branch 'lzylinl/master' 2017-11-05 12:57:29 -06:00
terrafrost 6f6b93b012 BigInteger/GMP: use gmp_import / gmp_export 2017-11-05 12:33:22 -06:00
terrafrost 5801806d23 BigInteger/GMP: fix casting error 2017-11-05 12:28:16 -06:00
terrafrost 1041131bb1 Merge branch '2.0' 2017-11-05 11:53:59 -06:00
terrafrost c7606818e0 BigInteger/Engines/PHP: small optimization to EvalBarrett engine 2017-11-05 01:56:04 -05:00
terrafrost ff595f9951 BigInteger/Engines/PHP: fix issues with EvalBarrett reduction 2017-11-05 01:33:57 -05:00
terrafrost 5eec16041d BigInteger/Engines/PHP: HAC 14.42.2 does mod $b^{k+1}$ 2017-11-04 12:28:38 -05:00
terrafrost 5e9c67b2d0 Tests/BigInteger: re-enable primality testing in 32-bit PHP7 2017-11-04 09:42:15 -05:00
terrafrost f01cc6b099 BigInteger/Engines/PHP: fix issue with regular barrett engine 2017-11-04 02:16:01 -05:00
terrafrost 410e5aed96 BigInteger/Engines/PHP: use regular barrett for PHP32 engine 2017-11-04 02:15:32 -05:00
Peter Bittner 31b02fe7cc Unveil received value in unexpected value exceptions (SFTP) 2017-11-02 14:36:22 +01:00
Sokolovskyy Roman f40ea062c2 Lots of PHPDoc fixes 2017-10-25 11:44:14 +02:00
terrafrost a5038e2fd9 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2017-10-24 07:48:24 -05:00
terrafrost cdeeba9ecd Tests/BigInteger: randomPrime(128) on PHP32 is just too slow 2017-10-24 00:50:48 -05:00
zylin 2fcc294cc6 Sometimes at php7 uniqid() return same result as their previous call. Here generates few equal labels wich makes error on eval. Does not know why uniqid() return same values but this is fact and my construction is more correct than previous. No need to call label id generation and use dirty goto :') 2017-10-23 22:31:18 +02:00
terrafrost 12f7358c67 Merge branch '2.0' 2017-10-23 00:09:07 -05:00
terrafrost 7a2f2e8e6b BigInteger\PHP: self::$primes -> static::$primes 2017-10-21 12:32:56 -05:00
terrafrost a59d046c9d Tests/BigInteger: add unit test for randomPrime 2017-10-21 12:25:13 -05:00
terrafrost 0a912b4818 Merge pull request #1193 from eternalharvest/bugfix/doccomment
Fix wrong doccomment annotation and Suggestion
2017-10-10 06:03:03 -05:00
terrafrost 37abd02cc9 Merge pull request #1192 from eternalharvest/feature/aes_mode_cfb8
Add 'cfb8' cipher mode of operation support
2017-10-10 05:41:25 -05:00
Takuya Sawada 9e037309b9 SymmetricKey: refactor to simplify the code 2017-10-10 19:06:14 +09:00
Takuya Sawada 65cbc60918 SymmetricKey: fix indent style to follows the PSR-2 codeing style 2017-10-10 19:02:55 +09:00
terrafrost ce92283c10 Merge branch '2.0' 2017-10-05 05:42:38 -05:00
terrafrost 35af260322 Merge branch '2.0' 2017-10-05 05:32:13 -05:00
terrafrost e395a4a367 Merge branch '1.0' into 2.0 2017-10-05 05:31:51 -05:00
terrafrost 163f9c76f5 Merge branch '2.0' 2017-10-05 05:29:11 -05:00
terrafrost 0be79559c2 Merge branch '2.0' 2017-10-05 05:27:05 -05:00
Takuya Sawada 18a5867e16 Tests/AES: add newly added 'cfb8' cipher mode of operation for unit test 2017-10-05 19:06:50 +09:00
Takuya Sawada 7aa400745c SymmetricKey: add Eval engine implementation for 'cfb8' cipher mode of operation 2017-10-05 19:06:47 +09:00
Takuya Sawada 8604e327a3 SymmetricKey: add 'cfb8' cipher mode of operation support 2017-10-05 19:06:45 +09:00
Takuya Sawada e3bdbf5e0a fix doccomment annotations 2017-10-05 18:46:59 +09:00
terrafrost 736cdf8e8f Merge branch '2.0-use-eval' 2017-10-04 17:16:30 -05:00
terrafrost 03e15a5ab9 BigInteger: make constructor catch behave same as setEngine 2017-10-01 07:55:00 +01:00
terrafrost 256ffcca7b Merge remote-tracking branch 'pcf0/fix-biginteger-badconfigurationexception' 2017-10-01 07:53:54 +01:00
terrafrost 1c0ee79999 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2017-10-01 07:04:17 +01:00
terrafrost fabb42c20d Merge branch '2.0' 2017-09-30 22:56:43 +01:00
terrafrost 1f7d1bc18a Revert "date format fix"
This reverts commit 508f04fab8.
2017-09-30 22:50:24 +01:00
terrafrost 4f2ece4d7d Merge remote-tracking branch 'rrran/Bugfixes2' 2017-09-30 22:50:06 +01:00
PCF d71b6ae3e7
fixup! TestCase for BadConfigurationException in BigInteger 2017-09-30 13:44:37 +02:00
terrafrost 1e9d20364c Merge pull request #1182 from eternalharvest/bugfix/doccomment
Fix wrong doccomment annotation of return type
2017-09-30 08:07:06 +01:00
terrafrost af6048b48e AsymmetricKey: visibility fixes 2017-09-30 07:58:07 +01:00
PCF e598a027b8
fixup! TestCase for BadConfigurationException in BigInteger 2017-09-30 03:23:39 +02:00
PCF 43803c6872
Catch BadConfigurationException in BigInteger 2017-09-30 02:47:00 +02:00
PCF c12ffe0b37
TestCase for BadConfigurationException in BigInteger 2017-09-30 02:46:49 +02:00
terrafrost fc6a97083c Merge branch '2.0' 2017-09-29 21:34:51 +01:00
Takuya Sawada 5a87cc525f fix wrong doccomment annotation of return type 2017-09-18 02:23:14 +09:00
Sokolovskyy Roman c6020a4c42 Unit tests fixes.
A PHPDoc fix
2017-09-14 09:42:37 +02:00
Sokolovskyy Roman 508f04fab8 date format fix 2017-09-11 13:33:43 +02:00
Sokolovskyy Roman 4f399d5c33 Merge remote-tracking branch 'origin/master' into Bugfixes2 2017-09-11 11:13:03 +02:00
Sokolovskyy Roman 137b5dae42 Merge remote-tracking branch 'upstream/master' 2017-09-11 11:11:41 +02:00
terrafrost 761f8765fc Merge branch '2.0' 2017-09-10 15:15:38 -05:00
terrafrost a2182d503f Merge branch '2.0' 2017-09-09 20:40:25 -05:00
terrafrost 1fafe157d6 SSH2: fix bad merge 2017-09-06 00:44:38 -05:00
terrafrost 8d16642469 Merge branch 'ssh2-fix-multi-channel-2.0' into ssh2-fix-multi-channel-master 2017-09-06 00:28:25 -05:00
terrafrost ac19043c8b Merge branch 'ssh2-fix-multi-channel-2.0' into ssh2-fix-multi-channel-master 2017-09-05 23:42:05 -05:00
terrafrost 932419c7e9 Revert "Composer: update lock file"
This reverts commit 5e843160db.
2017-09-05 23:06:39 -05:00
terrafrost cfdb122ff0 Merge branch '2.0' 2017-09-05 22:52:46 -05:00
terrafrost 9228d7b5c9 Merge branch '2.0' 2017-09-05 22:00:45 -05:00
terrafrost 5e843160db Composer: update lock file 2017-08-29 22:45:31 -05:00
terrafrost 9f7a925bf4 Composer: update deps 2017-08-29 22:42:24 -05:00
terrafrost ee3fd38682 SSH2: fix typo in comment found by Iewa 2017-08-29 07:42:51 -05:00
terrafrost f257fceabb Merge branch '2.0' 2017-08-28 23:32:19 -05:00
terrafrost ae210871e3 Merge branch '2.0' 2017-08-28 22:45:18 -05:00
terrafrost ee5172ece5 Merge branch 'arcfour256-fix-2.0' 2017-08-27 12:33:19 -05:00
terrafrost b27655a262 Merge branch '2.0' 2017-08-24 23:56:08 -05:00
terrafrost c43ebe3a0a Merge branch 'datetime-2.0' into datetime-master 2017-08-24 12:50:47 -05:00
Sokolovskyy Roman 25c1ae6e00 Merge remote-tracking branch 'origin/master' into Bugfixes2 2017-08-09 12:28:02 +02:00
Sokolovskyy Roman 9115febb0e Merge remote-tracking branch 'upstream/master' 2017-08-09 12:26:49 +02:00
terrafrost 04fce0b39b Merge branch '2.0' 2017-08-08 22:04:59 -05:00
Sokolovskyy Roman d9cc8072ac Merge remote-tracking branch 'upstream/master' 2017-08-08 09:10:41 +02:00
terrafrost 9d8f014748 SymmetricKey: isValidKey took ints instead of strings 2017-08-07 23:57:02 -05:00
terrafrost e7e30cd239 BigInteger: undo visibility changes 2017-08-07 22:38:56 -05:00
terrafrost ce5eb7e1c9 Tests/X509/CRLTest: fix path for crl.bin 2017-08-07 22:35:29 -05:00
terrafrost 3fcce89f78 Merge remote-tracking branch 'rrran/Bugfixes' 2017-08-07 21:47:06 -05:00
terrafrost 93a3139475 Merge branch 'pre-1157-changes' 2017-08-07 21:46:28 -05:00
terrafrost 520c56a797 Merge branch 'send-kex-and-id-first-or-last-2.0' 2017-08-07 20:09:26 -05:00
terrafrost 9f540a82e6 minor fixes to X509 and SSH2 2017-08-06 17:29:30 -05:00
terrafrost bd489a16dc Tests/X509: add CRL test 2017-08-06 12:35:52 -05:00
terrafrost 135a4decf1 Tests/X509: add setEndDate 2017-08-06 10:49:03 -05:00
terrafrost 0ac8b5d5ed ASN1: rm unused method (decodeLength) 2017-08-06 10:30:29 -05:00
Sokolovskyy Roman 55cacdf7cd More PHPDOC fixes 2017-08-04 12:06:25 +02:00
Sokolovskyy Roman eb21fb2bcb Default value for a parameter missed 2017-08-03 11:25:20 +02:00
Sokolovskyy Roman de2e4662b0 Fixed wrong use of new self(1); 2017-08-03 09:26:46 +02:00
Sokolovskyy Roman 7bffa6bb8f Set of PHPDOC fixes 2017-08-03 09:26:09 +02:00
Sokolovskyy Roman 6f36c49baa Fixed methods visibility 2017-08-03 09:20:33 +02:00
Sokolovskyy Roman d13f429b77 PHPDOC fixes 2017-08-03 09:20:17 +02:00
Sokolovskyy Roman f314f9795f Fixed methods visibility 2017-08-03 09:20:05 +02:00
Sokolovskyy Roman 0fd58aeb7e Set of PHPDOC fixes
Fixed methods visibility
2017-08-03 09:19:11 +02:00
Sokolovskyy Roman ccfb6c92bf Set of PHPDOC fixes 2017-08-03 09:16:37 +02:00
Sokolovskyy Roman 6181b2bfbd Set of PHPDOC fixes 2017-08-03 09:16:16 +02:00
Sokolovskyy Roman 5583703040 Set of PHPDOC fixes 2017-08-03 09:15:16 +02:00
Sokolovskyy Roman a3b252150b Set of PHPDOC fixes 2017-08-03 09:14:32 +02:00
Sokolovskyy Roman f48995ac96 Wrong class name fix
PHPDOC fixes
2017-08-03 09:13:44 +02:00
Sokolovskyy Roman 0c6d8607ce added missing use statement
PHPDOC fix
2017-08-03 09:12:56 +02:00
Sokolovskyy Roman 5fe61b325d PHPDOC fix 2017-08-03 09:12:07 +02:00
Sokolovskyy Roman 167718a046 Set of PHPDOC fixes 2017-08-03 09:11:44 +02:00
terrafrost bf537059b1 Merge branch '2.0' 2017-07-30 16:20:38 -05:00
terrafrost 4a7d3d27ba DSA/Signatures/SSH2: self generated signatures wouldn't verify 2017-07-30 16:03:47 -05:00
terrafrost 610d3d6ea0 Merge remote-tracking branch 'rrran/Bugfixes' 2017-07-30 15:58:12 -05:00
terrafrost 885dc96185 Tests/DSA: expand test to reproduce issue identified in #1151 2017-07-30 15:57:53 -05:00
terrafrost 0b34a8e543 Tests/ASN1: add additional unit test inspired by #1151 2017-07-30 11:24:58 -05:00
terrafrost c5a73e948f Merge branch '2.0' 2017-07-30 10:18:41 -05:00
Sokolovskyy Roman 3df0f7ccb4 Added missing break in case (reverted from commit 31d9cf3015) 2017-07-20 14:56:54 +02:00
Sokolovskyy Roman 800b81d3ef remove unneeded strlen call 2017-07-20 11:36:51 +02:00
Sokolovskyy Roman 65d9e2bb49 Added missin break
removed return statement
2017-07-20 11:35:08 +02:00
Sokolovskyy Roman cc3f0c1ec1 Added missing private field 2017-07-20 11:10:06 +02:00
Sokolovskyy Roman c603c2b2d0 Remove unused use
Fix in PHPDoc block
Wrong variable name fix
2017-07-20 11:09:29 +02:00
Sokolovskyy Roman 7a25abe60a PHPDoc fix
Using property instead of method call fix
2017-07-20 11:08:03 +02:00
Sokolovskyy Roman 654bb1a704 Function setVar should not retun a value 2017-07-20 11:03:26 +02:00
Sokolovskyy Roman 31d9cf3015 Added missing break in case 2017-07-20 11:02:26 +02:00
Sokolovskyy Roman 0178d4f56e Fix: Local variable to property
Fix: Constants names
2017-07-20 11:01:47 +02:00
terrafrost 2b80803042 Merge branch '2.0' 2017-07-16 12:10:37 -05:00
terrafrost 669a7542ea Merge branch '2.0' 2017-07-16 11:32:15 -05:00
terrafrost 7ef3864d22 RSA: RSAKeyValue -> RSAKeyPair for XML private keys 2017-06-28 23:19:50 -05:00
terrafrost b46bedbdf7 SymmetricKey: use static::class instead of getClassContext() method 2017-06-28 07:34:51 -05:00
terrafrost 4171262b9e SymmetricKey: use strings for constructor and setPreferredEngine 2017-06-28 06:54:10 -05:00
terrafrost 819a165246 RSA: add enableBlinding() / disableBlinding() static methods 2017-06-26 23:19:30 -05:00
terrafrost 1630a6710d RSA/DSA: support XML keys with XML declarations 2017-06-26 21:58:20 -05:00
terrafrost 62a8047fa1 Hash: use hash extension for sha512/224 & sha512/256 on PHP 7.1+ 2017-06-26 21:45:29 -05:00
terrafrost 5fe629a171 BigInteger: modularize / modernize class and add new powmod engines 2017-06-26 20:07:10 -05:00
terrafrost 6a7e0210bc Merge branch '2.0' 2017-06-22 23:37:45 -05:00
terrafrost 0bbac3ebed Merge branch '2.0' 2017-06-19 22:37:21 -05:00
terrafrost b6eb7b2009 Merge branch '2.0' 2017-06-19 22:34:28 -05:00
terrafrost 9814140055 Merge branch '1.0' into 2.0 2017-06-19 22:34:20 -05:00
terrafrost 8ea3edf0d2 Merge branch '2.0' 2017-06-12 22:37:06 -05:00
terrafrost 03ca09a104 Merge branch '2.0' 2017-06-12 21:26:20 -05:00
terrafrost f5e0cab82d Merge branch '2.0' 2017-06-05 01:33:15 -05:00
terrafrost 39b66d512d Tests/RSA: update test for master branch 2017-05-29 06:34:06 -05:00
terrafrost 6ca7323401 Merge branch '2.0' 2017-05-29 06:33:24 -05:00
terrafrost 29b5a4dd25 Merge branch '2.0' 2017-05-28 09:59:18 -05:00
terrafrost a312a1d4f0 SSH2: update a few function calls to work with renamed methods 2017-05-28 09:44:38 -05:00
terrafrost 2d226b057c Merge branch '2.0' 2017-05-28 09:11:06 -05:00
terrafrost e1827f35cf Merge branch '2.0' 2017-05-14 15:36:08 -05:00
terrafrost c25eb3ed9b Merge branch 'master-crypt-fix-old-openssl' 2017-05-14 15:35:22 -05:00
terrafrost 450d5bd5ce Merge branch '2.0' 2017-05-14 09:44:43 -05:00
terrafrost baeb68eb82 Merge branch '2.0' 2017-05-14 08:50:57 -05:00
terrafrost 085d5ed495 Merge branch '2.0-crypt-fix-old-openssl' 2017-05-13 23:24:53 -05:00
terrafrost 5c51c2570c Merge branch '2.0' 2017-05-11 07:33:55 -05:00
terrafrost e017a0b6c6 Merge branch '2.0' 2017-05-09 21:32:17 -05:00
terrafrost 7882249a14 Merge branch '2.0' 2017-05-08 00:58:42 -05:00
terrafrost 31f4406b6e Merge branch 'master' of https://github.com/phpseclib/phpseclib 2017-05-07 15:08:36 -05:00
terrafrost 851e662544 Merge branch '2.0' 2017-05-07 15:07:18 -05:00
terrafrost 84d40ad8e0 Merge branch '2.0' 2017-05-07 13:26:39 -05:00
terrafrost 3fe35a4976 Merge pull request #1115 from langemeijer/master
Refactor create_function() into anonymous function
2017-04-18 00:15:03 -05:00
Casper Langemeijer 4a0118bae6 Refactor create_function() into anonymous function 2017-04-17 15:35:00 +02:00
terrafrost 4a069f7c85 rm redundant files 2017-04-15 19:35:07 -05:00
terrafrost 4058e3e217 Merge pull request #1090 from terrafrost/dsa-test-2
add DSA implementation
2017-04-15 15:49:04 -05:00
terrafrost 0a6fe37285 Merge branch '2.0' 2017-04-09 10:30:23 -05:00
terrafrost 22bf2339d7 Merge branch '2.0' 2017-03-07 22:20:21 -06:00
terrafrost 9cbf357ac5 Merge branch '2.0' 2017-03-01 22:27:31 -06:00
terrafrost 42def63b00 Merge remote-tracking branch 'upstream/master' into dsa-test-2 2017-02-02 21:07:47 -05:00
terrafrost ab1da5ac1f Merge pull request #1084 from terrafrost/php5-updates
PHP5 updates for master branch
2017-02-02 21:03:07 -05:00
terrafrost eb459daeaf add DSA implementation 2017-02-02 20:20:47 -05:00
terrafrost 9220bcd49a fix bad merge 2017-01-27 14:44:21 -06:00
terrafrost 7d2e44b430 Merge branch '2.0' 2017-01-27 12:40:23 -06:00
terrafrost 8e44671766 visibility fixes 2017-01-21 15:51:49 -06:00
terrafrost a25c841108 Merge remote-tracking branch 'upstream/master' into php5-updates 2017-01-17 22:40:24 -06:00
terrafrost b9b4f67a0f Net: add public / private / protected 2017-01-17 10:23:28 -06:00
terrafrost fae358cc3c BigInteger: use public / private / protected 2017-01-05 00:20:18 -06:00
Andreas Fischer 74abcb45ed Merge branch '2.0'
* 2.0:
  README: Fix typos.
2016-12-25 16:50:17 +01:00
terrafrost c8c61055d1 Merge branch '2.0' 2016-12-24 21:34:30 -06:00
terrafrost 68b5a8896f Merge branch '2.0' 2016-12-24 20:06:51 -06:00
terrafrost 2a7c99ef1b ... 2016-12-17 17:22:11 -06:00
terrafrost 9ae5206588 RSA: setEngine -> setPreferredEngine (make it like SymmetricKey) 2016-12-11 09:59:50 -06:00
terrafrost 242e0dcb7f Files: add public / protected / private 2016-12-11 08:23:59 -06:00
terrafrost e6e34f3543 Merge pull request #1065 from terrafrost/asn1-revamp-pt3
ASN.1 revamp
2016-12-10 19:27:37 -06:00
terrafrost 1dfd315725 RSA: use public / private / protected 2016-12-10 19:09:54 -06:00
terrafrost 813b85b5b2 Crypt: define visibility for more variables / methods 2016-12-09 16:46:01 -06:00
terrafrost 067c1882e5 SymmetricCiphers: rm some redundant methods / variables 2016-12-09 15:51:31 -06:00
terrafrost d34a911402 SymmetricCiphers: don't cache "hi-optimized code"
Also add a new engine - ENGINE_EVAL. Previously ENGINE_INTERNAL
had three different modes - a "hi-optimized" version, a
"lo-optimized" version and a version that didn't depend on
create_function and there wasn't a way to really isolate these
modes and test them individually.
2016-12-08 09:20:19 -06:00
terrafrost 2a1177b256 SymmetricCiphers: add public / private / protected as appropriate 2016-12-07 22:19:20 -06:00
terrafrost 496fb80020 Strings: make this an abstract class as well 2016-11-30 21:43:03 -06:00
terrafrost c852bae3c8 use short array syntax for arrays 2016-11-30 21:29:38 -06:00
terrafrost 7182ec393b make classes with only static methods abstract 2016-11-30 09:25:04 -06:00
terrafrost 72a6aab872 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-11-29 23:18:44 -06:00
terrafrost e34e5f5135 Merge branch '2.0' 2016-11-29 23:00:03 -06:00
terrafrost 81bae5ce8b Merge pull request #1061 from terrafrost/pkcs18-rewrite
RSA: refactor PKCS1/PKCS8 to facilitate re-use
2016-11-29 19:15:21 -06:00
terrafrost a4d05f8445 ASN1: rm an alternative approach for dealing with ASN1\Element 2016-11-29 08:15:08 -06:00
terrafrost 4dc3b7ed43 ASN1: don't return false after exception is thrown 2016-11-28 22:40:55 -06:00
terrafrost 370fbec300 ASN1: don't require octet / bit strings be base64-encoded 2016-11-28 20:51:21 -06:00
terrafrost 874ada8d93 ASN1: make methods static 2016-11-27 22:38:11 -06:00
terrafrost df6d55fd97 ASN1: move ASN1 maps to external files for reuse 2016-11-22 23:56:07 -06:00
terrafrost 865904f636 Merge branch '2.0' 2016-11-20 18:13:48 -06:00
terrafrost ad03dcad1c Merge branch '2.0' 2016-11-20 18:05:02 -06:00
terrafrost 6807791d42 Merge branch '2.0' 2016-11-20 11:14:48 -06:00
terrafrost b8e1a15291 Merge branch '2.0' 2016-11-19 20:40:04 -06:00
terrafrost d1fa327ef9 Merge branch '2.0' 2016-11-18 20:48:18 -06:00
terrafrost d6bf2b4f73 Merge branch '2.0' 2016-11-18 20:37:26 -06:00
terrafrost 989fc3735a Merge branch '2.0' 2016-11-17 20:55:53 -06:00
terrafrost 272ae9c64c Merge branch 'master' into pkcs18-rewrite 2016-11-17 08:10:55 -06:00
terrafrost 863ff6789b RSA: refactor PKCS1/PKCS8 to facilitate re-use 2016-11-17 08:09:10 -06:00
terrafrost 66aef4874a Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-11-08 09:51:59 -06:00
terrafrost 49c002d2c5 Merge branch '2.0' 2016-11-08 09:43:16 -06:00
terrafrost 2d2bf2990e Merge branch '2.0' 2016-11-08 09:23:53 -06:00
terrafrost 83a6f8b788 Merge branch '2.0' 2016-11-04 02:26:08 -05:00
terrafrost 9d5aa56c2f README: update download link to 1.0.4 2016-10-29 13:06:22 -05:00
terrafrost 59912baef1 Merge branch '2.0' 2016-10-22 23:43:39 -05:00
terrafrost 0de3553877 Merge branch '2.0' 2016-10-22 13:11:51 -05:00
terrafrost 8d41749d9e Merge branch '2.0' 2016-10-22 13:10:38 -05:00
terrafrost db7b8ad48f Merge branch '1.0' into 2.0 2016-10-22 13:10:21 -05:00
terrafrost b54b5b5945 Merge branch '2.0' 2016-10-04 08:59:32 -05:00
terrafrost d66b6c251c Merge branch '2.0' 2016-10-03 19:57:11 -05:00
terrafrost 4f4de2df28 Merge branch '2.0' 2016-10-02 22:09:05 -05:00
terrafrost 711079764e Merge branch '2.0' 2016-10-02 08:18:16 -05:00
terrafrost a862837a9a Merge remote-tracking branch 'origin/danog2' 2016-09-23 10:20:07 -05:00
terrafrost 8019baee62 BigInteger: add randomRange / randomPrimeRange
...and redo random / randomPrime such that they take the byte size
as the parameter instead of the range.
2016-09-17 19:48:51 -07:00
terrafrost c17a2604a0 Merge branch 'master-reorg' 2016-09-17 09:15:11 -07:00
terrafrost bf9489c28d Merge branch '2.0' 2016-09-11 22:27:30 -07:00
terrafrost 03937a7933 Merge branch '2.0' 2016-09-10 11:16:52 -07:00
terrafrost 0ee24aa218 BigInteger: rm loopforeach method 2016-09-09 20:59:54 -08:00
terrafrost 72d1bdf60b a few changes to danog's changes 2016-09-08 00:22:30 -08:00
terrafrost 6f22a957c2 Merge branch '2.0' 2016-08-28 23:17:11 -05:00
terrafrost 80440047e8 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-08-28 10:45:48 -05:00
terrafrost 5416b9eddc Merge branch '2.0' 2016-08-28 10:45:37 -05:00
terrafrost 47faa5736e RSA/PKCS8: CS adjustment 2016-08-18 14:53:21 -05:00
terrafrost 77c29d774f Merge branch '2.0' 2016-08-18 13:49:32 -05:00
terrafrost 8b4ead6aef Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-08-18 13:49:28 -05:00
terrafrost da0c41ddac Merge branch '2.0' 2016-08-11 23:10:43 -05:00
terrafrost cc75d317a8 Merge branch '2.0' 2016-08-04 01:08:20 -05:00
terrafrost 3a53545eb7 Merge branch '2.0' 2016-08-04 00:52:16 -05:00
klemens dd23d91d41 spelling fixes 2016-08-04 00:47:52 -05:00
danogentili 7cf300984c Added root, pow, max, min, loopforeach functions and tests. 2016-08-03 10:51:19 -04:00
terrafrost d64599f799 Move _encodeLength and _decodeLength to Common\Functions\ASN1.php 2016-07-31 09:37:13 -05:00
terrafrost c509909004 Organizational Revamp
- rename \phpseclib\Crypt\Base to \phpseclib\Crypt\Common\SymmetricKey
- create BlockCipher and StreamCipher to extend SymmetricKey
- replace _string_shift with \phpseclib\Common\Functions\Strings::shift
2016-07-30 22:18:06 -05:00
terrafrost ec62e5d9f5 RSA: update PKCS1/8 comments 2016-07-28 22:14:37 -05:00
terrafrost c12500cace RSA: code cleanup 2016-07-28 13:08:47 -05:00
terrafrost 06ed64ef3d Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-07-28 11:01:44 -05:00
terrafrost caa7eed299 Merge branch '2.0' 2016-07-28 11:00:33 -05:00
terrafrost a5201bf6fc Merge branch '2.0' 2016-07-23 18:55:45 -05:00
terrafrost f339c5adcc Tests/X509: update test to work with master branch 2016-07-23 18:44:20 -05:00
terrafrost a9bee37187 Merge branch '2.0' 2016-07-23 18:39:41 -05:00
terrafrost d31c89a8ae Merge branch '2.0' 2016-07-20 00:18:17 -05:00
terrafrost 7eb0712a01 Merge branch '2.0' 2016-07-19 23:52:15 -05:00
terrafrost f7585d99d1 Merge branch '2.0' 2016-07-10 13:22:09 -05:00
terrafrost 3c1985a619 Merge branch '2.0' 2016-07-10 12:56:12 -05:00
terrafrost a490e06b48 Merge branch '2.0' 2016-06-26 20:43:33 -05:00
terrafrost 552980b086 Merge branch '2.0' 2016-06-22 12:39:02 -05:00
terrafrost e5dbb1bc25 Merge branch '2.0' 2016-06-22 10:17:07 -05:00
terrafrost 1e7bfe75b1 Tests/RSA: fix bad merge 2016-06-22 09:47:56 -05:00
terrafrost 4516227f13 Merge branch '2.0' 2016-06-21 22:55:33 -05:00
terrafrost 1c4fe6b5ba Merge branch 'unsupported-hash-update' 2016-06-19 19:47:04 -05:00
terrafrost 15f0c3e5e6 Merge branch '2.0' 2016-06-19 19:45:08 -05:00
terrafrost 5b464a169a Merge branch '2.0' 2016-06-19 10:54:43 -05:00
terrafrost 52014b25d2 Merge branch '2.0' 2016-06-18 23:33:58 -05:00
terrafrost ffe912d621 rm PHP 5.3 / 5.4 from .travis.yml
I guess one of phpseclib's require-dev dependencies broke BC by
upping the version requirements..
2016-06-18 20:50:38 -05:00
terrafrost e7bf628613 composer.lock update 2016-06-18 20:33:46 -05:00
terrafrost f815e43077 Merge branch '2.0' 2016-06-12 14:19:56 -05:00
terrafrost 7a628c62b0 don't do phpinfo() check 2016-06-11 20:29:02 -05:00
terrafrost 68a09b8af0 SSH2: i incorrectly thought i had saved when i did git commit -a 2016-06-11 19:38:23 -05:00
terrafrost 2bae0c3881 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-06-11 19:17:15 -05:00
terrafrost 414b980b83 Merge branch '2.0' 2016-06-11 19:16:25 -05:00
terrafrost a06ca1d212 Merge pull request #997 from DennisBirkholz/pull-change-defaults
Change default signature algorithm from SHA1 to SHA256
2016-06-05 11:35:48 -05:00
terrafrost e64a55955f Crypt/Base: trie -> true 2016-06-05 11:28:28 -05:00
Dennis Birkholz 18200131df Change default signature algorithm from SHA1 to SHA256 2016-06-05 18:09:00 +02:00
terrafrost fc2a7cef20 RSA: adjustments for master branch 2016-06-04 23:46:40 -05:00
terrafrost 80e9d663cf Tests/RSA: update unit test for master branch changes 2016-06-04 23:24:49 -05:00
terrafrost 5714875b71 Merge branch '2.0' 2016-06-04 23:22:24 -05:00
terrafrost 39913e1248 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-06-04 22:58:32 -05:00
terrafrost 6b66c1cd52 Merge branch '2.0' 2016-06-04 22:56:55 -05:00
terrafrost 41d3d04a08 Merge pull request #996 from terrafrost/constanttime-adjustments
remove a few calls to paragonie/constant_time_encoding
2016-06-04 22:50:17 -05:00
terrafrost e2a0b701c7 remove a few calls to paragonie/constant_time_encoding
- Hex::decode('aabb') can be replaced with "\xaa\xbb"
- Hex::decode(sha1('...')) can be replaced with sha1('...', true)
2016-06-04 22:31:23 -05:00
terrafrost 2db6b8421a Merge branch '2.0' 2016-06-04 14:56:54 -05:00
terrafrost 48fef11389 Merge branch 'cte' 2016-05-21 17:34:05 -05:00
Paragon Initiative Enterprises adcbecae78 Use paragonie/constant_time_encoding 2016-05-21 12:57:53 -05:00
terrafrost 4cac42745e Merge remote-tracking branch 'scott/v3.0-cte' 2016-05-21 12:00:32 -05:00
terrafrost ed6ccb4bd7 Merge branch '2.0' 2016-05-12 20:15:44 -05:00
Paragon Initiative Enterprises 0e8fa93676 Use paragonie/constant_time_encoding 2016-05-12 16:28:40 -04:00
terrafrost a2130ff111 Merge branch '2.0' 2016-05-08 01:36:04 -05:00
terrafrost a3fdde757d Merge branch '2.0' 2016-05-07 19:01:46 -05:00
terrafrost 1f138916fa Merge branch '2.0' 2016-05-07 02:40:04 -05:00
terrafrost 43d68c6619 Merge branch '2.0' 2016-05-06 12:23:35 -05:00
terrafrost 1b92fd84f9 Merge branch '2.0' 2016-05-06 11:50:26 -05:00
terrafrost e4c4824ddb Hash: throw exceptions if hash isn't explicitly supported 2016-05-05 14:20:24 -05:00
terrafrost e47af2bd88 Merge branch 'master' of https://github.com/phpseclib/phpseclib 2016-04-30 16:26:53 -05:00
terrafrost 398a795e1f Revert "undo merging of master to 2.0 branch"
This reverts commit 8fb4c3363d.
2016-04-30 16:23:35 -05:00
terrafrost e40d6cc1cc Hash: small tweaks per Joey3000 2016-04-12 11:32:40 -05:00
449 changed files with 65726 additions and 22345 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,12 @@
# These are supported funding model platforms
github: terrafrost
patreon: phpseclib
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: "packagist/phpseclib/phpseclib"
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@ -16,13 +16,39 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: php-parallel-lint/php-parallel-lint:1
env:
update: true
- name: Composer Install
run: composer install --classmap-authoritative --no-interaction --no-cache
- name: Lint
run: parallel-lint --show-deprecated build phpseclib tests
run: vendor/bin/parallel-lint --show-deprecated build phpseclib tests
strategy:
fail-fast: false
matrix:
php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php-version: ['8.1', '8.2', '8.3']
quality_tools:
name: Quality Tools
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
env:
update: true
- name: Composer Install
run: composer install --classmap-authoritative --no-interaction --no-cache
- name: PHP_CodeSniffer
run: vendor/bin/phpcs --standard=build/php_codesniffer.xml
- name: PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --config=build/php-cs-fixer.php --diff --dry-run --using-cache=no
- name: Psalm
run: vendor/bin/psalm --config=build/psalm.xml --no-cache --long-progress --report-show-info=false
strategy:
fail-fast: false
tests:
name: Tests
timeout-minutes: 10
@ -34,11 +60,10 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
env:
update: true
- name: Composer Install
run: composer install --no-interaction --no-cache
- name: Make Tests Compatiable With PHPUnit 9+
if: contains(fromJSON('["7.3", "7.4", "8.0", "8.1", "8.2"]'), matrix.php-version)
run: php tests/make_compatible_with_phpunit9.php
run: composer install --classmap-authoritative --no-interaction --no-cache --ignore-platform-req=php
- name: Setup Secure Shell Functional Tests
if: matrix.os == 'ubuntu-latest'
run: |
@ -62,15 +87,9 @@ jobs:
echo "PHPSECLIB_SSH_HOME=/home/phpseclib" >> $GITHUB_ENV
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
- name: PHPUnit
run: vendor/bin/phpunit
run: vendor/bin/paratest --verbose --configuration=tests/phpunit.xml --runner=WrapperRunner
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
exclude:
# PHP 5.3 / 5.4 on windows don't have openssl or curl installed, which prevents composer from running
- os: windows-latest
php-version: '5.3'
- os: windows-latest
php-version: '5.4'
php-version: ['8.1', '8.2', '8.3']

8
.gitignore vendored
View File

@ -1,3 +1,7 @@
/vendor
/.idea/
/build/php-cs-fixer.cache
/composer.lock
/composer.phar
composer.lock
/tests/.phpunit.result.cache
/vendor/
.gitignore

View File

@ -4,4 +4,4 @@ phpseclib Developers: monnerat (Patrick Monnerat)
bantu (Andreas Fischer)
petrich (Hans-Jürgen Petrich)
GrahamCampbell (Graham Campbell)
hc-jworman
jack-worman (Jack Worman)

View File

@ -13,4 +13,5 @@ phpseclib ongoing development is made possible by [Tidelift](https://tidelift.co
- [Rachel Fish](https://github.com/itsrachelfish)
- Tharyrok
- [cjhaas](https://github.com/cjhaas)
- [istiak-tridip](https://github.com/istiak-tridip)
- [istiak-tridip](https://github.com/istiak-tridip)
- [Anna Filina](https://github.com/afilina)

View File

@ -1,5 +1,259 @@
# Changelog
## 3.0.37 - 2024-03-02
- SSH2: don't set stream timeout if timeout is 0 (#1986)
## 3.0.36 - 2024-02-25
- BigInteger: put guardrails on isPrime() and randomPrime() (CVE-2024-27354)
- ASN1: limit OID length (CVE-2024-27355)
- EC: when using openssl to do signing use unencrypted key (#1979)
- SSH2: add different options to isConnected() (#1983)
## 3.0.35 - 2023-12-18
- SSH2: implement terrapin attack countermeasures (#1972)
- SSH2: only capture login info once (#1970)
- Crypt/AsymmetricKey: loading hidden custom key plugins didn't work (#1971)
## 3.0.34 - 2023-11-27
- SSH2: add support for RFC8308 (#1960)
- SSH2: don't use AES GCM for TurboFTP Server (#1957)
- SSH2: reset more internal variables when connection is reset (#1961)
- PKCS8: PBES1 / RC2 and PBES2 / DES keys didn't work (#1958)
- EC/Signature/Format: add new IEEE format (#1956)
- Math/BigInteger/Engines/PHP: PHP 8.2.13+ fixes Windows JIT issue
- Math/BinaryField: fix for excessively large degrees (CVE-2023-49316)
- Math/PrimeField: fix occasional error with squareRoot method
## 3.0.33 - 2023-10-21
- SSH2: fix for PHP 7.3 (#1953)
- Crypt: improve ARM detection code (#1949)
- Rijndael: fix for PHP 8.3+ compatability (#1944)
- X509: fix for weird characters in subjaltname (#1943)
- move JIT check to BigInteger (#1942)
## 3.0.23 - 2023-09-18
- fix "Undefined index: jit" error on Windows (#1940)
## 3.0.22 - 2023-09-15
- SFTP: make it so SFTP::RESUME also sets offset of local file (#1921)
- SFTP: RESUME_START didn't work as described (#1921)
- SFTP: fix SFTPv2 errors when logging errors (#1933)
- SFTP: fix issue with get() downloading to files / streams (#1934)
- BigInteger: use GMP if available (#1928)
- Rijndael: fix E_DEPRECATED (#1935)
- improve PHP32 compatibility (#1931)
## 3.0.21 - 2023-07-09
- BigInteger: speed up powMod() method (#1919)
- SSH2: fix stream_select(): Unable to select [4]: Interrupted system call (max_fd=29) error (#1851)
- SSH2: add EOF test isConnected() (#1926)
- SFTP: make it so SFTP::RESUME also sets offset of local file (#1921)
- SFTP: SFTP::RESUME_START didn't work as described (#1921)
## 3.0.20 - 2023-06-13
- SSH2: better support for multiple interactive channels & expose shell functions (#1888)
- SFTP: add optional $recursive parameter to filesize() (#1782)
- SFTP: fix NET_SFTP_ATTR_EXTENDED (#1907)
- ASN1: speed up decodeBER (#1894)
- X509: add support for EV DN's (#1916)
- X509: getChain() should always return array of X509 objects (#1914)
- RSA: setting sig padding broke enc padding and vice versa
## 3.0.19 - 2023-03-05
- AsymmetricKey: error out on unsupported operations (#1879)
- Blowfish: fix issues on 32-bit PHP installs
- BigInteger: fix for hex numbers with new lines in them
- SFTP: fix "Creating default object from empty value" error (#1876)
- SSH2: add getTimeout() method (#1889)
- PrimeField: prevent infinite loop with composite primefields (CVE-2023-27560)
## 3.0.18 - 2022-12-17
- fix for PHP 8.2 deprecations (#1869, #1873)
- SSH2: if logging in with rsa-sha2-256/512 fails, try ssh-rsa (#1865)
- SSH/Agent: add support for named pipes on windows (for pageant) (#1866)
- Crypt/Base: add a function to check continuous buffer status (#1870)
- OpenSSL 3.0.1+ deprecated some algorithms (RC2, RC4, DES, Blowfish)
## 3.0.17 - 2022-10-24
- X509: make it so CRLs, CSRs and SPKACs can support PSS keys (#1837)
- X509: make it so PKCS1 X509 certs can create PSS sigs (#1837)
- SFTP: fix deprecated implicit float to int on 32-bit PHP 8.1 (#1841)
- SFTP: restore orig behavior when deleting non-existant folder (#1847)
- Random: fix fallback on PHP 8.1+
## 3.0.16 - 2022-09-05
- SSH2: fix type hinting for keyboard_interactive_process (#1836)
## 3.0.15 - 2022-09-02
- PublicKeyLoader: add support for OpenSSH encrypted keys (#1737, #1733, #1531, #1490)
- PublicKeyLoader: add support for JSON Web Keys (#1817)
- SSH2: make login method return false under rare situation (#1790)
- SSH2: fix possibly undefined variable error (#1802)
- SFTP: fix enableDatePreservation bug w.r.t. mtime (#1670)
- SFTP: try to delete dir even if it can't be opened (#1791)
- SFTP: try without path canonicalization if initial realpath() fails (#1796)
- SFTP: detect if stream metadata has wrapper_type set for put() method (#1792)
- BigInteger: tweak to the phpinfo checks (#1726)
- BigInteger: fix behavior on 32-bit PHP installs (#1820)
- EC/PKCS8: OpenSSL didn't like phpseclib formed Ed25519 public keys (#1819)
- don't use dynamic properties, which are deprecated in PHP 8.2 (#1808, #1822)
- fix deprecated implicit float to int on 32-bit PHP 8.1
## 3.0.14 - 2022-04-04
- RSA: add support for loading PuTTY v3 keys
- Crypt/Base: fix CTR mode with continuous buffer with non-eval PHP
- Crypt/Base: use sodium_increment in _increment_str
- Crypt/Base: fix deprecation notice (#1770)
- SSH2/Agent: rm unused parameter (#1757)
- BigInteger: add precision to __debugInfo
- BigInteger: fix random engine issues
- call useBestEngine() when getEngine() is called
## 3.0.13 - 2022-01-30
- SSH2: make login() return false if no valid auth methods are found (#1744)
- SSH2: show a more helpful error message when logging in with pubkey (#1718)
- SSH2: rsa-sha2-256 and rsa-sha2-512 sigs weren't verifying (#1743)
- SFTP: fix chgrp() for version < 4 (#1730)
- Crypt/Base: add OFB8 as a new mode (phpseclib/mcrypt_compat#33)
- Crypt/Salsa20: fix PHP 5.6 error (#1717)
- RSA & BigInteger: check phpinfo() available before using it (#1726)
- Fixed psalm level 6 errors in phpseclib/Net/ (#1746)
## 3.0.12 - 2021-11-28
- SSH2: add "smart multi factor" login mode (enabled by default) (#1648)
- SSH2: error out when no data is received from the server (#1647)
- SFTP: don't attempt to parse unsupported attributes (#1708)
- SFTP: getSupportedVersions() call didn't work
- EC: error out when scalar is out of range (#1712)
- RSA: add support for raw private keys (#1711)
- SymmetricKey: add getMode()
## 3.0.11 - 2021-10-26
- SSH2: add support for zlib and zlib@openssh.com compression
- SFTP: add support for SFTPv4/5/6
- SFTP: add option to allow arbitrary length packets (#1691)
- SFTP: errors weren't being logged (#1702)
- RSA: ssh-keygen -yf private.key fails if \r is present (#1698)
## 3.0.10 - 2021-08-15
- SFTP: don't check SFTP packet size after SFTP initialization (#1606)
- SFTP: timeout during SFTP init should return false (#1684)
- SFTP: return false if get_channel_packet returns false (#1678)
- ASN1: return false when not enough bytes are available (#1676)
- BigInteger: Serializable is being deprecated in PHP 8.1 (#1680)
- explicitly define methods as being static (#1689)
- plug memory leaks (#1672)
## 3.0.9 - 2021-06-13
- SSH2: add getAuthMethodsToContinue() method (#1648)
- SSH2: timeout would occasionally infinitely loop
- SSH2: fix PHP7.4 errors about accessing bool as string (#1656)
- SSH2: fix issue with key re-exchange (#1644)
- SFTP: reopen channel on channel closure (#1654)
- X509: extra characters before cert weren't being removed (#1659)
- X509: signing with pw protected PSS keys yielded errors (#1657)
- ASN1: fix timezone issue when non-utc time is given (#1562)
- ASN1: change how default values are processed for ints and enums (#1665)
- RSA: OAEP decryption didn't check labels correctly (#1669)
## 3.0.8 - 2021-04-20
- AsymetrticKey: add getComment() method (#1638)
- SymmetricKey: cipher_name_openssl_ecb shouldn't be static because of AES (#1636)
- X509: don't filter basicConstraints on unique values (#1639)
- X509: make it so extensions can be set as critical (#1640)
## 3.0.7 - 2021-04-06
- X509: always parse the first cert of a bundle (#1568)
- SSH2: behave like putty with broken publickey auth (#1572)
- SSH2: don't close channel on unexpected response to channel request (#1631)
- RSA: cleanup RSA PKCS#1 v1.5 signature verification (CVE-2021-30130)
- Crypt: use a custom error handler for mcrypt to avoid deprecation errors
## 3.0.6 - 2021-03-13
- SFTP/Stream: make it so you can write past the end of a file (#1618)
- SFTP/Stream: fix undefined index notice in stream touch() (#1615)
- SFTP/Stream: mkdir didn't work (#1617)
- BigInteger: fix issue with toBits on 32-bit PHP 8 installs
- SFTP: digit only filenames were converted to integers by php (#1623)
## 3.0.5 - 2021-02-12
- X509: add getCurrentCert method (since $currentCert is now private) (#1602)
- PublicKeyLoader: add loadPrivateKey() and loadPublicKey() methods (#1603)
- Rijndael: calling setIV() after setBlockLength() can result in err (#1599)
- RSA: use OpenSSL for generating private keys (#1596)
- BigInteger: big speedups for when OpenSSL is used (#1596)
## 3.0.4 - 2021-01-25
- Random: use v9.99.99 of random_compat if appropriate (#1585, #1571)
- SSH/Agent: EC keys didn't work with agent (#1593)
- X509: fix niche issue with computeKeyIdentifier (#1586)
## 3.0.3 - 2021-01-16
- X509: passing DateTime objects to setEndDate produced errors (#1578)
- X509: always parse the first cert of a bundle (#1568)
- X509: streamline the management of custom extensions (#1573)
- EC: fix case sensitivity errors when using Symfony autoloader (#1570)
- RSA: improve identification of public / private PKCS1 / PKCS8 keys (#1579)
- RSA: add support for PSS keys that don't have parameters present (#1583)
- RSA: tweaks to how the salt length works
- RSA: throw exceptions instead of returning false
- SSH2: behave like putty with broken publickey auth (#1572)
## 3.0.2 - 2020-12-24
- EC/PKCS1: throw exception when trying to load non-strings (#1559)
- X509: make date methods accept DateTimeInterface instead of DateTime (#1562)
- SSH2: suppress errors on stream_select calls (#1560)
## 3.0.1 - 2020-12-19
- PKCS8: fix E_WARNING (#1551)
- SSH2/Stream: stream_select needs to be able to access $fsock (#1552)
- SFTP: resuming uploads didn't work (#1553)
## 3.0.0 - 2020-12-16
- drop SSH1 and SCP support
- add support for the following crypto algorithms:
- Ed25519 / Ed449 / Curve25519 / Curve449
- ECDSA / ECDH (66 curves)
- DSA / DH
- GCM / Poly1305
- Salsa20 / ChaCha20
- namespace changed from `phpseclib\` to `\phpseclib3` to facilitate phpseclib 2 shim (phpseclib2_compat)
## 2.0.47 - 2024-02-25
- BigInteger: add getLength() and getLengthInBytes() methods
- BigInteger: put guardrails on isPrime() and randomPrime() (CVE-2024-27354)
- ASN1: limit OID length (CVE-2024-27355)
## 2.0.46 - 2023-12-28
- SSH2: implement terrapin attack countermeasures (#1972)
@ -366,6 +620,12 @@
- Classes were renamed and namespaced ([#243](https://github.com/phpseclib/phpseclib/issues/243))
- The use of an autoloader is now required (e.g. Composer)
## 1.0.23 - 2024-02-25
- BigInteger: add getLength() and getLengthInBytes() methods
- BigInteger: put guardrails on isPrime() and randomPrime() (CVE-2024-27354)
- ASN1: limit OID length (CVE-2024-27355)
## 1.0.22 - 2023-12-28
- SFTP: fix issue with get() downloading to files / streams (#1934)

View File

@ -1,6 +1,6 @@
# phpseclib - PHP Secure Communications Library
[![Build Status](https://travis-ci.com/phpseclib/phpseclib.svg?branch=2.0)](https://travis-ci.com/github/phpseclib/phpseclib)
[![CI Status](https://github.com/phpseclib/phpseclib/actions/workflows/ci.yml/badge.svg?branch=master&event=push "CI Status")](https://github.com/phpseclib/phpseclib/actions/workflows/ci.yml?query=branch%3Amaster)
## Supporting phpseclib
@ -19,7 +19,7 @@ SSH-2, SFTP, X.509, an arbitrary-precision integer arithmetic library, Ed25519 /
## Documentation
* [Documentation / Manual](https://phpseclib.com/)
* [API Documentation](https://api.phpseclib.com/2.0/) (generated by Doctum)
* [API Documentation](https://api.phpseclib.com/master/) (generated by Doctum)
## Branches
@ -51,7 +51,7 @@ SSH-2, SFTP, X.509, an arbitrary-precision integer arithmetic library, Ed25519 /
* PHP4 compatible
* Composer compatible (PSR-0 autoloading)
* Install using Composer: `composer require phpseclib/phpseclib:~1.0`
* [Download 1.0.22 as ZIP](http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.22.zip/download)
* [Download 1.0.23 as ZIP](http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.23.zip/download)
## Security contact information
@ -79,22 +79,15 @@ Special Thanks to our $50+ sponsors!:
2. Ensure you have Composer installed (see [Composer Download Instructions](https://getcomposer.org/download/))
3. Install Development Dependencies
``` sh
```sh
composer install
```
4. Create a Feature Branch
5. (Recommended) Run the Test Suite
``` sh
vendor/bin/phpunit
```
6. (Recommended) Check whether your code conforms to our Coding Standards by running
``` sh
vendor/bin/phing -f build/build.xml sniff
```
7. Send us a Pull Request
5. Run continuous integration checks:
```sh
composer run-script all-quality-tools
```
6. Send us a Pull Request

View File

@ -1,27 +0,0 @@
build: false
shallow_clone: false
platform:
- x86
- x64
clone_folder: C:\projects\phpseclib
install:
- cinst -y OpenSSL.Light
- SET PATH=C:\Program Files\OpenSSL;%PATH%
- sc config wuauserv start= auto
- net start wuauserv
- cinst -y php --version 5.6.30
- cd c:\tools\php56
- copy php.ini-production php.ini
- echo date.timezone="UTC" >> php.ini
- echo extension_dir=ext >> php.ini
- echo extension=php_openssl.dll >> php.ini
- echo extension=php_gmp.dll >> php.ini
- cd C:\projects\phpseclib
- SET PATH=C:\tools\php56;%PATH%
- php.exe -r "readfile('http://getcomposer.org/installer');" | php.exe
- php.exe composer.phar install --prefer-source --no-interaction
test_script:
- cd C:\projects\phpseclib
- vendor\bin\phpunit.bat tests/Windows32Test.php

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="phpseclib"
description="PHP Secure Communications Library"
default="all"
>
<target name="all" depends="sniff" />
<!-- Code Sniffer -->
<target name="sniff" depends="sniff-php-code,sniff-php-tests" />
<target name="sniff-php-code">
<exec command="vendor/bin/phpcs -s
--extensions=php
--standard=build/code-sniffer-ruleset.xml
phpseclib/"
dir=".." checkreturn="true" passthru="true" />
</target>
<target name="sniff-php-tests">
<exec command="vendor/bin/phpcs -s
--extensions=php
--standard=build/code-sniffer-ruleset-tests.xml
tests/"
dir=".." checkreturn="true" passthru="true" />
</target>
</project>

View File

@ -1,17 +0,0 @@
<?xml version="1.0"?>
<ruleset name="phpseclib Test Standard">
<description>phpseclib coding standard for tests</description>
<!-- In general rules that apply to library code also apply to tests. -->
<rule ref="./code-sniffer-ruleset.xml">
<!-- Exceptions to the library coding standard follow. -->
<!-- Test classes do not have to be namespaced but may use pseudo-namespacing
using underscore. -->
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule>
</ruleset>

View File

@ -1,35 +0,0 @@
<?xml version="1.0"?>
<ruleset name="phpseclib Standard">
<description>phpseclib coding standard</description>
<!-- We are using the PSR2 standard as a base -->
<rule ref="PSR2">
<!-- Exceptions due to legacy code with PHP4 compatibility -->
<exclude name="PSR2.Classes.PropertyDeclaration.ScopeMissing" />
<exclude name="PSR2.Classes.PropertyDeclaration.VarUsed" />
<exclude name="Squiz.Scope.MethodScope.Missing" />
<!-- Exceptions for backward compatibility -->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<!-- Exceptions for whitespacing -->
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT" />
<!-- Other Exceptions -->
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
</rule>
<!-- Useful additional rules follow -->
<!-- "for (; bar; )" should be "while (bar)" instead -->
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
<!-- A method MUST not only call its parent -->
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
</ruleset>

32
build/php-cs-fixer.php Normal file
View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
return (new PhpCsFixer\Config())
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__ . '/..'))
->setCacheFile(__DIR__ . '/php-cs-fixer.cache')
->setRiskyAllowed(true)
// https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/index.rst
->setRules(
[
// Array
'array_syntax' => ['syntax' => 'short'],
// Function Notation
'native_function_invocation' => ['exclude' => [], 'include' => [], 'scope' => 'all', 'strict' => true],
// Import
'fully_qualified_strict_types' => true,
'global_namespace_import' => ['import_constants' => false, 'import_functions' => false, 'import_classes' => false],
'no_leading_import_slash' => true,
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['class', 'const', 'function']],
'single_import_per_statement' => true,
'single_line_after_imports' => true,
// PHPDoc
'no_superfluous_phpdoc_tags' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_trim' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
]
);

20
build/php_codesniffer.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset name="phpseclib">
<file>../build/php-cs-fixer.php</file>
<file>../phpseclib/</file>
<file>../tests/</file>
<arg name="extensions" value="php"/>
<arg name="basepath" value=".."/>
<arg name="report" value="diff"/>
<arg value="s"/>
<arg value="n"/>
<arg value="p"/>
<rule ref="PSR12">
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<exclude name="PSR12.Files.FileHeader.IncorrectOrder"/>
</rule>
</ruleset>

25
build/psalm.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<psalm
xmlns="https://getpsalm.org/schema/config"
errorLevel="1"
errorBaseline="psalm_baseline.xml"
findUnusedCode="true"
findUnusedPsalmSuppress="true"
sealAllMethods="true"
ensureArrayStringOffsetsExist="true"
ensureArrayIntOffsetsExist="true"
ignoreInternalFunctionNullReturn="false"
ignoreInternalFunctionFalseReturn="false"
>
<projectFiles>
<directory name="../phpseclib"/>
<directory name="../tests"/>
</projectFiles>
<issueHandlers>
<Trace>
<errorLevel type="error">
<directory name=".."/>
</errorLevel>
</Trace>
</issueHandlers>
</psalm>

17830
build/psalm_baseline.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,8 @@
"asn1",
"asn.1",
"BigInteger"
],
"homepage": "http://phpseclib.sourceforge.net",
],
"homepage": "https://phpseclib.com/",
"license": "MIT",
"authors": [
{
@ -48,29 +48,63 @@
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
},
{
"name": "Jack Worman",
"email": "jack.worman@gmail.com",
"role": "Developer",
"homepage": "https://jackworman.com"
}
],
"require": {
"php": ">=5.3.3"
"php": ">=8.1",
"paragonie/constant_time_encoding": "^2|^3"
},
"require-dev": {
"phing/phing": "~2.7",
"phpunit/phpunit": "^4.8.35|^5.7|^6.0|^9.4",
"squizlabs/php_codesniffer": "~2.0"
"ext-xml": "*",
"brianium/paratest": "^6.6",
"friendsofphp/php-cs-fixer": "^3.12",
"php-parallel-lint/php-parallel-lint": "^1.3",
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "^4.29"
},
"suggest": {
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-xml": "Install the XML extension to load XML formatted public keys."
"ext-dom": "Install the DOM extension to load XML formatted public keys."
},
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib\\": "phpseclib/"
"phpseclib3\\": "phpseclib/"
}
},
"autoload-dev": {
"psr-4": {
"phpseclib3\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true
},
"scripts": {
"lint": "vendor/bin/parallel-lint --show-deprecated build phpseclib tests",
"php_codesniffer": "vendor/bin/phpcs --standard=build/php_codesniffer.xml",
"php_codesniffer-fix": "vendor/bin/phpcbf --standard=build/php_codesniffer.xml",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --config=build/php-cs-fixer.php --diff --using-cache=no --dry-run",
"php-cs-fixer-fix": "vendor/bin/php-cs-fixer fix --config=build/php-cs-fixer.php --diff --using-cache=no",
"psalm": "vendor/bin/psalm --config=build/psalm.xml --no-cache --long-progress --threads=4",
"psalm-set-baseline": "vendor/bin/psalm --config=build/psalm.xml --no-cache --long-progress --set-baseline=psalm_baseline.xml --threads=4",
"test": "vendor/bin/paratest --verbose --configuration=tests/phpunit.xml --runner=WrapperRunner",
"all-quality-tools": [
"@lint",
"@phpcs",
"@php-cs-fixer",
"@psalm",
"@test"
]
}
}

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace phpseclib3\Common;
use phpseclib3\Exception\InvalidArgumentException;
/**
* @internal
*/
trait ConstantUtilityTrait
{
/** @var string[]|null */
private static $valueToConstantNameMap = null;
/**
* @param string|int $value
*/
public static function findConstantNameByValue($value): ?string
{
if (!self::$valueToConstantNameMap) {
$reflectionClass = new \ReflectionClass(static::class);
$constantNameToValueMap = $reflectionClass->getConstants();
self::$valueToConstantNameMap = array_flip($constantNameToValueMap);
}
if (isset(self::$valueToConstantNameMap[$value])) {
return self::$valueToConstantNameMap[$value];
}
return null;
}
/**
* @param string|int $value
*/
public static function getConstantNameByValue($value): string
{
$constantName = static::findConstantNameByValue($value);
if ($constantName === null) {
throw new InvalidArgumentException(sprintf('"%s" does not have constant with value "%s".', static::class, $value));
}
return $constantName;
}
}

View File

@ -0,0 +1,461 @@
<?php
/**
* Common String Functions
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Common\Functions;
use ParagonIE\ConstantTime\Base64;
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\ConstantTime\Hex;
use phpseclib3\Exception\InvalidArgumentException;
use phpseclib3\Exception\LengthException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\Common\FiniteField;
/**
* Common String Functions
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class Strings
{
/**
* String Shift
*
* Inspired by array_shift
*/
public static function shift(string &$string, int $index = 1): string
{
$substr = substr($string, 0, $index);
$string = substr($string, $index);
return $substr;
}
/**
* String Pop
*
* Inspired by array_pop
*/
public static function pop(string &$string, int $index = 1): string
{
$substr = substr($string, -$index);
$string = substr($string, 0, -$index);
return $substr;
}
/**
* Parse SSH2-style string
*
* Returns either an array or a boolean if $data is malformed.
*
* Valid characters for $format are as follows:
*
* C = byte
* b = boolean (true/false)
* N = uint32
* Q = uint64
* s = string
* i = mpint
* L = name-list
*
* uint64 is not supported.
*/
public static function unpackSSH2(string $format, string &$data): array
{
$format = self::formatPack($format);
$result = [];
for ($i = 0; $i < strlen($format); $i++) {
switch ($format[$i]) {
case 'C':
case 'b':
if (!strlen($data)) {
throw new LengthException('At least one byte needs to be present for successful C / b decodes');
}
break;
case 'N':
case 'i':
case 's':
case 'L':
if (strlen($data) < 4) {
throw new LengthException('At least four byte needs to be present for successful N / i / s / L decodes');
}
break;
case 'Q':
if (strlen($data) < 8) {
throw new LengthException('At least eight byte needs to be present for successful N / i / s / L decodes');
}
break;
default:
throw new InvalidArgumentException('$format contains an invalid character');
}
switch ($format[$i]) {
case 'C':
$result[] = ord(self::shift($data));
continue 2;
case 'b':
$result[] = ord(self::shift($data)) != 0;
continue 2;
case 'N':
[, $temp] = unpack('N', self::shift($data, 4));
$result[] = $temp;
continue 2;
case 'Q':
// pack() added support for Q in PHP 5.6.3 and PHP 5.6 is phpseclib 3's minimum version
// so in theory we could support this BUT, "64-bit format codes are not available for
// 32-bit versions" and phpseclib works on 32-bit installs. on 32-bit installs
// 64-bit floats can be used to get larger numbers then 32-bit signed ints would allow
// for. sure, you're not gonna get the full precision of 64-bit numbers but just because
// you need > 32-bit precision doesn't mean you need the full 64-bit precision
extract(unpack('Nupper/Nlower', self::shift($data, 8)));
$temp = $upper ? 4294967296 * $upper : 0;
$temp += $lower < 0 ? ($lower & 0x7FFFFFFFF) + 0x80000000 : $lower;
// $temp = hexdec(bin2hex(self::shift($data, 8)));
$result[] = $temp;
continue 2;
}
[, $length] = unpack('N', self::shift($data, 4));
if (strlen($data) < $length) {
throw new LengthException("$length bytes needed; " . strlen($data) . ' bytes available');
}
$temp = self::shift($data, $length);
switch ($format[$i]) {
case 'i':
$result[] = new BigInteger($temp, -256);
break;
case 's':
$result[] = $temp;
break;
case 'L':
$result[] = explode(',', $temp);
}
}
return $result;
}
/**
* Create SSH2-style string
*
* @param string|int|float|array|bool ...$elements
*/
public static function packSSH2(string $format, ...$elements): string
{
$format = self::formatPack($format);
if (strlen($format) != count($elements)) {
throw new InvalidArgumentException('There must be as many arguments as there are characters in the $format string');
}
$result = '';
for ($i = 0; $i < strlen($format); $i++) {
$element = $elements[$i];
switch ($format[$i]) {
case 'C':
if (!is_int($element)) {
throw new InvalidArgumentException('Bytes must be represented as an integer between 0 and 255, inclusive.');
}
$result .= pack('C', $element);
break;
case 'b':
if (!is_bool($element)) {
throw new InvalidArgumentException('A boolean parameter was expected.');
}
$result .= $element ? "\1" : "\0";
break;
case 'Q':
if (!is_int($element) && !is_float($element)) {
throw new InvalidArgumentException('An integer was expected.');
}
// 4294967296 == 1 << 32
$result .= pack('NN', $element / 4294967296, $element);
break;
case 'N':
if (is_float($element)) {
$element = (int) $element;
}
if (!is_int($element)) {
throw new InvalidArgumentException('An integer was expected.');
}
$result .= pack('N', $element);
break;
case 's':
if (!self::is_stringable($element)) {
throw new InvalidArgumentException('A string was expected.');
}
$result .= pack('Na*', strlen($element), $element);
break;
case 'i':
if (!$element instanceof BigInteger && !$element instanceof FiniteField\Integer) {
throw new InvalidArgumentException('A phpseclib3\Math\BigInteger or phpseclib3\Math\Common\FiniteField\Integer object was expected.');
}
$element = $element->toBytes(true);
$result .= pack('Na*', strlen($element), $element);
break;
case 'L':
if (!is_array($element)) {
throw new InvalidArgumentException('An array was expected.');
}
$element = implode(',', $element);
$result .= pack('Na*', strlen($element), $element);
break;
default:
throw new InvalidArgumentException('$format contains an invalid character');
}
}
return $result;
}
/**
* Expand a pack string
*
* Converts C5 to CCCCC, for example.
*/
private static function formatPack(string $format): string
{
$parts = preg_split('#(\d+)#', $format, -1, PREG_SPLIT_DELIM_CAPTURE);
$format = '';
for ($i = 1; $i < count($parts); $i += 2) {
$format .= substr($parts[$i - 1], 0, -1) . str_repeat($parts[$i - 1][-1], (int) $parts[$i]);
}
$format .= $parts[$i - 1];
return $format;
}
/**
* Convert binary data into bits
*
* bin2hex / hex2bin refer to base-256 encoded data as binary, whilst
* decbin / bindec refer to base-2 encoded data as binary. For the purposes
* of this function, bin refers to base-256 encoded data whilst bits refers
* to base-2 encoded data
*/
public static function bits2bin(string $x): string
{
/*
// the pure-PHP approach is faster than the GMP approach
if (function_exists('gmp_export')) {
return strlen($x) ? gmp_export(gmp_init($x, 2)) : gmp_init(0);
}
*/
if (preg_match('#[^01]#', $x)) {
throw new RuntimeException('The only valid characters are 0 and 1');
}
if (!defined('PHP_INT_MIN')) {
define('PHP_INT_MIN', ~PHP_INT_MAX);
}
$length = strlen($x);
if (!$length) {
return '';
}
$block_size = PHP_INT_SIZE << 3;
$pad = $block_size - ($length % $block_size);
if ($pad != $block_size) {
$x = str_repeat('0', $pad) . $x;
}
$parts = str_split($x, $block_size);
$str = '';
foreach ($parts as $part) {
$xor = $part[0] == '1' ? PHP_INT_MIN : 0;
$part[0] = '0';
$str .= pack(
PHP_INT_SIZE == 4 ? 'N' : 'J',
$xor ^ eval('return 0b' . $part . ';')
);
}
return ltrim($str, "\0");
}
/**
* Convert bits to binary data
*/
public static function bin2bits(string $x, bool $trim = true): string
{
/*
// the pure-PHP approach is slower than the GMP approach BUT
// i want to the pure-PHP version to be easily unit tested as well
if (function_exists('gmp_import')) {
return gmp_strval(gmp_import($x), 2);
}
*/
$len = strlen($x);
$mod = $len % PHP_INT_SIZE;
if ($mod) {
$x = str_pad($x, $len + PHP_INT_SIZE - $mod, "\0", STR_PAD_LEFT);
}
$bits = '';
if (PHP_INT_SIZE == 4) {
$digits = unpack('N*', $x);
foreach ($digits as $digit) {
$bits .= sprintf('%032b', $digit);
}
} else {
$digits = unpack('J*', $x);
foreach ($digits as $digit) {
$bits .= sprintf('%064b', $digit);
}
}
return $trim ? ltrim($bits, '0') : $bits;
}
/**
* Switch Endianness Bit Order
*/
public static function switchEndianness(string $x): string
{
$r = '';
for ($i = strlen($x) - 1; $i >= 0; $i--) {
$b = ord($x[$i]);
if (PHP_INT_SIZE === 8) {
// 3 operations
// from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv
$r .= chr((($b * 0x0202020202) & 0x010884422010) % 1023);
} else {
// 7 operations
// from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits
$p1 = ($b * 0x0802) & 0x22110;
$p2 = ($b * 0x8020) & 0x88440;
$r .= chr(
(($p1 | $p2) * 0x10101) >> 16
);
}
}
return $r;
}
/**
* Increment the current string
*/
public static function increment_str(string &$var): string
{
if (function_exists('sodium_increment')) {
$var = strrev($var);
sodium_increment($var);
$var = strrev($var);
return $var;
}
for ($i = 4; $i <= strlen($var); $i += 4) {
$temp = substr($var, -$i, 4);
switch ($temp) {
case "\xFF\xFF\xFF\xFF":
$var = substr_replace($var, "\x00\x00\x00\x00", -$i, 4);
break;
case "\x7F\xFF\xFF\xFF":
$var = substr_replace($var, "\x80\x00\x00\x00", -$i, 4);
return $var;
default:
$temp = unpack('Nnum', $temp);
$var = substr_replace($var, pack('N', $temp['num'] + 1), -$i, 4);
return $var;
}
}
$remainder = strlen($var) % 4;
if ($remainder == 0) {
return $var;
}
$temp = unpack('Nnum', str_pad(substr($var, 0, $remainder), 4, "\0", STR_PAD_LEFT));
$temp = substr(pack('N', $temp['num'] + 1), -$remainder);
$var = substr_replace($var, $temp, 0, $remainder);
return $var;
}
/**
* Find whether the type of a variable is string (or could be converted to one)
*
* @psalm-assert-if-true string|\Stringable $var
*/
public static function is_stringable($var): bool
{
return is_string($var) || (is_object($var) && method_exists($var, '__toString'));
}
/**
* Constant Time Base64-decoding
*
* ParagoneIE\ConstantTime doesn't use libsodium if it's available so we'll do so
* ourselves. see https://github.com/paragonie/constant_time_encoding/issues/39
*/
public static function base64_decode(string $data): string
{
return function_exists('sodium_base642bin') ?
sodium_base642bin($data, SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING, '=') :
Base64::decode($data);
}
/**
* Constant Time Base64-decoding (URL safe)
*/
public static function base64url_decode(string $data): string
{
// return self::base64_decode(str_replace(['-', '_'], ['+', '/'], $data));
return function_exists('sodium_base642bin') ?
sodium_base642bin($data, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING, '=') :
Base64UrlSafe::decode($data);
}
/**
* Constant Time Base64-encoding
*/
public static function base64_encode(string $data): string
{
return function_exists('sodium_bin2base64') ?
sodium_bin2base64($data, SODIUM_BASE64_VARIANT_ORIGINAL) :
Base64::encode($data);
}
/**
* Constant Time Base64-encoding (URL safe)
*/
public static function base64url_encode(string $data): string
{
// return str_replace(['+', '/'], ['-', '_'], self::base64_encode($data));
return function_exists('sodium_bin2base64') ?
sodium_bin2base64($data, SODIUM_BASE64_VARIANT_URLSAFE) :
Base64UrlSafe::encode($data);
}
/**
* Constant Time Hex Decoder
*/
public static function hex2bin(string $data): string
{
return function_exists('sodium_hex2bin') ?
sodium_hex2bin($data) :
Hex::decode($data);
}
/**
* Constant Time Hex Encoder
*/
public static function bin2hex(string $data): string
{
return function_exists('sodium_bin2hex') ?
sodium_bin2hex($data) :
Hex::encode($data);
}
}

View File

@ -3,7 +3,7 @@
/**
* Pure-PHP implementation of AES.
*
* Uses mcrypt, if available/possible, and an internal implementation, otherwise.
* Uses OpenSSL, if available/possible, and an internal implementation, otherwise
*
* PHP version 5
*
@ -16,7 +16,7 @@
* it'll be null-padded to 192-bits and 192 bits will be the key length until {@link self::setKey() setKey()}
* is called, again, at which point, it'll be recalculated.
*
* Since \phpseclib\Crypt\AES extends \phpseclib\Crypt\Rijndael, some functions are available to be called that, in the context of AES, don't
* Since \phpseclib3\Crypt\AES extends \phpseclib3\Crypt\Rijndael, some functions are available to be called that, in the context of AES, don't
* make a whole lot of sense. {@link self::setBlockLength() setBlockLength()}, for instance. Calling that function,
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
*
@ -25,7 +25,7 @@
* <?php
* include 'vendor/autoload.php';
*
* $aes = new \phpseclib\Crypt\AES();
* $aes = new \phpseclib3\Crypt\AES('ctr');
*
* $aes->setKey('abcdefghijklmnop');
*
@ -39,58 +39,80 @@
* ?>
* </code>
*
* @category Crypt
* @package AES
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2008 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
namespace phpseclib\Crypt;
declare(strict_types=1);
namespace phpseclib3\Crypt;
use phpseclib3\Exception\BadMethodCallException;
use phpseclib3\Exception\LengthException;
/**
* Pure-PHP implementation of AES.
*
* @package AES
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class AES extends Rijndael
{
/**
* Dummy function
*
* Since \phpseclib\Crypt\AES extends \phpseclib\Crypt\Rijndael, this function is, technically, available, but it doesn't do anything.
* Since \phpseclib3\Crypt\AES extends \phpseclib3\Crypt\Rijndael, this function is, technically, available, but it doesn't do anything.
*
* @see \phpseclib\Crypt\Rijndael::setBlockLength()
* @access public
* @param int $length
* @throws BadMethodCallException anytime it's called
* @see \phpseclib3\Crypt\Rijndael::setBlockLength()
*/
function setBlockLength($length)
public function setBlockLength(int $length): void
{
return;
throw new BadMethodCallException('The block length cannot be set for AES.');
}
/**
* Sets the key length
*
* Valid key lengths are 128, 192, and 256. If the length is less than 128, it will be rounded up to
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
* Valid key lengths are 128, 192, and 256. Set the link to bool(false) to disable a fixed key length
*
* @see \phpseclib\Crypt\Rijndael:setKeyLength()
* @access public
* @param int $length
* @throws LengthException if the key length isn't supported
* @see \phpseclib3\Crypt\Rijndael:setKeyLength()
*/
function setKeyLength($length)
public function setKeyLength(int $length): void
{
parent::setKeyLength($length);
switch ($this->key_length) {
case 20:
$this->key_length = 24;
switch ($length) {
case 128:
case 192:
case 256:
break;
case 28:
$this->key_length = 32;
default:
throw new LengthException('Key of size ' . $length . ' not supported by this algorithm. Only keys of sizes 128, 192 or 256 supported');
}
parent::setKeyLength($length);
}
/**
* Sets the key.
*
* Rijndael supports five different key lengths, AES only supports three.
*
* @throws LengthException if the key length isn't supported
* @see \phpseclib3\Crypt\Rijndael:setKey()
* @see setKeyLength()
*/
public function setKey(string $key): void
{
switch (strlen($key)) {
case 16:
case 24:
case 32:
break;
default:
throw new LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported');
}
parent::setKey($key);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,788 @@
<?php
/**
* Pure-PHP implementation of ChaCha20.
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2019 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt;
use phpseclib3\Exception\BadDecryptionException;
use phpseclib3\Exception\InsufficientSetupException;
use phpseclib3\Exception\LengthException;
use phpseclib3\Exception\UnexpectedValueException;
/**
* Pure-PHP implementation of ChaCha20.
*
* @author Jim Wigginton <terrafrost@php.net>
*/
class ChaCha20 extends Salsa20
{
/**
* The OpenSSL specific name of the cipher
*
* @var string
*/
protected $cipher_name_openssl = 'chacha20';
/**
* Test for engine validity
*
* This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine()
*
* @see \phpseclib3\Crypt\Common\SymmetricKey::__construct()
*/
protected function isValidEngineHelper(int $engine): bool
{
switch ($engine) {
case self::ENGINE_LIBSODIUM:
// PHP 7.2.0 (30 Nov 2017) added support for libsodium
// we could probably make it so that if $this->counter == 0 then the first block would be done with either OpenSSL
// or PHP and then subsequent blocks would then be done with libsodium but idk - it's not a high priority atm
// we could also make it so that if $this->counter == 0 and $this->continuousBuffer then do the first string
// with libsodium and subsequent strings with openssl or pure-PHP but again not a high priority
return function_exists('sodium_crypto_aead_chacha20poly1305_ietf_encrypt') &&
$this->key_length == 32 &&
(($this->usePoly1305 && !isset($this->poly1305Key) && $this->counter == 0) || $this->counter == 1) &&
!$this->continuousBuffer;
case self::ENGINE_OPENSSL:
// OpenSSL 1.1.0 (released 25 Aug 2016) added support for chacha20.
// PHP didn't support OpenSSL 1.1.0 until 7.0.19 (11 May 2017)
// if you attempt to provide openssl with a 128 bit key (as opposed to a 256 bit key) openssl will null
// pad the key to 256 bits and still use the expansion constant for 256-bit keys. the fact that
// openssl treats the IV as both the counter and nonce, however, let's us use openssl in continuous mode
// whereas libsodium does not
if ($this->key_length != 32) {
return false;
}
}
return parent::isValidEngineHelper($engine);
}
/**
* Encrypts a message.
*
* @return string $ciphertext
* @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt()
* @see self::crypt()
*/
public function encrypt(string $plaintext): string
{
$this->setup();
if ($this->engine == self::ENGINE_LIBSODIUM) {
return $this->encrypt_with_libsodium($plaintext);
}
return parent::encrypt($plaintext);
}
/**
* Decrypts a message.
*
* $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)).
* At least if the continuous buffer is disabled.
*
* @return string $plaintext
* @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt()
* @see self::crypt()
*/
public function decrypt(string $ciphertext): string
{
$this->setup();
if ($this->engine == self::ENGINE_LIBSODIUM) {
return $this->decrypt_with_libsodium($ciphertext);
}
return parent::decrypt($ciphertext);
}
/**
* Encrypts a message with libsodium
*
* @return string $text
* @see self::encrypt()
*/
private function encrypt_with_libsodium(string $plaintext): string
{
$params = [$plaintext, $this->aad, $this->nonce, $this->key];
$ciphertext = strlen($this->nonce) == 8 ?
sodium_crypto_aead_chacha20poly1305_encrypt(...$params) :
sodium_crypto_aead_chacha20poly1305_ietf_encrypt(...$params);
if (!$this->usePoly1305) {
return substr($ciphertext, 0, strlen($plaintext));
}
$newciphertext = substr($ciphertext, 0, strlen($plaintext));
$this->newtag = $this->usingGeneratedPoly1305Key && strlen($this->nonce) == 12 ?
substr($ciphertext, strlen($plaintext)) :
$this->poly1305($newciphertext);
return $newciphertext;
}
/**
* Decrypts a message with libsodium
*
* @return string $text
* @see self::decrypt()
*/
private function decrypt_with_libsodium(string $ciphertext): string
{
$params = [$ciphertext, $this->aad, $this->nonce, $this->key];
if (isset($this->poly1305Key)) {
if ($this->oldtag === false) {
throw new InsufficientSetupException('Authentication Tag has not been set');
}
if ($this->usingGeneratedPoly1305Key && strlen($this->nonce) == 12) {
$plaintext = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(...$params);
$this->oldtag = false;
if ($plaintext === false) {
throw new BadDecryptionException('Derived authentication tag and supplied authentication tag do not match');
}
return $plaintext;
}
$newtag = $this->poly1305($ciphertext);
if ($this->oldtag != substr($newtag, 0, strlen($this->oldtag))) {
$this->oldtag = false;
throw new BadDecryptionException('Derived authentication tag and supplied authentication tag do not match');
}
$this->oldtag = false;
}
$plaintext = strlen($this->nonce) == 8 ?
sodium_crypto_aead_chacha20poly1305_encrypt(...$params) :
sodium_crypto_aead_chacha20poly1305_ietf_encrypt(...$params);
return substr($plaintext, 0, strlen($ciphertext));
}
/**
* Sets the nonce.
*/
public function setNonce(string $nonce): void
{
if (!is_string($nonce)) {
throw new UnexpectedValueException('The nonce should be a string');
}
/*
from https://tools.ietf.org/html/rfc7539#page-7
"Note also that the original ChaCha had a 64-bit nonce and 64-bit
block count. We have modified this here to be more consistent with
recommendations in Section 3.2 of [RFC5116]."
*/
switch (strlen($nonce)) {
case 8: // 64 bits
case 12: // 96 bits
break;
default:
throw new LengthException('Nonce of size ' . strlen($nonce) . ' not supported by this algorithm. Only 64-bit nonces or 96-bit nonces are supported');
}
$this->nonce = $nonce;
$this->changed = true;
$this->setEngine();
}
/**
* Setup the self::ENGINE_INTERNAL $engine
*
* (re)init, if necessary, the internal cipher $engine
*
* _setup() will be called each time if $changed === true
* typically this happens when using one or more of following public methods:
*
* - setKey()
*
* - setNonce()
*
* - First run of encrypt() / decrypt() with no init-settings
*
* @see self::setKey()
* @see self::setNonce()
* @see self::disableContinuousBuffer()
*/
protected function setup(): void
{
if (!$this->changed) {
return;
}
$this->enbuffer = $this->debuffer = ['ciphertext' => '', 'counter' => $this->counter];
$this->changed = $this->nonIVChanged = false;
if ($this->nonce === false) {
throw new InsufficientSetupException('No nonce has been defined');
}
if ($this->key === false) {
throw new InsufficientSetupException('No key has been defined');
}
if ($this->usePoly1305 && !isset($this->poly1305Key)) {
$this->usingGeneratedPoly1305Key = true;
if ($this->engine == self::ENGINE_LIBSODIUM) {
return;
}
$this->createPoly1305Key();
}
$key = $this->key;
if (strlen($key) == 16) {
$constant = 'expand 16-byte k';
$key .= $key;
} else {
$constant = 'expand 32-byte k';
}
$this->p1 = $constant . $key;
$this->p2 = $this->nonce;
if (strlen($this->nonce) == 8) {
$this->p2 = "\0\0\0\0" . $this->p2;
}
}
/**
* The quarterround function
*/
protected static function quarterRound(int &$a, int &$b, int &$c, int &$d): void
{
// in https://datatracker.ietf.org/doc/html/rfc7539#section-2.1 the addition,
// xor'ing and rotation are all on the same line so i'm keeping it on the same
// line here as well
// @codingStandardsIgnoreStart
$a+= $b; $d = self::leftRotate(intval($d) ^ intval($a), 16);
$c+= $d; $b = self::leftRotate(intval($b) ^ intval($c), 12);
$a+= $b; $d = self::leftRotate(intval($d) ^ intval($a), 8);
$c+= $d; $b = self::leftRotate(intval($b) ^ intval($c), 7);
// @codingStandardsIgnoreEnd
}
/**
* The doubleround function
*
* @param int $x0 (by reference)
* @param int $x1 (by reference)
* @param int $x2 (by reference)
* @param int $x3 (by reference)
* @param int $x4 (by reference)
* @param int $x5 (by reference)
* @param int $x6 (by reference)
* @param int $x7 (by reference)
* @param int $x8 (by reference)
* @param int $x9 (by reference)
* @param int $x10 (by reference)
* @param int $x11 (by reference)
* @param int $x12 (by reference)
* @param int $x13 (by reference)
* @param int $x14 (by reference)
* @param int $x15 (by reference)
*/
protected static function doubleRound(int &$x0, int &$x1, int &$x2, int &$x3, int &$x4, int &$x5, int &$x6, int &$x7, int &$x8, int &$x9, int &$x10, int &$x11, int &$x12, int &$x13, int &$x14, int &$x15): void
{
// columnRound
static::quarterRound($x0, $x4, $x8, $x12);
static::quarterRound($x1, $x5, $x9, $x13);
static::quarterRound($x2, $x6, $x10, $x14);
static::quarterRound($x3, $x7, $x11, $x15);
// rowRound
static::quarterRound($x0, $x5, $x10, $x15);
static::quarterRound($x1, $x6, $x11, $x12);
static::quarterRound($x2, $x7, $x8, $x13);
static::quarterRound($x3, $x4, $x9, $x14);
}
/**
* The Salsa20 hash function function
*
* On my laptop this loop unrolled / function dereferenced version of parent::salsa20 encrypts 1mb of text in
* 0.65s vs the 0.85s that it takes with the parent method.
*
* If we were free to assume that the host OS would always be 64-bits then the if condition in leftRotate could
* be eliminated and we could knock this done to 0.60s.
*
* For comparison purposes, RC4 takes 0.16s and AES in CTR mode with the Eval engine takes 0.48s.
* AES in CTR mode with the PHP engine takes 1.19s. Salsa20 / ChaCha20 do not benefit as much from the Eval
* approach due to the fact that there are a lot less variables to de-reference, fewer loops to unroll, etc
*/
protected static function salsa20(string $x)
{
[, $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15] = unpack('V*', $x);
$z0 = $x0;
$z1 = $x1;
$z2 = $x2;
$z3 = $x3;
$z4 = $x4;
$z5 = $x5;
$z6 = $x6;
$z7 = $x7;
$z8 = $x8;
$z9 = $x9;
$z10 = $x10;
$z11 = $x11;
$z12 = $x12;
$z13 = $x13;
$z14 = $x14;
$z15 = $x15;
// @codingStandardsIgnoreStart
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// columnRound
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 16);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 12);
$x0+= $x4; $x12 = self::leftRotate(intval($x12) ^ intval($x0), 8);
$x8+= $x12; $x4 = self::leftRotate(intval($x4) ^ intval($x8), 7);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 16);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 12);
$x1+= $x5; $x13 = self::leftRotate(intval($x13) ^ intval($x1), 8);
$x9+= $x13; $x5 = self::leftRotate(intval($x5) ^ intval($x9), 7);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 16);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 12);
$x2+= $x6; $x14 = self::leftRotate(intval($x14) ^ intval($x2), 8);
$x10+= $x14; $x6 = self::leftRotate(intval($x6) ^ intval($x10), 7);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 16);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 12);
$x3+= $x7; $x15 = self::leftRotate(intval($x15) ^ intval($x3), 8);
$x11+= $x15; $x7 = self::leftRotate(intval($x7) ^ intval($x11), 7);
// rowRound
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 16);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 12);
$x0+= $x5; $x15 = self::leftRotate(intval($x15) ^ intval($x0), 8);
$x10+= $x15; $x5 = self::leftRotate(intval($x5) ^ intval($x10), 7);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 16);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 12);
$x1+= $x6; $x12 = self::leftRotate(intval($x12) ^ intval($x1), 8);
$x11+= $x12; $x6 = self::leftRotate(intval($x6) ^ intval($x11), 7);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 16);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 12);
$x2+= $x7; $x13 = self::leftRotate(intval($x13) ^ intval($x2), 8);
$x8+= $x13; $x7 = self::leftRotate(intval($x7) ^ intval($x8), 7);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 16);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 12);
$x3+= $x4; $x14 = self::leftRotate(intval($x14) ^ intval($x3), 8);
$x9+= $x14; $x4 = self::leftRotate(intval($x4) ^ intval($x9), 7);
// @codingStandardsIgnoreEnd
$x0 += $z0;
$x1 += $z1;
$x2 += $z2;
$x3 += $z3;
$x4 += $z4;
$x5 += $z5;
$x6 += $z6;
$x7 += $z7;
$x8 += $z8;
$x9 += $z9;
$x10 += $z10;
$x11 += $z11;
$x12 += $z12;
$x13 += $z13;
$x14 += $z14;
$x15 += $z15;
return pack('V*', $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15);
}
}

View File

@ -0,0 +1,532 @@
<?php
/**
* Base Class for all asymmetric key ciphers
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common;
use phpseclib3\Crypt\Hash;
use phpseclib3\Exception\NoKeyLoadedException;
use phpseclib3\Exception\UnsupportedFormatException;
use phpseclib3\Math\BigInteger;
/**
* Base Class for all asymmetric cipher classes
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class AsymmetricKey
{
/**
* Precomputed Zero
*
* @var BigInteger
*/
protected static $zero;
/**
* Precomputed One
*
* @var BigInteger
*/
protected static $one;
/**
* Format of the loaded key
*
* @var string
*/
protected $format;
/**
* Hash function
*
* @var Hash
*/
protected $hash;
/**
* HMAC function
*
* @var Hash
*/
private $hmac;
/**
* Supported plugins (lower case)
*
* @see self::initialize_static_variables()
* @var array
*/
private static $plugins = [];
/**
* Invisible plugins
*
* @see self::initialize_static_variables()
* @var array
*/
private static $invisiblePlugins = [];
/**
* Available Engines
*
* @var boolean[]
*/
protected static $engines = [];
/**
* Key Comment
*
* @var null|string
*/
private $comment;
abstract public function toString(string $type, array $options = []): array|string;
/**
* The constructor
*/
protected function __construct()
{
self::initialize_static_variables();
$this->hash = new Hash('sha256');
$this->hmac = new Hash('sha256');
}
/**
* Initialize static variables
*/
protected static function initialize_static_variables(): void
{
if (!isset(self::$zero)) {
self::$zero = new BigInteger(0);
self::$one = new BigInteger(1);
}
self::loadPlugins('Keys');
if (static::ALGORITHM != 'RSA' && static::ALGORITHM != 'DH') {
self::loadPlugins('Signature');
}
}
/**
* Load the key
*
* @param string|array $key
* @return \phpseclib3\Crypt\Common\PublicKey|\phpseclib3\Crypt\Common\PrivateKey
*/
public static function load($key, ?string $password = null): AsymmetricKey
{
self::initialize_static_variables();
$class = new \ReflectionClass(static::class);
if ($class->isFinal()) {
throw new \RuntimeException('load() should not be called from final classes (' . static::class . ')');
}
$components = false;
foreach (self::$plugins[static::ALGORITHM]['Keys'] as $format) {
if (isset(self::$invisiblePlugins[static::ALGORITHM]) && in_array($format, self::$invisiblePlugins[static::ALGORITHM])) {
continue;
}
try {
$components = $format::load($key, $password);
} catch (\Exception $e) {
$components = false;
}
if ($components !== false) {
break;
}
}
if ($components === false) {
throw new NoKeyLoadedException('Unable to read key');
}
$components['format'] = $format;
$components['secret'] ??= '';
$comment = $components['comment'] ?? null;
$new = static::onLoad($components);
$new->format = $format;
$new->comment = $comment;
return $new instanceof PrivateKey ?
$new->withPassword($password) :
$new;
}
/**
* Loads a private key
*
* @param string|array $key
* @param string $password optional
*/
public static function loadPrivateKey($key, string $password = ''): PrivateKey
{
$key = self::load($key, $password);
if (!$key instanceof PrivateKey) {
throw new NoKeyLoadedException('The key that was loaded was not a private key');
}
return $key;
}
/**
* Loads a public key
*
* @param string|array $key
*/
public static function loadPublicKey($key): PublicKey
{
$key = self::load($key);
if (!$key instanceof PublicKey) {
throw new NoKeyLoadedException('The key that was loaded was not a public key');
}
return $key;
}
/**
* Loads parameters
*
* @param string|array $key
*/
public static function loadParameters($key): AsymmetricKey
{
$key = self::load($key);
if (!$key instanceof PrivateKey && !$key instanceof PublicKey) {
throw new NoKeyLoadedException('The key that was loaded was not a parameter');
}
return $key;
}
/**
* Load the key, assuming a specific format
*
* @return static
*/
public static function loadFormat(string $type, string $key, ?string $password = null): AsymmetricKey
{
self::initialize_static_variables();
$components = false;
$format = strtolower($type);
if (isset(self::$plugins[static::ALGORITHM]['Keys'][$format])) {
$format = self::$plugins[static::ALGORITHM]['Keys'][$format];
$components = $format::load($key, $password);
}
if ($components === false) {
throw new NoKeyLoadedException('Unable to read key');
}
$components['format'] = $format;
$components['secret'] ??= '';
$new = static::onLoad($components);
$new->format = $format;
return $new instanceof PrivateKey ?
$new->withPassword($password) :
$new;
}
/**
* Loads a private key
*/
public static function loadPrivateKeyFormat(string $type, string $key, ?string $password = null): PrivateKey
{
$key = self::loadFormat($type, $key, $password);
if (!$key instanceof PrivateKey) {
throw new NoKeyLoadedException('The key that was loaded was not a private key');
}
return $key;
}
/**
* Loads a public key
*/
public static function loadPublicKeyFormat(string $type, string $key): PublicKey
{
$key = self::loadFormat($type, $key);
if (!$key instanceof PublicKey) {
throw new NoKeyLoadedException('The key that was loaded was not a public key');
}
return $key;
}
/**
* Loads parameters
*
* @param string|array $key
*/
public static function loadParametersFormat(string $type, $key): AsymmetricKey
{
$key = self::loadFormat($type, $key);
if (!$key instanceof PrivateKey && !$key instanceof PublicKey) {
throw new NoKeyLoadedException('The key that was loaded was not a parameter');
}
return $key;
}
/**
* Validate Plugin
*
* @param string|null $method optional
*/
protected static function validatePlugin(string $format, string $type, ?string $method = null)
{
$type = strtolower($type);
if (!isset(self::$plugins[static::ALGORITHM][$format][$type])) {
throw new UnsupportedFormatException("$type is not a supported format");
}
$type = self::$plugins[static::ALGORITHM][$format][$type];
if (isset($method) && !method_exists($type, $method)) {
throw new UnsupportedFormatException("$type does not implement $method");
}
return $type;
}
/**
* Load Plugins
*/
private static function loadPlugins(string $format): void
{
if (!isset(self::$plugins[static::ALGORITHM][$format])) {
self::$plugins[static::ALGORITHM][$format] = [];
foreach (new \DirectoryIterator(__DIR__ . '/../' . static::ALGORITHM . '/Formats/' . $format . '/') as $file) {
if ($file->getExtension() != 'php') {
continue;
}
$name = $file->getBasename('.php');
if ($name[0] == '.') {
continue;
}
$type = 'phpseclib3\Crypt\\' . static::ALGORITHM . '\\Formats\\' . $format . '\\' . $name;
$reflect = new \ReflectionClass($type);
if ($reflect->isTrait()) {
continue;
}
self::$plugins[static::ALGORITHM][$format][strtolower($name)] = $type;
if ($reflect->hasConstant('IS_INVISIBLE')) {
self::$invisiblePlugins[static::ALGORITHM][] = $type;
}
}
}
}
/**
* Returns a list of supported formats.
*/
public static function getSupportedKeyFormats(): array
{
self::initialize_static_variables();
return self::$plugins[static::ALGORITHM]['Keys'];
}
/**
* Add a fileformat plugin
*
* The plugin needs to either already be loaded or be auto-loadable.
* Loading a plugin whose shortname overwrite an existing shortname will overwrite the old plugin.
*
* @see self::load()
*/
public static function addFileFormat(string $fullname): void
{
self::initialize_static_variables();
if (class_exists($fullname)) {
$meta = new \ReflectionClass($fullname);
$shortname = $meta->getShortName();
self::$plugins[static::ALGORITHM]['Keys'][strtolower($shortname)] = $fullname;
if ($meta->hasConstant('IS_INVISIBLE')) {
self::$invisiblePlugins[static::ALGORITHM][] = strtolower($shortname);
}
}
}
/**
* Returns the format of the loaded key.
*
* If the key that was loaded wasn't in a valid or if the key was auto-generated
* with RSA::createKey() then this will throw an exception.
*
* @see self::load()
*/
public function getLoadedFormat(): string
{
if (empty($this->format)) {
throw new NoKeyLoadedException('This key was created with createKey - it was not loaded with load. Therefore there is no "loaded format"');
}
$meta = new \ReflectionClass($this->format);
return $meta->getShortName();
}
/**
* Returns the key's comment
*
* Not all key formats support comments. If you want to set a comment use toString()
*/
public function getComment(): ?string
{
return $this->comment;
}
/**
* Tests engine validity
*/
public static function useBestEngine(): array
{
static::$engines = [
'PHP' => true,
'OpenSSL' => extension_loaded('openssl'),
// this test can be satisfied by either of the following:
// http://php.net/manual/en/book.sodium.php
// https://github.com/paragonie/sodium_compat
'libsodium' => function_exists('sodium_crypto_sign_keypair'),
];
return static::$engines;
}
/**
* Flag to use internal engine only (useful for unit testing)
*/
public static function useInternalEngine(): void
{
static::$engines = [
'PHP' => true,
'OpenSSL' => false,
'libsodium' => false,
];
}
/**
* __toString() magic method
*
* @return string
*/
public function __toString()
{
return $this->toString('PKCS8');
}
/**
* Determines which hashing function should be used
*/
public function withHash(string $hash): AsymmetricKey
{
$new = clone $this;
$new->hash = new Hash($hash);
$new->hmac = new Hash($hash);
return $new;
}
/**
* Returns the hash algorithm currently being used
*/
public function getHash(): Hash
{
return clone $this->hash;
}
/**
* Compute the pseudorandom k for signature generation,
* using the process specified for deterministic DSA.
*
* @return string
*/
protected function computek(string $h1)
{
$v = str_repeat("\1", strlen($h1));
$k = str_repeat("\0", strlen($h1));
$x = $this->int2octets($this->x);
$h1 = $this->bits2octets($h1);
$this->hmac->setKey($k);
$k = $this->hmac->hash($v . "\0" . $x . $h1);
$this->hmac->setKey($k);
$v = $this->hmac->hash($v);
$k = $this->hmac->hash($v . "\1" . $x . $h1);
$this->hmac->setKey($k);
$v = $this->hmac->hash($v);
$qlen = $this->q->getLengthInBytes();
while (true) {
$t = '';
while (strlen($t) < $qlen) {
$v = $this->hmac->hash($v);
$t = $t . $v;
}
$k = $this->bits2int($t);
if (!$k->equals(self::$zero) && $k->compare($this->q) < 0) {
break;
}
$k = $this->hmac->hash($v . "\0");
$this->hmac->setKey($k);
$v = $this->hmac->hash($v);
}
return $k;
}
/**
* Integer to Octet String
*/
private function int2octets(BigInteger $v): string
{
$out = $v->toBytes();
$rolen = $this->q->getLengthInBytes();
if (strlen($out) < $rolen) {
return str_pad($out, $rolen, "\0", STR_PAD_LEFT);
} elseif (strlen($out) > $rolen) {
return substr($out, -$rolen);
} else {
return $out;
}
}
/**
* Bit String to Integer
*/
protected function bits2int(string $in): BigInteger
{
$v = new BigInteger($in, 256);
$vlen = strlen($in) << 3;
$qlen = $this->q->getLength();
if ($vlen > $qlen) {
return $v->bitwise_rightShift($vlen - $qlen);
}
return $v;
}
/**
* Bit String to Octet String
*/
private function bits2octets(string $in): string
{
$z1 = $this->bits2int($in);
$z2 = $z1->subtract($this->q);
return $z2->compare(self::$zero) < 0 ?
$this->int2octets($z1) :
$this->int2octets($z2);
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Base Class for all block ciphers
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common;
/**
* Base Class for all block cipher classes
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class BlockCipher extends SymmetricKey
{
}

View File

@ -0,0 +1,60 @@
<?php
/**
* JSON Web Key (RFC7517) Handler
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
/**
* JSON Web Key Formatted Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class JWK
{
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
protected static function loadHelper($key): \stdClass
{
if (!Strings::is_stringable($key)) {
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
$key = preg_replace('#\s#', '', $key); // remove whitespace
$key = json_decode($key, null, 512, JSON_THROW_ON_ERROR);
if (isset($key->kty)) {
return $key;
}
if (count($key->keys) != 1) {
throw new \RuntimeException('Although the JWK key format supports multiple keys phpseclib does not');
}
return $key->keys[0];
}
/**
* Wrap a key appropriately
*/
protected static function wrapKey(array $key, array $options): string
{
return json_encode(['keys' => [$key + $options]]);
}
}

View File

@ -0,0 +1,217 @@
<?php
/**
* OpenSSH Key Handler
*
* PHP version 5
*
* Place in $HOME/.ssh/authorized_keys
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\AES;
use phpseclib3\Crypt\Random;
use phpseclib3\Exception\BadDecryptionException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnexpectedValueException;
/**
* OpenSSH Formatted RSA Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class OpenSSH
{
/**
* Default comment
*
* @var string
*/
protected static $comment = 'phpseclib-generated-key';
/**
* Binary key flag
*
* @var bool
*/
protected static $binary = false;
/**
* Sets the default comment
*/
public static function setComment(string $comment): void
{
self::$comment = str_replace(["\r", "\n"], '', $comment);
}
/**
* Break a public or private key down into its constituent components
*
* $type can be either ssh-dss or ssh-rsa
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): array
{
if (!Strings::is_stringable($key)) {
throw new UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
// key format is described here:
// https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.key?annotate=HEAD
if (str_contains($key, 'BEGIN OPENSSH PRIVATE KEY')) {
$key = preg_replace('#(?:^-.*?-[\r\n]*$)|\s#ms', '', $key);
$key = Strings::base64_decode($key);
$magic = Strings::shift($key, 15);
if ($magic != "openssh-key-v1\0") {
throw new RuntimeException('Expected openssh-key-v1');
}
[$ciphername, $kdfname, $kdfoptions, $numKeys] = Strings::unpackSSH2('sssN', $key);
if ($numKeys != 1) {
// if we wanted to support multiple keys we could update PublicKeyLoader to preview what the # of keys
// would be; it'd then call Common\Keys\OpenSSH.php::load() and get the paddedKey. it'd then pass
// that to the appropriate key loading parser $numKey times or something
throw new RuntimeException('Although the OpenSSH private key format supports multiple keys phpseclib does not');
}
switch ($ciphername) {
case 'none':
break;
case 'aes256-ctr':
if ($kdfname != 'bcrypt') {
throw new RuntimeException('Only the bcrypt kdf is supported (' . $kdfname . ' encountered)');
}
[$salt, $rounds] = Strings::unpackSSH2('sN', $kdfoptions);
$crypto = new AES('ctr');
//$crypto->setKeyLength(256);
//$crypto->disablePadding();
$crypto->setPassword($password, 'bcrypt', $salt, $rounds, 32);
break;
default:
throw new RuntimeException('The only supported ciphers are: none, aes256-ctr (' . $ciphername . ' is being used)');
}
[$publicKey, $paddedKey] = Strings::unpackSSH2('ss', $key);
[$type] = Strings::unpackSSH2('s', $publicKey);
if (isset($crypto)) {
$paddedKey = $crypto->decrypt($paddedKey);
}
[$checkint1, $checkint2] = Strings::unpackSSH2('NN', $paddedKey);
// any leftover bytes in $paddedKey are for padding? but they should be sequential bytes. eg. 1, 2, 3, etc.
if ($checkint1 != $checkint2) {
if (isset($crypto)) {
throw new BadDecryptionException('Unable to decrypt key - please verify the password you are using');
}
throw new RuntimeException("The two checkints do not match ($checkint1 vs. $checkint2)");
}
self::checkType($type);
return compact('type', 'publicKey', 'paddedKey');
}
$parts = explode(' ', $key, 3);
if (!isset($parts[1])) {
$key = base64_decode($parts[0]);
$comment = false;
} else {
$asciiType = $parts[0];
self::checkType($parts[0]);
$key = base64_decode($parts[1]);
$comment = $parts[2] ?? false;
}
if ($key === false) {
throw new UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
[$type] = Strings::unpackSSH2('s', $key);
self::checkType($type);
if (isset($asciiType) && $asciiType != $type) {
throw new RuntimeException('Two different types of keys are claimed: ' . $asciiType . ' and ' . $type);
}
if (strlen($key) <= 4) {
throw new UnexpectedValueException('Key appears to be malformed');
}
$publicKey = $key;
return compact('type', 'publicKey', 'comment');
}
/**
* Toggle between binary and printable keys
*
* Printable keys are what are generated by default. These are the ones that go in
* $HOME/.ssh/authorized_key.
*/
public static function setBinaryOutput(bool $enabled): void
{
self::$binary = $enabled;
}
/**
* Checks to see if the type is valid
*/
private static function checkType(string $candidate): void
{
if (!in_array($candidate, static::$types)) {
throw new RuntimeException("The key type ($candidate) is not equal to: " . implode(',', static::$types));
}
}
/**
* Wrap a private key appropriately
*
* @param string|false $password
*/
protected static function wrapPrivateKey(string $publicKey, string $privateKey, $password, array $options): string
{
[, $checkint] = unpack('N', Random::string(4));
$comment = $options['comment'] ?? self::$comment;
$paddedKey = Strings::packSSH2('NN', $checkint, $checkint) .
$privateKey .
Strings::packSSH2('s', $comment);
$usesEncryption = !empty($password) && is_string($password);
/*
from http://tools.ietf.org/html/rfc4253#section-6 :
Note that the length of the concatenation of 'packet_length',
'padding_length', 'payload', and 'random padding' MUST be a multiple
of the cipher block size or 8, whichever is larger.
*/
$blockSize = $usesEncryption ? 16 : 8;
$paddingLength = (($blockSize - 1) * strlen($paddedKey)) % $blockSize;
for ($i = 1; $i <= $paddingLength; $i++) {
$paddedKey .= chr($i);
}
if (!$usesEncryption) {
$key = Strings::packSSH2('sssNss', 'none', 'none', '', 1, $publicKey, $paddedKey);
} else {
$rounds = $options['rounds'] ?? 16;
$salt = Random::string(16);
$kdfoptions = Strings::packSSH2('sN', $salt, $rounds);
$crypto = new AES('ctr');
$crypto->setPassword($password, 'bcrypt', $salt, $rounds, 32);
$paddedKey = $crypto->encrypt($paddedKey);
$key = Strings::packSSH2('sssNss', 'aes256-ctr', 'bcrypt', $kdfoptions, 1, $publicKey, $paddedKey);
}
$key = "openssh-key-v1\0$key";
return "-----BEGIN OPENSSH PRIVATE KEY-----\n" .
chunk_split(Strings::base64_encode($key), 70, "\n") .
"-----END OPENSSH PRIVATE KEY-----\n";
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* PKCS Formatted Key Handler
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Formats\Keys;
/**
* PKCS1 Formatted Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PKCS
{
/**
* Auto-detect the format
*/
public const MODE_ANY = 0;
/**
* Require base64-encoded PEM's be supplied
*/
public const MODE_PEM = 1;
/**
* Require raw DER's be supplied
*/
public const MODE_DER = 2;
/**#@-*/
/**
* Is the key a base-64 encoded PEM, DER or should it be auto-detected?
*
* @var int
*/
protected static $format = self::MODE_ANY;
/**
* Require base64-encoded PEM's be supplied
*/
public static function requirePEM(): void
{
self::$format = self::MODE_PEM;
}
/**
* Require raw DER's be supplied
*/
public static function requireDER(): void
{
self::$format = self::MODE_DER;
}
/**
* Accept any format and auto detect the format
*
* This is the default setting
*/
public static function requireAny(): void
{
self::$format = self::MODE_ANY;
}
}

View File

@ -0,0 +1,195 @@
<?php
/**
* PKCS1 Formatted Key Handler
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\AES;
use phpseclib3\Crypt\DES;
use phpseclib3\Crypt\Random;
use phpseclib3\Crypt\TripleDES;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Exception\UnsupportedAlgorithmException;
use phpseclib3\File\ASN1;
/**
* PKCS1 Formatted Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PKCS1 extends PKCS
{
/**
* Default encryption algorithm
*
* @var string
*/
private static $defaultEncryptionAlgorithm = 'AES-128-CBC';
/**
* Sets the default encryption algorithm
*/
public static function setEncryptionAlgorithm(string $algo): void
{
self::$defaultEncryptionAlgorithm = $algo;
}
/**
* Returns the mode constant corresponding to the mode string
*
* @return int
* @throws UnexpectedValueException if the block cipher mode is unsupported
*/
private static function getEncryptionMode(string $mode)
{
switch ($mode) {
case 'CBC':
case 'ECB':
case 'CFB':
case 'OFB':
case 'CTR':
return $mode;
}
throw new UnexpectedValueException('Unsupported block cipher mode of operation');
}
/**
* Returns a cipher object corresponding to a string
*
* @return AES|DES|TripleDES
* @throws UnexpectedValueException if the encryption algorithm is unsupported
*/
private static function getEncryptionObject(string $algo)
{
$modes = '(CBC|ECB|CFB|OFB|CTR)';
switch (true) {
case preg_match("#^AES-(128|192|256)-$modes$#", $algo, $matches):
$cipher = new AES(self::getEncryptionMode($matches[2]));
$cipher->setKeyLength((int) $matches[1]);
return $cipher;
case preg_match("#^DES-EDE3-$modes$#", $algo, $matches):
return new TripleDES(self::getEncryptionMode($matches[1]));
case preg_match("#^DES-$modes$#", $algo, $matches):
return new DES(self::getEncryptionMode($matches[1]));
default:
throw new UnsupportedAlgorithmException($algo . ' is not a supported algorithm');
}
}
/**
* Generate a symmetric key for PKCS#1 keys
*/
private static function generateSymmetricKey(string $password, string $iv, int $length): string
{
$symkey = '';
$iv = substr($iv, 0, 8);
while (strlen($symkey) < $length) {
$symkey .= md5($symkey . $password . $iv, true);
}
return substr($symkey, 0, $length);
}
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
* @return array|string
*/
protected static function load($key, ?string $password = null)
{
if (!Strings::is_stringable($key)) {
throw new UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
/* Although PKCS#1 proposes a format that public and private keys can use, encrypting them is
"outside the scope" of PKCS#1. PKCS#1 then refers you to PKCS#12 and PKCS#15 if you're wanting to
protect private keys, however, that's not what OpenSSL* does. OpenSSL protects private keys by adding
two new "fields" to the key - DEK-Info and Proc-Type. These fields are discussed here:
http://tools.ietf.org/html/rfc1421#section-4.6.1.1
http://tools.ietf.org/html/rfc1421#section-4.6.1.3
DES-EDE3-CBC as an algorithm, however, is not discussed anywhere, near as I can tell.
DES-CBC and DES-EDE are discussed in RFC1423, however, DES-EDE3-CBC isn't, nor is its key derivation
function. As is, the definitive authority on this encoding scheme isn't the IETF but rather OpenSSL's
own implementation. ie. the implementation *is* the standard and any bugs that may exist in that
implementation are part of the standard, as well.
* OpenSSL is the de facto standard. It's utilized by OpenSSH and other projects */
if (preg_match('#DEK-Info: (.+),(.+)#', $key, $matches)) {
$iv = Strings::hex2bin(trim($matches[2]));
// remove the Proc-Type / DEK-Info sections as they're no longer needed
$key = preg_replace('#^(?:Proc-Type|DEK-Info): .*#m', '', $key);
$ciphertext = ASN1::extractBER($key);
if ($ciphertext === false) {
$ciphertext = $key;
}
$crypto = self::getEncryptionObject($matches[1]);
$crypto->setKey(self::generateSymmetricKey($password, $iv, $crypto->getKeyLength() >> 3));
$crypto->setIV($iv);
$key = $crypto->decrypt($ciphertext);
} else {
if (self::$format != self::MODE_DER) {
$decoded = ASN1::extractBER($key);
if ($decoded !== false) {
$key = $decoded;
} elseif (self::$format == self::MODE_PEM) {
throw new UnexpectedValueException('Expected base64-encoded PEM format but was unable to decode base64 text');
}
}
}
return $key;
}
/**
* Wrap a private key appropriately
*
* @param string|false $password
* @param array $options optional
*/
protected static function wrapPrivateKey(string $key, string $type, $password, array $options = []): string
{
if (empty($password) || !is_string($password)) {
return "-----BEGIN $type PRIVATE KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END $type PRIVATE KEY-----";
}
$encryptionAlgorithm = $options['encryptionAlgorithm'] ?? self::$defaultEncryptionAlgorithm;
$cipher = self::getEncryptionObject($encryptionAlgorithm);
$iv = Random::string($cipher->getBlockLength() >> 3);
$cipher->setKey(self::generateSymmetricKey($password, $iv, $cipher->getKeyLength() >> 3));
$cipher->setIV($iv);
$iv = strtoupper(Strings::bin2hex($iv));
return "-----BEGIN $type PRIVATE KEY-----\r\n" .
"Proc-Type: 4,ENCRYPTED\r\n" .
"DEK-Info: " . $encryptionAlgorithm . ",$iv\r\n" .
"\r\n" .
chunk_split(Strings::base64_encode($cipher->encrypt($key)), 64) .
"-----END $type PRIVATE KEY-----";
}
/**
* Wrap a public key appropriately
*/
protected static function wrapPublicKey(string $key, string $type): string
{
return "-----BEGIN $type PUBLIC KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END $type PUBLIC KEY-----";
}
}

View File

@ -0,0 +1,697 @@
<?php
/**
* PKCS#8 Formatted Key Handler
*
* PHP version 5
*
* Used by PHP's openssl_public_encrypt() and openssl's rsautl (when -pubin is set)
*
* Processes keys with the following headers:
*
* -----BEGIN ENCRYPTED PRIVATE KEY-----
* -----BEGIN PRIVATE KEY-----
* -----BEGIN PUBLIC KEY-----
*
* Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
* is specific to private keys it's basically creating a DER-encoded wrapper
* for keys. This just extends that same concept to public keys (much like ssh-keygen)
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\AES;
use phpseclib3\Crypt\Common\SymmetricKey;
use phpseclib3\Crypt\DES;
use phpseclib3\Crypt\Random;
use phpseclib3\Crypt\RC2;
use phpseclib3\Crypt\RC4;
use phpseclib3\Crypt\TripleDES;
use phpseclib3\Exception\InsufficientSetupException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Exception\UnsupportedAlgorithmException;
use phpseclib3\File\ASN1;
use phpseclib3\File\ASN1\Maps;
/**
* PKCS#8 Formatted Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PKCS8 extends PKCS
{
/**
* Default encryption algorithm
*
* @var string
*/
private static $defaultEncryptionAlgorithm = 'id-PBES2';
/**
* Default encryption scheme
*
* Only used when defaultEncryptionAlgorithm is id-PBES2
*
* @var string
*/
private static $defaultEncryptionScheme = 'aes128-CBC-PAD';
/**
* Default PRF
*
* Only used when defaultEncryptionAlgorithm is id-PBES2
*
* @var string
*/
private static $defaultPRF = 'id-hmacWithSHA256';
/**
* Default Iteration Count
*
* @var int
*/
private static $defaultIterationCount = 2048;
/**
* OIDs loaded
*
* @var bool
*/
private static $oidsLoaded = false;
/**
* Sets the default encryption algorithm
*/
public static function setEncryptionAlgorithm(string $algo): void
{
self::$defaultEncryptionAlgorithm = $algo;
}
/**
* Sets the default encryption algorithm for PBES2
*/
public static function setEncryptionScheme(string $algo): void
{
self::$defaultEncryptionScheme = $algo;
}
/**
* Sets the iteration count
*/
public static function setIterationCount(int $count): void
{
self::$defaultIterationCount = $count;
}
/**
* Sets the PRF for PBES2
*/
public static function setPRF(string $algo): void
{
self::$defaultPRF = $algo;
}
/**
* Returns a SymmetricKey object based on a PBES1 $algo
*
* @return SymmetricKey
*/
private static function getPBES1EncryptionObject(string $algo)
{
$algo = preg_match('#^pbeWith(?:MD2|MD5|SHA1|SHA)And(.*?)-CBC$#', $algo, $matches) ?
$matches[1] :
substr($algo, 13); // strlen('pbeWithSHAAnd') == 13
switch ($algo) {
case 'DES':
$cipher = new DES('cbc');
break;
case 'RC2':
$cipher = new RC2('cbc');
$cipher->setKeyLength(64);
break;
case '3-KeyTripleDES':
$cipher = new TripleDES('cbc');
break;
case '2-KeyTripleDES':
$cipher = new TripleDES('cbc');
$cipher->setKeyLength(128);
break;
case '128BitRC2':
$cipher = new RC2('cbc');
$cipher->setKeyLength(128);
break;
case '40BitRC2':
$cipher = new RC2('cbc');
$cipher->setKeyLength(40);
break;
case '128BitRC4':
$cipher = new RC4();
$cipher->setKeyLength(128);
break;
case '40BitRC4':
$cipher = new RC4();
$cipher->setKeyLength(40);
break;
default:
throw new UnsupportedAlgorithmException("$algo is not a supported algorithm");
}
return $cipher;
}
/**
* Returns a hash based on a PBES1 $algo
*/
private static function getPBES1Hash(string $algo): string
{
if (preg_match('#^pbeWith(MD2|MD5|SHA1|SHA)And.*?-CBC$#', $algo, $matches)) {
return $matches[1] == 'SHA' ? 'sha1' : $matches[1];
}
return 'sha1';
}
/**
* Returns a KDF baesd on a PBES1 $algo
*/
private static function getPBES1KDF(string $algo): string
{
switch ($algo) {
case 'pbeWithMD2AndDES-CBC':
case 'pbeWithMD2AndRC2-CBC':
case 'pbeWithMD5AndDES-CBC':
case 'pbeWithMD5AndRC2-CBC':
case 'pbeWithSHA1AndDES-CBC':
case 'pbeWithSHA1AndRC2-CBC':
return 'pbkdf1';
}
return 'pkcs12';
}
/**
* Returns a SymmetricKey object baesd on a PBES2 $algo
*/
private static function getPBES2EncryptionObject(string $algo): SymmetricKey
{
switch ($algo) {
case 'desCBC':
$cipher = new DES('cbc');
break;
case 'des-EDE3-CBC':
$cipher = new TripleDES('cbc');
break;
case 'rc2CBC':
$cipher = new RC2('cbc');
// in theory this can be changed
$cipher->setKeyLength(128);
break;
case 'rc5-CBC-PAD':
throw new UnsupportedAlgorithmException('rc5-CBC-PAD is not supported for PBES2 PKCS#8 keys');
case 'aes128-CBC-PAD':
case 'aes192-CBC-PAD':
case 'aes256-CBC-PAD':
$cipher = new AES('cbc');
$cipher->setKeyLength((int) substr($algo, 3, 3));
break;
default:
throw new UnsupportedAlgorithmException("$algo is not supported");
}
return $cipher;
}
/**
* Initialize static variables
*/
private static function initialize_static_variables(): void
{
if (!isset(static::$childOIDsLoaded)) {
throw new InsufficientSetupException('This class should not be called directly');
}
if (!static::$childOIDsLoaded) {
ASN1::loadOIDs(is_array(static::OID_NAME) ?
array_combine(static::OID_NAME, static::OID_VALUE) :
[static::OID_NAME => static::OID_VALUE]);
static::$childOIDsLoaded = true;
}
if (!self::$oidsLoaded) {
// from https://tools.ietf.org/html/rfc2898
ASN1::loadOIDs([
// PBES1 encryption schemes
'pbeWithMD2AndDES-CBC' => '1.2.840.113549.1.5.1',
'pbeWithMD2AndRC2-CBC' => '1.2.840.113549.1.5.4',
'pbeWithMD5AndDES-CBC' => '1.2.840.113549.1.5.3',
'pbeWithMD5AndRC2-CBC' => '1.2.840.113549.1.5.6',
'pbeWithSHA1AndDES-CBC' => '1.2.840.113549.1.5.10',
'pbeWithSHA1AndRC2-CBC' => '1.2.840.113549.1.5.11',
// from PKCS#12:
// https://tools.ietf.org/html/rfc7292
'pbeWithSHAAnd128BitRC4' => '1.2.840.113549.1.12.1.1',
'pbeWithSHAAnd40BitRC4' => '1.2.840.113549.1.12.1.2',
'pbeWithSHAAnd3-KeyTripleDES-CBC' => '1.2.840.113549.1.12.1.3',
'pbeWithSHAAnd2-KeyTripleDES-CBC' => '1.2.840.113549.1.12.1.4',
'pbeWithSHAAnd128BitRC2-CBC' => '1.2.840.113549.1.12.1.5',
'pbeWithSHAAnd40BitRC2-CBC' => '1.2.840.113549.1.12.1.6',
'id-PBKDF2' => '1.2.840.113549.1.5.12',
'id-PBES2' => '1.2.840.113549.1.5.13',
'id-PBMAC1' => '1.2.840.113549.1.5.14',
// from PKCS#5 v2.1:
// http://www.rsa.com/rsalabs/pkcs/files/h11302-wp-pkcs5v2-1-password-based-cryptography-standard.pdf
'id-hmacWithSHA1' => '1.2.840.113549.2.7',
'id-hmacWithSHA224' => '1.2.840.113549.2.8',
'id-hmacWithSHA256' => '1.2.840.113549.2.9',
'id-hmacWithSHA384' => '1.2.840.113549.2.10',
'id-hmacWithSHA512' => '1.2.840.113549.2.11',
'id-hmacWithSHA512-224' => '1.2.840.113549.2.12',
'id-hmacWithSHA512-256' => '1.2.840.113549.2.13',
'desCBC' => '1.3.14.3.2.7',
'des-EDE3-CBC' => '1.2.840.113549.3.7',
'rc2CBC' => '1.2.840.113549.3.2',
'rc5-CBC-PAD' => '1.2.840.113549.3.9',
'aes128-CBC-PAD' => '2.16.840.1.101.3.4.1.2',
'aes192-CBC-PAD' => '2.16.840.1.101.3.4.1.22',
'aes256-CBC-PAD' => '2.16.840.1.101.3.4.1.42',
]);
self::$oidsLoaded = true;
}
}
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
protected static function load($key, ?string $password = null): array
{
if (!Strings::is_stringable($key)) {
throw new UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
$isPublic = str_contains($key, 'PUBLIC');
$isPrivate = str_contains($key, 'PRIVATE');
$decoded = self::preParse($key);
$meta = [];
$decrypted = ASN1::asn1map($decoded[0], Maps\EncryptedPrivateKeyInfo::MAP);
if ($password !== null && strlen($password) && is_array($decrypted)) {
$algorithm = $decrypted['encryptionAlgorithm']['algorithm'];
switch ($algorithm) {
// PBES1
case 'pbeWithMD2AndDES-CBC':
case 'pbeWithMD2AndRC2-CBC':
case 'pbeWithMD5AndDES-CBC':
case 'pbeWithMD5AndRC2-CBC':
case 'pbeWithSHA1AndDES-CBC':
case 'pbeWithSHA1AndRC2-CBC':
case 'pbeWithSHAAnd3-KeyTripleDES-CBC':
case 'pbeWithSHAAnd2-KeyTripleDES-CBC':
case 'pbeWithSHAAnd128BitRC2-CBC':
case 'pbeWithSHAAnd40BitRC2-CBC':
case 'pbeWithSHAAnd128BitRC4':
case 'pbeWithSHAAnd40BitRC4':
$cipher = self::getPBES1EncryptionObject($algorithm);
$hash = self::getPBES1Hash($algorithm);
$kdf = self::getPBES1KDF($algorithm);
$meta['meta']['algorithm'] = $algorithm;
$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
if (!$temp) {
throw new RuntimeException('Unable to decode BER');
}
extract(ASN1::asn1map($temp[0], Maps\PBEParameter::MAP));
$iterationCount = (int) $iterationCount->toString();
$cipher->setPassword($password, $kdf, $hash, $salt, $iterationCount);
$key = $cipher->decrypt($decrypted['encryptedData']);
$decoded = ASN1::decodeBER($key);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER 2');
}
break;
case 'id-PBES2':
$meta['meta']['algorithm'] = $algorithm;
$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
if (!$temp) {
throw new RuntimeException('Unable to decode BER');
}
$temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP);
extract($temp);
$cipher = self::getPBES2EncryptionObject($encryptionScheme['algorithm']);
$meta['meta']['cipher'] = $encryptionScheme['algorithm'];
$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
if (!$temp) {
throw new RuntimeException('Unable to decode BER');
}
$temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP);
extract($temp);
if (!$cipher instanceof RC2) {
$cipher->setIV($encryptionScheme['parameters']['octetString']);
} else {
$temp = ASN1::decodeBER($encryptionScheme['parameters']);
if (!$temp) {
throw new RuntimeException('Unable to decode BER');
}
extract(ASN1::asn1map($temp[0], Maps\RC2CBCParameter::MAP));
$effectiveKeyLength = (int) $rc2ParametersVersion->toString();
switch ($effectiveKeyLength) {
case 160:
$effectiveKeyLength = 40;
break;
case 120:
$effectiveKeyLength = 64;
break;
case 58:
$effectiveKeyLength = 128;
break;
//default: // should be >= 256
}
$cipher->setIV($iv);
$cipher->setKeyLength($effectiveKeyLength);
}
$meta['meta']['keyDerivationFunc'] = $keyDerivationFunc['algorithm'];
switch ($keyDerivationFunc['algorithm']) {
case 'id-PBKDF2':
$temp = ASN1::decodeBER($keyDerivationFunc['parameters']);
if (!$temp) {
throw new RuntimeException('Unable to decode BER');
}
$prf = ['algorithm' => 'id-hmacWithSHA1'];
$params = ASN1::asn1map($temp[0], Maps\PBKDF2params::MAP);
extract($params);
$meta['meta']['prf'] = $prf['algorithm'];
$hash = str_replace('-', '/', substr($prf['algorithm'], 11));
$params = [
$password,
'pbkdf2',
$hash,
$salt,
(int) $iterationCount->toString(),
];
if (isset($keyLength)) {
$params[] = (int) $keyLength->toString();
}
$cipher->setPassword(...$params);
$key = $cipher->decrypt($decrypted['encryptedData']);
$decoded = ASN1::decodeBER($key);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER 3');
}
break;
default:
throw new UnsupportedAlgorithmException('Only PBKDF2 is supported for PBES2 PKCS#8 keys');
}
break;
case 'id-PBMAC1':
//$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
//$value = ASN1::asn1map($temp[0], Maps\PBMAC1params::MAP);
// since i can't find any implementation that does PBMAC1 it is unsupported
throw new UnsupportedAlgorithmException('Only PBES1 and PBES2 PKCS#8 keys are supported.');
// at this point we'll assume that the key conforms to PublicKeyInfo
}
}
$private = ASN1::asn1map($decoded[0], Maps\OneAsymmetricKey::MAP);
if (is_array($private)) {
if ($isPublic) {
throw new UnexpectedValueException('Human readable string claims public key but DER encoded string claims private key');
}
if (isset($private['privateKeyAlgorithm']['parameters']) && !$private['privateKeyAlgorithm']['parameters'] instanceof ASN1\Element && isset($decoded[0]['content'][1]['content'][1])) {
$temp = $decoded[0]['content'][1]['content'][1];
$private['privateKeyAlgorithm']['parameters'] = new ASN1\Element(substr($key, $temp['start'], $temp['length']));
}
if (is_array(static::OID_NAME)) {
if (!in_array($private['privateKeyAlgorithm']['algorithm'], static::OID_NAME)) {
throw new UnsupportedAlgorithmException($private['privateKeyAlgorithm']['algorithm'] . ' is not a supported key type');
}
} else {
if ($private['privateKeyAlgorithm']['algorithm'] != static::OID_NAME) {
throw new UnsupportedAlgorithmException('Only ' . static::OID_NAME . ' keys are supported; this is a ' . $private['privateKeyAlgorithm']['algorithm'] . ' key');
}
}
if (isset($private['publicKey'])) {
if ($private['publicKey'][0] != "\0") {
throw new UnexpectedValueException('The first byte of the public key should be null - not ' . bin2hex($private['publicKey'][0]));
}
$private['publicKey'] = substr($private['publicKey'], 1);
}
return $private + $meta;
}
// EncryptedPrivateKeyInfo and PublicKeyInfo have largely identical "signatures". the only difference
// is that the former has an octet string and the later has a bit string. the first byte of a bit
// string represents the number of bits in the last byte that are to be ignored but, currently,
// bit strings wanting a non-zero amount of bits trimmed are not supported
$public = ASN1::asn1map($decoded[0], Maps\PublicKeyInfo::MAP);
if (is_array($public)) {
if ($isPrivate) {
throw new UnexpectedValueException('Human readable string claims private key but DER encoded string claims public key');
}
if ($public['publicKey'][0] != "\0") {
throw new UnexpectedValueException('The first byte of the public key should be null - not ' . bin2hex($public['publicKey'][0]));
}
if (is_array(static::OID_NAME)) {
if (!in_array($public['publicKeyAlgorithm']['algorithm'], static::OID_NAME)) {
throw new UnsupportedAlgorithmException($public['publicKeyAlgorithm']['algorithm'] . ' is not a supported key type');
}
} else {
if ($public['publicKeyAlgorithm']['algorithm'] != static::OID_NAME) {
throw new UnsupportedAlgorithmException('Only ' . static::OID_NAME . ' keys are supported; this is a ' . $public['publicKeyAlgorithm']['algorithm'] . ' key');
}
}
if (isset($public['publicKeyAlgorithm']['parameters']) && !$public['publicKeyAlgorithm']['parameters'] instanceof ASN1\Element && isset($decoded[0]['content'][0]['content'][1])) {
$temp = $decoded[0]['content'][0]['content'][1];
$public['publicKeyAlgorithm']['parameters'] = new ASN1\Element(substr($key, $temp['start'], $temp['length']));
}
$public['publicKey'] = substr($public['publicKey'], 1);
return $public;
}
throw new RuntimeException('Unable to parse using either OneAsymmetricKey or PublicKeyInfo ASN1 maps');
}
/**
* Wrap a private key appropriately
*
* @param array|string $attr
* @param string|false $password
* @param string|null $oid optional
* @param string $publicKey optional
* @param array $options optional
*/
protected static function wrapPrivateKey(string $key, $attr, $params, $password, ?string $oid = null, string $publicKey = '', array $options = []): string
{
self::initialize_static_variables();
$key = [
'version' => 'v1',
'privateKeyAlgorithm' => [
'algorithm' => is_string(static::OID_NAME) ? static::OID_NAME : $oid,
],
'privateKey' => $key,
];
if ($oid != 'id-Ed25519' && $oid != 'id-Ed448') {
$key['privateKeyAlgorithm']['parameters'] = $params;
}
if (!empty($attr)) {
$key['attributes'] = $attr;
}
if (!empty($publicKey)) {
$key['version'] = 'v2';
$key['publicKey'] = $publicKey;
}
$key = ASN1::encodeDER($key, Maps\OneAsymmetricKey::MAP);
if (!empty($password) && is_string($password)) {
$salt = Random::string(8);
$iterationCount = $options['iterationCount'] ?? self::$defaultIterationCount;
$encryptionAlgorithm = $options['encryptionAlgorithm'] ?? self::$defaultEncryptionAlgorithm;
$encryptionScheme = $options['encryptionScheme'] ?? self::$defaultEncryptionScheme;
$prf = $options['PRF'] ?? self::$defaultPRF;
if ($encryptionAlgorithm == 'id-PBES2') {
$crypto = self::getPBES2EncryptionObject($encryptionScheme);
$hash = str_replace('-', '/', substr($prf, 11));
$kdf = 'pbkdf2';
$iv = Random::string($crypto->getBlockLength() >> 3);
$PBKDF2params = [
'salt' => $salt,
'iterationCount' => $iterationCount,
'prf' => ['algorithm' => $prf, 'parameters' => null],
];
$PBKDF2params = ASN1::encodeDER($PBKDF2params, Maps\PBKDF2params::MAP);
if (!$crypto instanceof RC2) {
$params = ['octetString' => $iv];
} else {
$params = [
'rc2ParametersVersion' => 58,
'iv' => $iv,
];
$params = ASN1::encodeDER($params, Maps\RC2CBCParameter::MAP);
$params = new ASN1\Element($params);
}
$params = [
'keyDerivationFunc' => [
'algorithm' => 'id-PBKDF2',
'parameters' => new ASN1\Element($PBKDF2params),
],
'encryptionScheme' => [
'algorithm' => $encryptionScheme,
'parameters' => $params,
],
];
$params = ASN1::encodeDER($params, Maps\PBES2params::MAP);
$crypto->setIV($iv);
} else {
$crypto = self::getPBES1EncryptionObject($encryptionAlgorithm);
$hash = self::getPBES1Hash($encryptionAlgorithm);
$kdf = self::getPBES1KDF($encryptionAlgorithm);
$params = [
'salt' => $salt,
'iterationCount' => $iterationCount,
];
$params = ASN1::encodeDER($params, Maps\PBEParameter::MAP);
}
$crypto->setPassword($password, $kdf, $hash, $salt, $iterationCount);
$key = $crypto->encrypt($key);
$key = [
'encryptionAlgorithm' => [
'algorithm' => $encryptionAlgorithm,
'parameters' => new ASN1\Element($params),
],
'encryptedData' => $key,
];
$key = ASN1::encodeDER($key, Maps\EncryptedPrivateKeyInfo::MAP);
return "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END ENCRYPTED PRIVATE KEY-----";
}
return "-----BEGIN PRIVATE KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END PRIVATE KEY-----";
}
/**
* Wrap a public key appropriately
*/
protected static function wrapPublicKey(string $key, $params, ?string $oid = null): string
{
self::initialize_static_variables();
$key = [
'publicKeyAlgorithm' => [
'algorithm' => is_string(static::OID_NAME) ? static::OID_NAME : $oid,
],
'publicKey' => "\0" . $key,
];
if ($oid != 'id-Ed25519' && $oid != 'id-Ed448') {
$key['publicKeyAlgorithm']['parameters'] = $params;
}
$key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP);
return "-----BEGIN PUBLIC KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END PUBLIC KEY-----";
}
/**
* Perform some preliminary parsing of the key
*
* @param string|array $key
*/
private static function preParse(&$key): array
{
self::initialize_static_variables();
if (self::$format != self::MODE_DER) {
$decoded = ASN1::extractBER($key);
if ($decoded !== false) {
$key = $decoded;
} elseif (self::$format == self::MODE_PEM) {
throw new UnexpectedValueException('Expected base64-encoded PEM format but was unable to decode base64 text');
}
}
$decoded = ASN1::decodeBER($key);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER');
}
return $decoded;
}
/**
* Returns the encryption parameters used by the key
*/
public static function extractEncryptionAlgorithm(string $key): array
{
if (!Strings::is_stringable($key)) {
throw new UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
$decoded = self::preParse($key);
$r = ASN1::asn1map($decoded[0], ASN1\Maps\EncryptedPrivateKeyInfo::MAP);
if (!is_array($r)) {
throw new RuntimeException('Unable to parse using EncryptedPrivateKeyInfo map');
}
if ($r['encryptionAlgorithm']['algorithm'] == 'id-PBES2') {
$decoded = ASN1::decodeBER($r['encryptionAlgorithm']['parameters']->element);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER');
}
$r['encryptionAlgorithm']['parameters'] = ASN1::asn1map($decoded[0], ASN1\Maps\PBES2params::MAP);
$kdf = &$r['encryptionAlgorithm']['parameters']['keyDerivationFunc'];
switch ($kdf['algorithm']) {
case 'id-PBKDF2':
$decoded = ASN1::decodeBER($kdf['parameters']->element);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER');
}
$kdf['parameters'] = ASN1::asn1map($decoded[0], Maps\PBKDF2params::MAP);
}
}
return $r['encryptionAlgorithm'];
}
}

View File

@ -0,0 +1,353 @@
<?php
/**
* PuTTY Formatted Key Handler
*
* See PuTTY's SSHPUBK.C and https://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixC.html
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\AES;
use phpseclib3\Crypt\Hash;
use phpseclib3\Crypt\Random;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Exception\UnsupportedAlgorithmException;
/**
* PuTTY Formatted Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PuTTY
{
/**
* Default comment
*
* @var string
*/
private static $comment = 'phpseclib-generated-key';
/**
* Default version
*
* @var int
*/
private static $version = 2;
/**
* Sets the default comment
*/
public static function setComment(string $comment): void
{
self::$comment = str_replace(["\r", "\n"], '', $comment);
}
/**
* Sets the default version
*/
public static function setVersion(int $version): void
{
if ($version != 2 && $version != 3) {
throw new RuntimeException('Only supported versions are 2 and 3');
}
self::$version = $version;
}
/**
* Generate a symmetric key for PuTTY v2 keys
*/
private static function generateV2Key(string $password, int $length): string
{
$symkey = '';
$sequence = 0;
while (strlen($symkey) < $length) {
$temp = pack('Na*', $sequence++, $password);
$symkey .= Strings::hex2bin(sha1($temp));
}
return substr($symkey, 0, $length);
}
/**
* Generate a symmetric key for PuTTY v3 keys
*/
private static function generateV3Key(string $password, string $flavour, int $memory, int $passes, string $salt): array
{
if (!function_exists('sodium_crypto_pwhash')) {
throw new RuntimeException('sodium_crypto_pwhash needs to exist for Argon2 password hasing');
}
switch ($flavour) {
case 'Argon2i':
$flavour = SODIUM_CRYPTO_PWHASH_ALG_ARGON2I13;
break;
case 'Argon2id':
$flavour = SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13;
break;
default:
throw new UnsupportedAlgorithmException('Only Argon2i and Argon2id are supported');
}
$length = 80; // keylen + ivlen + mac_keylen
$temp = sodium_crypto_pwhash($length, $password, $salt, $passes, $memory << 10, $flavour);
$symkey = substr($temp, 0, 32);
$symiv = substr($temp, 32, 16);
$hashkey = substr($temp, -32);
return compact('symkey', 'symiv', 'hashkey');
}
/**
* Break a public or private key down into its constituent components
*
* @param array|string $key
* @param string|false $password
* @return array|false
*/
public static function load($key, $password)
{
if (!Strings::is_stringable($key)) {
throw new UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
if (str_contains($key, 'BEGIN SSH2 PUBLIC KEY')) {
$lines = preg_split('#[\r\n]+#', $key);
switch (true) {
case $lines[0] != '---- BEGIN SSH2 PUBLIC KEY ----':
throw new UnexpectedValueException('Key doesn\'t start with ---- BEGIN SSH2 PUBLIC KEY ----');
case $lines[count($lines) - 1] != '---- END SSH2 PUBLIC KEY ----':
throw new UnexpectedValueException('Key doesn\'t end with ---- END SSH2 PUBLIC KEY ----');
}
$lines = array_splice($lines, 1, -1);
$lines = array_map(fn ($line) => rtrim($line, "\r\n"), $lines);
$data = $current = '';
$values = [];
$in_value = false;
foreach ($lines as $line) {
switch (true) {
case preg_match('#^(.*?): (.*)#', $line, $match):
$in_value = $line[-1] == '\\';
$current = strtolower($match[1]);
$values[$current] = $in_value ? substr($match[2], 0, -1) : $match[2];
break;
case $in_value:
$in_value = $line[-1] == '\\';
$values[$current] .= $in_value ? substr($line, 0, -1) : $line;
break;
default:
$data .= $line;
}
}
$components = call_user_func([static::PUBLIC_HANDLER, 'load'], $data);
if ($components === false) {
throw new UnexpectedValueException('Unable to decode public key');
}
$components += $values;
$components['comment'] = str_replace(['\\\\', '\"'], ['\\', '"'], $values['comment']);
return $components;
}
$components = [];
$key = preg_split('#\r\n|\r|\n#', trim($key));
if (Strings::shift($key[0], strlen('PuTTY-User-Key-File-')) != 'PuTTY-User-Key-File-') {
return false;
}
$version = (int) Strings::shift($key[0], 3); // should be either "2: " or "3: 0" prior to int casting
if ($version != 2 && $version != 3) {
throw new RuntimeException('Only v2 and v3 PuTTY private keys are supported');
}
$components['type'] = $type = rtrim($key[0]);
if (!in_array($type, static::$types)) {
$error = count(static::$types) == 1 ?
'Only ' . static::$types[0] . ' keys are supported. ' :
'';
throw new UnsupportedAlgorithmException($error . 'This is an unsupported ' . $type . ' key');
}
$encryption = trim(preg_replace('#Encryption: (.+)#', '$1', $key[1]));
$components['comment'] = trim(preg_replace('#Comment: (.+)#', '$1', $key[2]));
$publicLength = (int) trim(preg_replace('#Public-Lines: (\d+)#', '$1', $key[3]));
$public = Strings::base64_decode(implode('', array_map('trim', array_slice($key, 4, $publicLength))));
$source = Strings::packSSH2('ssss', $type, $encryption, $components['comment'], $public);
extract(unpack('Nlength', Strings::shift($public, 4)));
$newtype = Strings::shift($public, $length);
if ($newtype != $type) {
throw new RuntimeException('The binary type does not match the human readable type field');
}
$components['public'] = $public;
switch ($version) {
case 3:
$hashkey = '';
break;
case 2:
$hashkey = 'putty-private-key-file-mac-key';
}
$offset = $publicLength + 4;
switch ($encryption) {
case 'aes256-cbc':
$crypto = new AES('cbc');
switch ($version) {
case 3:
$flavour = trim(preg_replace('#Key-Derivation: (.*)#', '$1', $key[$offset++]));
$memory = trim(preg_replace('#Argon2-Memory: (\d+)#', '$1', $key[$offset++]));
$passes = trim(preg_replace('#Argon2-Passes: (\d+)#', '$1', $key[$offset++]));
$parallelism = trim(preg_replace('#Argon2-Parallelism: (\d+)#', '$1', $key[$offset++]));
$salt = Strings::hex2bin(trim(preg_replace('#Argon2-Salt: ([0-9a-f]+)#', '$1', $key[$offset++])));
extract(self::generateV3Key($password, $flavour, (int)$memory, (int)$passes, $salt));
break;
case 2:
$symkey = self::generateV2Key($password, 32);
$symiv = str_repeat("\0", $crypto->getBlockLength() >> 3);
$hashkey .= $password;
}
}
switch ($version) {
case 3:
$hash = new Hash('sha256');
$hash->setKey($hashkey);
break;
case 2:
$hash = new Hash('sha1');
$hash->setKey(sha1($hashkey, true));
}
$privateLength = (int) trim(preg_replace('#Private-Lines: (\d+)#', '$1', $key[$offset++]));
$private = Strings::base64_decode(implode('', array_map('trim', array_slice($key, $offset, $privateLength))));
if ($encryption != 'none') {
$crypto->setKey($symkey);
$crypto->setIV($symiv);
$crypto->disablePadding();
$private = $crypto->decrypt($private);
}
$source .= Strings::packSSH2('s', $private);
$hmac = trim(preg_replace('#Private-MAC: (.+)#', '$1', $key[$offset + $privateLength]));
$hmac = Strings::hex2bin($hmac);
if (!hash_equals($hash->hash($source), $hmac)) {
throw new UnexpectedValueException('MAC validation error');
}
$components['private'] = $private;
return $components;
}
/**
* Wrap a private key appropriately
*
* @param string|false $password
* @param array $options optional
*/
protected static function wrapPrivateKey(string $public, string $private, string $type, $password, array $options = []): string
{
$encryption = (!empty($password) || is_string($password)) ? 'aes256-cbc' : 'none';
$comment = $options['comment'] ?? self::$comment;
$version = $options['version'] ?? self::$version;
$key = "PuTTY-User-Key-File-$version: $type\r\n";
$key .= "Encryption: $encryption\r\n";
$key .= "Comment: $comment\r\n";
$public = Strings::packSSH2('s', $type) . $public;
$source = Strings::packSSH2('ssss', $type, $encryption, $comment, $public);
$public = Strings::base64_encode($public);
$key .= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n";
$key .= chunk_split($public, 64);
if (empty($password) && !is_string($password)) {
$source .= Strings::packSSH2('s', $private);
switch ($version) {
case 3:
$hash = new Hash('sha256');
$hash->setKey('');
break;
case 2:
$hash = new Hash('sha1');
$hash->setKey(sha1('putty-private-key-file-mac-key', true));
}
} else {
$private .= Random::string(16 - (strlen($private) & 15));
$source .= Strings::packSSH2('s', $private);
$crypto = new AES('cbc');
switch ($version) {
case 3:
$salt = Random::string(16);
$key .= "Key-Derivation: Argon2id\r\n";
$key .= "Argon2-Memory: 8192\r\n";
$key .= "Argon2-Passes: 13\r\n";
$key .= "Argon2-Parallelism: 1\r\n";
$key .= "Argon2-Salt: " . Strings::bin2hex($salt) . "\r\n";
extract(self::generateV3Key($password, 'Argon2id', 8192, 13, $salt));
$hash = new Hash('sha256');
$hash->setKey($hashkey);
break;
case 2:
$symkey = self::generateV2Key($password, 32);
$symiv = str_repeat("\0", $crypto->getBlockLength() >> 3);
$hashkey = 'putty-private-key-file-mac-key' . $password;
$hash = new Hash('sha1');
$hash->setKey(sha1($hashkey, true));
}
$crypto->setKey($symkey);
$crypto->setIV($symiv);
$crypto->disablePadding();
$private = $crypto->encrypt($private);
$mac = $hash->hash($source);
}
$private = Strings::base64_encode($private);
$key .= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
$key .= chunk_split($private, 64);
$key .= 'Private-MAC: ' . Strings::bin2hex($hash->hash($source)) . "\r\n";
return $key;
}
/**
* Wrap a public key appropriately
*
* This is basically the format described in RFC 4716 (https://tools.ietf.org/html/rfc4716)
*/
protected static function wrapPublicKey(string $key, string $type): string
{
$key = pack('Na*a*', strlen($type), $type, $key);
$key = "---- BEGIN SSH2 PUBLIC KEY ----\r\n" .
'Comment: "' . str_replace(['\\', '"'], ['\\\\', '\"'], self::$comment) . "\"\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
'---- END SSH2 PUBLIC KEY ----';
return $key;
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Raw Signature Handler
*
* PHP version 5
*
* Handles signatures as arrays
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Formats\Signature;
use phpseclib3\Math\BigInteger;
/**
* Raw Signature Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class Raw
{
/**
* Loads a signature
*
* @return array|bool
*/
public static function load(array $sig)
{
switch (true) {
case !is_array($sig):
case !isset($sig['r']) || !isset($sig['s']):
case !$sig['r'] instanceof BigInteger:
case !$sig['s'] instanceof BigInteger:
return false;
}
return [
'r' => $sig['r'],
's' => $sig['s'],
];
}
/**
* Returns a signature in the appropriate format
*/
public static function save(BigInteger $r, BigInteger $s): string
{
return compact('r', 's');
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* PrivateKey interface
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2009 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common;
/**
* PrivateKey interface
*
* @author Jim Wigginton <terrafrost@php.net>
*/
interface PrivateKey
{
public function sign($message);
//public function decrypt($ciphertext);
public function getPublicKey();
public function toString(string $type, array $options = []): string;
/**
* @return static
*/
public function withPassword(?string $password = null): PrivateKey;
}

View File

@ -0,0 +1,27 @@
<?php
/**
* PublicKey interface
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2009 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common;
/**
* PublicKey interface
*
* @author Jim Wigginton <terrafrost@php.net>
*/
interface PublicKey
{
public function verify($message, $signature);
//public function encrypt($plaintext);
public function toString(string $type, array $options = []): string;
public function getFingerprint($algorithm);
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Base Class for all stream ciphers
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common;
/**
* Base Class for all stream cipher classes
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class StreamCipher extends SymmetricKey
{
/**
* Block Length of the cipher
*
* Stream ciphers do not have a block size
*
* @see \phpseclib3\Crypt\Common\SymmetricKey::block_size
* @var int
*/
protected $block_size = 0;
/**
* Default Constructor.
*
* @see \phpseclib3\Crypt\Common\SymmetricKey::__construct()
* @return StreamCipher
*/
public function __construct()
{
parent::__construct('stream');
}
/**
* Stream ciphers not use an IV
*/
public function usesIV(): bool
{
return false;
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Fingerprint Trait for Public Keys
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Traits;
use phpseclib3\Crypt\Hash;
/**
* Fingerprint Trait for Private Keys
*
* @author Jim Wigginton <terrafrost@php.net>
*/
trait Fingerprint
{
/**
* Returns the public key's fingerprint
*
* The public key's fingerprint is returned, which is equivalent to running `ssh-keygen -lf rsa.pub`. If there is
* no public key currently loaded, false is returned.
* Example output (md5): "c1:b1:30:29:d7:b8:de:6c:97:77:10:d7:46:41:63:87" (as specified by RFC 4716)
*
* @param string $algorithm The hashing algorithm to be used. Valid options are 'md5' and 'sha256'. False is returned
* for invalid values.
*/
public function getFingerprint($algorithm = 'md5')
{
$type = self::validatePlugin('Keys', 'OpenSSH', 'savePublicKey');
if ($type === false) {
return false;
}
$key = $this->toString('OpenSSH', ['binary' => true]);
if ($key === false) {
return false;
}
switch ($algorithm) {
case 'sha256':
$hash = new Hash('sha256');
$base = base64_encode($hash->hash($key));
return substr($base, 0, strlen($base) - 1);
case 'md5':
return substr(chunk_split(md5($key), 2, ':'), 0, -1);
default:
return false;
}
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* Password Protected Trait for Private Keys
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\Common\Traits;
/**
* Password Protected Trait for Private Keys
*
* @author Jim Wigginton <terrafrost@php.net>
*/
trait PasswordProtected
{
/**
* @var string|null
*/
private $password = null;
/**
* Sets the password
*
* Private keys can be encrypted with a password. To unset the password, pass in the empty string or false.
* Or rather, pass in $password such that empty($password) && !is_string($password) is true.
*
* @see self::createKey()
* @see self::load()
*
* @return static
*/
public function withPassword(?string $password = null): self
{
$new = clone $this;
$new->password = $password;
return $new;
}
}

File diff suppressed because it is too large Load Diff

397
phpseclib/Crypt/DH.php Normal file
View File

@ -0,0 +1,397 @@
<?php
/**
* Pure-PHP (EC)DH implementation
*
* PHP version 5
*
* Here's an example of how to compute a shared secret with this library:
* <code>
* <?php
* include 'vendor/autoload.php';
*
* $ourPrivate = \phpseclib3\Crypt\DH::createKey();
* $secret = DH::computeSecret($ourPrivate, $theirPublic);
*
* ?>
* </code>
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt;
use phpseclib3\Crypt\Common\AsymmetricKey;
use phpseclib3\Crypt\DH\Parameters;
use phpseclib3\Crypt\DH\PrivateKey;
use phpseclib3\Crypt\DH\PublicKey;
use phpseclib3\Exception\InvalidArgumentException;
use phpseclib3\Exception\NoKeyLoadedException;
use phpseclib3\Exception\UnsupportedOperationException;
use phpseclib3\Math\BigInteger;
/**
* Pure-PHP (EC)DH implementation
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class DH extends AsymmetricKey
{
/**
* Algorithm Name
*
* @var string
*/
public const ALGORITHM = 'DH';
/**
* DH prime
*
* @var BigInteger
*/
protected $prime;
/**
* DH Base
*
* Prime divisor of p-1
*
* @var BigInteger
*/
protected $base;
/**
* Public Key
*
* @var BigInteger
*/
protected $publicKey;
/**
* Create DH parameters
*
* This method is a bit polymorphic. It can take any of the following:
* - two BigInteger's (prime and base)
* - an integer representing the size of the prime in bits (the base is assumed to be 2)
* - a string (eg. diffie-hellman-group14-sha1)
*/
public static function createParameters(...$args): Parameters
{
$class = new \ReflectionClass(static::class);
if ($class->isFinal()) {
throw new \RuntimeException('createParameters() should not be called from final classes (' . static::class . ')');
}
$params = new Parameters();
if (count($args) == 2 && $args[0] instanceof BigInteger && $args[1] instanceof BigInteger) {
//if (!$args[0]->isPrime()) {
// throw new \phpseclib3\Exception\InvalidArgumentException('The first parameter should be a prime number');
//}
$params->prime = $args[0];
$params->base = $args[1];
return $params;
} elseif (count($args) == 1 && is_numeric($args[0])) {
$params->prime = BigInteger::randomPrime($args[0]);
$params->base = new BigInteger(2);
return $params;
} elseif (count($args) != 1 || !is_string($args[0])) {
throw new InvalidArgumentException('Valid parameters are either: two BigInteger\'s (prime and base), a single integer (the length of the prime; base is assumed to be 2) or a string');
}
switch ($args[0]) {
// see http://tools.ietf.org/html/rfc2409#section-6.2 and
// http://tools.ietf.org/html/rfc2412, appendex E
case 'diffie-hellman-group1-sha1':
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF';
break;
// see http://tools.ietf.org/html/rfc3526#section-3
case 'diffie-hellman-group14-sha1': // 2048-bit MODP Group
case 'diffie-hellman-group14-sha256':
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
'3995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF';
break;
// see https://tools.ietf.org/html/rfc3526#section-4
case 'diffie-hellman-group15-sha512': // 3072-bit MODP Group
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF';
break;
// see https://tools.ietf.org/html/rfc3526#section-5
case 'diffie-hellman-group16-sha512': // 4096-bit MODP Group
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7' .
'88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8' .
'DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' .
'233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9' .
'93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF';
break;
// see https://tools.ietf.org/html/rfc3526#section-6
case 'diffie-hellman-group17-sha512': // 6144-bit MODP Group
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7' .
'88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8' .
'DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' .
'233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9' .
'93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026' .
'C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AE' .
'B06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B' .
'DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92EC' .
'F032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E' .
'59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA' .
'CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76' .
'F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468' .
'043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF';
break;
// see https://tools.ietf.org/html/rfc3526#section-7
case 'diffie-hellman-group18-sha512': // 8192-bit MODP Group
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7' .
'88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8' .
'DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' .
'233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9' .
'93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026' .
'C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AE' .
'B06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B' .
'DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92EC' .
'F032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E' .
'59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA' .
'CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76' .
'F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468' .
'043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E4' .
'38777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED' .
'2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652D' .
'E3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B' .
'4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A6' .
'6D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851D' .
'F9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92' .
'4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA' .
'9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF';
break;
default:
throw new InvalidArgumentException('Invalid named prime provided');
}
$params->prime = new BigInteger($prime, 16);
$params->base = new BigInteger(2);
return $params;
}
/**
* Create public / private key pair.
*
* The rationale for the second parameter is described in http://tools.ietf.org/html/rfc4419#section-6.2 :
*
* "To increase the speed of the key exchange, both client and server may
* reduce the size of their private exponents. It should be at least
* twice as long as the key material that is generated from the shared
* secret. For more details, see the paper by van Oorschot and Wiener
* [VAN-OORSCHOT]."
*
* $length is in bits
*
* @param int $length optional
*/
public static function createKey(Parameters $params, int $length = 0): PrivateKey
{
$class = new \ReflectionClass(static::class);
if ($class->isFinal()) {
throw new \RuntimeException('createKey() should not be called from final classes (' . static::class . ')');
}
$one = new BigInteger(1);
if ($length) {
$max = $one->bitwise_leftShift($length);
$max = $max->subtract($one);
} else {
$max = $params->prime->subtract($one);
}
$key = new PrivateKey();
$key->prime = $params->prime;
$key->base = $params->base;
$key->privateKey = BigInteger::randomRange($one, $max);
$key->publicKey = $key->base->powMod($key->privateKey, $key->prime);
return $key;
}
/**
* Compute Shared Secret
*
* @param PrivateKey|EC $private
* @param PublicKey|BigInteger|string $public
*/
public static function computeSecret($private, $public)
{
if ($private instanceof PrivateKey) { // DH\PrivateKey
switch (true) {
case $public instanceof PublicKey:
if (!$private->prime->equals($public->prime) || !$private->base->equals($public->base)) {
throw new InvalidArgumentException('The public and private key do not share the same prime and / or base numbers');
}
return $public->publicKey->powMod($private->privateKey, $private->prime)->toBytes(true);
case is_string($public):
$public = new BigInteger($public, -256);
// fall-through
case $public instanceof BigInteger:
return $public->powMod($private->privateKey, $private->prime)->toBytes(true);
default:
throw new InvalidArgumentException('$public needs to be an instance of DH\PublicKey, a BigInteger or a string');
}
}
if ($private instanceof EC\PrivateKey) {
switch (true) {
case $public instanceof EC\PublicKey:
$public = $public->getEncodedCoordinates();
// fall-through
case is_string($public):
$point = $private->multiply($public);
switch ($private->getCurve()) {
case 'Curve25519':
case 'Curve448':
$secret = $point;
break;
default:
// according to https://www.secg.org/sec1-v2.pdf#page=33 only X is returned
$secret = substr($point, 1, (strlen($point) - 1) >> 1);
}
/*
if (($secret[0] & "\x80") === "\x80") {
$secret = "\0$secret";
}
*/
return $secret;
default:
throw new InvalidArgumentException('$public needs to be an instance of EC\PublicKey or a string (an encoded coordinate)');
}
}
}
/**
* Load the key
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): AsymmetricKey
{
try {
return EC::load($key, $password);
} catch (NoKeyLoadedException $e) {
}
return parent::load($key, $password);
}
/**
* OnLoad Handler
*
* @return Parameters|PrivateKey|PublicKey
*/
protected static function onLoad(array $components)
{
if (!isset($components['privateKey']) && !isset($components['publicKey'])) {
$new = new Parameters();
} else {
$new = isset($components['privateKey']) ?
new PrivateKey() :
new PublicKey();
}
$new->prime = $components['prime'];
$new->base = $components['base'];
if (isset($components['privateKey'])) {
$new->privateKey = $components['privateKey'];
}
if (isset($components['publicKey'])) {
$new->publicKey = $components['publicKey'];
}
return $new;
}
/**
* Determines which hashing function should be used
*/
public function withHash(string $hash): AsymmetricKey
{
throw new UnsupportedOperationException('DH does not use a hash algorithm');
}
/**
* Returns the hash algorithm currently being used
*/
public function getHash(): Hash
{
throw new UnsupportedOperationException('DH does not use a hash algorithm');
}
/**
* Returns the parameters
*
* A public / private key is only returned if the currently loaded "key" contains an x or y
* value.
*
* @see self::getPublicKey()
*/
public function getParameters(): AsymmetricKey
{
$type = DH::validatePlugin('Keys', 'PKCS1', 'saveParameters');
$key = $type::saveParameters($this->prime, $this->base);
return DH::load($key, 'PKCS1');
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* "PKCS1" Formatted EC Key Handler
*
* PHP version 5
*
* Processes keys with the following headers:
*
* -----BEGIN DH PARAMETERS-----
*
* Technically, PKCS1 is for RSA keys, only, but we're using PKCS1 to describe
* DSA, whose format isn't really formally described anywhere, so might as well
* use it to describe this, too.
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DH\Formats\Keys;
use phpseclib3\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\File\ASN1;
use phpseclib3\File\ASN1\Maps;
use phpseclib3\Math\BigInteger;
/**
* "PKCS1" Formatted DH Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PKCS1 extends Progenitor
{
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): array
{
$key = parent::load($key, $password);
$decoded = ASN1::decodeBER($key);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER');
}
$components = ASN1::asn1map($decoded[0], Maps\DHParameter::MAP);
if (!is_array($components)) {
throw new RuntimeException('Unable to perform ASN1 mapping on parameters');
}
return $components;
}
/**
* Convert EC parameters to the appropriate format
*/
public static function saveParameters(BigInteger $prime, BigInteger $base, array $options = []): string
{
$params = [
'prime' => $prime,
'base' => $base,
];
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
return "-----BEGIN DH PARAMETERS-----\r\n" .
chunk_split(base64_encode($params), 64) .
"-----END DH PARAMETERS-----\r\n";
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* PKCS#8 Formatted DH Key Handler
*
* PHP version 5
*
* Processes keys with the following headers:
*
* -----BEGIN ENCRYPTED PRIVATE KEY-----
* -----BEGIN PRIVATE KEY-----
* -----BEGIN PUBLIC KEY-----
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DH\Formats\Keys;
use phpseclib3\Crypt\Common\Formats\Keys\PKCS8 as Progenitor;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\File\ASN1;
use phpseclib3\File\ASN1\Maps;
use phpseclib3\Math\BigInteger;
/**
* PKCS#8 Formatted DH Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PKCS8 extends Progenitor
{
/**
* OID Name
*
* @var string
*/
public const OID_NAME = 'dhKeyAgreement';
/**
* OID Value
*
* @var string
*/
public const OID_VALUE = '1.2.840.113549.1.3.1';
/**
* Child OIDs loaded
*
* @var bool
*/
protected static $childOIDsLoaded = false;
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): array
{
$key = parent::load($key, $password);
$type = isset($key['privateKey']) ? 'privateKey' : 'publicKey';
$decoded = ASN1::decodeBER($key[$type . 'Algorithm']['parameters']->element);
if (empty($decoded)) {
throw new RuntimeException('Unable to decode BER of parameters');
}
$components = ASN1::asn1map($decoded[0], Maps\DHParameter::MAP);
if (!is_array($components)) {
throw new RuntimeException('Unable to perform ASN1 mapping on parameters');
}
$decoded = ASN1::decodeBER($key[$type]);
switch (true) {
case !isset($decoded):
case !isset($decoded[0]['content']):
case !$decoded[0]['content'] instanceof BigInteger:
throw new RuntimeException('Unable to decode BER of parameters');
}
$components[$type] = $decoded[0]['content'];
return $components;
}
/**
* Convert a private key to the appropriate format.
*/
public static function savePrivateKey(BigInteger $prime, BigInteger $base, BigInteger $privateKey, BigInteger $publicKey, ?string $password = null, array $options = []): string
{
$params = [
'prime' => $prime,
'base' => $base,
];
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
$params = new ASN1\Element($params);
$key = ASN1::encodeDER($privateKey, ['type' => ASN1::TYPE_INTEGER]);
return self::wrapPrivateKey($key, [], $params, $password, null, '', $options);
}
/**
* Convert a public key to the appropriate format
*
* @param array $options optional
*/
public static function savePublicKey(BigInteger $prime, BigInteger $base, BigInteger $publicKey, array $options = []): string
{
$params = [
'prime' => $prime,
'base' => $base,
];
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
$params = new ASN1\Element($params);
$key = ASN1::encodeDER($publicKey, ['type' => ASN1::TYPE_INTEGER]);
return self::wrapPublicKey($key, $params);
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* DH Parameters
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DH;
use phpseclib3\Crypt\DH;
/**
* DH Parameters
*
* @author Jim Wigginton <terrafrost@php.net>
*/
final class Parameters extends DH
{
/**
* Returns the parameters
*
* @param array $options optional
*/
public function toString(string $type = 'PKCS1', array $options = []): string
{
$type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
return $type::saveParameters($this->prime, $this->base, $options);
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* DH Private Key
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DH;
use phpseclib3\Crypt\Common;
use phpseclib3\Crypt\DH;
use phpseclib3\Math\BigInteger;
/**
* DH Private Key
*
* @author Jim Wigginton <terrafrost@php.net>
*/
final class PrivateKey extends DH
{
use Common\Traits\PasswordProtected;
/**
* Private Key
*
* @var BigInteger
*/
protected $privateKey;
/**
* Public Key
*
* @var BigInteger
*/
protected $publicKey;
/**
* Returns the public key
*
* @return DH\PublicKey
*/
public function getPublicKey(): PublicKey
{
$type = self::validatePlugin('Keys', 'PKCS8', 'savePublicKey');
if (!isset($this->publicKey)) {
$this->publicKey = $this->base->powMod($this->privateKey, $this->prime);
}
$key = $type::savePublicKey($this->prime, $this->base, $this->publicKey);
return DH::loadFormat('PKCS8', $key);
}
/**
* Returns the private key
*
* @param array $options optional
*/
public function toString(string $type, array $options = []): string
{
$type = self::validatePlugin('Keys', $type, 'savePrivateKey');
if (!isset($this->publicKey)) {
$this->publicKey = $this->base->powMod($this->privateKey, $this->prime);
}
return $type::savePrivateKey($this->prime, $this->base, $this->privateKey, $this->publicKey, $this->password, $options);
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* DH Public Key
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DH;
use phpseclib3\Crypt\Common;
use phpseclib3\Crypt\DH;
use phpseclib3\Math\BigInteger;
/**
* DH Public Key
*
* @author Jim Wigginton <terrafrost@php.net>
*/
final class PublicKey extends DH
{
use Common\Traits\Fingerprint;
/**
* Returns the public key
*
* @param array $options optional
*/
public function toString(string $type, array $options = []): string
{
$type = self::validatePlugin('Keys', $type, 'savePublicKey');
return $type::savePublicKey($this->prime, $this->base, $this->publicKey, $options);
}
/**
* Returns the public key as a BigInteger
*/
public function toBigInteger(): BigInteger
{
return $this->publicKey;
}
}

330
phpseclib/Crypt/DSA.php Normal file
View File

@ -0,0 +1,330 @@
<?php
/**
* Pure-PHP FIPS 186-4 compliant implementation of DSA.
*
* PHP version 5
*
* Here's an example of how to create signatures and verify signatures with this library:
* <code>
* <?php
* include 'vendor/autoload.php';
*
* $private = \phpseclib3\Crypt\DSA::createKey();
* $public = $private->getPublicKey();
*
* $plaintext = 'terrafrost';
*
* $signature = $private->sign($plaintext);
*
* echo $public->verify($plaintext, $signature) ? 'verified' : 'unverified';
* ?>
* </code>
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt;
use phpseclib3\Crypt\Common\AsymmetricKey;
use phpseclib3\Crypt\DSA\Parameters;
use phpseclib3\Crypt\DSA\PrivateKey;
use phpseclib3\Crypt\DSA\PublicKey;
use phpseclib3\Exception\InsufficientSetupException;
use phpseclib3\Exception\InvalidArgumentException;
use phpseclib3\Math\BigInteger;
/**
* Pure-PHP FIPS 186-4 compliant implementation of DSA.
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class DSA extends AsymmetricKey
{
/**
* Algorithm Name
*
* @var string
*/
public const ALGORITHM = 'DSA';
/**
* DSA Prime P
*
* @var BigInteger
*/
protected $p;
/**
* DSA Group Order q
*
* Prime divisor of p-1
*
* @var BigInteger
*/
protected $q;
/**
* DSA Group Generator G
*
* @var BigInteger
*/
protected $g;
/**
* DSA public key value y
*
* @var BigInteger
*/
protected $y;
/**
* Signature Format
*
* @var string
*/
protected $sigFormat;
/**
* Signature Format (Short)
*
* @var string
*/
protected $shortFormat;
/**
* Create DSA parameters
*
* @return DSA|bool
*/
public static function createParameters(int $L = 2048, int $N = 224)
{
self::initialize_static_variables();
$class = new \ReflectionClass(static::class);
if ($class->isFinal()) {
throw new \RuntimeException('createParameters() should not be called from final classes (' . static::class . ')');
}
if (!isset(self::$engines['PHP'])) {
self::useBestEngine();
}
switch (true) {
case $N == 160:
/*
in FIPS 186-1 and 186-2 N was fixed at 160 whereas K had an upper bound of 1024.
RFC 4253 (SSH Transport Layer Protocol) references FIPS 186-2 and as such most
SSH DSA implementations only support keys with an N of 160.
puttygen let's you set the size of L (but not the size of N) and uses 2048 as the
default L value. that's not really compliant with any of the FIPS standards, however,
for the purposes of maintaining compatibility with puttygen, we'll support it
*/
//case ($L >= 512 || $L <= 1024) && (($L & 0x3F) == 0) && $N == 160:
// FIPS 186-3 changed this as follows:
//case $L == 1024 && $N == 160:
case $L == 2048 && $N == 224:
case $L == 2048 && $N == 256:
case $L == 3072 && $N == 256:
break;
default:
throw new InvalidArgumentException('Invalid values for N and L');
}
$two = new BigInteger(2);
$q = BigInteger::randomPrime($N);
$divisor = $q->multiply($two);
do {
$x = BigInteger::random($L);
[, $c] = $x->divide($divisor);
$p = $x->subtract($c->subtract(self::$one));
} while ($p->getLength() != $L || !$p->isPrime());
$p_1 = $p->subtract(self::$one);
[$e] = $p_1->divide($q);
// quoting http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf#page=50 ,
// "h could be obtained from a random number generator or from a counter that
// changes after each use". PuTTY (sshdssg.c) starts h off at 1 and increments
// it on each loop. wikipedia says "commonly h = 2 is used" so we'll just do that
$h = clone $two;
while (true) {
$g = $h->powMod($e, $p);
if (!$g->equals(self::$one)) {
break;
}
$h = $h->add(self::$one);
}
$dsa = new Parameters();
$dsa->p = $p;
$dsa->q = $q;
$dsa->g = $g;
return $dsa;
}
/**
* Create public / private key pair.
*
* This method is a bit polymorphic. It can take a DSA/Parameters object, L / N as two distinct parameters or
* no parameters (at which point L and N will be generated with this method)
*
* Returns the private key, from which the publickey can be extracted
*
* @param int[] ...$args
*/
public static function createKey(...$args): PrivateKey
{
self::initialize_static_variables();
$class = new \ReflectionClass(static::class);
if ($class->isFinal()) {
throw new \RuntimeException('createKey() should not be called from final classes (' . static::class . ')');
}
if (!isset(self::$engines['PHP'])) {
self::useBestEngine();
}
if (count($args) == 2 && is_int($args[0]) && is_int($args[1])) {
$params = self::createParameters($args[0], $args[1]);
} elseif (count($args) == 1 && $args[0] instanceof Parameters) {
$params = $args[0];
} elseif (!count($args)) {
$params = self::createParameters();
} else {
throw new InsufficientSetupException('Valid parameters are either two integers (L and N), a single DSA object or no parameters at all.');
}
$private = new PrivateKey();
$private->p = $params->p;
$private->q = $params->q;
$private->g = $params->g;
$private->x = BigInteger::randomRange(self::$one, $private->q->subtract(self::$one));
$private->y = $private->g->powMod($private->x, $private->p);
//$public = clone $private;
//unset($public->x);
return $private
->withHash($params->hash->getHash())
->withSignatureFormat($params->shortFormat);
}
/**
* OnLoad Handler
*
* @return Parameters|PrivateKey|PublicKey
*/
protected static function onLoad(array $components)
{
if (!isset(self::$engines['PHP'])) {
self::useBestEngine();
}
if (!isset($components['x']) && !isset($components['y'])) {
$new = new Parameters();
} elseif (isset($components['x'])) {
$new = new PrivateKey();
$new->x = $components['x'];
} else {
$new = new PublicKey();
}
$new->p = $components['p'];
$new->q = $components['q'];
$new->g = $components['g'];
if (isset($components['y'])) {
$new->y = $components['y'];
}
return $new;
}
/**
* Constructor
*
* PublicKey and PrivateKey objects can only be created from abstract RSA class
*/
protected function __construct()
{
$this->sigFormat = self::validatePlugin('Signature', 'ASN1');
$this->shortFormat = 'ASN1';
parent::__construct();
}
/**
* Returns the key size
*
* More specifically, this L (the length of DSA Prime P) and N (the length of DSA Group Order q)
*/
public function getLength(): array
{
return ['L' => $this->p->getLength(), 'N' => $this->q->getLength()];
}
/**
* Returns the current engine being used
*
* @see self::useInternalEngine()
* @see self::useBestEngine()
*/
public function getEngine(): string
{
if (!isset(self::$engines['PHP'])) {
self::useBestEngine();
}
return self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods()) ?
'OpenSSL' : 'PHP';
}
/**
* Returns the parameters
*
* A public / private key is only returned if the currently loaded "key" contains an x or y
* value.
*
* @see self::getPublicKey()
*/
public function getParameters()
{
$type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
$key = $type::saveParameters($this->p, $this->q, $this->g);
return DSA::load($key, 'PKCS1')
->withHash($this->hash->getHash())
->withSignatureFormat($this->shortFormat);
}
/**
* Determines the signature padding mode
*
* Valid values are: ASN1, SSH2, Raw
*/
public function withSignatureFormat(string $format): DSA
{
$new = clone $this;
$new->shortFormat = $format;
$new->sigFormat = self::validatePlugin('Signature', $format);
return $new;
}
/**
* Returns the signature format currently being used
*/
public function getSignatureFormat(): string
{
return $this->shortFormat;
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* OpenSSH Formatted DSA Key Handler
*
* PHP version 5
*
* Place in $HOME/.ssh/authorized_keys
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\Common\Formats\Keys\OpenSSH as Progenitor;
use phpseclib3\Exception\InvalidArgumentException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Math\BigInteger;
/**
* OpenSSH Formatted DSA Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class OpenSSH extends Progenitor
{
/**
* Supported Key Types
*
* @var array
*/
protected static $types = ['ssh-dss'];
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): array
{
$parsed = parent::load($key, $password);
if (isset($parsed['paddedKey'])) {
[$type] = Strings::unpackSSH2('s', $parsed['paddedKey']);
if ($type != $parsed['type']) {
throw new RuntimeException("The public and private keys are not of the same type ($type vs $parsed[type])");
}
[$p, $q, $g, $y, $x, $comment] = Strings::unpackSSH2('i5s', $parsed['paddedKey']);
return compact('p', 'q', 'g', 'y', 'x', 'comment');
}
[$p, $q, $g, $y] = Strings::unpackSSH2('iiii', $parsed['publicKey']);
$comment = $parsed['comment'];
return compact('p', 'q', 'g', 'y', 'comment');
}
/**
* Convert a public key to the appropriate format
*
* @param array $options optional
*/
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, array $options = []): string
{
if ($q->getLength() != 160) {
throw new InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
}
// from <http://tools.ietf.org/html/rfc4253#page-15>:
// string "ssh-dss"
// mpint p
// mpint q
// mpint g
// mpint y
$DSAPublicKey = Strings::packSSH2('siiii', 'ssh-dss', $p, $q, $g, $y);
if ($options['binary'] ?? self::$binary) {
return $DSAPublicKey;
}
$comment = $options['comment'] ?? self::$comment;
$DSAPublicKey = 'ssh-dss ' . base64_encode($DSAPublicKey) . ' ' . $comment;
return $DSAPublicKey;
}
/**
* Convert a private key to the appropriate format.
*/
public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, ?string $password = null, array $options = []): string
{
$publicKey = self::savePublicKey($p, $q, $g, $y, ['binary' => true]);
$privateKey = Strings::packSSH2('si5', 'ssh-dss', $p, $q, $g, $y, $x);
return self::wrapPrivateKey($publicKey, $privateKey, $password, $options);
}
}

View File

@ -0,0 +1,127 @@
<?php
/**
* PKCS#1 Formatted DSA Key Handler
*
* PHP version 5
*
* Used by File/X509.php
*
* Processes keys with the following headers:
*
* -----BEGIN DSA PRIVATE KEY-----
* -----BEGIN DSA PUBLIC KEY-----
* -----BEGIN DSA PARAMETERS-----
*
* Analogous to ssh-keygen's pem format (as specified by -m)
*
* Also, technically, PKCS1 decribes RSA but I am not aware of a formal specification for DSA.
* The DSA private key format seems to have been adapted from the RSA private key format so
* we're just re-using that as the name.
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\File\ASN1;
use phpseclib3\File\ASN1\Maps;
use phpseclib3\Math\BigInteger;
/**
* PKCS#1 Formatted DSA Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PKCS1 extends Progenitor
{
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): array
{
$key = parent::load($key, $password);
$decoded = ASN1::decodeBER($key);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER');
}
$key = ASN1::asn1map($decoded[0], Maps\DSAParams::MAP);
if (is_array($key)) {
return $key;
}
$key = ASN1::asn1map($decoded[0], Maps\DSAPrivateKey::MAP);
if (is_array($key)) {
return $key;
}
$key = ASN1::asn1map($decoded[0], Maps\DSAPublicKey::MAP);
if (is_array($key)) {
return $key;
}
throw new RuntimeException('Unable to perform ASN1 mapping');
}
/**
* Convert DSA parameters to the appropriate format
*/
public static function saveParameters(BigInteger $p, BigInteger $q, BigInteger $g): string
{
$key = [
'p' => $p,
'q' => $q,
'g' => $g,
];
$key = ASN1::encodeDER($key, Maps\DSAParams::MAP);
return "-----BEGIN DSA PARAMETERS-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END DSA PARAMETERS-----\r\n";
}
/**
* Convert a private key to the appropriate format.
*
* @param string $password optional
* @param array $options optional
*/
public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, string $password = '', array $options = []): string
{
$key = [
'version' => 0,
'p' => $p,
'q' => $q,
'g' => $g,
'y' => $y,
'x' => $x,
];
$key = ASN1::encodeDER($key, Maps\DSAPrivateKey::MAP);
return self::wrapPrivateKey($key, 'DSA', $password, $options);
}
/**
* Convert a public key to the appropriate format
*/
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y): string
{
$key = ASN1::encodeDER($y, Maps\DSAPublicKey::MAP);
return self::wrapPublicKey($key, 'DSA');
}
}

View File

@ -0,0 +1,133 @@
<?php
/**
* PKCS#8 Formatted DSA Key Handler
*
* PHP version 5
*
* Processes keys with the following headers:
*
* -----BEGIN ENCRYPTED PRIVATE KEY-----
* -----BEGIN PRIVATE KEY-----
* -----BEGIN PUBLIC KEY-----
*
* Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
* is specific to private keys it's basically creating a DER-encoded wrapper
* for keys. This just extends that same concept to public keys (much like ssh-keygen)
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Keys;
use phpseclib3\Crypt\Common\Formats\Keys\PKCS8 as Progenitor;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\File\ASN1;
use phpseclib3\File\ASN1\Maps;
use phpseclib3\Math\BigInteger;
/**
* PKCS#8 Formatted DSA Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PKCS8 extends Progenitor
{
/**
* OID Name
*
* @var string
*/
public const OID_NAME = 'id-dsa';
/**
* OID Value
*
* @var string
*/
public const OID_VALUE = '1.2.840.10040.4.1';
/**
* Child OIDs loaded
*
* @var bool
*/
protected static $childOIDsLoaded = false;
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): array
{
$key = parent::load($key, $password);
$type = isset($key['privateKey']) ? 'privateKey' : 'publicKey';
$decoded = ASN1::decodeBER($key[$type . 'Algorithm']['parameters']->element);
if (!$decoded) {
throw new RuntimeException('Unable to decode BER of parameters');
}
$components = ASN1::asn1map($decoded[0], Maps\DSAParams::MAP);
if (!is_array($components)) {
throw new RuntimeException('Unable to perform ASN1 mapping on parameters');
}
$decoded = ASN1::decodeBER($key[$type]);
if (empty($decoded)) {
throw new RuntimeException('Unable to decode BER');
}
$var = $type == 'privateKey' ? 'x' : 'y';
$components[$var] = ASN1::asn1map($decoded[0], Maps\DSAPublicKey::MAP);
if (!$components[$var] instanceof BigInteger) {
throw new RuntimeException('Unable to perform ASN1 mapping');
}
if (isset($key['meta'])) {
$components['meta'] = $key['meta'];
}
return $components;
}
/**
* Convert a private key to the appropriate format.
*/
public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, ?string $password = null, array $options = []): string
{
$params = [
'p' => $p,
'q' => $q,
'g' => $g,
];
$params = ASN1::encodeDER($params, Maps\DSAParams::MAP);
$params = new ASN1\Element($params);
$key = ASN1::encodeDER($x, Maps\DSAPublicKey::MAP);
return self::wrapPrivateKey($key, [], $params, $password, null, '', $options);
}
/**
* Convert a public key to the appropriate format
*
* @param array $options optional
*/
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, array $options = []): string
{
$params = [
'p' => $p,
'q' => $q,
'g' => $g,
];
$params = ASN1::encodeDER($params, Maps\DSAParams::MAP);
$params = new ASN1\Element($params);
$key = ASN1::encodeDER($y, Maps\DSAPublicKey::MAP);
return self::wrapPublicKey($key, $params);
}
}

View File

@ -0,0 +1,97 @@
<?php
/**
* PuTTY Formatted DSA Key Handler
*
* puttygen does not generate DSA keys with an N of anything other than 160, however,
* it can still load them and convert them. PuTTY will load them, too, but SSH servers
* won't accept them. Since PuTTY formatted keys are primarily used with SSH this makes
* keys with N > 160 kinda useless, hence this handlers not supporting such keys.
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\Common\Formats\Keys\PuTTY as Progenitor;
use phpseclib3\Exception\InvalidArgumentException;
use phpseclib3\Math\BigInteger;
/**
* PuTTY Formatted DSA Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class PuTTY extends Progenitor
{
/**
* Public Handler
*
* @var string
*/
public const PUBLIC_HANDLER = 'phpseclib3\Crypt\DSA\Formats\Keys\OpenSSH';
/**
* Algorithm Identifier
*
* @var array
*/
protected static $types = ['ssh-dss'];
/**
* Break a public or private key down into its constituent components
*
* @param array|string $key
* @param string|false $password
* @return array|false
*/
public static function load($key, $password)
{
$components = parent::load($key, $password);
if (!isset($components['private'])) {
return $components;
}
extract($components);
unset($components['public'], $components['private']);
[$p, $q, $g, $y] = Strings::unpackSSH2('iiii', $public);
[$x] = Strings::unpackSSH2('i', $private);
return compact('p', 'q', 'g', 'y', 'x', 'comment');
}
/**
* Convert a private key to the appropriate format.
*/
public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, ?string $password = null, array $options = []): string
{
if ($q->getLength() != 160) {
throw new InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
}
$public = Strings::packSSH2('iiii', $p, $q, $g, $y);
$private = Strings::packSSH2('i', $x);
return self::wrapPrivateKey($public, $private, 'ssh-dss', $password, $options);
}
/**
* Convert a public key to the appropriate format
*/
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y): string
{
if ($q->getLength() != 160) {
throw new InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
}
return self::wrapPublicKey(Strings::packSSH2('iiii', $p, $q, $g, $y), 'ssh-dss');
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* Raw DSA Key Handler
*
* PHP version 5
*
* Reads and creates arrays as DSA keys
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Keys;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Math\BigInteger;
/**
* Raw DSA Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class Raw
{
/**
* Break a public or private key down into its constituent components
*
* @param string|array $key
*/
public static function load($key, ?string $password = null): array
{
if (!is_array($key)) {
throw new UnexpectedValueException('Key should be a array - not a ' . gettype($key));
}
switch (true) {
case !isset($key['p']) || !isset($key['q']) || !isset($key['g']):
case !$key['p'] instanceof BigInteger:
case !$key['q'] instanceof BigInteger:
case !$key['g'] instanceof BigInteger:
case !isset($key['x']) && !isset($key['y']):
case isset($key['x']) && !$key['x'] instanceof BigInteger:
case isset($key['y']) && !$key['y'] instanceof BigInteger:
throw new UnexpectedValueException('Key appears to be malformed');
}
$options = ['p' => 1, 'q' => 1, 'g' => 1, 'x' => 1, 'y' => 1];
return array_intersect_key($key, $options);
}
/**
* Convert a private key to the appropriate format.
*
* @param string $password optional
*/
public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, string $password = ''): string
{
return compact('p', 'q', 'g', 'y', 'x');
}
/**
* Convert a public key to the appropriate format
*/
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y): string
{
return compact('p', 'q', 'g', 'y');
}
}

View File

@ -0,0 +1,125 @@
<?php
/**
* XML Formatted DSA Key Handler
*
* While XKMS defines a private key format for RSA it does not do so for DSA. Quoting that standard:
*
* "[XKMS] does not specify private key parameters for the DSA signature algorithm since the algorithm only
* supports signature modes and so the application of server generated keys and key recovery is of limited
* value"
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Keys;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Exception\BadConfigurationException;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Math\BigInteger;
/**
* XML Formatted DSA Key Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class XML
{
/**
* Break a public or private key down into its constituent components
*/
public static function load(string $key, ?string $password = null): array
{
if (!Strings::is_stringable($key)) {
throw new UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
if (!class_exists('DOMDocument')) {
throw new BadConfigurationException('The dom extension is not setup correctly on this system');
}
$use_errors = libxml_use_internal_errors(true);
$dom = new \DOMDocument();
if (substr($key, 0, 5) != '<?xml') {
$key = '<xml>' . $key . '</xml>';
}
if (!$dom->loadXML($key)) {
libxml_use_internal_errors($use_errors);
throw new UnexpectedValueException('Key does not appear to contain XML');
}
$xpath = new \DOMXPath($dom);
$keys = ['p', 'q', 'g', 'y', 'j', 'seed', 'pgencounter'];
foreach ($keys as $key) {
// $dom->getElementsByTagName($key) is case-sensitive
$temp = $xpath->query("//*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='$key']");
if (!$temp->length) {
continue;
}
$value = new BigInteger(Strings::base64_decode($temp->item(0)->nodeValue), 256);
switch ($key) {
case 'p': // a prime modulus meeting the [DSS] requirements
// Parameters P, Q, and G can be public and common to a group of users. They might be known
// from application context. As such, they are optional but P and Q must either both appear
// or both be absent
$components['p'] = $value;
break;
case 'q': // an integer in the range 2**159 < Q < 2**160 which is a prime divisor of P-1
$components['q'] = $value;
break;
case 'g': // an integer with certain properties with respect to P and Q
$components['g'] = $value;
break;
case 'y': // G**X mod P (where X is part of the private key and not made public)
$components['y'] = $value;
// the remaining options do not do anything
case 'j': // (P - 1) / Q
// Parameter J is available for inclusion solely for efficiency as it is calculatable from
// P and Q
case 'seed': // a DSA prime generation seed
// Parameters seed and pgenCounter are used in the DSA prime number generation algorithm
// specified in [DSS]. As such, they are optional but must either both be present or both
// be absent
case 'pgencounter': // a DSA prime generation counter
}
}
libxml_use_internal_errors($use_errors);
if (!isset($components['y'])) {
throw new UnexpectedValueException('Key is missing y component');
}
switch (true) {
case !isset($components['p']):
case !isset($components['q']):
case !isset($components['g']):
return ['y' => $components['y']];
}
return $components;
}
/**
* Convert a public key to the appropriate format
*
* See https://www.w3.org/TR/xmldsig-core/#sec-DSAKeyValue
*/
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y): string
{
return "<DSAKeyValue>\r\n" .
' <P>' . Strings::base64_encode($p->toBytes()) . "</P>\r\n" .
' <Q>' . Strings::base64_encode($q->toBytes()) . "</Q>\r\n" .
' <G>' . Strings::base64_encode($g->toBytes()) . "</G>\r\n" .
' <Y>' . Strings::base64_encode($y->toBytes()) . "</Y>\r\n" .
'</DSAKeyValue>';
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* ASN1 Signature Handler
*
* PHP version 5
*
* Handles signatures in the format described in
* https://tools.ietf.org/html/rfc3279#section-2.2.2
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Signature;
use phpseclib3\File\ASN1 as Encoder;
use phpseclib3\File\ASN1\Maps;
use phpseclib3\Math\BigInteger;
/**
* ASN1 Signature Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class ASN1
{
/**
* Loads a signature
*
* @return array|bool
*/
public static function load(string $sig)
{
if (!is_string($sig)) {
return false;
}
$decoded = Encoder::decodeBER($sig);
if (empty($decoded)) {
return false;
}
$components = Encoder::asn1map($decoded[0], Maps\DssSigValue::MAP);
return $components;
}
/**
* Returns a signature in the appropriate format
*/
public static function save(BigInteger $r, BigInteger $s): string
{
return Encoder::encodeDER(compact('r', 's'), Maps\DssSigValue::MAP);
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* Raw DSA Signature Handler
*
* PHP version 5
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Signature;
use phpseclib3\Crypt\Common\Formats\Signature\Raw as Progenitor;
/**
* Raw DSA Signature Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class Raw extends Progenitor
{
}

View File

@ -0,0 +1,71 @@
<?php
/**
* SSH2 Signature Handler
*
* PHP version 5
*
* Handles signatures in the format used by SSH2
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA\Formats\Signature;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Math\BigInteger;
/**
* SSH2 Signature Handler
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class SSH2
{
/**
* Loads a signature
*/
public static function load(string $sig)
{
if (!is_string($sig)) {
return false;
}
$result = Strings::unpackSSH2('ss', $sig);
if ($result === false) {
return false;
}
[$type, $blob] = $result;
if ($type != 'ssh-dss' || strlen($blob) != 40) {
return false;
}
return [
'r' => new BigInteger(substr($blob, 0, 20), 256),
's' => new BigInteger(substr($blob, 20), 256),
];
}
/**
* Returns a signature in the appropriate format
*
* @return string
*/
public static function save(BigInteger $r, BigInteger $s)
{
if ($r->getLength() > 160 || $s->getLength() > 160) {
return false;
}
return Strings::packSSH2(
'ss',
'ssh-dss',
str_pad($r->toBytes(), 20, "\0", STR_PAD_LEFT) .
str_pad($s->toBytes(), 20, "\0", STR_PAD_LEFT)
);
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* DSA Parameters
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA;
use phpseclib3\Crypt\DSA;
/**
* DSA Parameters
*
* @author Jim Wigginton <terrafrost@php.net>
*/
final class Parameters extends DSA
{
/**
* Returns the parameters
*
* @param array $options optional
*/
public function toString(string $type = 'PKCS1', array $options = []): string
{
$type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
return $type::saveParameters($this->p, $this->q, $this->g, $options);
}
}

View File

@ -0,0 +1,150 @@
<?php
/**
* DSA Private Key
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA;
use phpseclib3\Crypt\Common;
use phpseclib3\Crypt\DSA;
use phpseclib3\Crypt\DSA\Formats\Signature\ASN1 as ASN1Signature;
use phpseclib3\Math\BigInteger;
/**
* DSA Private Key
*
* @author Jim Wigginton <terrafrost@php.net>
*/
final class PrivateKey extends DSA implements Common\PrivateKey
{
use Common\Traits\PasswordProtected;
/**
* DSA secret exponent x
*
* @var BigInteger
*/
protected $x;
/**
* Returns the public key
*
* If you do "openssl rsa -in private.rsa -pubout -outform PEM" you get a PKCS8 formatted key
* that contains a publicKeyAlgorithm AlgorithmIdentifier and a publicKey BIT STRING.
* An AlgorithmIdentifier contains an OID and a parameters field. With RSA public keys this
* parameters field is NULL. With DSA PKCS8 public keys it is not - it contains the p, q and g
* variables. The publicKey BIT STRING contains, simply, the y variable. This can be verified
* by getting a DSA PKCS8 public key:
*
* "openssl dsa -in private.dsa -pubout -outform PEM"
*
* ie. just swap out rsa with dsa in the rsa command above.
*
* A PKCS1 public key corresponds to the publicKey portion of the PKCS8 key. In the case of RSA
* the publicKey portion /is/ the key. In the case of DSA it is not. You cannot verify a signature
* without the parameters and the PKCS1 DSA public key format does not include the parameters.
*
* @see self::getPrivateKey()
*/
public function getPublicKey()
{
$type = self::validatePlugin('Keys', 'PKCS8', 'savePublicKey');
if (!isset($this->y)) {
$this->y = $this->g->powMod($this->x, $this->p);
}
$key = $type::savePublicKey($this->p, $this->q, $this->g, $this->y);
return DSA::loadFormat('PKCS8', $key)
->withHash($this->hash->getHash())
->withSignatureFormat($this->shortFormat);
}
/**
* Create a signature
*
* @see self::verify()
* @param string $message
*/
public function sign($message): string
{
$format = $this->sigFormat;
if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) {
$signature = '';
$result = openssl_sign($message, $signature, $this->toString('PKCS8'), $this->hash->getHash());
if ($result) {
if ($this->shortFormat == 'ASN1') {
return $signature;
}
extract(ASN1Signature::load($signature));
return $format::save($r, $s);
}
}
$h = $this->hash->hash($message);
$h = $this->bits2int($h);
while (true) {
$k = BigInteger::randomRange(self::$one, $this->q->subtract(self::$one));
$r = $this->g->powMod($k, $this->p);
[, $r] = $r->divide($this->q);
if ($r->equals(self::$zero)) {
continue;
}
$kinv = $k->modInverse($this->q);
$temp = $h->add($this->x->multiply($r));
$temp = $kinv->multiply($temp);
[, $s] = $temp->divide($this->q);
if (!$s->equals(self::$zero)) {
break;
}
}
// the following is an RFC6979 compliant implementation of deterministic DSA
// it's unused because it's mainly intended for use when a good CSPRNG isn't
// available. if phpseclib's CSPRNG isn't good then even key generation is
// suspect
/*
$h1 = $this->hash->hash($message);
$k = $this->computek($h1);
$r = $this->g->powMod($k, $this->p);
list(, $r) = $r->divide($this->q);
$kinv = $k->modInverse($this->q);
$h1 = $this->bits2int($h1);
$temp = $h1->add($this->x->multiply($r));
$temp = $kinv->multiply($temp);
list(, $s) = $temp->divide($this->q);
*/
return $format::save($r, $s);
}
/**
* Returns the private key
*
* @param array $options optional
*/
public function toString(string $type, array $options = []): string
{
$type = self::validatePlugin('Keys', $type, 'savePrivateKey');
if (!isset($this->y)) {
$this->y = $this->g->powMod($this->x, $this->p);
}
return $type::savePrivateKey($this->p, $this->q, $this->g, $this->y, $this->x, $this->password, $options);
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* DSA Public Key
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\DSA;
use phpseclib3\Crypt\Common;
use phpseclib3\Crypt\DSA;
use phpseclib3\Crypt\DSA\Formats\Signature\ASN1 as ASN1Signature;
/**
* DSA Public Key
*
* @author Jim Wigginton <terrafrost@php.net>
*/
final class PublicKey extends DSA implements Common\PublicKey
{
use Common\Traits\Fingerprint;
/**
* Verify a signature
*
* @see self::verify()
* @param string $message
* @param string $signature
*/
public function verify($message, $signature): bool
{
$format = $this->sigFormat;
$params = $format::load($signature);
if ($params === false || count($params) != 2) {
return false;
}
extract($params);
if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) {
$sig = $format != 'ASN1' ? ASN1Signature::save($r, $s) : $signature;
$result = openssl_verify($message, $sig, $this->toString('PKCS8'), $this->hash->getHash());
if ($result != -1) {
return (bool) $result;
}
}
$q_1 = $this->q->subtract(self::$one);
if (!$r->between(self::$one, $q_1) || !$s->between(self::$one, $q_1)) {
return false;
}
$w = $s->modInverse($this->q);
$h = $this->hash->hash($message);
$h = $this->bits2int($h);
[, $u1] = $h->multiply($w)->divide($this->q);
[, $u2] = $r->multiply($w)->divide($this->q);
$v1 = $this->g->powMod($u1, $this->p);
$v2 = $this->y->powMod($u2, $this->p);
[, $v] = $v1->multiply($v2)->divide($this->p);
[, $v] = $v->divide($this->q);
return $v->equals($r);
}
/**
* Returns the public key
*
* @param array $options optional
*/
public function toString(string $type, array $options = []): string
{
$type = self::validatePlugin('Keys', $type, 'savePublicKey');
return $type::savePublicKey($this->p, $this->q, $this->g, $this->y, $options);
}
}

470
phpseclib/Crypt/EC.php Normal file
View File

@ -0,0 +1,470 @@
<?php
/**
* Pure-PHP implementation of EC.
*
* PHP version 5
*
* Here's an example of how to create signatures and verify signatures with this library:
* <code>
* <?php
* include 'vendor/autoload.php';
*
* $private = \phpseclib3\Crypt\EC::createKey('secp256k1');
* $public = $private->getPublicKey();
*
* $plaintext = 'terrafrost';
*
* $signature = $private->sign($plaintext);
*
* echo $public->verify($plaintext, $signature) ? 'verified' : 'unverified';
* ?>
* </code>
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
declare(strict_types=1);
namespace phpseclib3\Crypt;
use phpseclib3\Crypt\Common\AsymmetricKey;
use phpseclib3\Crypt\EC\BaseCurves\Base;
use phpseclib3\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
use phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
use phpseclib3\Crypt\EC\Curves\Curve25519;
use phpseclib3\Crypt\EC\Curves\Ed25519;
use phpseclib3\Crypt\EC\Curves\Ed448;
use phpseclib3\Crypt\EC\Formats\Keys\PKCS1;
use phpseclib3\Crypt\EC\Parameters;
use phpseclib3\Crypt\EC\PrivateKey;
use phpseclib3\Crypt\EC\PublicKey;
use phpseclib3\Exception\InvalidArgumentException;
use phpseclib3\Exception\LengthException;
use phpseclib3\Exception\UnsupportedAlgorithmException;
use phpseclib3\Exception\UnsupportedCurveException;
use phpseclib3\Exception\UnsupportedOperationException;
use phpseclib3\File\ASN1;
use phpseclib3\File\ASN1\Maps\ECParameters;
use phpseclib3\Math\BigInteger;
/**
* Pure-PHP implementation of EC.
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class EC extends AsymmetricKey
{
/**
* Algorithm Name
*
* @var string
*/
public const ALGORITHM = 'EC';
/**
* Public Key QA
*
* @var object[]
*/
protected $QA;
/**
* Curve
*
* @var Base
*/
protected $curve;
/**
* Signature Format
*
* @var string
*/
protected $format;
/**
* Signature Format (Short)
*
* @var string
*/
protected $shortFormat;
/**
* Curve Name
*
* @var string
*/
private $curveName;
/**
* Curve Order
*
* Used for deterministic ECDSA
*
* @var BigInteger
*/
protected $q;
/**
* Alias for the private key
*
* Used for deterministic ECDSA. AsymmetricKey expects $x. I don't like x because
* with x you have x * the base point yielding an (x, y)-coordinate that is the
* public key. But the x is different depending on which side of the equal sign
* you're on. It's less ambiguous if you do dA * base point = (x, y)-coordinate.
*
* @var BigInteger
*/
protected $x;
/**
* Context
*
* @var string
*/
protected $context;
/**
* Signature Format
*
* @var string
*/
protected $sigFormat;
/**
* Create public / private key pair.
*/
public static function createKey(string $curve): PrivateKey
{
self::initialize_static_variables();
$class = new \ReflectionClass(static::class);
if ($class->isFinal()) {
throw new \RuntimeException('createKey() should not be called from final classes (' . static::class . ')');
}
if (!isset(self::$engines['PHP'])) {
self::useBestEngine();
}
$curve = strtolower($curve);
if (self::$engines['libsodium'] && $curve == 'ed25519' && function_exists('sodium_crypto_sign_keypair')) {
$kp = sodium_crypto_sign_keypair();
$privatekey = EC::loadFormat('libsodium', sodium_crypto_sign_secretkey($kp));
//$publickey = EC::loadFormat('libsodium', sodium_crypto_sign_publickey($kp));
$privatekey->curveName = 'Ed25519';
//$publickey->curveName = $curve;
return $privatekey;
}
$privatekey = new PrivateKey();
$curveName = $curve;
if (preg_match('#(?:^curve|^ed)\d+$#', $curveName)) {
$curveName = ucfirst($curveName);
} elseif (substr($curveName, 0, 10) == 'brainpoolp') {
$curveName = 'brainpoolP' . substr($curveName, 10);
}
$curve = '\phpseclib3\Crypt\EC\Curves\\' . $curveName;
if (!class_exists($curve)) {
throw new UnsupportedCurveException('Named Curve of ' . $curveName . ' is not supported');
}
$reflect = new \ReflectionClass($curve);
$curveName = $reflect->isFinal() ?
$reflect->getParentClass()->getShortName() :
$reflect->getShortName();
$curve = new $curve();
if ($curve instanceof TwistedEdwardsCurve) {
$arr = $curve->extractSecret(Random::string($curve instanceof Ed448 ? 57 : 32));
$privatekey->dA = $dA = $arr['dA'];
$privatekey->secret = $arr['secret'];
} else {
$privatekey->dA = $dA = $curve->createRandomMultiplier();
}
if ($curve instanceof Curve25519 && self::$engines['libsodium']) {
//$r = pack('H*', '0900000000000000000000000000000000000000000000000000000000000000');
//$QA = sodium_crypto_scalarmult($dA->toBytes(), $r);
$QA = sodium_crypto_box_publickey_from_secretkey($dA->toBytes());
$privatekey->QA = [$curve->convertInteger(new BigInteger(strrev($QA), 256))];
} else {
$privatekey->QA = $curve->multiplyPoint($curve->getBasePoint(), $dA);
}
$privatekey->curve = $curve;
//$publickey = clone $privatekey;
//unset($publickey->dA);
//unset($publickey->x);
$privatekey->curveName = $curveName;
//$publickey->curveName = $curveName;
if ($privatekey->curve instanceof TwistedEdwardsCurve) {
return $privatekey->withHash($curve::HASH);
}
return $privatekey;
}
/**
* OnLoad Handler
*
* @return AsymmetricKey|Parameters|PrivateKey|PublicKey
*/
protected static function onLoad(array $components)
{
if (!isset(self::$engines['PHP'])) {
self::useBestEngine();
}
if (!isset($components['dA']) && !isset($components['QA'])) {
$new = new Parameters();
$new->curve = $components['curve'];
return $new;
}
$new = isset($components['dA']) ?
new PrivateKey() :
new PublicKey();
$new->curve = $components['curve'];
$new->QA = $components['QA'];
if (isset($components['dA'])) {
$new->dA = $components['dA'];
$new->secret = $components['secret'];
}
if ($new->curve instanceof TwistedEdwardsCurve) {
return $new->withHash($components['curve']::HASH);
}
return $new;
}
/**
* Constructor
*
* PublicKey and PrivateKey objects can only be created from abstract RSA class
*/
protected function __construct()
{
$this->sigFormat = self::validatePlugin('Signature', 'ASN1');
$this->shortFormat = 'ASN1';
parent::__construct();
}
/**
* Returns the curve
*
* Returns a string if it's a named curve, an array if not
*
* @return string|array
*/
public function getCurve()
{
if ($this->curveName) {
return $this->curveName;
}
if ($this->curve instanceof MontgomeryCurve) {
$this->curveName = $this->curve instanceof Curve25519 ? 'Curve25519' : 'Curve448';
return $this->curveName;
}
if ($this->curve instanceof TwistedEdwardsCurve) {
$this->curveName = $this->curve instanceof Ed25519 ? 'Ed25519' : 'Ed448';
return $this->curveName;
}
$params = $this->getParameters()->toString('PKCS8', ['namedCurve' => true]);
$decoded = ASN1::extractBER($params);
$decoded = ASN1::decodeBER($decoded);
$decoded = ASN1::asn1map($decoded[0], ECParameters::MAP);
if (isset($decoded['namedCurve'])) {
$this->curveName = $decoded['namedCurve'];
return $decoded['namedCurve'];
}
if (!$namedCurves) {
PKCS1::useSpecifiedCurve();
}
return $decoded;
}
/**
* Returns the key size
*
* Quoting https://tools.ietf.org/html/rfc5656#section-2,
*
* "The size of a set of elliptic curve domain parameters on a prime
* curve is defined as the number of bits in the binary representation
* of the field order, commonly denoted by p. Size on a
* characteristic-2 curve is defined as the number of bits in the binary
* representation of the field, commonly denoted by m. A set of
* elliptic curve domain parameters defines a group of order n generated
* by a base point P"
*/
public function getLength(): int
{
return $this->curve->getLength();
}
/**
* Returns the current engine being used
*
* @see self::useInternalEngine()
* @see self::useBestEngine()
*/
public function getEngine(): string
{
if (!isset(self::$engines['PHP'])) {
self::useBestEngine();
}
if ($this->curve instanceof TwistedEdwardsCurve) {
return $this->curve instanceof Ed25519 && self::$engines['libsodium'] && !isset($this->context) ?
'libsodium' : 'PHP';
}
return self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods()) ?
'OpenSSL' : 'PHP';
}
/**
* Returns the public key coordinates as a string
*
* Used by ECDH
*/
public function getEncodedCoordinates(): string
{
if ($this->curve instanceof MontgomeryCurve) {
return strrev($this->QA[0]->toBytes(true));
}
if ($this->curve instanceof TwistedEdwardsCurve) {
return $this->curve->encodePoint($this->QA);
}
return "\4" . $this->QA[0]->toBytes(true) . $this->QA[1]->toBytes(true);
}
/**
* Returns the parameters
*
* @param string $type optional
* @see self::getPublicKey()
*/
public function getParameters(string $type = 'PKCS1')
{
$type = self::validatePlugin('Keys', $type, 'saveParameters');
$key = $type::saveParameters($this->curve);
return EC::load($key, 'PKCS1')
->withHash($this->hash->getHash())
->withSignatureFormat($this->shortFormat);
}
/**
* Determines the signature padding mode
*
* Valid values are: ASN1, SSH2, Raw
*/
public function withSignatureFormat(string $format): EC
{
if ($this->curve instanceof MontgomeryCurve) {
throw new UnsupportedOperationException('Montgomery Curves cannot be used to create signatures');
}
$new = clone $this;
$new->shortFormat = $format;
$new->sigFormat = self::validatePlugin('Signature', $format);
return $new;
}
/**
* Returns the signature format currently being used
*/
public function getSignatureFormat(): string
{
return $this->shortFormat;
}
/**
* Sets the context
*
* Used by Ed25519 / Ed448.
*
* @param string|null $context optional
* @see self::verify()
* @see self::sign()
*/
public function withContext(?string $context = null): EC
{
if (!$this->curve instanceof TwistedEdwardsCurve) {
throw new UnsupportedCurveException('Only Ed25519 and Ed448 support contexts');
}
$new = clone $this;
if (!isset($context)) {
$new->context = null;
return $new;
}
if (!is_string($context)) {
throw new InvalidArgumentException('setContext expects a string');
}
if (strlen($context) > 255) {
throw new LengthException('The context is supposed to be, at most, 255 bytes long');
}
$new->context = $context;
return $new;
}
/**
* Returns the signature format currently being used
*/
public function getContext(): string
{
return $this->context;
}
/**
* Determines which hashing function should be used
*/
public function withHash(string $hash): AsymmetricKey
{
if ($this->curve instanceof MontgomeryCurve) {
throw new UnsupportedOperationException('Montgomery Curves cannot be used to create signatures');
}
if ($this->curve instanceof Ed25519 && $hash != 'sha512') {
throw new UnsupportedAlgorithmException('Ed25519 only supports sha512 as a hash');
}
if ($this->curve instanceof Ed448 && $hash != 'shake256-912') {
throw new UnsupportedAlgorithmException('Ed448 only supports shake256 with a length of 114 bytes');
}
return parent::withHash($hash);
}
/**
* __toString() magic method
*
* @return string
*/
public function __toString()
{
if ($this->curve instanceof MontgomeryCurve) {
return '';
}
return parent::__toString();
}
}

View File

@ -0,0 +1,217 @@
<?php
/**
* Curve methods common to all curves
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\BaseCurves;
use phpseclib3\Exception\RangeException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\FiniteField\Integer;
/**
* Base
*
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class Base
{
/**
* The Order
*
* @var BigInteger
*/
protected $order;
/**
* Finite Field Integer factory
*
* @var Integer
*/
protected $factory;
/**
* Returns a random integer
*
* @return object
*/
public function randomInteger()
{
return $this->factory->randomInteger();
}
/**
* Converts a BigInteger to a \phpseclib3\Math\FiniteField\Integer integer
*
* @return object
*/
public function convertInteger(BigInteger $x)
{
return $this->factory->newInteger($x);
}
/**
* Returns the length, in bytes, of the modulo
*
* @return integer
*/
public function getLengthInBytes(): int
{
return $this->factory->getLengthInBytes();
}
/**
* Returns the length, in bits, of the modulo
*
* @return integer
*/
public function getLength(): int
{
return $this->factory->getLength();
}
/**
* Multiply a point on the curve by a scalar
*
* Uses the montgomery ladder technique as described here:
*
* https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Montgomery_ladder
* https://github.com/phpecc/phpecc/issues/16#issuecomment-59176772
*/
public function multiplyPoint(array $p, BigInteger $d): array
{
$alreadyInternal = isset($p[2]);
$r = $alreadyInternal ?
[[], $p] :
[[], $this->convertToInternal($p)];
$d = $d->toBits();
for ($i = 0; $i < strlen($d); $i++) {
$d_i = (int) $d[$i];
$r[1 - $d_i] = $this->addPoint($r[0], $r[1]);
$r[$d_i] = $this->doublePoint($r[$d_i]);
}
return $alreadyInternal ? $r[0] : $this->convertToAffine($r[0]);
}
/**
* Creates a random scalar multiplier
*/
public function createRandomMultiplier(): BigInteger
{
static $one;
if (!isset($one)) {
$one = new BigInteger(1);
}
return BigInteger::randomRange($one, $this->order->subtract($one));
}
/**
* Performs range check
*/
public function rangeCheck(BigInteger $x): void
{
static $zero;
if (!isset($zero)) {
$zero = new BigInteger();
}
if (!isset($this->order)) {
throw new RuntimeException('setOrder needs to be called before this method');
}
if ($x->compare($this->order) > 0 || $x->compare($zero) <= 0) {
throw new RangeException('x must be between 1 and the order of the curve');
}
}
/**
* Sets the Order
*/
public function setOrder(BigInteger $order): void
{
$this->order = $order;
}
/**
* Returns the Order
*/
public function getOrder(): BigInteger
{
return $this->order;
}
/**
* Use a custom defined modular reduction function
*
* @return object
*/
public function setReduction(callable $func)
{
$this->factory->setReduction($func);
}
/**
* Returns the affine point
*
* @return object[]
*/
public function convertToAffine(array $p): array
{
return $p;
}
/**
* Converts an affine point to a jacobian coordinate
*
* @return object[]
*/
public function convertToInternal(array $p): array
{
return $p;
}
/**
* Negates a point
*
* @return object[]
*/
public function negatePoint(array $p): array
{
$temp = [
$p[0],
$p[1]->negate(),
];
if (isset($p[2])) {
$temp[] = $p[2];
}
return $temp;
}
/**
* Multiply and Add Points
*
* @return int[]
*/
public function multiplyAddPoints(array $points, array $scalars): array
{
$p1 = $this->convertToInternal($points[0]);
$p2 = $this->convertToInternal($points[1]);
$p1 = $this->multiplyPoint($p1, $scalars[0]);
$p2 = $this->multiplyPoint($p2, $scalars[1]);
$r = $this->addPoint($p1, $p2);
return $this->convertToAffine($r);
}
}

View File

@ -0,0 +1,371 @@
<?php
/**
* Curves over y^2 + x*y = x^3 + a*x^2 + b
*
* These are curves used in SEC 2 over prime fields: http://www.secg.org/SEC2-Ver-1.0.pdf
* The curve is a weierstrass curve with a[3] and a[2] set to 0.
*
* Uses Jacobian Coordinates for speed if able:
*
* https://en.wikipedia.org/wiki/Jacobian_curve
* https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\BaseCurves;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\BinaryField;
use phpseclib3\Math\BinaryField\Integer as BinaryInteger;
use phpseclib3\Math\PrimeField\Integer;
/**
* Curves over y^2 + x*y = x^3 + a*x^2 + b
*
* @author Jim Wigginton <terrafrost@php.net>
*/
class Binary extends Base
{
/**
* Binary Field Integer factory
*
* @var BinaryField
*/
protected $factory;
/**
* Cofficient for x^1
*
* @var object
*/
protected $a;
/**
* Cofficient for x^0
*
* @var object
*/
protected $b;
/**
* Base Point
*
* @var object
*/
protected $p;
/**
* The number one over the specified finite field
*
* @var object
*/
protected $one;
/**
* The modulo
*
* @var array
*/
protected $modulo;
/**
* The Order
*
* @var BigInteger
*/
protected $order;
/**
* Sets the modulo
*/
public function setModulo(int ...$modulo): void
{
$this->modulo = $modulo;
$this->factory = new BinaryField(...$modulo);
$this->one = $this->factory->newInteger("\1");
}
/**
* Set coefficients a and b
*/
public function setCoefficients(string $a, string $b): void
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->a = $this->factory->newInteger(pack('H*', $a));
$this->b = $this->factory->newInteger(pack('H*', $b));
}
/**
* Set x and y coordinates for the base point
*
* @param string|BinaryInteger $x
* @param string|BinaryInteger $y
*/
public function setBasePoint($x, $y): void
{
switch (true) {
case !is_string($x) && !$x instanceof BinaryInteger:
throw new UnexpectedValueException('Argument 1 passed to Binary::setBasePoint() must be a string or an instance of BinaryField\Integer');
case !is_string($y) && !$y instanceof BinaryInteger:
throw new UnexpectedValueException('Argument 2 passed to Binary::setBasePoint() must be a string or an instance of BinaryField\Integer');
}
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->p = [
is_string($x) ? $this->factory->newInteger(pack('H*', $x)) : $x,
is_string($y) ? $this->factory->newInteger(pack('H*', $y)) : $y,
];
}
/**
* Retrieve the base point as an array
*
* @return array
*/
public function getBasePoint()
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
/*
if (!isset($this->p)) {
throw new \phpseclib3\Exception\RuntimeException('setBasePoint needs to be called before this method');
}
*/
return $this->p;
}
/**
* Adds two points on the curve
*
* @return FiniteField[]
*/
public function addPoint(array $p, array $q): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p) || !count($q)) {
if (count($q)) {
return $q;
}
if (count($p)) {
return $p;
}
return [];
}
if (!isset($p[2]) || !isset($q[2])) {
throw new RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
}
if ($p[0]->equals($q[0])) {
return !$p[1]->equals($q[1]) ? [] : $this->doublePoint($p);
}
// formulas from http://hyperelliptic.org/EFD/g12o/auto-shortw-jacobian.html
[$x1, $y1, $z1] = $p;
[$x2, $y2, $z2] = $q;
$o1 = $z1->multiply($z1);
$b = $x2->multiply($o1);
if ($z2->equals($this->one)) {
$d = $y2->multiply($o1)->multiply($z1);
$e = $x1->add($b);
$f = $y1->add($d);
$z3 = $e->multiply($z1);
$h = $f->multiply($x2)->add($z3->multiply($y2));
$i = $f->add($z3);
$g = $z3->multiply($z3);
$p1 = $this->a->multiply($g);
$p2 = $f->multiply($i);
$p3 = $e->multiply($e)->multiply($e);
$x3 = $p1->add($p2)->add($p3);
$y3 = $i->multiply($x3)->add($g->multiply($h));
return [$x3, $y3, $z3];
}
$o2 = $z2->multiply($z2);
$a = $x1->multiply($o2);
$c = $y1->multiply($o2)->multiply($z2);
$d = $y2->multiply($o1)->multiply($z1);
$e = $a->add($b);
$f = $c->add($d);
$g = $e->multiply($z1);
$h = $f->multiply($x2)->add($g->multiply($y2));
$z3 = $g->multiply($z2);
$i = $f->add($z3);
$p1 = $this->a->multiply($z3->multiply($z3));
$p2 = $f->multiply($i);
$p3 = $e->multiply($e)->multiply($e);
$x3 = $p1->add($p2)->add($p3);
$y3 = $i->multiply($x3)->add($g->multiply($g)->multiply($h));
return [$x3, $y3, $z3];
}
/**
* Doubles a point on a curve
*
* @return FiniteField[]
*/
public function doublePoint(array $p): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p)) {
return [];
}
if (!isset($p[2])) {
throw new RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
}
// formulas from http://hyperelliptic.org/EFD/g12o/auto-shortw-jacobian.html
[$x1, $y1, $z1] = $p;
$a = $x1->multiply($x1);
$b = $a->multiply($a);
if ($z1->equals($this->one)) {
$x3 = $b->add($this->b);
$z3 = clone $x1;
$p1 = $a->add($y1)->add($z3)->multiply($this->b);
$p2 = $a->add($y1)->multiply($b);
$y3 = $p1->add($p2);
return [$x3, $y3, $z3];
}
$c = $z1->multiply($z1);
$d = $c->multiply($c);
$x3 = $b->add($this->b->multiply($d->multiply($d)));
$z3 = $x1->multiply($c);
$p1 = $b->multiply($z3);
$p2 = $a->add($y1->multiply($z1))->add($z3)->multiply($x3);
$y3 = $p1->add($p2);
return [$x3, $y3, $z3];
}
/**
* Returns the X coordinate and the derived Y coordinate
*
* Not supported because it is covered by patents.
* Quoting https://www.openssl.org/docs/man1.1.0/apps/ecparam.html ,
*
* "Due to patent issues the compressed option is disabled by default for binary curves
* and can be enabled by defining the preprocessor macro OPENSSL_EC_BIN_PT_COMP at
* compile time."
*/
public function derivePoint($m): array
{
throw new RuntimeException('Point compression on binary finite field elliptic curves is not supported');
}
/**
* Tests whether or not the x / y values satisfy the equation
*
* @return boolean
*/
public function verifyPoint(array $p): bool
{
[$x, $y] = $p;
$lhs = $y->multiply($y);
$lhs = $lhs->add($x->multiply($y));
$x2 = $x->multiply($x);
$x3 = $x2->multiply($x);
$rhs = $x3->add($this->a->multiply($x2))->add($this->b);
return $lhs->equals($rhs);
}
/**
* Returns the modulo
*/
public function getModulo(): array
{
return $this->modulo;
}
/**
* Returns the a coefficient
*
* @return Integer
*/
public function getA()
{
return $this->a;
}
/**
* Returns the a coefficient
*
* @return Integer
*/
public function getB()
{
return $this->b;
}
/**
* Returns the affine point
*
* A Jacobian Coordinate is of the form (x, y, z).
* To convert a Jacobian Coordinate to an Affine Point
* you do (x / z^2, y / z^3)
*
* @return Integer[]
*/
public function convertToAffine(array $p): array
{
if (!isset($p[2])) {
return $p;
}
[$x, $y, $z] = $p;
$z = $this->one->divide($z);
$z2 = $z->multiply($z);
return [
$x->multiply($z2),
$y->multiply($z2)->multiply($z),
];
}
/**
* Converts an affine point to a jacobian coordinate
*
* @return Integer[]
*/
public function convertToInternal(array $p): array
{
if (isset($p[2])) {
return $p;
}
$p[2] = clone $this->one;
$p['fresh'] = true;
return $p;
}
}

View File

@ -0,0 +1,335 @@
<?php
/**
* Generalized Koblitz Curves over y^2 = x^3 + b.
*
* According to http://www.secg.org/SEC2-Ver-1.0.pdf Koblitz curves are over the GF(2**m)
* finite field. Both the $a$ and $b$ coefficients are either 0 or 1. However, SEC2
* generalizes the definition to include curves over GF(P) "which possess an efficiently
* computable endomorphism".
*
* For these generalized Koblitz curves $b$ doesn't have to be 0 or 1. Whether or not $a$
* has any restrictions on it is unclear, however, for all the GF(P) Koblitz curves defined
* in SEC2 v1.0 $a$ is $0$ so all of the methods defined herein will assume that it is.
*
* I suppose we could rename the $b$ coefficient to $a$, however, the documentation refers
* to $b$ so we'll just keep it.
*
* If a later version of SEC2 comes out wherein some $a$ values are non-zero we can create a
* new method for those. eg. KoblitzA1Prime.php or something.
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\BaseCurves;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\PrimeField;
/**
* Curves over y^2 = x^3 + b
*
* @author Jim Wigginton <terrafrost@php.net>
*/
class KoblitzPrime extends Prime
{
/**
* Basis
*
* @var list<array{a: BigInteger, b: BigInteger}>
*/
public $basis;
/**
* Beta
*
* @var PrimeField\Integer
*/
public $beta;
// don't overwrite setCoefficients() with one that only accepts one parameter so that
// one might be able to switch between KoblitzPrime and Prime more easily (for benchmarking
// purposes).
/**
* Multiply and Add Points
*
* Uses a efficiently computable endomorphism to achieve a slight speedup
*
* Adapted from:
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/curve/short.js#L219
*
* @return int[]
*/
public function multiplyAddPoints(array $points, array $scalars): array
{
static $zero, $one, $two;
if (!isset($two)) {
$two = new BigInteger(2);
$one = new BigInteger(1);
}
if (!isset($this->beta)) {
// get roots
$inv = $this->one->divide($this->two)->negate();
$s = $this->three->negate()->squareRoot()->multiply($inv);
$betas = [
$inv->add($s),
$inv->subtract($s),
];
$this->beta = $betas[0]->compare($betas[1]) < 0 ? $betas[0] : $betas[1];
//echo strtoupper($this->beta->toHex(true)) . "\n"; exit;
}
if (!isset($this->basis)) {
$factory = new PrimeField($this->order);
$tempOne = $factory->newInteger($one);
$tempTwo = $factory->newInteger($two);
$tempThree = $factory->newInteger(new BigInteger(3));
$inv = $tempOne->divide($tempTwo)->negate();
$s = $tempThree->negate()->squareRoot()->multiply($inv);
$lambdas = [
$inv->add($s),
$inv->subtract($s),
];
$lhs = $this->multiplyPoint($this->p, $lambdas[0])[0];
$rhs = $this->p[0]->multiply($this->beta);
$lambda = $lhs->equals($rhs) ? $lambdas[0] : $lambdas[1];
$this->basis = static::extendedGCD($lambda->toBigInteger(), $this->order);
///*
foreach ($this->basis as $basis) {
echo strtoupper($basis['a']->toHex(true)) . "\n";
echo strtoupper($basis['b']->toHex(true)) . "\n\n";
}
exit;
//*/
}
$npoints = $nscalars = [];
for ($i = 0; $i < count($points); $i++) {
$p = $points[$i];
$k = $scalars[$i]->toBigInteger();
// begin split
[$v1, $v2] = $this->basis;
$c1 = $v2['b']->multiply($k);
[$c1, $r] = $c1->divide($this->order);
if ($this->order->compare($r->multiply($two)) <= 0) {
$c1 = $c1->add($one);
}
$c2 = $v1['b']->negate()->multiply($k);
[$c2, $r] = $c2->divide($this->order);
if ($this->order->compare($r->multiply($two)) <= 0) {
$c2 = $c2->add($one);
}
$p1 = $c1->multiply($v1['a']);
$p2 = $c2->multiply($v2['a']);
$q1 = $c1->multiply($v1['b']);
$q2 = $c2->multiply($v2['b']);
$k1 = $k->subtract($p1)->subtract($p2);
$k2 = $q1->add($q2)->negate();
// end split
$beta = [
$p[0]->multiply($this->beta),
$p[1],
clone $this->one,
];
if (isset($p['naf'])) {
$beta['naf'] = array_map(function ($p) {
return [
$p[0]->multiply($this->beta),
$p[1],
clone $this->one,
];
}, $p['naf']);
$beta['nafwidth'] = $p['nafwidth'];
}
if ($k1->isNegative()) {
$k1 = $k1->negate();
$p = $this->negatePoint($p);
}
if ($k2->isNegative()) {
$k2 = $k2->negate();
$beta = $this->negatePoint($beta);
}
$pos = 2 * $i;
$npoints[$pos] = $p;
$nscalars[$pos] = $this->factory->newInteger($k1);
$pos++;
$npoints[$pos] = $beta;
$nscalars[$pos] = $this->factory->newInteger($k2);
}
return parent::multiplyAddPoints($npoints, $nscalars);
}
/**
* Returns the numerator and denominator of the slope
*
* @return FiniteField[]
*/
protected function doublePointHelper(array $p): array
{
$numerator = $this->three->multiply($p[0])->multiply($p[0]);
$denominator = $this->two->multiply($p[1]);
return [$numerator, $denominator];
}
/**
* Doubles a jacobian coordinate on the curve
*
* See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l
*
* @return FiniteField[]
*/
protected function jacobianDoublePoint(array $p): array
{
[$x1, $y1, $z1] = $p;
$a = $x1->multiply($x1);
$b = $y1->multiply($y1);
$c = $b->multiply($b);
$d = $x1->add($b);
$d = $d->multiply($d)->subtract($a)->subtract($c)->multiply($this->two);
$e = $this->three->multiply($a);
$f = $e->multiply($e);
$x3 = $f->subtract($this->two->multiply($d));
$y3 = $e->multiply($d->subtract($x3))->subtract(
$this->eight->multiply($c)
);
$z3 = $this->two->multiply($y1)->multiply($z1);
return [$x3, $y3, $z3];
}
/**
* Doubles a "fresh" jacobian coordinate on the curve
*
* See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-mdbl-2007-bl
*
* @return FiniteField[]
*/
protected function jacobianDoublePointMixed(array $p): array
{
[$x1, $y1] = $p;
$xx = $x1->multiply($x1);
$yy = $y1->multiply($y1);
$yyyy = $yy->multiply($yy);
$s = $x1->add($yy);
$s = $s->multiply($s)->subtract($xx)->subtract($yyyy)->multiply($this->two);
$m = $this->three->multiply($xx);
$t = $m->multiply($m)->subtract($this->two->multiply($s));
$x3 = $t;
$y3 = $s->subtract($t);
$y3 = $m->multiply($y3)->subtract($this->eight->multiply($yyyy));
$z3 = $this->two->multiply($y1);
return [$x3, $y3, $z3];
}
/**
* Tests whether or not the x / y values satisfy the equation
*
* @return boolean
*/
public function verifyPoint(array $p): bool
{
[$x, $y] = $p;
$lhs = $y->multiply($y);
$temp = $x->multiply($x)->multiply($x);
$rhs = $temp->add($this->b);
return $lhs->equals($rhs);
}
/**
* Calculates the parameters needed from the Euclidean algorithm as discussed at
* http://diamond.boisestate.edu/~liljanab/MATH308/GuideToECC.pdf#page=148
*
* @return BigInteger[]
*/
protected static function extendedGCD(BigInteger $u, BigInteger $v): array
{
$one = new BigInteger(1);
$zero = new BigInteger();
$a = clone $one;
$b = clone $zero;
$c = clone $zero;
$d = clone $one;
$stop = $v->bitwise_rightShift($v->getLength() >> 1);
$a1 = clone $zero;
$b1 = clone $zero;
$a2 = clone $zero;
$b2 = clone $zero;
$postGreatestIndex = 0;
while (!$v->equals($zero)) {
[$q] = $u->divide($v);
$temp = $u;
$u = $v;
$v = $temp->subtract($v->multiply($q));
$temp = $a;
$a = $c;
$c = $temp->subtract($a->multiply($q));
$temp = $b;
$b = $d;
$d = $temp->subtract($b->multiply($q));
if ($v->compare($stop) > 0) {
$a0 = $v;
$b0 = $c;
} else {
$postGreatestIndex++;
}
if ($postGreatestIndex == 1) {
$a1 = $v;
$b1 = $c->negate();
}
if ($postGreatestIndex == 2) {
$rhs = $a0->multiply($a0)->add($b0->multiply($b0));
$lhs = $v->multiply($v)->add($b->multiply($b));
if ($lhs->compare($rhs) <= 0) {
$a2 = $a0;
$b2 = $b0->negate();
} else {
$a2 = $v;
$b2 = $c->negate();
}
break;
}
}
return [
['a' => $a1, 'b' => $b1],
['a' => $a2, 'b' => $b2],
];
}
}

View File

@ -0,0 +1,281 @@
<?php
/**
* Curves over y^2 = x^3 + a*x + x
*
* Technically, a Montgomery curve has a coefficient for y^2 but for Curve25519 and Curve448 that
* coefficient is 1.
*
* Curve25519 and Curve448 do not make use of the y coordinate, which makes it unsuitable for use
* with ECDSA / EdDSA. A few other differences between Curve25519 and Ed25519 are discussed at
* https://crypto.stackexchange.com/a/43058/4520
*
* More info:
*
* https://en.wikipedia.org/wiki/Montgomery_curve
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2019 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\BaseCurves;
use phpseclib3\Crypt\EC\Curves\Curve25519;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\PrimeField;
use phpseclib3\Math\PrimeField\Integer as PrimeInteger;
/**
* Curves over y^2 = x^3 + a*x + x
*
* @author Jim Wigginton <terrafrost@php.net>
*/
class Montgomery extends Base
{
/**
* Prime Field Integer factory
*
* @var PrimeField
*/
protected $factory;
/**
* Cofficient for x
*
* @var object
*/
protected $a;
/**
* Constant used for point doubling
*
* @var object
*/
protected $a24;
/**
* The Number Zero
*
* @var object
*/
protected $zero;
/**
* The Number One
*
* @var object
*/
protected $one;
/**
* Base Point
*
* @var object
*/
protected $p;
/**
* The modulo
*
* @var BigInteger
*/
protected $modulo;
/**
* The Order
*
* @var BigInteger
*/
protected $order;
/**
* Sets the modulo
*/
public function setModulo(BigInteger $modulo): void
{
$this->modulo = $modulo;
$this->factory = new PrimeField($modulo);
$this->zero = $this->factory->newInteger(new BigInteger());
$this->one = $this->factory->newInteger(new BigInteger(1));
}
/**
* Set coefficients a
*/
public function setCoefficients(BigInteger $a): void
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->a = $this->factory->newInteger($a);
$two = $this->factory->newInteger(new BigInteger(2));
$four = $this->factory->newInteger(new BigInteger(4));
$this->a24 = $this->a->subtract($two)->divide($four);
}
/**
* Set x and y coordinates for the base point
*
* @param BigInteger|PrimeInteger $x
* @param BigInteger|PrimeInteger $y
* @return PrimeInteger[]
*/
public function setBasePoint($x, $y): array
{
switch (true) {
case !$x instanceof BigInteger && !$x instanceof PrimeInteger:
throw new UnexpectedValueException('Argument 1 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
case !$y instanceof BigInteger && !$y instanceof PrimeInteger:
throw new UnexpectedValueException('Argument 2 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
}
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->p = [
$x instanceof BigInteger ? $this->factory->newInteger($x) : $x,
$y instanceof BigInteger ? $this->factory->newInteger($y) : $y,
];
}
/**
* Retrieve the base point as an array
*
* @return array
*/
public function getBasePoint()
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
/*
if (!isset($this->p)) {
throw new \phpseclib3\Exception\RuntimeException('setBasePoint needs to be called before this method');
}
*/
return $this->p;
}
/**
* Doubles and adds a point on a curve
*
* See https://tools.ietf.org/html/draft-ietf-tls-curve25519-01#appendix-A.1.3
*
* @return FiniteField[][]
*/
private function doubleAndAddPoint(array $p, array $q, PrimeInteger $x1): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p) || !count($q)) {
return [];
}
if (!isset($p[1])) {
throw new RuntimeException('Affine coordinates need to be manually converted to XZ coordinates');
}
[$x2, $z2] = $p;
[$x3, $z3] = $q;
$a = $x2->add($z2);
$aa = $a->multiply($a);
$b = $x2->subtract($z2);
$bb = $b->multiply($b);
$e = $aa->subtract($bb);
$c = $x3->add($z3);
$d = $x3->subtract($z3);
$da = $d->multiply($a);
$cb = $c->multiply($b);
$temp = $da->add($cb);
$x5 = $temp->multiply($temp);
$temp = $da->subtract($cb);
$z5 = $x1->multiply($temp->multiply($temp));
$x4 = $aa->multiply($bb);
$temp = static::class == Curve25519::class ? $bb : $aa;
$z4 = $e->multiply($temp->add($this->a24->multiply($e)));
return [
[$x4, $z4],
[$x5, $z5],
];
}
/**
* Multiply a point on the curve by a scalar
*
* Uses the montgomery ladder technique as described here:
*
* https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Montgomery_ladder
* https://github.com/phpecc/phpecc/issues/16#issuecomment-59176772
*/
public function multiplyPoint(array $p, BigInteger $d): array
{
$p1 = [$this->one, $this->zero];
$alreadyInternal = isset($x[1]);
$p2 = $this->convertToInternal($p);
$x = $p[0];
$b = $d->toBits();
$b = str_pad($b, 256, '0', STR_PAD_LEFT);
for ($i = 0; $i < strlen($b); $i++) {
$b_i = (int) $b[$i];
if ($b_i) {
[$p2, $p1] = $this->doubleAndAddPoint($p2, $p1, $x);
} else {
[$p1, $p2] = $this->doubleAndAddPoint($p1, $p2, $x);
}
}
return $alreadyInternal ? $p1 : $this->convertToAffine($p1);
}
/**
* Converts an affine point to an XZ coordinate
*
* From https://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html
*
* XZ coordinates represent x y as X Z satsfying the following equations:
*
* x=X/Z
*
* @return PrimeInteger[]
*/
public function convertToInternal(array $p): array
{
if (empty($p)) {
return [clone $this->zero, clone $this->one];
}
if (isset($p[1])) {
return $p;
}
$p[1] = clone $this->one;
return $p;
}
/**
* Returns the affine point
*
* @return PrimeInteger[]
*/
public function convertToAffine(array $p): array
{
if (!isset($p[1])) {
return $p;
}
[$x, $z] = $p;
return [$x->divide($z)];
}
}

View File

@ -0,0 +1,785 @@
<?php
/**
* Curves over y^2 = x^3 + a*x + b
*
* These are curves used in SEC 2 over prime fields: http://www.secg.org/SEC2-Ver-1.0.pdf
* The curve is a weierstrass curve with a[1], a[3] and a[2] set to 0.
*
* Uses Jacobian Coordinates for speed if able:
*
* https://en.wikipedia.org/wiki/Jacobian_curve
* https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\BaseCurves;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\Common\FiniteField\Integer;
use phpseclib3\Math\PrimeField;
use phpseclib3\Math\PrimeField\Integer as PrimeInteger;
use phpseclib3\Math\PrimeFields;
/**
* Curves over y^2 = x^3 + a*x + b
*
* @author Jim Wigginton <terrafrost@php.net>
*/
class Prime extends Base
{
/**
* Prime Field Integer factory
*
* @var PrimeFields
*/
protected $factory;
/**
* Cofficient for x^1
*
* @var object
*/
protected $a;
/**
* Cofficient for x^0
*
* @var object
*/
protected $b;
/**
* Base Point
*
* @var object
*/
protected $p;
/**
* The number one over the specified finite field
*
* @var object
*/
protected $one;
/**
* The number two over the specified finite field
*
* @var object
*/
protected $two;
/**
* The number three over the specified finite field
*
* @var object
*/
protected $three;
/**
* The number four over the specified finite field
*
* @var object
*/
protected $four;
/**
* The number eight over the specified finite field
*
* @var object
*/
protected $eight;
/**
* The modulo
*
* @var BigInteger
*/
protected $modulo;
/**
* The Order
*
* @var BigInteger
*/
protected $order;
/**
* Sets the modulo
*/
public function setModulo(BigInteger $modulo): void
{
$this->modulo = $modulo;
$this->factory = new PrimeField($modulo);
$this->two = $this->factory->newInteger(new BigInteger(2));
$this->three = $this->factory->newInteger(new BigInteger(3));
// used by jacobian coordinates
$this->one = $this->factory->newInteger(new BigInteger(1));
$this->four = $this->factory->newInteger(new BigInteger(4));
$this->eight = $this->factory->newInteger(new BigInteger(8));
}
/**
* Set coefficients a and b
*/
public function setCoefficients(BigInteger $a, BigInteger $b): void
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->a = $this->factory->newInteger($a);
$this->b = $this->factory->newInteger($b);
}
/**
* Set x and y coordinates for the base point
*
* @param BigInteger|PrimeInteger $x
* @param BigInteger|PrimeInteger $y
*/
public function setBasePoint($x, $y): void
{
switch (true) {
case !$x instanceof BigInteger && !$x instanceof PrimeInteger:
throw new UnexpectedValueException('Argument 1 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
case !$y instanceof BigInteger && !$y instanceof PrimeInteger:
throw new UnexpectedValueException('Argument 2 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
}
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->p = [
$x instanceof BigInteger ? $this->factory->newInteger($x) : $x,
$y instanceof BigInteger ? $this->factory->newInteger($y) : $y,
];
}
/**
* Retrieve the base point as an array
*
* @return array
*/
public function getBasePoint()
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
/*
if (!isset($this->p)) {
throw new \phpseclib3\Exception\RuntimeException('setBasePoint needs to be called before this method');
}
*/
return $this->p;
}
/**
* Adds two "fresh" jacobian form on the curve
*
* @return FiniteField[]
*/
protected function jacobianAddPointMixedXY(array $p, array $q): array
{
[$u1, $s1] = $p;
[$u2, $s2] = $q;
if ($u1->equals($u2)) {
if (!$s1->equals($s2)) {
return [];
} else {
return $this->doublePoint($p);
}
}
$h = $u2->subtract($u1);
$r = $s2->subtract($s1);
$h2 = $h->multiply($h);
$h3 = $h2->multiply($h);
$v = $u1->multiply($h2);
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
$y3 = $r->multiply(
$v->subtract($x3)
)->subtract(
$s1->multiply($h3)
);
return [$x3, $y3, $h];
}
/**
* Adds one "fresh" jacobian form on the curve
*
* The second parameter should be the "fresh" one
*
* @return FiniteField[]
*/
protected function jacobianAddPointMixedX(array $p, array $q): array
{
[$u1, $s1, $z1] = $p;
[$x2, $y2] = $q;
$z12 = $z1->multiply($z1);
$u2 = $x2->multiply($z12);
$s2 = $y2->multiply($z12->multiply($z1));
if ($u1->equals($u2)) {
if (!$s1->equals($s2)) {
return [];
} else {
return $this->doublePoint($p);
}
}
$h = $u2->subtract($u1);
$r = $s2->subtract($s1);
$h2 = $h->multiply($h);
$h3 = $h2->multiply($h);
$v = $u1->multiply($h2);
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
$y3 = $r->multiply(
$v->subtract($x3)
)->subtract(
$s1->multiply($h3)
);
$z3 = $h->multiply($z1);
return [$x3, $y3, $z3];
}
/**
* Adds two jacobian coordinates on the curve
*
* @return FiniteField[]
*/
protected function jacobianAddPoint(array $p, array $q): array
{
[$x1, $y1, $z1] = $p;
[$x2, $y2, $z2] = $q;
$z12 = $z1->multiply($z1);
$z22 = $z2->multiply($z2);
$u1 = $x1->multiply($z22);
$u2 = $x2->multiply($z12);
$s1 = $y1->multiply($z22->multiply($z2));
$s2 = $y2->multiply($z12->multiply($z1));
if ($u1->equals($u2)) {
if (!$s1->equals($s2)) {
return [];
} else {
return $this->doublePoint($p);
}
}
$h = $u2->subtract($u1);
$r = $s2->subtract($s1);
$h2 = $h->multiply($h);
$h3 = $h2->multiply($h);
$v = $u1->multiply($h2);
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
$y3 = $r->multiply(
$v->subtract($x3)
)->subtract(
$s1->multiply($h3)
);
$z3 = $h->multiply($z1)->multiply($z2);
return [$x3, $y3, $z3];
}
/**
* Adds two points on the curve
*
* @return FiniteField[]
*/
public function addPoint(array $p, array $q): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p) || !count($q)) {
if (count($q)) {
return $q;
}
if (count($p)) {
return $p;
}
return [];
}
// use jacobian coordinates
if (isset($p[2]) && isset($q[2])) {
if (isset($p['fresh']) && isset($q['fresh'])) {
return $this->jacobianAddPointMixedXY($p, $q);
}
if (isset($p['fresh'])) {
return $this->jacobianAddPointMixedX($q, $p);
}
if (isset($q['fresh'])) {
return $this->jacobianAddPointMixedX($p, $q);
}
return $this->jacobianAddPoint($p, $q);
}
if (isset($p[2]) || isset($q[2])) {
throw new RuntimeException('Affine coordinates need to be manually converted to Jacobi coordinates or vice versa');
}
if ($p[0]->equals($q[0])) {
if (!$p[1]->equals($q[1])) {
return [];
} else { // eg. doublePoint
[$numerator, $denominator] = $this->doublePointHelper($p);
}
} else {
$numerator = $q[1]->subtract($p[1]);
$denominator = $q[0]->subtract($p[0]);
}
$slope = $numerator->divide($denominator);
$x = $slope->multiply($slope)->subtract($p[0])->subtract($q[0]);
$y = $slope->multiply($p[0]->subtract($x))->subtract($p[1]);
return [$x, $y];
}
/**
* Returns the numerator and denominator of the slope
*
* @return FiniteField[]
*/
protected function doublePointHelper(array $p): array
{
$numerator = $this->three->multiply($p[0])->multiply($p[0])->add($this->a);
$denominator = $this->two->multiply($p[1]);
return [$numerator, $denominator];
}
/**
* Doubles a jacobian coordinate on the curve
*
* @return FiniteField[]
*/
protected function jacobianDoublePoint(array $p): array
{
[$x, $y, $z] = $p;
$x2 = $x->multiply($x);
$y2 = $y->multiply($y);
$z2 = $z->multiply($z);
$s = $this->four->multiply($x)->multiply($y2);
$m1 = $this->three->multiply($x2);
$m2 = $this->a->multiply($z2->multiply($z2));
$m = $m1->add($m2);
$x1 = $m->multiply($m)->subtract($this->two->multiply($s));
$y1 = $m->multiply($s->subtract($x1))->subtract(
$this->eight->multiply($y2->multiply($y2))
);
$z1 = $this->two->multiply($y)->multiply($z);
return [$x1, $y1, $z1];
}
/**
* Doubles a "fresh" jacobian coordinate on the curve
*
* @return FiniteField[]
*/
protected function jacobianDoublePointMixed(array $p): array
{
[$x, $y] = $p;
$x2 = $x->multiply($x);
$y2 = $y->multiply($y);
$s = $this->four->multiply($x)->multiply($y2);
$m1 = $this->three->multiply($x2);
$m = $m1->add($this->a);
$x1 = $m->multiply($m)->subtract($this->two->multiply($s));
$y1 = $m->multiply($s->subtract($x1))->subtract(
$this->eight->multiply($y2->multiply($y2))
);
$z1 = $this->two->multiply($y);
return [$x1, $y1, $z1];
}
/**
* Doubles a point on a curve
*
* @return FiniteField[]
*/
public function doublePoint(array $p): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p)) {
return [];
}
// use jacobian coordinates
if (isset($p[2])) {
if (isset($p['fresh'])) {
return $this->jacobianDoublePointMixed($p);
}
return $this->jacobianDoublePoint($p);
}
[$numerator, $denominator] = $this->doublePointHelper($p);
$slope = $numerator->divide($denominator);
$x = $slope->multiply($slope)->subtract($p[0])->subtract($p[0]);
$y = $slope->multiply($p[0]->subtract($x))->subtract($p[1]);
return [$x, $y];
}
/**
* Returns the X coordinate and the derived Y coordinate
*/
public function derivePoint($m): array
{
$y = ord(Strings::shift($m));
$x = new BigInteger($m, 256);
$xp = $this->convertInteger($x);
switch ($y) {
case 2:
$ypn = false;
break;
case 3:
$ypn = true;
break;
default:
throw new RuntimeException('Coordinate not in recognized format');
}
$temp = $xp->multiply($this->a);
$temp = $xp->multiply($xp)->multiply($xp)->add($temp);
$temp = $temp->add($this->b);
$b = $temp->squareRoot();
if (!$b) {
throw new RuntimeException('Unable to derive Y coordinate');
}
$bn = $b->isOdd();
$yp = $ypn == $bn ? $b : $b->negate();
return [$xp, $yp];
}
/**
* Tests whether or not the x / y values satisfy the equation
*
* @return boolean
*/
public function verifyPoint(array $p): bool
{
[$x, $y] = $p;
$lhs = $y->multiply($y);
$temp = $x->multiply($this->a);
$temp = $x->multiply($x)->multiply($x)->add($temp);
$rhs = $temp->add($this->b);
return $lhs->equals($rhs);
}
/**
* Returns the modulo
*/
public function getModulo(): BigInteger
{
return $this->modulo;
}
/**
* Returns the a coefficient
*
* @return PrimeInteger
*/
public function getA()
{
return $this->a;
}
/**
* Returns the a coefficient
*
* @return PrimeInteger
*/
public function getB()
{
return $this->b;
}
/**
* Multiply and Add Points
*
* Adapted from:
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/curve/base.js#L125
*
* @return int[]
*/
public function multiplyAddPoints(array $points, array $scalars): array
{
$length = count($points);
foreach ($points as &$point) {
$point = $this->convertToInternal($point);
}
$wnd = [$this->getNAFPoints($points[0], 7)];
$wndWidth = [$points[0]['nafwidth'] ?? 7];
for ($i = 1; $i < $length; $i++) {
$wnd[] = $this->getNAFPoints($points[$i], 1);
$wndWidth[] = $points[$i]['nafwidth'] ?? 1;
}
$naf = [];
// comb all window NAFs
$max = 0;
for ($i = $length - 1; $i >= 1; $i -= 2) {
$a = $i - 1;
$b = $i;
if ($wndWidth[$a] != 1 || $wndWidth[$b] != 1) {
$naf[$a] = $scalars[$a]->getNAF($wndWidth[$a]);
$naf[$b] = $scalars[$b]->getNAF($wndWidth[$b]);
$max = max(count($naf[$a]), count($naf[$b]), $max);
continue;
}
$comb = [
$points[$a], // 1
null, // 3
null, // 5
$points[$b], // 7
];
$comb[1] = $this->addPoint($points[$a], $points[$b]);
$comb[2] = $this->addPoint($points[$a], $this->negatePoint($points[$b]));
$index = [
-3, /* -1 -1 */
-1, /* -1 0 */
-5, /* -1 1 */
-7, /* 0 -1 */
0, /* 0 -1 */
7, /* 0 1 */
5, /* 1 -1 */
1, /* 1 0 */
3, /* 1 1 */
];
$jsf = self::getJSFPoints($scalars[$a], $scalars[$b]);
$max = max(count($jsf[0]), $max);
if ($max > 0) {
$naf[$a] = array_fill(0, $max, 0);
$naf[$b] = array_fill(0, $max, 0);
} else {
$naf[$a] = [];
$naf[$b] = [];
}
for ($j = 0; $j < $max; $j++) {
$ja = $jsf[0][$j] ?? 0;
$jb = $jsf[1][$j] ?? 0;
$naf[$a][$j] = $index[3 * ($ja + 1) + $jb + 1];
$naf[$b][$j] = 0;
$wnd[$a] = $comb;
}
}
$acc = [];
$temp = [0, 0, 0, 0];
for ($i = $max; $i >= 0; $i--) {
$k = 0;
while ($i >= 0) {
$zero = true;
for ($j = 0; $j < $length; $j++) {
$temp[$j] = $naf[$j][$i] ?? 0;
if ($temp[$j] != 0) {
$zero = false;
}
}
if (!$zero) {
break;
}
$k++;
$i--;
}
if ($i >= 0) {
$k++;
}
while ($k--) {
$acc = $this->doublePoint($acc);
}
if ($i < 0) {
break;
}
for ($j = 0; $j < $length; $j++) {
$z = $temp[$j];
$p = null;
if ($z == 0) {
continue;
}
$p = $z > 0 ?
$wnd[$j][($z - 1) >> 1] :
$this->negatePoint($wnd[$j][(-$z - 1) >> 1]);
$acc = $this->addPoint($acc, $p);
}
}
return $this->convertToAffine($acc);
}
/**
* Precomputes NAF points
*
* Adapted from:
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/curve/base.js#L351
*
* @return list<array>
*/
private function getNAFPoints(array $point, int $wnd): array
{
if (isset($point['naf'])) {
return $point['naf'];
}
$res = [$point];
$max = (1 << $wnd) - 1;
$dbl = $max == 1 ? null : $this->doublePoint($point);
for ($i = 1; $i < $max; $i++) {
$res[] = $this->addPoint($res[$i - 1], $dbl);
}
$point['naf'] = $res;
/*
$str = '';
foreach ($res as $re) {
$re[0] = bin2hex($re[0]->toBytes());
$re[1] = bin2hex($re[1]->toBytes());
$str.= " ['$re[0]', '$re[1]'],\r\n";
}
file_put_contents('temp.txt', $str);
exit;
*/
return $res;
}
/**
* Precomputes points in Joint Sparse Form
*
* Adapted from:
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/utils.js#L96
*
* @return int[]
*/
private static function getJSFPoints(Integer $k1, Integer $k2): array
{
static $three;
if (!isset($three)) {
$three = new BigInteger(3);
}
$jsf = [[], []];
$k1 = $k1->toBigInteger();
$k2 = $k2->toBigInteger();
$d1 = 0;
$d2 = 0;
while ($k1->compare(new BigInteger(-$d1)) > 0 || $k2->compare(new BigInteger(-$d2)) > 0) {
// first phase
$m14 = $k1->testBit(0) + 2 * $k1->testBit(1);
$m14 += $d1;
$m14 &= 3;
$m24 = $k2->testBit(0) + 2 * $k2->testBit(1);
$m24 += $d2;
$m24 &= 3;
if ($m14 == 3) {
$m14 = -1;
}
if ($m24 == 3) {
$m24 = -1;
}
$u1 = 0;
if ($m14 & 1) { // if $m14 is odd
$m8 = $k1->testBit(0) + 2 * $k1->testBit(1) + 4 * $k1->testBit(2);
$m8 += $d1;
$m8 &= 7;
$u1 = ($m8 == 3 || $m8 == 5) && $m24 == 2 ? -$m14 : $m14;
}
$jsf[0][] = $u1;
$u2 = 0;
if ($m24 & 1) { // if $m24 is odd
$m8 = $k2->testBit(0) + 2 * $k2->testBit(1) + 4 * $k2->testBit(2);
$m8 += $d2;
$m8 &= 7;
$u2 = ($m8 == 3 || $m8 == 5) && $m14 == 2 ? -$m24 : $m24;
}
$jsf[1][] = $u2;
// second phase
if (2 * $d1 == $u1 + 1) {
$d1 = 1 - $d1;
}
if (2 * $d2 == $u2 + 1) {
$d2 = 1 - $d2;
}
$k1 = $k1->bitwise_rightShift(1);
$k2 = $k2->bitwise_rightShift(1);
}
return $jsf;
}
/**
* Returns the affine point
*
* A Jacobian Coordinate is of the form (x, y, z).
* To convert a Jacobian Coordinate to an Affine Point
* you do (x / z^2, y / z^3)
*
* @return PrimeInteger[]
*/
public function convertToAffine(array $p): array
{
if (!isset($p[2])) {
return $p;
}
[$x, $y, $z] = $p;
$z = $this->one->divide($z);
$z2 = $z->multiply($z);
return [
$x->multiply($z2),
$y->multiply($z2)->multiply($z),
];
}
/**
* Converts an affine point to a jacobian coordinate
*
* @return PrimeInteger[]
*/
public function convertToInternal(array $p): array
{
if (isset($p[2])) {
return $p;
}
$p[2] = clone $this->one;
$p['fresh'] = true;
return $p;
}
}

View File

@ -0,0 +1,215 @@
<?php
/**
* Curves over a*x^2 + y^2 = 1 + d*x^2*y^2
*
* http://www.secg.org/SEC2-Ver-1.0.pdf provides for curves with custom parameters.
* ie. the coefficients can be arbitrary set through specially formatted keys, etc.
* As such, Prime.php is built very generically and it's not able to take full
* advantage of curves with 0 coefficients to produce simplified point doubling,
* point addition. Twisted Edwards curves, in contrast, do not have a way, currently,
* to customize them. As such, we can omit the super generic stuff from this class
* and let the named curves (Ed25519 and Ed448) define their own custom tailored
* point addition and point doubling methods.
*
* More info:
*
* https://en.wikipedia.org/wiki/Twisted_Edwards_curve
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\BaseCurves;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnexpectedValueException;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\PrimeField;
use phpseclib3\Math\PrimeField\Integer as PrimeInteger;
/**
* Curves over a*x^2 + y^2 = 1 + d*x^2*y^2
*
* @author Jim Wigginton <terrafrost@php.net>
*/
class TwistedEdwards extends Base
{
/**
* The modulo
*
* @var BigInteger
*/
protected $modulo;
/**
* Cofficient for x^2
*
* @var object
*/
protected $a;
/**
* Cofficient for x^2*y^2
*
* @var object
*/
protected $d;
/**
* Base Point
*
* @var object[]
*/
protected $p;
/**
* The number zero over the specified finite field
*
* @var object
*/
protected $zero;
/**
* The number one over the specified finite field
*
* @var object
*/
protected $one;
/**
* The number two over the specified finite field
*
* @var object
*/
protected $two;
/**
* Sets the modulo
*/
public function setModulo(BigInteger $modulo): void
{
$this->modulo = $modulo;
$this->factory = new PrimeField($modulo);
$this->zero = $this->factory->newInteger(new BigInteger(0));
$this->one = $this->factory->newInteger(new BigInteger(1));
$this->two = $this->factory->newInteger(new BigInteger(2));
}
/**
* Set coefficients a and b
*/
public function setCoefficients(BigInteger $a, BigInteger $d): void
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->a = $this->factory->newInteger($a);
$this->d = $this->factory->newInteger($d);
}
/**
* Set x and y coordinates for the base point
*/
public function setBasePoint($x, $y): void
{
switch (true) {
case !$x instanceof BigInteger && !$x instanceof PrimeInteger:
throw new UnexpectedValueException('Argument 1 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
case !$y instanceof BigInteger && !$y instanceof PrimeInteger:
throw new UnexpectedValueException('Argument 2 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
}
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
$this->p = [
$x instanceof BigInteger ? $this->factory->newInteger($x) : $x,
$y instanceof BigInteger ? $this->factory->newInteger($y) : $y,
];
}
/**
* Returns the a coefficient
*
* @return PrimeInteger
*/
public function getA()
{
return $this->a;
}
/**
* Returns the a coefficient
*
* @return PrimeInteger
*/
public function getD()
{
return $this->d;
}
/**
* Retrieve the base point as an array
*/
public function getBasePoint(): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
/*
if (!isset($this->p)) {
throw new \phpseclib3\Exception\RuntimeException('setBasePoint needs to be called before this method');
}
*/
return $this->p;
}
/**
* Returns the affine point
*
* @return PrimeInteger[]
*/
public function convertToAffine(array $p): array
{
if (!isset($p[2])) {
return $p;
}
[$x, $y, $z] = $p;
$z = $this->one->divide($z);
return [
$x->multiply($z),
$y->multiply($z),
];
}
/**
* Returns the modulo
*/
public function getModulo(): BigInteger
{
return $this->modulo;
}
/**
* Tests whether or not the x / y values satisfy the equation
*
* @return boolean
*/
public function verifyPoint(array $p): bool
{
[$x, $y] = $p;
$x2 = $x->multiply($x);
$y2 = $y->multiply($y);
$lhs = $this->a->multiply($x2)->add($y2);
$rhs = $this->d->multiply($x2)->multiply($y2)->add($this->one);
return $lhs->equals($rhs);
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* Curve25519
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2019 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Montgomery;
use phpseclib3\Exception\RangeException;
use phpseclib3\Math\BigInteger;
class Curve25519 extends Montgomery
{
public function __construct()
{
// 2^255 - 19
$this->setModulo(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED', 16));
$this->a24 = $this->factory->newInteger(new BigInteger('121666'));
$this->p = [$this->factory->newInteger(new BigInteger(9))];
// 2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
$this->setOrder(new BigInteger('1000000000000000000000000000000014DEF9DEA2F79CD65812631A5CF5D3ED', 16));
/*
$this->setCoefficients(
new BigInteger('486662'), // a
);
$this->setBasePoint(
new BigInteger(9),
new BigInteger('14781619447589544791020593568409986887264606134616475288964881837755586237401')
);
*/
}
/**
* Multiply a point on the curve by a scalar
*
* Modifies the scalar as described at https://tools.ietf.org/html/rfc7748#page-8
*/
public function multiplyPoint(array $p, BigInteger $d): array
{
//$r = strrev(sodium_crypto_scalarmult($d->toBytes(), strrev($p[0]->toBytes())));
//return [$this->factory->newInteger(new BigInteger($r, 256))];
$d = $d->toBytes();
$d &= "\xF8" . str_repeat("\xFF", 30) . "\x7F";
$d = strrev($d);
$d |= "\x40";
$d = new BigInteger($d, -256);
return parent::multiplyPoint($p, $d);
}
/**
* Creates a random scalar multiplier
*/
public function createRandomMultiplier(): BigInteger
{
return BigInteger::random(256);
}
/**
* Performs range check
*/
public function rangeCheck(BigInteger $x): void
{
if ($x->getLength() > 256 || $x->isNegative()) {
throw new RangeException('x must be a positive integer less than 256 bytes in length');
}
}
}

View File

@ -0,0 +1,91 @@
<?php
/**
* Curve448
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2019 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Montgomery;
use phpseclib3\Exception\RangeException;
use phpseclib3\Math\BigInteger;
class Curve448 extends Montgomery
{
public function __construct()
{
// 2^448 - 2^224 - 1
$this->setModulo(new BigInteger(
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
16
));
$this->a24 = $this->factory->newInteger(new BigInteger('39081'));
$this->p = [$this->factory->newInteger(new BigInteger(5))];
// 2^446 - 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
$this->setOrder(new BigInteger(
'3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' .
'7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3',
16
));
/*
$this->setCoefficients(
new BigInteger('156326'), // a
);
$this->setBasePoint(
new BigInteger(5),
new BigInteger(
'355293926785568175264127502063783334808976399387714271831880898' .
'435169088786967410002932673765864550910142774147268105838985595290' .
'606362')
);
*/
}
/**
* Multiply a point on the curve by a scalar
*
* Modifies the scalar as described at https://tools.ietf.org/html/rfc7748#page-8
*/
public function multiplyPoint(array $p, BigInteger $d): array
{
//$r = strrev(sodium_crypto_scalarmult($d->toBytes(), strrev($p[0]->toBytes())));
//return [$this->factory->newInteger(new BigInteger($r, 256))];
$d = $d->toBytes();
$d[0] = $d[0] & "\xFC";
$d = strrev($d);
$d |= "\x80";
$d = new BigInteger($d, 256);
return parent::multiplyPoint($p, $d);
}
/**
* Creates a random scalar multiplier
*/
public function createRandomMultiplier(): BigInteger
{
return BigInteger::random(446);
}
/**
* Performs range check
*/
public function rangeCheck(BigInteger $x): void
{
if ($x->getLength() > 448 || $x->isNegative()) {
throw new RangeException('x must be a positive integer less than 446 bytes in length');
}
}
}

View File

@ -0,0 +1,330 @@
<?php
/**
* Ed25519
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards;
use phpseclib3\Crypt\Hash;
use phpseclib3\Crypt\Random;
use phpseclib3\Exception\LengthException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Math\BigInteger;
class Ed25519 extends TwistedEdwards
{
public const HASH = 'sha512';
/*
Per https://tools.ietf.org/html/rfc8032#page-6 EdDSA has several parameters, one of which is b:
2. An integer b with 2^(b-1) > p. EdDSA public keys have exactly b
bits, and EdDSA signatures have exactly 2*b bits. b is
recommended to be a multiple of 8, so public key and signature
lengths are an integral number of octets.
SIZE corresponds to b
*/
public const SIZE = 32;
public function __construct()
{
// 2^255 - 19
$this->setModulo(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED', 16));
$this->setCoefficients(
// -1
new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC', 16), // a
// -121665/121666
new BigInteger('52036CEE2B6FFE738CC740797779E89800700A4D4141D8AB75EB4DCA135978A3', 16) // d
);
$this->setBasePoint(
new BigInteger('216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A', 16),
new BigInteger('6666666666666666666666666666666666666666666666666666666666666658', 16)
);
$this->setOrder(new BigInteger('1000000000000000000000000000000014DEF9DEA2F79CD65812631A5CF5D3ED', 16));
// algorithm 14.47 from http://cacr.uwaterloo.ca/hac/about/chap14.pdf#page=16
/*
$this->setReduction(function($x) {
$parts = $x->bitwise_split(255);
$className = $this->className;
if (count($parts) > 2) {
list(, $r) = $x->divide($className::$modulo);
return $r;
}
$zero = new BigInteger();
$c = new BigInteger(19);
switch (count($parts)) {
case 2:
list($qi, $ri) = $parts;
break;
case 1:
$qi = $zero;
list($ri) = $parts;
break;
case 0:
return $zero;
}
$r = $ri;
while ($qi->compare($zero) > 0) {
$temp = $qi->multiply($c)->bitwise_split(255);
if (count($temp) == 2) {
list($qi, $ri) = $temp;
} else {
$qi = $zero;
list($ri) = $temp;
}
$r = $r->add($ri);
}
while ($r->compare($className::$modulo) > 0) {
$r = $r->subtract($className::$modulo);
}
return $r;
});
*/
}
/**
* Recover X from Y
*
* Implements steps 2-4 at https://tools.ietf.org/html/rfc8032#section-5.1.3
*
* Used by EC\Keys\Common.php
*
* @param boolean $sign
* @return object[]
*/
public function recoverX(BigInteger $y, bool $sign): array
{
$y = $this->factory->newInteger($y);
$y2 = $y->multiply($y);
$u = $y2->subtract($this->one);
$v = $this->d->multiply($y2)->add($this->one);
$x2 = $u->divide($v);
if ($x2->equals($this->zero)) {
if ($sign) {
throw new RuntimeException('Unable to recover X coordinate (x2 = 0)');
}
return clone $this->zero;
}
// find the square root
/* we don't do $x2->squareRoot() because, quoting from
https://tools.ietf.org/html/rfc8032#section-5.1.1:
"For point decoding or "decompression", square roots modulo p are
needed. They can be computed using the Tonelli-Shanks algorithm or
the special case for p = 5 (mod 8). To find a square root of a,
first compute the candidate root x = a^((p+3)/8) (mod p)."
*/
$exp = $this->getModulo()->add(new BigInteger(3));
$exp = $exp->bitwise_rightShift(3);
$x = $x2->pow($exp);
// If v x^2 = -u (mod p), set x <-- x * 2^((p-1)/4), which is a square root.
if (!$x->multiply($x)->subtract($x2)->equals($this->zero)) {
$temp = $this->getModulo()->subtract(new BigInteger(1));
$temp = $temp->bitwise_rightShift(2);
$temp = $this->two->pow($temp);
$x = $x->multiply($temp);
if (!$x->multiply($x)->subtract($x2)->equals($this->zero)) {
throw new RuntimeException('Unable to recover X coordinate');
}
}
if ($x->isOdd() != $sign) {
$x = $x->negate();
}
return [$x, $y];
}
/**
* Extract Secret Scalar
*
* Implements steps 1-3 at https://tools.ietf.org/html/rfc8032#section-5.1.5
*
* Used by the various key handlers
*
* @return array
*/
public function extractSecret(string $str)
{
if (strlen($str) != 32) {
throw new LengthException('Private Key should be 32-bytes long');
}
// 1. Hash the 32-byte private key using SHA-512, storing the digest in
// a 64-octet large buffer, denoted h. Only the lower 32 bytes are
// used for generating the public key.
$hash = new Hash('sha512');
$h = $hash->hash($str);
$h = substr($h, 0, 32);
// 2. Prune the buffer: The lowest three bits of the first octet are
// cleared, the highest bit of the last octet is cleared, and the
// second highest bit of the last octet is set.
$h[0] = $h[0] & chr(0xF8);
$h = strrev($h);
$h[0] = ($h[0] & chr(0x3F)) | chr(0x40);
// 3. Interpret the buffer as the little-endian integer, forming a
// secret scalar s.
$dA = new BigInteger($h, 256);
return [
'dA' => $dA,
'secret' => $str,
];
}
/**
* Encode a point as a string
*/
public function encodePoint(array $point): string
{
[$x, $y] = $point;
$y = $y->toBytes();
$y[0] = $y[0] & chr(0x7F);
if ($x->isOdd()) {
$y[0] = $y[0] | chr(0x80);
}
$y = strrev($y);
return $y;
}
/**
* Creates a random scalar multiplier
*/
public function createRandomMultiplier(): BigInteger
{
return $this->extractSecret(Random::string(32))['dA'];
}
/**
* Converts an affine point to an extended homogeneous coordinate
*
* From https://tools.ietf.org/html/rfc8032#section-5.1.4 :
*
* A point (x,y) is represented in extended homogeneous coordinates (X, Y, Z, T),
* with x = X/Z, y = Y/Z, x * y = T/Z.
*
* @return Integer[]
*/
public function convertToInternal(array $p): array
{
if (empty($p)) {
return [clone $this->zero, clone $this->one, clone $this->one, clone $this->zero];
}
if (isset($p[2])) {
return $p;
}
$p[2] = clone $this->one;
$p[3] = $p[0]->multiply($p[1]);
return $p;
}
/**
* Doubles a point on a curve
*
* @return FiniteField[]
*/
public function doublePoint(array $p): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p)) {
return [];
}
if (!isset($p[2])) {
throw new RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
}
// from https://tools.ietf.org/html/rfc8032#page-12
[$x1, $y1, $z1, $t1] = $p;
$a = $x1->multiply($x1);
$b = $y1->multiply($y1);
$c = $this->two->multiply($z1)->multiply($z1);
$h = $a->add($b);
$temp = $x1->add($y1);
$e = $h->subtract($temp->multiply($temp));
$g = $a->subtract($b);
$f = $c->add($g);
$x3 = $e->multiply($f);
$y3 = $g->multiply($h);
$t3 = $e->multiply($h);
$z3 = $f->multiply($g);
return [$x3, $y3, $z3, $t3];
}
/**
* Adds two points on the curve
*
* @return FiniteField[]
*/
public function addPoint(array $p, array $q): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p) || !count($q)) {
if (count($q)) {
return $q;
}
if (count($p)) {
return $p;
}
return [];
}
if (!isset($p[2]) || !isset($q[2])) {
throw new RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
}
if ($p[0]->equals($q[0])) {
return !$p[1]->equals($q[1]) ? [] : $this->doublePoint($p);
}
// from https://tools.ietf.org/html/rfc8032#page-12
[$x1, $y1, $z1, $t1] = $p;
[$x2, $y2, $z2, $t2] = $q;
$a = $y1->subtract($x1)->multiply($y2->subtract($x2));
$b = $y1->add($x1)->multiply($y2->add($x2));
$c = $t1->multiply($this->two)->multiply($this->d)->multiply($t2);
$d = $z1->multiply($this->two)->multiply($z2);
$e = $b->subtract($a);
$f = $d->subtract($c);
$g = $d->add($c);
$h = $b->add($a);
$x3 = $e->multiply($f);
$y3 = $g->multiply($h);
$t3 = $e->multiply($h);
$z3 = $f->multiply($g);
return [$x3, $y3, $z3, $t3];
}
}

View File

@ -0,0 +1,268 @@
<?php
/**
* Ed448
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards;
use phpseclib3\Crypt\Hash;
use phpseclib3\Crypt\Random;
use phpseclib3\Exception\LengthException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\PrimeField\Integer;
class Ed448 extends TwistedEdwards
{
public const HASH = 'shake256-912';
public const SIZE = 57;
public function __construct()
{
// 2^448 - 2^224 - 1
$this->setModulo(new BigInteger(
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
16
));
$this->setCoefficients(
new BigInteger(1),
// -39081
new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6756', 16)
);
$this->setBasePoint(
new BigInteger('4F1970C66BED0DED221D15A622BF36DA9E146570470F1767EA6DE324' .
'A3D3A46412AE1AF72AB66511433B80E18B00938E2626A82BC70CC05E', 16),
new BigInteger('693F46716EB6BC248876203756C9C7624BEA73736CA3984087789C1E' .
'05A0C2D73AD3FF1CE67C39C4FDBD132C4ED7C8AD9808795BF230FA14', 16)
);
$this->setOrder(new BigInteger(
'3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' .
'7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3',
16
));
}
/**
* Recover X from Y
*
* Implements steps 2-4 at https://tools.ietf.org/html/rfc8032#section-5.2.3
*
* Used by EC\Keys\Common.php
*
* @param boolean $sign
* @return object[]
*/
public function recoverX(BigInteger $y, bool $sign): array
{
$y = $this->factory->newInteger($y);
$y2 = $y->multiply($y);
$u = $y2->subtract($this->one);
$v = $this->d->multiply($y2)->subtract($this->one);
$x2 = $u->divide($v);
if ($x2->equals($this->zero)) {
if ($sign) {
throw new RuntimeException('Unable to recover X coordinate (x2 = 0)');
}
return clone $this->zero;
}
// find the square root
$exp = $this->getModulo()->add(new BigInteger(1));
$exp = $exp->bitwise_rightShift(2);
$x = $x2->pow($exp);
if (!$x->multiply($x)->subtract($x2)->equals($this->zero)) {
throw new RuntimeException('Unable to recover X coordinate');
}
if ($x->isOdd() != $sign) {
$x = $x->negate();
}
return [$x, $y];
}
/**
* Extract Secret Scalar
*
* Implements steps 1-3 at https://tools.ietf.org/html/rfc8032#section-5.2.5
*
* Used by the various key handlers
*
* @return array
*/
public function extractSecret(string $str)
{
if (strlen($str) != 57) {
throw new LengthException('Private Key should be 57-bytes long');
}
// 1. Hash the 57-byte private key using SHAKE256(x, 114), storing the
// digest in a 114-octet large buffer, denoted h. Only the lower 57
// bytes are used for generating the public key.
$hash = new Hash('shake256-912');
$h = $hash->hash($str);
$h = substr($h, 0, 57);
// 2. Prune the buffer: The two least significant bits of the first
// octet are cleared, all eight bits the last octet are cleared, and
// the highest bit of the second to last octet is set.
$h[0] = $h[0] & chr(0xFC);
$h = strrev($h);
$h[0] = "\0";
$h[1] = $h[1] | chr(0x80);
// 3. Interpret the buffer as the little-endian integer, forming a
// secret scalar s.
$dA = new BigInteger($h, 256);
return [
'dA' => $dA,
'secret' => $str,
];
}
/**
* Encode a point as a string
*/
public function encodePoint(array $point): string
{
[$x, $y] = $point;
$y = "\0" . $y->toBytes();
if ($x->isOdd()) {
$y[0] = $y[0] | chr(0x80);
}
$y = strrev($y);
return $y;
}
/**
* Creates a random scalar multiplier
*/
public function createRandomMultiplier(): BigInteger
{
return $this->extractSecret(Random::string(57))['dA'];
}
/**
* Converts an affine point to an extended homogeneous coordinate
*
* From https://tools.ietf.org/html/rfc8032#section-5.2.4 :
*
* A point (x,y) is represented in extended homogeneous coordinates (X, Y, Z, T),
* with x = X/Z, y = Y/Z, x * y = T/Z.
*
* @return Integer[]
*/
public function convertToInternal(array $p): array
{
if (empty($p)) {
return [clone $this->zero, clone $this->one, clone $this->one];
}
if (isset($p[2])) {
return $p;
}
$p[2] = clone $this->one;
return $p;
}
/**
* Doubles a point on a curve
*
* @return FiniteField[]
*/
public function doublePoint(array $p): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p)) {
return [];
}
if (!isset($p[2])) {
throw new RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
}
// from https://tools.ietf.org/html/rfc8032#page-18
[$x1, $y1, $z1] = $p;
$b = $x1->add($y1);
$b = $b->multiply($b);
$c = $x1->multiply($x1);
$d = $y1->multiply($y1);
$e = $c->add($d);
$h = $z1->multiply($z1);
$j = $e->subtract($this->two->multiply($h));
$x3 = $b->subtract($e)->multiply($j);
$y3 = $c->subtract($d)->multiply($e);
$z3 = $e->multiply($j);
return [$x3, $y3, $z3];
}
/**
* Adds two points on the curve
*
* @return FiniteField[]
*/
public function addPoint(array $p, array $q): array
{
if (!isset($this->factory)) {
throw new RuntimeException('setModulo needs to be called before this method');
}
if (!count($p) || !count($q)) {
if (count($q)) {
return $q;
}
if (count($p)) {
return $p;
}
return [];
}
if (!isset($p[2]) || !isset($q[2])) {
throw new RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
}
if ($p[0]->equals($q[0])) {
return !$p[1]->equals($q[1]) ? [] : $this->doublePoint($p);
}
// from https://tools.ietf.org/html/rfc8032#page-17
[$x1, $y1, $z1] = $p;
[$x2, $y2, $z2] = $q;
$a = $z1->multiply($z2);
$b = $a->multiply($a);
$c = $x1->multiply($x2);
$d = $y1->multiply($y2);
$e = $this->d->multiply($c)->multiply($d);
$f = $b->subtract($e);
$g = $b->add($e);
$h = $x1->add($y1)->multiply($x2->add($y2));
$x3 = $a->multiply($f)->multiply($h->subtract($c)->subtract($d));
$y3 = $a->multiply($g)->multiply($d->subtract($c));
$z3 = $f->multiply($g);
return [$x3, $y3, $z3];
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* brainpoolP160r1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP160r1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('E95E4A5F737059DC60DFC7AD95B3D8139515620F', 16));
$this->setCoefficients(
new BigInteger('340E7BE2A280EB74E2BE61BADA745D97E8F7C300', 16),
new BigInteger('1E589A8595423412134FAA2DBDEC95C8D8675E58', 16)
);
$this->setBasePoint(
new BigInteger('BED5AF16EA3F6A4F62938C4631EB5AF7BDBCDBC3', 16),
new BigInteger('1667CB477A1A8EC338F94741669C976316DA6321', 16)
);
$this->setOrder(new BigInteger('E95E4A5F737059DC60DF5991D45029409E60FC09', 16));
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* brainpoolP160t1
*
* This curve is a twisted version of brainpoolP160r1 with A = -3. With brainpool,
* the curves ending in r1 are the "regular" curves and the curves ending in "t1"
* are the twisted version of the r1 curves. Per https://tools.ietf.org/html/rfc5639#page-7
* you can convert a point on an r1 curve to a point on a t1 curve thusly:
*
* F(x,y) := (x*Z^2, y*Z^3)
*
* The advantage of A = -3 is that some of the point doubling and point addition can be
* slightly optimized. See http://hyperelliptic.org/EFD/g1p/auto-shortw-projective-3.html
* vs http://hyperelliptic.org/EFD/g1p/auto-shortw-projective.html for example.
*
* phpseclib does not currently take advantage of this optimization opportunity
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP160t1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('E95E4A5F737059DC60DFC7AD95B3D8139515620F', 16));
$this->setCoefficients(
new BigInteger('E95E4A5F737059DC60DFC7AD95B3D8139515620C', 16), // eg. -3
new BigInteger('7A556B6DAE535B7B51ED2C4D7DAA7A0B5C55F380', 16)
);
$this->setBasePoint(
new BigInteger('B199B13B9B34EFC1397E64BAEB05ACC265FF2378', 16),
new BigInteger('ADD6718B7C7C1961F0991B842443772152C9E0AD', 16)
);
$this->setOrder(new BigInteger('E95E4A5F737059DC60DF5991D45029409E60FC09', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* brainpoolP192r1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP192r1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297', 16));
$this->setCoefficients(
new BigInteger('6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF', 16),
new BigInteger('469A28EF7C28CCA3DC721D044F4496BCCA7EF4146FBF25C9', 16)
);
$this->setBasePoint(
new BigInteger('C0A0647EAAB6A48753B033C56CB0F0900A2F5C4853375FD6', 16),
new BigInteger('14B690866ABD5BB88B5F4828C1490002E6773FA2FA299B8F', 16)
);
$this->setOrder(new BigInteger('C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* brainpoolP192t1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP192t1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297', 16));
$this->setCoefficients(
new BigInteger('C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86294', 16), // eg. -3
new BigInteger('13D56FFAEC78681E68F9DEB43B35BEC2FB68542E27897B79', 16)
);
$this->setBasePoint(
new BigInteger('3AE9E58C82F63C30282E1FE7BBF43FA72C446AF6F4618129', 16),
new BigInteger('097E2C5667C2223A902AB5CA449D0084B7E5B3DE7CCC01C9', 16)
);
$this->setOrder(new BigInteger('C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* brainpoolP224r1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP224r1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF', 16));
$this->setCoefficients(
new BigInteger('68A5E62CA9CE6C1C299803A6C1530B514E182AD8B0042A59CAD29F43', 16),
new BigInteger('2580F63CCFE44138870713B1A92369E33E2135D266DBB372386C400B', 16)
);
$this->setBasePoint(
new BigInteger('0D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C1E6EFDEE12C07D', 16),
new BigInteger('58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D3761402CD', 16)
);
$this->setOrder(new BigInteger('D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* brainpoolP224t1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP224t1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF', 16));
$this->setCoefficients(
new BigInteger('D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FC', 16), // eg. -3
new BigInteger('4B337D934104CD7BEF271BF60CED1ED20DA14C08B3BB64F18A60888D', 16)
);
$this->setBasePoint(
new BigInteger('6AB1E344CE25FF3896424E7FFE14762ECB49F8928AC0C76029B4D580', 16),
new BigInteger('0374E9F5143E568CD23F3F4D7C0D4B1E41C8CC0D1C6ABD5F1A46DB4C', 16)
);
$this->setOrder(new BigInteger('D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* brainpoolP256r1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP256r1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377', 16));
$this->setCoefficients(
new BigInteger('7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9', 16),
new BigInteger('26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6', 16)
);
$this->setBasePoint(
new BigInteger('8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262', 16),
new BigInteger('547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997', 16)
);
$this->setOrder(new BigInteger('A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* brainpoolP256t1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP256t1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377', 16));
$this->setCoefficients(
new BigInteger('A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5374', 16), // eg. -3
new BigInteger('662C61C430D84EA4FE66A7733D0B76B7BF93EBC4AF2F49256AE58101FEE92B04', 16)
);
$this->setBasePoint(
new BigInteger('A3E8EB3CC1CFE7B7732213B23A656149AFA142C47AAFBC2B79A191562E1305F4', 16),
new BigInteger('2D996C823439C56D7F7B22E14644417E69BCB6DE39D027001DABE8F35B25C9BE', 16)
);
$this->setOrder(new BigInteger('A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7', 16));
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* brainpoolP320r1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP320r1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F9' .
'2B9EC7893EC28FCD412B1F1B32E27', 16));
$this->setCoefficients(
new BigInteger('3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9F4' .
'92F375A97D860EB4', 16),
new BigInteger('520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD88453981' .
'6F5EB4AC8FB1F1A6', 16)
);
$this->setBasePoint(
new BigInteger('43BD7E9AFB53D8B85289BCC48EE5BFE6F20137D10A087EB6E7871E2A10A599C7' .
'10AF8D0D39E20611', 16),
new BigInteger('14FDD05545EC1CC8AB4093247F77275E0743FFED117182EAA9C77877AAAC6AC7' .
'D35245D1692E8EE1', 16)
);
$this->setOrder(new BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D4' .
'82EC7EE8658E98691555B44C59311', 16));
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* brainpoolP320t1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP320t1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F9' .
'2B9EC7893EC28FCD412B1F1B32E27', 16));
$this->setCoefficients(
new BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28' .
'FCD412B1F1B32E24', 16), // eg. -3
new BigInteger('A7F561E038EB1ED560B3D147DB782013064C19F27ED27C6780AAF77FB8A547CE' .
'B5B4FEF422340353', 16)
);
$this->setBasePoint(
new BigInteger('925BE9FB01AFC6FB4D3E7D4990010F813408AB106C4F09CB7EE07868CC136FFF' .
'3357F624A21BED52', 16),
new BigInteger('63BA3A7A27483EBF6671DBEF7ABB30EBEE084E58A0B077AD42A5A0989D1EE71B' .
'1B9BC0455FB0D2C3', 16)
);
$this->setOrder(new BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D4' .
'82EC7EE8658E98691555B44C59311', 16));
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* brainpoolP384r1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP384r1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger(
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A7' .
'1874700133107EC53',
16
));
$this->setCoefficients(
new BigInteger(
'7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503' .
'AD4EB04A8C7DD22CE2826',
16
),
new BigInteger(
'4A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DB' .
'C9943AB78696FA504C11',
16
)
);
$this->setBasePoint(
new BigInteger(
'1D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10E8E826E03436D' .
'646AAEF87B2E247D4AF1E',
16
),
new BigInteger(
'8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129280E464621779' .
'1811142820341263C5315',
16
)
);
$this->setOrder(new BigInteger(
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC31' .
'03B883202E9046565',
16
));
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* brainpoolP384t1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP384t1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger(
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A7' .
'1874700133107EC53',
16
));
$this->setCoefficients(
new BigInteger(
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901' .
'D1A71874700133107EC50',
16
), // eg. -3
new BigInteger(
'7F519EADA7BDA81BD826DBA647910F8C4B9346ED8CCDC64E4B1ABD11756DCE1D2074AA263B8' .
'8805CED70355A33B471EE',
16
)
);
$this->setBasePoint(
new BigInteger(
'18DE98B02DB9A306F2AFCD7235F72A819B80AB12EBD653172476FECD462AABFFC4FF191B946' .
'A5F54D8D0AA2F418808CC',
16
),
new BigInteger(
'25AB056962D30651A114AFD2755AD336747F93475B7A1FCA3B88F2B6A208CCFE469408584DC' .
'2B2912675BF5B9E582928',
16
)
);
$this->setOrder(new BigInteger(
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC31' .
'03B883202E9046565',
16
));
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* brainpoolP512r1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP512r1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger(
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' .
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3',
16
));
$this->setCoefficients(
new BigInteger(
'7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA82' .
'53AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA',
16
),
new BigInteger(
'3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C' .
'1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723',
16
)
);
$this->setBasePoint(
new BigInteger(
'81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D' .
'0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822',
16
),
new BigInteger(
'7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5' .
'F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892',
16
)
);
$this->setOrder(new BigInteger(
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA' .
'92619418661197FAC10471DB1D381085DDADDB58796829CA90069',
16
));
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* brainpoolP512t1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class brainpoolP512t1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger(
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' .
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3',
16
));
$this->setCoefficients(
new BigInteger(
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' .
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F0',
16
), // eg. -3
new BigInteger(
'7CBBBCF9441CFAB76E1890E46884EAE321F70C0BCB4981527897504BEC3E36A62BCDFA23049' .
'76540F6450085F2DAE145C22553B465763689180EA2571867423E',
16
)
);
$this->setBasePoint(
new BigInteger(
'640ECE5C12788717B9C1BA06CBC2A6FEBA85842458C56DDE9DB1758D39C0313D82BA51735CD' .
'B3EA499AA77A7D6943A64F7A3F25FE26F06B51BAA2696FA9035DA',
16
),
new BigInteger(
'5B534BD595F5AF0FA2C892376C84ACE1BB4E3019B71634C01131159CAE03CEE9D9932184BEE' .
'F216BD71DF2DADF86A627306ECFF96DBB8BACE198B61E00F8B332',
16
)
);
$this->setOrder(new BigInteger(
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA' .
'92619418661197FAC10471DB1D381085DDADDB58796829CA90069',
16
));
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistb233
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistb233 extends sect233r1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistb409
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistb409 extends sect409r1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistk163
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistk163 extends sect163k1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistk233
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistk233 extends sect233k1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* sect283k1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistk283 extends sect283k1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistk409
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistk409 extends sect409k1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistp192
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistp192 extends secp192r1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistp224
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistp224 extends secp224r1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistp256
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistp256 extends secp256r1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistp384
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistp384 extends secp384r1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistp521
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistp521 extends secp521r1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* nistt571
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class nistt571 extends sect571k1
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* prime192v1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class prime192v1 extends secp192r1
{
}

View File

@ -0,0 +1,36 @@
<?php
/**
* prime192v2
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class prime192v2 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF', 16));
$this->setCoefficients(
new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC', 16),
new BigInteger('CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953', 16)
);
$this->setBasePoint(
new BigInteger('EEA2BAE7E1497842F2DE7769CFE9C989C072AD696F48034A', 16),
new BigInteger('6574D11D69B6EC7A672BB82A083DF2F2B0847DE970B2DE15', 16)
);
$this->setOrder(new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* prime192v3
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class prime192v3 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF', 16));
$this->setCoefficients(
new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC', 16),
new BigInteger('22123DC2395A05CAA7423DAECCC94760A7D462256BD56916', 16)
);
$this->setBasePoint(
new BigInteger('7D29778100C65A1DA1783716588DCE2B8B4AEE8E228F1896', 16),
new BigInteger('38A90F22637337334B49DCB66A6DC8F9978ACA7648A943B0', 16)
);
$this->setOrder(new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* prime239v1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class prime239v1 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF', 16));
$this->setCoefficients(
new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC', 16),
new BigInteger('6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A', 16)
);
$this->setBasePoint(
new BigInteger('0FFA963CDCA8816CCC33B8642BEDF905C3D358573D3F27FBBD3B3CB9AAAF', 16),
new BigInteger('7DEBE8E4E90A5DAE6E4054CA530BA04654B36818CE226B39FCCB7B02F1AE', 16)
);
$this->setOrder(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* prime239v2
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class prime239v2 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF', 16));
$this->setCoefficients(
new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC', 16),
new BigInteger('617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C', 16)
);
$this->setBasePoint(
new BigInteger('38AF09D98727705120C921BB5E9E26296A3CDCF2F35757A0EAFD87B830E7', 16),
new BigInteger('5B0125E4DBEA0EC7206DA0FC01D9B081329FB555DE6EF460237DFF8BE4BA', 16)
);
$this->setOrder(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063', 16));
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* prime239v3
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
use phpseclib3\Crypt\EC\BaseCurves\Prime;
use phpseclib3\Math\BigInteger;
class prime239v3 extends Prime
{
public function __construct()
{
$this->setModulo(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF', 16));
$this->setCoefficients(
new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC', 16),
new BigInteger('255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E', 16)
);
$this->setBasePoint(
new BigInteger('6768AE8E18BB92CFCF005C949AA2C6D94853D0E660BBF854B1C9505FE95A', 16),
new BigInteger('1607E6898F390C06BC1D552BAD226F3B6FCFE48B6E818499AF18E3ED6CF3', 16)
);
$this->setOrder(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551', 16));
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* prime256v1
*
* PHP version 5 and 7
*
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2017 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://pear.php.net/package/Math_BigInteger
*/
declare(strict_types=1);
namespace phpseclib3\Crypt\EC\Curves;
final class prime256v1 extends secp256r1
{
}

Some files were not shown because too many files have changed in this diff Show More