phpseclib: BigInteger Introduction

Operations

Bitwise Operations

Formating

Misc

Speed Analysis

The following heat map shows how many seconds Math_BigInteger takes to perform encryption / decryption with a 2048-bit RSA key on a 1.73GHz Intel Core i7-820QM under various environments. See speed.phps for the source code.

Math_BigInteger automatically picks the fastest settings to use depending on what extensions it has available at its disposal.

InternalBCMathInternalBCMathGMP
w/o OpenSSLw/ OpenSSL
PHP 4.426.4485.0033.2050.454
PHP 5.025.8024.8733.2790.455
PHP 5.18.9074.9621.7780.4340.021
PHP 5.28.3634.6721.5950.3910.018
PHP 5.36.4774.4541.1240.5700.087
PHP 5.44.9709.1460.7020.4030.013

Internal Engine

The major limiting factor for the internal implementation is the PHP engine itself. Each successive major version brings with it speed improvements but there's only so much it can do.

GMP Engine

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

OpenSSL Enhancements

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