ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
DiffieHellman.php
Go to the documentation of this file.
1<?php
2
17require_once 'Auth/OpenID.php';
18require_once 'Auth/OpenID/BigMath.php';
19
21{
22 return '155172898181473697471232257763715539915724801'.
23 '966915404479707795314057629378541917580651227423'.
24 '698188993727816152646631438561595825688188889951'.
25 '272158842675419950341258706556549803580104870537'.
26 '681476726513255747040765857479291291572334510643'.
27 '245094715007229621094194349783925984760375594985'.
28 '848253359305585439638443';
29}
30
32{
33 return '2';
34}
35
44
45 var $mod;
46 var $gen;
48 var $lib = null;
49
50 function Auth_OpenID_DiffieHellman($mod = null, $gen = null,
51 $private = null, $lib = null)
52 {
53 if ($lib === null) {
54 $this->lib = Auth_OpenID_getMathLib();
55 } else {
56 $this->lib = $lib;
57 }
58
59 if ($mod === null) {
60 $this->mod = $this->lib->init(Auth_OpenID_getDefaultMod());
61 } else {
62 $this->mod = $mod;
63 }
64
65 if ($gen === null) {
66 $this->gen = $this->lib->init(Auth_OpenID_getDefaultGen());
67 } else {
68 $this->gen = $gen;
69 }
70
71 if ($private === null) {
72 $r = $this->lib->rand($this->mod);
73 $this->private = $this->lib->add($r, 1);
74 } else {
75 $this->private = $private;
76 }
77
78 $this->public = $this->lib->powmod($this->gen, $this->private,
79 $this->mod);
80 }
81
82 function getSharedSecret($composite)
83 {
84 return $this->lib->powmod($composite, $this->private, $this->mod);
85 }
86
87 function getPublicKey()
88 {
89 return $this->public;
90 }
91
93 {
94 return ($this->mod == Auth_OpenID_getDefaultMod() &&
95 $this->gen == Auth_OpenID_getDefaultGen());
96 }
97
98 function xorSecret($composite, $secret, $hash_func)
99 {
100 $dh_shared = $this->getSharedSecret($composite);
101 $dh_shared_str = $this->lib->longToBinary($dh_shared);
102 $hash_dh_shared = $hash_func($dh_shared_str);
103
104 $xsecret = "";
105 for ($i = 0; $i < Auth_OpenID::bytes($secret); $i++) {
106 $xsecret .= chr(ord($secret[$i]) ^ ord($hash_dh_shared[$i]));
107 }
108
109 return $xsecret;
110 }
111}
112
113
Auth_OpenID_getMathLib()
Definition: BigMath.php:400
Auth_OpenID_getDefaultGen()
Auth_OpenID_getDefaultMod()
xorSecret($composite, $secret, $hash_func)
Auth_OpenID_DiffieHellman($mod=null, $gen=null, $private=null, $lib=null)
static bytes($str)
Count the number of bytes in a string independently of multibyte support conditions.
Definition: OpenID.php:462
$r
Definition: example_031.php:79