PHP Classes

File: src/Halite.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Halite   src/Halite.php   Download  
File: src/Halite.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Halite
Perform cryptography operations with libsodium
Author: By
Last change: Add Halite::isLibsodiumSetupCorrectly()
For version 2, let's use strict types!
Switch passwords and key derivation to crypto_pwhash() (Argon2i)
Date: 8 years ago
Size: 1,370 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace
ParagonIE\Halite;

/**
 * This is just an abstract class that hosts some constants
 *
 * Version Tag Info:
 *
 * \x31\x41 => 3.141 (approx. pi)
 * \x31\x42 => 3.142 (approx. pi)
 * Because pi is the symbol we use for Paragon Initiative Enterprises
 * \x00\x07 => version 0.07
 */
abstract class Halite
{
    const
VERSION = '2.0.0';

    const
HALITE_VERSION_KEYS = "\x31\x40\x02\x00";
    const
HALITE_VERSION_FILE = "\x31\x41\x02\x00";
    const
HALITE_VERSION = "\x31\x42\x02\x00";
   
    const
VERSION_TAG_LEN = 4;

    public static function
isLibsodiumSetupCorrectly(bool $echo = false): bool
   
{
       
// Require libsodium 1.0.9
       
$major = \Sodium\library_version_major();
       
$minor = \Sodium\library_version_minor();
        if (
$major < 9 || ($major === 9 && $minor < 2)) {
            if (
$echo) {
                echo
'Halite needs libsodium 1.0.9 or higher. You have: ', \Sodium\version_string(), "\n";
            }
            return
false;
        }

       
// Added in version 1.0.3 of the PHP extension
       
if (!\function_exists('\\Sodium\\crypto_pwhash_str')) {
            if (
$echo) {
                echo
'Halite needs version 1.0.3 or higher of the PHP extension installed.', "\n";
            }
            return
false;
        }

        return
true;
    }
}