phpseclib

phpseclib

  • Docs
  • API
  • Support
  • GitHub

›Introduction

Introduction

  • Why phpseclib?
  • Installation
  • Speed
  • Versioning

SSH2

  • Connecting
  • Authenticating
  • Running Commands
  • SFTP
  • Diagnosing Issues

Public Keys

  • Overview
  • RSA
  • DSA
  • Elliptic Curves
  • (EC)DH
  • Example: JWT

Symmetric Keys

  • Overview

X.509

  • X.509
  • CSR
  • SPKAC
  • CRL

Interoperability

  • Overview
  • Python
  • Java
  • JavaScript
  • Node.js
  • Go
  • Ruby
  • C#
  • C
  • PHP

Speed

Where math operations are concerned phpseclib will use whatever extensions are availale to speed up operations. The impact of these extensions on various versions of PHP is shown below.

Note that the following benchmarks were performed with phpseclib v1. phpseclib v3's performance should be comparable. The reason phpseclib v1 was employed is to show how PHP has sped up over the years.

The benchmarks were performed on GitHub Actions using Docker containers from phpseclib/docker-php.

Benchmarks

PHP32PHP64BCMathPHP32PHP64BCMathGMP
w/o OpenSSLw/ OpenSSL
PHP 4.47.0844.5382.3010.6850.5840.0620.002
PHP 5.07.3384.7562.2900.7130.6050.0620.002
PHP 5.13.2362.0312.2400.4030.3350.0600.002
PHP 5.23.6742.0402.2350.3660.3210.0620.002
PHP 5.33.2811.9422.2670.3510.2930.0570.002
PHP 5.42.0531.2392.2670.2490.2090.0570.002
PHP 5.52.0261.1342.2820.2620.2020.0600.002
PHP 5.61.9421.1612.3510.2560.2090.0560.002
PHP 7.00.9070.5512.2750.0890.0740.0620.002
PHP 7.10.7830.5012.3030.0850.0690.0550.002
PHP 7.20.6840.4482.3030.0650.0560.0540.001
PHP 7.30.6810.4462.2940.0720.0540.0520.002
PHP 7.40.6090.3932.3430.0590.0500.0610.001
PHP 8.00.6430.4112.2370.0620.0500.0520.001
PHP 8.10.6240.4162.2220.0600.0520.0550.002
PHP 8.20.6160.4012.2180.0590.0510.0530.002
PHP 8.30.6300.4192.1970.0630.0510.0510.002

Benchmarks with JIT

PHP 8 introduced a new Just-In-Time (JIT) compilation engine. The specific JIT settings that were used can be seen in the Docker containers opcache.ini.

PHP32PHP64BCMathPHP32PHP64BCMathGMP
w/o OpenSSLw/ OpenSSL
PHP 8.00.2100.1002.2470.0320.0280.0530.002
PHP 8.10.1880.0872.2280.0330.0290.0530.002
PHP 8.20.1970.0872.2220.0320.0280.0530.002
PHP 8.30.1890.0892.2020.0320.0290.0520.002

GMP Engine

GMP, to quote wikipedia, "aims to be faster than any other bignum library", using "highly optimized assembly language code".

PHP32 / PHP64

These days, most systems are 64-bit, however, a notable exception are Raspberry Pi's.

On 32-bit systems phpseclib uses base-2**26 to reduce the number of digits of each number. When two 26-bit numbers are multiplied together the result is a 64-bit floating point (of which only 48 bits are used), which is then converted back to two 32-bit signed integers (of which only 26 bits are used).

On 64-bit systems phpseclib uses base-2**31 to reduce the number of digits of each number. When two 31-bit numbers are multiplied together the result is a 64-bit signed integer (of which only 62 bits are used), which is then converted back to two 32-bit signed integers (of which only 31 bits are used).

OpenSSL Enhancements

Only used for powMod(). Converts the exponent and the modulo to an appropriately formatted RSA public key and performs unpadded RSA encryption with that.

← InstallationVersioning →
  • Benchmarks
  • Benchmarks with JIT
  • GMP Engine
  • PHP32 / PHP64
  • OpenSSL Enhancements
phpseclib
Docs
IntroductionSSH2 / SFTPPublic Key CryptoSymmetric Key CryptoX.509 / CSR / SPKAC / CRLInteroperability
Support
Docs (1.0 / 2.0)Stack OverflowGitHubStar
Sponsor
PatreonGitHubPayPal
Copyright © 2025 Jim Wigginton