You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB
Plaintext

<?php /* -*- php -*- */
function fulcrm_uuid_stir_mt_srand() {
if ( function_exists( 'drupal_random_bytes' ) )
mt_srand( crc32( drupal_random_bytes( 4 ) ) );
else if ( function_exists( 'microtime' ) )
mt_srand( crc32( microtime() ) );
else {
$e1 = variable_get( 'fulcrm_uuid_entropy_1', '' );
mt_srand( crc32( $e1 ) );
}
}
function fulcrm_uuid_stir_entropy() {
fulcrm_uuid_stir_mt_srand();
$entropy = '';
if ( function_exists( 'drupal_random_bytes' ) ) {
$entropy .= drupal_random_bytes( 32 );
} else {
$entropy .= mt_rand();
$entropy .= rand();
$entropy .= time();
if ( function_exists( 'microtime' ) )
$entropy .= microtime();
$entropy .= variable_get( 'cron_key', '' );
$entropy .= variable_get( 'cron_last', '' );
$entropy .= variable_get( 'drupal_private_key', '' );
$entropy .= variable_get( 'site_name', '' );
if ( function_exists( 'openssl_random_pseudo_bytes' ) )
$entropy .= openssl_random_pseudo_bytes( 32 );
$handle = fopen( '/dev/urandom', 'r' );
$entropy .= fread( $handle, 32 );
fclose( $handle );
}
$old_entropy = ( variable_get( 'fulcrm_uuid_entropy_1', '' ) .
variable_get( 'fulcrm_uuid_entropy_2', '' ) );
variable_set( 'fulcrm_uuid_entropy_1', sha1( $entropy ) );
variable_set( 'fulcrm_uuid_entropy_2', md5( $old_entropy . $entropy ) );
fulcrm_uuid_stir_mt_srand();
}
function fulcrm_uuid_cron() {
fulcrm_uuid_stir_entropy();
}
function fulcrm_uuid_uuid4() {
static $data = '';
if ( function_exists( 'drupal_random_bytes' ) )
$data = $data . drupal_random_bytes( 4 );
else
$data = $data . uniqid( $more_entropy = true );
$data = ( variable_get( 'fulcrm_uuid_entropy_2', '' ) .
$data .
variable_get( 'fulcrm_uuid_entropy_2', '' ) );
$data = md5( $data );
$rdata = hex2bin( $data );
$rdata[ 6 ] = chr( ord( $rdata[ 6 ] ) & 0x0f | 0x40 );
$rdata[ 8 ] = chr( ord( $rdata[ 8 ] ) & 0x3f | 0x80 );
return vsprintf( '%s%s-%s-%s-%s-%s%s%s', str_split( bin2hex( $rdata ), 4 ) );
}