Oath
Oath implementation of the OATH specification for both HOTP and TOTP one time passwords (RFC4226 and its extension HOTPTimeBased Internet-Draft, respectively).
See http://www.openauthentication.org
Table of Contents
Properties
| $crypto | |
| $digits_power | Precomputed power values |
| $drift | |
| $length | |
| $moving_factor | |
| $secret |
Methods
| __construct() | Construct a new OATH object using the given secret and HMAC hash function |
| checkHotp() | Checks whether the given one time password is a valid HOTP password using the given counter and VLAV (Validation Look Ahead Value) |
| checkTotp() | Checks whether the given one time password is a valid TOTP password using the given time |
| hotp() | Generate an HOTP pass phrase |
| setCrypto() | Set the algorithm to use during the HMAC calculation |
| setSecret() | Set the secret key to use along with the HMAC calculation |
| totp() | Generate an TOTP pass phrase |
| hex2Bin() | Detects if the given string is in hex format, if not, converts it to hex |
| hexStr2Bin() | Converts a hex string to a binary string |
| truncate() | Truncates the given hash per the RFC4226 truncation method |
Properties
$crypto
private
string
$crypto
= 'sha1'
The hash function to use during the HMAC calculation
$digits_power
Precomputed power values
private
static mixed
$digits_power
= [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000]
$drift
private
int
$drift
= 180
The number of seconds of drift to account for (+/- 3 minutes)
$length
private
int
$length
= 6
Length of one time password
$moving_factor
private
int
$moving_factor
= 30
Moving factor of TOTP
$secret
private
string
$secret
Shared secret
Methods
__construct()
Construct a new OATH object using the given secret and HMAC hash function
public
__construct([string $secret = null ][, string $crypto = 'sha1' ]) : mixed
Parameters
- $secret : string = null
-
The shared secret
- $crypto : string = 'sha1'
-
The crypto system to use during the HMAC calculation
checkHotp()
Checks whether the given one time password is a valid HOTP password using the given counter and VLAV (Validation Look Ahead Value)
public
checkHotp(string $otp, int $counter[, int $vlav = 0 ]) : bool
Parameters
- $otp : string
-
The one time password to validate
- $counter : int
-
The counter value
- $vlav : int = 0
-
The validation look ahead value
Return values
bool —True if this OTP is valid, false otherwise
checkTotp()
Checks whether the given one time password is a valid TOTP password using the given time
public
checkTotp(string $otp, int $time) : bool
Parameters
- $otp : string
-
The one time password to validate
- $time : int
-
The time value
Return values
bool —True if this OTP is valid, false otherwise
hotp()
Generate an HOTP pass phrase
public
static hotp(string $key, int $counter[, mixed $digit_length = 6 ][, mixed $crypto = 'sha1' ]) : string
Parameters
- $key : string
-
The secret key
- $counter : int
-
The counter value
- $digit_length : mixed = 6
-
The length of the resulting pass phrase
- $crypto : mixed = 'sha1'
-
The algorithm to use in the HMAC calculation
Return values
string —The HOTP pass pharse
setCrypto()
Set the algorithm to use during the HMAC calculation
public
setCrypto(string $crypto) : mixed
Parameters
- $crypto : string
-
The crypto system to use during the HMAC calculation
setSecret()
Set the secret key to use along with the HMAC calculation
public
setSecret(string $secret) : mixed
Parameters
- $secret : string
-
The shared secret
totp()
Generate an TOTP pass phrase
public
static totp(string $key, int $counter[, mixed $digit_length = 6 ][, mixed $crypto = 'sha1' ]) : string
Parameters
- $key : string
-
The secret key
- $counter : int
-
The counter value (e.g. Unix time)
- $digit_length : mixed = 6
-
The length of the resulting pass phrase
- $crypto : mixed = 'sha1'
-
The algorithm to use in the HMAC calculation
Return values
string —The TOTP pass pharse
hex2Bin()
Detects if the given string is in hex format, if not, converts it to hex
private
static hex2Bin(mixed $string) : mixed
Parameters
- $string : mixed
hexStr2Bin()
Converts a hex string to a binary string
private
static hexStr2Bin(int $hex) : string
Parameters
- $hex : int
-
The hex value to convert
Return values
string —The byte representation of the given hex
truncate()
Truncates the given hash per the RFC4226 truncation method
private
static truncate(string $hash[, int $digit_length = 6 ]) : string
Parameters
- $hash : string
-
The hash as a hexadecimal string
- $digit_length : int = 6
-
The length of the result
Return values
string —The truncated hash