Home » Encryption » Crypt_CHAP » Manual
Classes for generating packets for various CHAP Protocols
Introduction
Introduction – encryption
CHAP - Challenge Handshake Authentication Protocol
CHAP is a part usualy of PPP (Point-to-Point Protocol) software, implemented in the authentication subsystem. CHAP avoid's sending plaintext passwords over an insecure link. The traditional CHAP-MD5 needs the plaintext password stored on the server. MS-CHAP doesen't need this, but also needs the password either as NT-Hash and/or as LAN-Manager-Hash. LAN-Manager-Hashes are weak and shouldn't be used anymore.
This package provides 3 classes:
- Crypt_CHAP::Crypt_CHAP_MD5() - for generating CHAP-MD5 (RFC 1994) compliant pakets
- Crypt_CHAP::Crypt_CHAP_MSv1() - for generating MS-CHAPv1 (RFC 2433) compliant pakets
- Crypt_CHAP::Crypt_CHAP_MSv2() - for generating MS-CHAPv2 (RFC 2759) compliant pakets
Crypt_CHAP::Crypt_CHAP is an abstract base class.
In order to get the MS-CHAP* to work you need the mhash extension.
Crypt_CHAP::generateChallenge()
Crypt_CHAP::generateChallenge() – Generates a new random challenge.
Synopsis
string Crypt_CHAP::generateChallenge (
string $varname = 'challenge'
, int $size = 8
)
Description
This method generates a new random challenge and stores it in the given property, the default size of the challenge is 8 bytes.
Parameter
-
string $varname- name of the property for storing the challenge -
int $size- the size of the challenge
Return value
string - a String containing the challenge
Note
This function can not be called statically.
Example
Using Crypt_CHAP::generateChallenge()
<?php
require_once 'File/SMBPasswd.php';
$cr = new Crypt_CHAP_MD5();
echo bin2hex($cr->challenge);
// or generate a new challenge
echo bin2hex(echo $cr->generateChallenge());
?>
Crypt_CHAP_MD5::Crypt_CHAP_MD5()
Crypt_CHAP_MD5::Crypt_CHAP_MD5() – constructor
Synopsis
require_once 'Crypt/CHAP.php';
void
Crypt_CHAP_MD5::Crypt_CHAP_MD5 (
)
Description
Generates a new Object for generating CHAP-MD5 compliant pakets.
Crypt_CHAP_MD5::challengeResponse()
Crypt_CHAP_MD5::challengeResponse() – Generates the challenge-response paket.
Synopsis
string Crypt_CHAP_MD5::challengeResponse (
)
Description
This method generates the challenge-response paket, by doing: md5(ID + Password + Challenge).
Return value
string - a String containing the challenge-response paket
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MD5::challengeResponse()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MD5();
$cr->password = 'MyPw';
echo bin2hex($cr->challengeResponse());
?>
Crypt_CHAP_MSv1::Crypt_CHAP_MSv1()
Crypt_CHAP_MSv1::Crypt_CHAP_MSv1() – constructor
Synopsis
require_once 'Crypt/CHAP.php';
void
Crypt_CHAP_MSv1::Crypt_CHAP_MSv1 (
)
Description
Generates a new Object for generating MS-CHAPv1 compliant pakets.
Note
You need the mhash extension in order to get this class to work.
Crypt_CHAP_MSv1::challengeResponse()
Crypt_CHAP_MSv1::challengeResponse() – Generates the Challenge-Response paket.
Synopsis
string Crypt_CHAP_MSv1::challengeResponse (
)
Description
This method generates the Challenge-Response paket.
Return value
string - a String containing the challenge-response paket
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv1::challengeResponse()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv1();
$cr->chapid = 1;
$cr->password = 'MyPw';
echo bin2hex($cr->challengeResponse());
?>
Crypt_CHAP_MSv1::lmChallengeResponse()
Crypt_CHAP_MSv1::lmChallengeResponse() – Generates the Challenge-Response paket using the LAN-Manager Hash.
Synopsis
string Crypt_CHAP_MSv1::lmChallengeResponse (
)
Description
This method generates the Challenge-Response using the LAN-Manager Hash.
Return value
string - a String containing the challenge-response
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv1::lmChallengeResponse()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv1();
$cr->password = 'MyPw';
echo bin2hex($cr->lmChallengeResponse());
?>
Crypt_CHAP_MSv1::ntChallengeResponse()
Crypt_CHAP_MSv1::ntChallengeResponse() – Generates the Challenge-Response paket using the NT-Hash.
Synopsis
string Crypt_CHAP_MSv1::ntChallengeResponse (
)
Description
This method generates the Challenge-Response using the NT-Hash.
Return value
string - a String containing the challenge-response
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv1::ntChallengeResponse()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv1();
$cr->password = 'MyPw';
echo bin2hex($cr->ntChallengeResponse());
?>
Crypt_CHAP_MSv1::ntPasswordHash()
Crypt_CHAP_MSv1::ntPasswordHash() – Generates the NT-Hash from the given plaintext-password.
Synopsis
string Crypt_CHAP_MSv1::ntPasswordHash (
string $password = ''
)
Description
This method generates NT-Hash from the given plaintext-password or from the password property. The NT-Hash is computed like this: md4(str2unicode(plaintext))
Parameter
-
string $password- the password to be hashed
Return value
string - a String containing the NT-Hash
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv1::ntPasswordHash()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv1();
$cr->password = 'MyPw';
echo bin2hex($cr->ntPasswordHash());
// or
echo bin2hex($cr->ntPasswordHash('MySecret'));
?>
Crypt_CHAP_MSv1::lmPasswordHash()
Crypt_CHAP_MSv1::lmPasswordHash() – Generates the LAN-Manager-Hash from the given plaintext-password.
Synopsis
string Crypt_CHAP_MSv1::lmPasswordHash (
string $password = ''
)
Description
This method generates LAN-Manager-Hash from the given plaintext-password or from the password property.
Parameter
-
string $password- the password to be hashed
Return value
string - a String containing the LAN-Manager-Hash
Note
This function can not be called statically.
LAN-Manager Hash are weak and should not be used anymore.
Example
Using Crypt_CHAP_MSv1::lmPasswordHash()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv1();
$cr->password = 'MyPw';
echo bin2hex($cr->lmPasswordHash());
// or
echo bin2hex($cr->lmPasswordHash('MySecret'));
?>
Crypt_CHAP_MSv1::str2unicode()
Crypt_CHAP_MSv1::str2unicode() – Converts a string to unicode.
Synopsis
string Crypt_CHAP_MSv1::str2unicode (
string $str
)
Description
This method generates converts the given string to unicode.
Parameter
-
string $str- the string to be unicoded
Return value
string - a String containing unicode representation of the given string
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv1::str2unicode()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv1();
echo bin2hex($cr->str2unicode('MyPw'));
?>
Crypt_CHAP_MSv1::response()
Crypt_CHAP_MSv1::response() – Generates the response-packet.
Synopsis
string Crypt_CHAP_MSv1::response (
bool $lm
= false
)
Description
This method generates the response paket, containing the NT-Challenge-Response and/or the LM-Challenge-Response. By default the LM-Challenge-Response is not included.
Parameter
-
bool $lm- wether including the LM-Challenge-Response
Return value
string - a String containing the paket
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv1::response()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv1();
$cr->password = 'MyPw';
echo bin2hex($cr->response());
?>
Crypt_CHAP_MSv2::Crypt_CHAP_MSv2()
Crypt_CHAP_MSv2::Crypt_CHAP_MSv2() – constructor
Synopsis
require_once 'Crypt/CHAP.php';
void
Crypt_CHAP_MSv2::Crypt_CHAP_MSv2 (
)
Description
Generates a new Object for generating MS-CHAPv2 compliant pakets. This version of CHAP uses also a Peer-Challenge, LM-Hashes are not used anymore. The Constructor generates automatically a Peer-Challenge and the Authenticator-Challenge.
Crypt_CHAP_MSv2::challengeHash()
Crypt_CHAP_MSv2::challengeHash() – Generates the Challenge-Hash.
Synopsis
string Crypt_CHAP_MSv2::challengeHash (
)
Description
This method generates the (SHA1) Challenge-Hash containing the authenticator and the peer challenge and the username.
Return value
string - a String containing the Challenge-Hash
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv2::challengeHash()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv2();
$cr->username = 'billy';
$cr->peerChallenge = $peerChallenge;
$cr->authChallenge = $authChallenge;
echo bin2hex($cr->challengeHash());
?>
Crypt_CHAP_MSv2::ntPasswordHashHash()
Crypt_CHAP_MSv2::ntPasswordHashHash() – Generates an MD4 Hash from the NT-Hash.
Synopsis
string Crypt_CHAP_MSv2::ntPasswordHashHash (
string $nthash
)
Description
This method generates an MD4 Hash from the given NT-Hash.
Parameter
-
string $nthash- the NT-Hash to be hashed
Return value
string - a String containing the NT-Hash
Note
This function can not be called statically.
Example
Using Crypt_CHAP_MSv2::ntPasswordHashHash()
<?php
require_once 'Crypt/CHAP.php';
$cr = new Crypt_CHAP_MSv2();
$nthash = $cr->ntPasswordHash('MyPw');
echo bin2hex($cr->ntPasswordHashHash($nthash));
?>