Subversion Repositories oidplus

Rev

Rev 224 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
221 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2020 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
277 daniel-mar 20
class OIDplusAuthPluginSha3SaltedBase64 extends OIDplusAuthPlugin {
221 daniel-mar 21
 
22
        public function verify($authKey, $salt, $check_password) {
23
                @list($s_authmethod, $s_authkey) = explode('#', $authKey, 2);
24
 
25
                if ($s_authmethod == 'A2') {
26
                        // Default OIDplus 2.0 behavior
27
                        // A2#X with X being sha3{base64}(salt+password)
28
                        $calc_authkey = base64_encode(version_compare(PHP_VERSION, '7.1.0') >= 0 ? hash('sha3-512', $salt.$check_password, true) : bb\Sha3\Sha3::hash($salt.$check_password, 512, true));
29
                } else {
30
                        // Invalid auth code
31
                        return false;
32
                }
33
 
34
                return hash_equals($calc_authkey, $s_authkey);
35
        }
277 daniel-mar 36
 
221 daniel-mar 37
}