Download the PHP package paragonie/sodium_compat without Composer

On this page you can find all versions of the php package paragonie/sodium_compat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sodium_compat

Sodium Compat

Build Status Psalm Status Windows Build Status Latest Stable Version Latest Unstable Version License Downloads

Sodium Compat is a pure PHP polyfill for the Sodium cryptography library (libsodium), a core extension in PHP 7.2.0+ and otherwise available in PECL.

This library tentatively supports PHP 5.2.4 - 8.x (latest), but officially only supports non-EOL'd versions of PHP.

If you have the PHP extension installed, Sodium Compat will opportunistically and transparently use the PHP extension instead of our implementation.

IMPORTANT!

This cryptography library has not been formally audited by an independent third party that specializes in cryptography or cryptanalysis.

If you require such an audit before you can use sodium_compat in your projects and have the funds for such an audit, please open an issue or contact security at paragonie dot com so we can help get the ball rolling.

However, sodium_compat has been adopted by high profile open source projects, such as Joomla! and Magento. Furthermore, sodium_compat was developed by Paragon Initiative Enterprises, a company that specializes in secure PHP development and PHP cryptography, and has been informally reviewed by many other security experts who also specialize in PHP.

If you'd like to learn more about the defensive security measures we've taken to prevent sodium_compat from being a source of vulnerability in your systems, please read Cryptographically Secure PHP Development.

Installing Sodium Compat

If you're using Composer:

Install From Source

If you're not using Composer, download a release tarball (which should be signed with our GnuPG public key), extract its contents, then include our autoload.php script in your project.

PHP Archives (Phar) Releases

Since version 1.3.0, sodium_compat releases include a PHP Archive (.phar file) and associated GPG signature. First, download both files and verify them with our GPG public key, like so:

Now, simply include this .phar file in your application.

Support

Commercial support for libsodium is available from multiple vendors. If you need help using sodium_compat in one of your projects, contact Paragon Initiative Enterprises.

Non-commercial report will be facilitated through Github issues. We offer no guarantees of our availability to resolve questions about integrating sodium_compat into third-party software for free, but will strive to fix any bugs (security-related or otherwise) in our library.

Support Contracts

If your company uses this library in their products or services, you may be interested in purchasing a support contract from Paragon Initiative Enterprises.

Using Sodium Compat

True Polyfill

As per the second vote on the libsodium RFC, PHP 7.2 uses sodium_* instead of \Sodium\*.

Polyfill For the Old PECL Extension API

If you're using PHP 5.3.0 or newer and do not have the PECL extension installed, you can just use the standard ext/sodium API features as-is and the polyfill will work its magic.

The polyfill does not expose this API on PHP < 5.3, or if you have the PHP extension installed already.

General-Use Polyfill

If your users are on PHP < 5.3, or you want to write code that will work whether or not the PECL extension is available, you'll want to use the ParagonIE_Sodium_Compat class for most of your libsodium needs.

The above example, written for general use:

Generally: If you replace \Sodium\ with ParagonIE_Sodium_Compat::, any code already written for the libsodium PHP extension should work with our polyfill without additional code changes.

Since this doesn't require a namespace, this API is exposed on PHP 5.2.

Since version 0.7.0, we have our own namespaced API (ParagonIE\Sodium\*) to allow brevity in software that uses PHP 5.3+. This is useful if you want to use our file cryptography features without writing ParagonIE_Sodium_File every time. This is not exposed on PHP < 5.3, so if your project supports PHP < 5.3, use the underscore method instead.

To learn how to use Libsodium, read Using Libsodium in PHP Projects.

Help, Sodium_Compat is Slow! How can I make it fast?

There are three ways to make it fast:

  1. Use a newer version of PHP (at least 7.2).
  2. Install the libsodium PHP extension from PECL.
  3. Only if the previous two options are not available for you:
    1. Verify that the processor you're using actually implements constant-time multiplication. Sodium_compat does, but it must trade some speed in order to attain cross-platform security.
    2. Only if you are 100% certain that your processor is safe, you can set ParagonIE_Sodium_Compat::$fastMult = true; without harming the security of your cryptography keys. If your processor isn't safe, then decide whether you want speed or security because you can't have both.

How can I tell if sodium_compat will be slow, at runtime?

Since version 1.8, you can use the polyfill_is_fast() static method to determine if sodium_compat will be slow at runtime.

Help, my PHP only has 32-Bit Integers! It's super slow!

If the PHP_INT_SIZE constant equals 4 instead of 8 (PHP 5 on Windows, Linux on i386, etc.), you will run into significant performance issues.

In particular: public-key cryptography (encryption and signatures) is affected. There is nothing we can do about that.

The root cause of these performance issues has to do with implementing cryptography algorithms in constant-time using 16-bit limbs (to avoid overflow) in pure PHP.

To mitigate these performance issues, simply install PHP 7.2 or newer and enable the sodium extension.

Affected users are encouraged to install the sodium extension (or libsodium from older version of PHP).

Windows users on PHP 5 may be able to simply upgrade to PHP 7 and the slowdown will be greatly reduced.

Documentation

First, you'll want to read the Libsodium Quick Reference. It aims to answer, "Which function should I use for [common problem]?".

If you don't find the answers in the Quick Reference page, check out Using Libsodium in PHP Projects.

Finally, the official libsodium documentation (which was written for the C library, not the PHP library) also contains a lot of insightful technical information you may find helpful.

API Coverage

Recommended reading: Libsodium Quick Reference

Cryptography Primitives Provided

Features Excluded from this Polyfill

PHPCompatibility Ruleset

For sodium_compat users and that utilize PHPCompatibility in their CI process, there is now a custom ruleset available which can be used to prevent false positives being thrown by PHPCompatibility for the native PHP functionality being polyfilled by this repo.

You can find the repo for the PHPCompatibilityParagonieSodiumCompat ruleset here on Github and on Packagist.


All versions of sodium_compat with dependencies

PHP Build Version
Package Version
Requires php Version ^5.2.4|^5.3|^5.4|^5.5|^5.6|^7|^8
paragonie/random_compat Version >=1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package paragonie/sodium_compat contains the following files

Loading the files please wait ....