default
[ class tree: default ] [ index: default ] [ all elements ]

Source for file emuhash_functions.php

Documentation is available at emuhash_functions.php

  1. <?php
  2. // $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/emuhash_functions.php,v 1.6.10.1 2007/12/21 12:11:55 wurley Exp $
  3.  
  4. /*****************************************************************************
  5.  * emuhash - partly emulates the php mhash functions
  6.  * version: 2004040701
  7.  *
  8.  * (c) 2004 - Simon Matter <simon.matter@invoca.ch>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  *
  24.  ******************************************************************************/
  25.  
  26.  
  27. /******************************************************************************/
  28. /* Do we have builtin mhash support in this PHP version ?                     */
  29. /******************************************************************************/
  30.  
  31. iffunction_exists'mhash' && function_exists'mhash_keygen_s2k' ) ) {
  32.     ifisset$emuhash_openssl ) )
  33.         $emuhash_openssl '/usr/bin/openssl';
  34.  
  35.     // don't create mhash functions if we don't have a working openssl
  36.         iffile_exists$emuhash_openssl ) )
  37.         unset$emuhash_openssl );
  38.  
  39.     elseif function_exists'is_executable' && is_executable$emuhash_openssl ) )
  40.         unset$emuhash_openssl );
  41.  
  42.     else {
  43.  
  44.         ifisset$emuhash_temp_dir ) )
  45.             $emuhash_temp_dir '/tmp';
  46.  
  47. /******************************************************************************/
  48. /* Define constants used in the mhash emulation code.                         */
  49. /******************************************************************************/
  50.  
  51.         define('MHASH_MD5''md5');
  52.         define('MHASH_SHA1''sha1');
  53.         define('MHASH_RIPEMD160''rmd160');
  54.  
  55. /******************************************************************************/
  56. /* Functions to emulate parts of php-mash.                                    */
  57. /******************************************************************************/
  58.  
  59.         function openssl_hash$openssl_hash_id$password_clear {
  60.             global $emuhash_openssl$emuhash_temp_dir;
  61.  
  62.             $current_magic_quotes get_magic_quotes_runtime();
  63.             set_magic_quotes_runtime);
  64.             $tmpfile tempnam$emuhash_temp_dir"emuhash" );
  65.             $pwhandle fopen$tmpfile"w" );
  66.  
  67.             if$pwhandle )
  68.                 pla_error"Unable to create a temporary file '$tmpfileto create hashed password);
  69.  
  70.             fwrite$pwhandle$password_clear );
  71.             fclose$pwhandle );
  72.             $cmd $emuhash_openssl ' ' $openssl_hash_id ' -binary < ' $tmpfile;
  73.             $prog popen$cmd"r" );
  74.             $pass fread$prog1024 );
  75.             pclose$prog );
  76.             unlink$tmpfile );
  77.             set_magic_quotes_runtime$current_magic_quotes );
  78.  
  79.             return $pass;
  80.         }
  81.  
  82.         function mhash$hash_id$password_clear {
  83.             switch$hash_id {
  84.                 case MHASH_MD5:
  85.                     $emuhash openssl_hashMHASH_MD5$password_clear );
  86.                     break;
  87.  
  88.                 case MHASH_SHA1:
  89.                     $emuhash openssl_hashMHASH_SHA1$password_clear );
  90.                     break;
  91.  
  92.                 case MHASH_RIPEMD160:
  93.                     $emuhash openssl_hashMHASH_RIPEMD160$password_clear );
  94.                     break;
  95.  
  96.                 default:
  97.                     $emuhash FALSE;
  98.             }
  99.  
  100.             return $emuhash;
  101.         }
  102.  
  103.         function mhash_keygen_s2k$hash_id$password_clear$salt$bytes {
  104.             return substr(pack("H*"bin2hex(mhash($hash_id($salt $password_clear))))0$bytes);
  105.         }
  106.  
  107. /******************************************************************************/
  108.  
  109.     }
  110.  
  111. }
  112. ?>

Documentation generated on Sun, 30 Dec 2007 17:49:32 -0800 by phpDocumentor 1.3.1