Subversion Repositories php_clientchallenge

Rev

Rev 4 | Rev 6 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
Line 23... Line 23...
23
 
23
 
24
        private static function sha3_512($message, $raw_output=false) {
24
        private static function sha3_512($message, $raw_output=false) {
25
                if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
25
                if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
26
                        return hash('sha3-512', $message, $raw_output);
26
                        return hash('sha3-512', $message, $raw_output);
27
                } else {
27
                } else {
28
                        return \bb\Sha3\Sha3::hash($message, 512, $raw_output);
28
                        return \bb\Sha3\Sha3::hash($message, 512, $raw_output); /** @phpstan-ignore-line */
29
                }
29
                }
30
        }
30
        }
31
 
31
 
32
        private static function sha3_512_hmac($message, $key, $raw_output=false) {
32
        private static function sha3_512_hmac($message, $key, $raw_output=false) {
33
                // RFC 2104 HMAC
33
                // RFC 2104 HMAC
Line 35... Line 35...
35
                        return hash_hmac('sha3-512', $message, $key, $raw_output);
35
                        return hash_hmac('sha3-512', $message, $key, $raw_output);
36
                } else {
36
                } else {
37
                        $blocksize = 576; // block size of sha-512!
37
                        $blocksize = 576; // block size of sha-512!
38
 
38
 
39
                        if (strlen($key) > ($blocksize/8)) {
39
                        if (strlen($key) > ($blocksize/8)) {
40
                                $k_ = sha3_512($key,true);
40
                                $k_ = self::sha3_512($key,true);
41
                        } else {
41
                        } else {
42
                                $k_ = $key;
42
                                $k_ = $key;
43
                        }
43
                        }
44
 
44
 
45
                        $k_opad = str_repeat(chr(0x5C),($blocksize/8));
45
                        $k_opad = str_repeat(chr(0x5C),($blocksize/8));
Line 47... Line 47...
47
                        for ($i=0; $i<strlen($k_); $i++) {
47
                        for ($i=0; $i<strlen($k_); $i++) {
48
                                $k_opad[$i] = $k_opad[$i] ^ $k_[$i];
48
                                $k_opad[$i] = $k_opad[$i] ^ $k_[$i];
49
                                $k_ipad[$i] = $k_ipad[$i] ^ $k_[$i];
49
                                $k_ipad[$i] = $k_ipad[$i] ^ $k_[$i];
50
                        }
50
                        }
51
 
51
 
52
                        return sha3_512($k_opad . sha3_512($k_ipad . $message, true));
52
                        return self::sha3_512($k_opad . self::sha3_512($k_ipad . $message, true));
53
                }
53
                }
54
        }
54
        }
55
 
55
 
56
        public static function checkValidation($max_time=10, $server_secret) {
56
        public static function checkValidation($max_time=10, $server_secret) {
57
 
57