summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-01-23 21:53:32 +0000
committerJosh Hoyt <josh@janrain.com>2006-01-23 21:53:32 +0000
commit8fb1497fa5fba3b5ac406938a439086f4404aecc (patch)
tree4ee6046acf4819ebb8dd966c2a328d6b580e59f8
parent9b5da78989fbfd2fd7de46c28733a23f54e9ec8e (diff)
downloadphp-openid-8fb1497fa5fba3b5ac406938a439086f4404aecc.zip
php-openid-8fb1497fa5fba3b5ac406938a439086f4404aecc.tar.gz
php-openid-8fb1497fa5fba3b5ac406938a439086f4404aecc.tar.bz2
[project @ Fold strxor into the DiffieHellman implementation]
-rw-r--r--Auth/OpenID/CryptUtil.php32
-rw-r--r--Auth/OpenID/DiffieHellman.php8
-rw-r--r--Tests/Auth/OpenID/CryptUtil.php42
3 files changed, 7 insertions, 75 deletions
diff --git a/Auth/OpenID/CryptUtil.php b/Auth/OpenID/CryptUtil.php
index 5dd297d..c3a1863 100644
--- a/Auth/OpenID/CryptUtil.php
+++ b/Auth/OpenID/CryptUtil.php
@@ -260,38 +260,6 @@ function Auth_OpenID_getBytes($num_bytes)
}
/**
- * Auth_OpenID_CryptUtil houses static utility functions.
- *
- * @package OpenID
- * @static
- */
-class Auth_OpenID_CryptUtil {
- /**
- * Given two strings of equal length, computes the exclusive-OR of
- * the two strings' ordinal values and returns the resulting
- * string.
- *
- * @param string $x A string
- * @param string $y A string
- * @return string $result The result of $x XOR $y
- */
- function strxor($x, $y)
- {
- if (strlen($x) != strlen($y)) {
- return null;
- }
-
- $str = "";
- for ($i = 0; $i < strlen($x); $i++) {
- $str .= chr(ord($x[$i]) ^ ord($y[$i]));
- }
-
- return $str;
- }
-
-}
-
-/**
* Exposes math library functionality.
*
* Auth_OpenID_MathWrapper is a base class that defines the interface
diff --git a/Auth/OpenID/DiffieHellman.php b/Auth/OpenID/DiffieHellman.php
index 3e12c21..4fd6fad 100644
--- a/Auth/OpenID/DiffieHellman.php
+++ b/Auth/OpenID/DiffieHellman.php
@@ -99,6 +99,12 @@ class Auth_OpenID_DiffieHellman {
$dh_shared = $this->getSharedSecret($composite);
$dh_shared_str = Auth_OpenID_longToBinary($dh_shared);
$sha1_dh_shared = Auth_OpenID_SHA1($dh_shared_str);
- return Auth_OpenID_CryptUtil::strxor($secret, $sha1_dh_shared);
+
+ $xsecret = "";
+ for ($i = 0; $i < strlen($x); $i++) {
+ $xsecret .= chr(ord($secret[$i]) ^ ord($sha1_dh_shared[$i]));
+ }
+
+ return $xsecret;
}
}
diff --git a/Tests/Auth/OpenID/CryptUtil.php b/Tests/Auth/OpenID/CryptUtil.php
index 3f3ef17..af05cea 100644
--- a/Tests/Auth/OpenID/CryptUtil.php
+++ b/Tests/Auth/OpenID/CryptUtil.php
@@ -69,48 +69,6 @@ class Tests_Auth_OpenID_ByteOps extends PHPUnit_TestCase {
$this->assertEquals(strlen($t), 32);
$this->assertFalse($s == $t);
}
-
- function test_strxor()
- {
- $NUL = "\x00";
-
- $cases = array(
- array($NUL, $NUL, $NUL),
- array("\x01", $NUL, "\x01"),
- array("a", "a", $NUL),
- array("a", $NUL, "a"),
- array("abc", str_repeat($NUL, 3), "abc"),
- array(str_repeat("x", 10),
- str_repeat($NUL, 10),
- str_repeat("x", 10)),
- array("\x01", "\x02", "\x03"),
- array("\xf0", "\x0f", "\xff"),
- array("\xff", "\x0f", "\xf0"),
- );
-
- while (list($index, $values) = each($cases)) {
- list($aa, $bb, $expected) = $values;
- $actual = Auth_OpenID_CryptUtil::strxor($aa, $bb);
- $this->assertEquals($actual, $expected);
- }
-
- $exc_cases = array(
- array('', 'a'),
- array('foo', 'ba'),
- array(str_repeat($NUL, 3),
- str_repeat($NUL, 4)),
- array(implode('', array_map('chr',
- range(0, 255))),
- implode('', array_map('chr',
- range(0, 127))))
- );
-
- while(list($index, $values) = each($exc_cases)) {
- list($aa, $bb) = $values;
- $unexpected = Auth_OpenID_CryptUtil::strxor($aa, $bb);
- $this->assertNull($unexpected);
- }
- }
}
class Tests_Auth_OpenID_BinLongConvertRnd extends PHPUnit_TestCase {