phpseclib: BigInteger Introduction

Download Now

Operations

Bitwise Operations

Formating

Speed Analysis

The following heat map shows how many seconds Math_BigInteger takes to perform encryption / decryption with a 2048-bit RSA key on an Intel Core i5-3320M CPU @ 2.6GHz under various environments. benchmark.phps was used to generate the heatmap. col*.php are all variations of speed.phps.

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.419.8404.1252.2270.186
PHP 5.020.3384.0992.3530.193
PHP 5.18.2904.1601.3430.1870.014
PHP 5.27.9443.9951.2100.1770.014
PHP 5.35.7583.2930.7910.2460.017
PHP 5.43.1595.4150.5190.2930.019
PHP 5.53.7194.4590.4850.2270.020

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.