ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HMAC.php File Reference

Go to the source code of this file.

Namespaces

namespace  OpenID
 This is the PHP OpenID library by JanRain, Inc.
 

Functions

 Auth_OpenID_SHA1 ($text)
 
 Auth_OpenID_HMACSHA1 ($key, $text)
 Compute an HMAC/SHA1 hash. More...
 

Variables

const Auth_OpenID_SHA1_BLOCKSIZE 64
 SHA1_BLOCKSIZE is this module's SHA1 blocksize used by the fallback implementation. More...
 
if(function_exists('hash') &&function_exists('hash_algos') &&(in_array('sha256', hash_algos()))) else
 

Function Documentation

◆ Auth_OpenID_HMACSHA1()

Auth_OpenID_HMACSHA1 (   $key,
  $text 
)

Compute an HMAC/SHA1 hash.

@access private

Parameters
string$keyThe HMAC key
string$textThe message text to hash
Returns
string $mac The MAC

Definition at line 57 of file HMAC.php.

58{
60 $key = Auth_OpenID_SHA1($key, true);
61 }
62
63 $key = str_pad($key, Auth_OpenID_SHA1_BLOCKSIZE, chr(0x00));
64 $ipad = str_repeat(chr(0x36), Auth_OpenID_SHA1_BLOCKSIZE);
65 $opad = str_repeat(chr(0x5c), Auth_OpenID_SHA1_BLOCKSIZE);
66 $hash1 = Auth_OpenID_SHA1(($key ^ $ipad) . $text, true);
67 $hmac = Auth_OpenID_SHA1(($key ^ $opad) . $hash1, true);
68 return $hmac;
69}
70
71if (function_exists('hash') &&
72 function_exists('hash_algos') &&
73 (in_array('sha256', hash_algos()))) {
74 function Auth_OpenID_SHA256($text)
75 {
76 // PHP 5 case: 'hash' available and 'sha256' algo supported.
77 return hash('sha256', $text, true);
78 }
79 define('Auth_OpenID_SHA256_SUPPORTED', true);
80} else {
81 define('Auth_OpenID_SHA256_SUPPORTED', false);
82}
83
84if (function_exists('hash_hmac') &&
85 function_exists('hash_algos') &&
86 (in_array('sha256', hash_algos()))) {
87
88 function Auth_OpenID_HMACSHA256($key, $text)
89 {
90 // Return raw MAC (not hex string).
91 return hash_hmac('sha256', $text, $key, true);
92 }
93
94 define('Auth_OpenID_HMACSHA256_SUPPORTED', true);
95} else {
const Auth_OpenID_SHA1_BLOCKSIZE
SHA1_BLOCKSIZE is this module's SHA1 blocksize used by the fallback implementation.
Definition: HMAC.php:23
Auth_OpenID_SHA1($text)
Definition: HMAC.php:25
static bytes($str)
Count the number of bytes in a string independently of multibyte support conditions.
Definition: OpenID.php:462
$text

References $text, Auth_OpenID_SHA1(), Auth_OpenID_SHA1_BLOCKSIZE, and Auth_OpenID\bytes().

+ Here is the call graph for this function:

◆ Auth_OpenID_SHA1()

Auth_OpenID_SHA1 (   $text)

Definition at line 25 of file HMAC.php.

26{
27 if (function_exists('hash') &&
28 function_exists('hash_algos') &&
29 (in_array('sha1', hash_algos()))) {
30 // PHP 5 case (sometimes): 'hash' available and 'sha1' algo
31 // supported.
32 return hash('sha1', $text, true);
33 } else if (function_exists('sha1')) {
34 // PHP 4 case: 'sha1' available.
35 $hex = sha1($text);
36 $raw = '';
37 for ($i = 0; $i < 40; $i += 2) {
38 $hexcode = substr($hex, $i, 2);
39 $charcode = (int)base_convert($hexcode, 16, 10);
40 $raw .= chr($charcode);
41 }
42 return $raw;
43 } else {
44 // Explode.
45 trigger_error('No SHA1 function found', E_USER_ERROR);
46 }
47}

References $text.

Referenced by Auth_OpenID_FileStore\_safe64(), Auth_OpenID_DumbStore\Auth_OpenID_DumbStore(), and Auth_OpenID_HMACSHA1().

+ Here is the caller graph for this function:

Variable Documentation

◆ Auth_OpenID_SHA1_BLOCKSIZE

const Auth_OpenID_SHA1_BLOCKSIZE 64

SHA1_BLOCKSIZE is this module's SHA1 blocksize used by the fallback implementation.

Definition at line 23 of file HMAC.php.

Referenced by Auth_OpenID_HMACSHA1().

◆ else

if (function_exists( 'hash_hmac') &&function_exists( 'hash_algos') &&(in_array( 'sha256', hash_algos()))) else
Initial value:
{
define('Auth_OpenID_SHA256_SUPPORTED', false)

Definition at line 80 of file HMAC.php.