1 |
<?php
|
2 |
//********************************************************************************
|
3 |
//Copyright (C)2006 David T. Ashley
|
4 |
//********************************************************************************
|
5 |
//This program or source file is free software; you can redistribute it and/or
|
6 |
//modify it under the terms of the GNU General Public License as published by
|
7 |
//the Free Software Foundation; either version 2 of the License, or (at your
|
8 |
//option) any later version.
|
9 |
//
|
10 |
//This program or source file is distributed in the hope that it will
|
11 |
//be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
//GNU General Public License for more details.
|
14 |
//
|
15 |
//You may have received a copy of the GNU General Public License
|
16 |
//along with this program; if not, write to the Free Software
|
17 |
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
//********************************************************************************
|
19 |
//Dave Ashley, 01/06
|
20 |
//
|
21 |
//This source file contains cryptographic hash functions.
|
22 |
//
|
23 |
//This constant is the hashing key. This must be concealed from all users of the system.
|
24 |
//Knowledge of this key would allow a user to forge hashes. The key consists of random
|
25 |
//typing, digits of PI, verbiage from the PHP website, and Thoreau quotes.
|
26 |
//
|
27 |
define("CRHSH_KEY_A", "kdj376xhadfhl134g;;hv adfhlLLL:::341324hdbvjkahsdfgh2834gigwreeiqrbuibwqvgzzxxaqkhlkagdviab;;" .
|
28 |
"wikiwikiboomboomWhen you remove constant in your pool.14159265358979323846264338hgiik123435 /" .
|
29 |
"628034825342117067982160631558817488152092096282925409171536436789259next greatest happiness " .
|
30 |
"always 762876110927543725 clear understanding that I do not attain //76234767960bbbhgquickbro" .
|
31 |
"hgalshdfthequickdoglazytheoverjumpedfoxquickbrownfox---mind was all undusted still,.........." );
|
32 |
|
33 |
//All of the functions below calculate an MD5 hash with various numbers of arguments. A
|
34 |
//function accepting a variable number of arguments is also provided. The return value
|
35 |
//in all cases is an MD5 hash of the arguments intermingled with the key.
|
36 |
//
|
37 |
//The functions are in all cases deterministic (same inputs will always produce same output).
|
38 |
//
|
39 |
//Once a database system is in operation, the key must not be changed, or it may render the database
|
40 |
//system unusable.
|
41 |
//
|
42 |
function CRHSH_hash01($arg)
|
43 |
{
|
44 |
$arg = (string) $arg;
|
45 |
|
46 |
$input = CRHSH_KEY_A . $arg . CRHSH_KEY_A;
|
47 |
|
48 |
//echo "<br>\n";
|
49 |
//echo $input;
|
50 |
//echo "<br>\n";
|
51 |
|
52 |
$rv = md5($input);
|
53 |
|
54 |
return($rv);
|
55 |
}
|
56 |
//
|
57 |
function CRHSH_hash02($arg01, $arg02)
|
58 |
{
|
59 |
$arg01 = (string) $arg01;
|
60 |
$arg02 = (string) $arg02;
|
61 |
|
62 |
$input = CRHSH_KEY_A . $arg01 . CRHSH_KEY_A . $arg02 . CRHSH_KEY_A;
|
63 |
|
64 |
//echo "<br>\n";
|
65 |
//echo $input;
|
66 |
//echo "<br>\n";
|
67 |
|
68 |
$rv = md5($input);
|
69 |
|
70 |
return($rv);
|
71 |
}
|
72 |
//
|
73 |
function CRHSH_hash03($arg01, $arg02, $arg03)
|
74 |
{
|
75 |
$arg01 = (string) $arg01;
|
76 |
$arg02 = (string) $arg02;
|
77 |
$arg03 = (string) $arg03;
|
78 |
|
79 |
$input = CRHSH_KEY_A . $arg01 . CRHSH_KEY_A . $arg02 . CRHSH_KEY_A . $arg03 . CRHSH_KEY_A;
|
80 |
|
81 |
$rv = md5($input);
|
82 |
|
83 |
return($rv);
|
84 |
}
|
85 |
//
|
86 |
function CRHSH_hash04($arg01, $arg02, $arg03, $arg04)
|
87 |
{
|
88 |
$arg01 = (string) $arg01;
|
89 |
$arg02 = (string) $arg02;
|
90 |
$arg03 = (string) $arg03;
|
91 |
$arg04 = (string) $arg04;
|
92 |
|
93 |
$input = CRHSH_KEY_A . $arg01 . CRHSH_KEY_A . $arg02 . CRHSH_KEY_A . $arg03 . CRHSH_KEY_A . $arg04 . CRHSH_KEY_A;
|
94 |
|
95 |
$rv = md5($input);
|
96 |
|
97 |
return($rv);
|
98 |
}
|
99 |
//
|
100 |
function CRHSH_hashva()
|
101 |
{
|
102 |
$input = CRHSH_KEY_A;
|
103 |
|
104 |
$num_args = func_num_args();
|
105 |
|
106 |
for ($i=0; $i<$num_args; $i++)
|
107 |
{
|
108 |
$input .= ((string) func_get_arg($i));
|
109 |
$input .= CRHSH_KEY_A;
|
110 |
}
|
111 |
|
112 |
$rv = md5($input);
|
113 |
|
114 |
return($rv);
|
115 |
}
|
116 |
?>
|