File "random_bytes_libsodium.php"

Full path: /home/kosmetik/public_html/wp-includes/random_compat/random_bytes_libsodium.php
File size: 921 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!is_callable('random_bytes')) {
    function random_bytes($bytes)
    {
        try {
            $bytes = RandomCompat_intval($bytes);
        } catch (TypeError $ex) {
            throw new TypeError('random_bytes(): $bytes must be an integer');
        }
        if ($bytes < 1) {
            throw new Error('Length must be greater than 0');
        }
        if ($bytes > 2147483647) {
            $buf = '';
            for ($i = 0; $i < $bytes; $i += 1073741824) {
                $n = $bytes - $i > 1073741824 ? 1073741824 : $bytes - $i;
                $buf .= \Sodium\randombytes_buf($n);
            }
        } else {
            $buf = \Sodium\randombytes_buf($bytes);
        }
        if ($buf !== false) {
            if (RandomCompat_strlen($buf) === $bytes) {
                return $buf;
            }
        }
        throw new Exception('Could not gather sufficient random data');
    }
}