[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/phpseclib/phpseclib/phpseclib/Crypt/ -> Hash.php (summary)

Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions. Uses hash() or mhash() if available and an internal implementation, otherwise.  Currently supports the following:

Author: Jim Wigginton
Copyright: 2007 Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
Link: http://phpseclib.sourceforge.net
File Size: 894 lines (29 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Hash:: (17 methods):
  __construct()
  setKey()
  _computeKey()
  getHash()
  setHash()
  hash()
  getLength()
  _md5()
  _sha1()
  _md2()
  _sha256()
  _sha512()
  _rightRotate()
  _rightShift()
  _not()
  _add()
  _string_shift()


Class: Hash  - X-Ref

Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.

__construct($hash = 'sha1')   X-Ref
Default Constructor.

param: string $hash
return: \phpseclib\Crypt\Hash

setKey($key = false)   X-Ref
Sets the key for HMACs

Keys can be of any length.

param: string $key

_computeKey()   X-Ref
Pre-compute the key used by the HMAC

Quoting http://tools.ietf.org/html/rfc2104#section-2, "Applications that use keys longer than B bytes
will first hash the key using H and then use the resultant L byte string as the actual key to HMAC."

As documented in https://www.reddit.com/r/PHP/comments/9nct2l/symfonypolyfill_hash_pbkdf2_correct_fix_for/
when doing an HMAC multiple times it's faster to compute the hash once instead of computing it during
every call


getHash()   X-Ref
Gets the hash function.

As set by the constructor or by the setHash() method.

return: string

setHash($hash)   X-Ref
Sets the hash function.

param: string $hash

hash($text)   X-Ref
Compute the HMAC.

param: string $text
return: string

getLength()   X-Ref
Returns the hash length (in bytes)

return: int

_md5($m)   X-Ref
Wrapper for MD5

param: string $m

_sha1($m)   X-Ref
Wrapper for SHA1

param: string $m

_md2($m)   X-Ref
Pure-PHP implementation of MD2

See {@link http://tools.ietf.org/html/rfc1319 RFC1319}.

param: string $m

_sha256($m)   X-Ref
Pure-PHP implementation of SHA256

See {@link http://en.wikipedia.org/wiki/SHA_hash_functions#SHA-256_.28a_SHA-2_variant.29_pseudocode SHA-256 (a SHA-2 variant) pseudocode - Wikipedia}.

param: string $m

_sha512($m)   X-Ref
Pure-PHP implementation of SHA384 and SHA512

param: string $m

_rightRotate($int, $amt)   X-Ref
Right Rotate

param: int $int
param: int $amt
return: int
see: self::_sha256()

_rightShift($int, $amt)   X-Ref
Right Shift

param: int $int
param: int $amt
return: int
see: self::_sha256()

_not($int)   X-Ref
Not

param: int $int
return: int
see: self::_sha256()

_add()   X-Ref
Add

_sha256() adds multiple unsigned 32-bit integers.  Since PHP doesn't support unsigned integers and since the
possibility of overflow exists, care has to be taken.  BigInteger could be used but this should be faster.

param: int $...
return: int
see: self::_sha256()

_string_shift(&$string, $index = 1)   X-Ref
String Shift

Inspired by array_shift

param: string $string
param: int $index
return: string