Code Duplication    Length = 14-15 lines in 2 locations

api/functions.php 1 location

@@ 2165-2179 (lines=15) @@
2162
    }
2163
}
2164
2165
function teampass_pbkdf2_hash($p, $s, $c, $kl, $st = 0, $a = 'sha256')
2166
{
2167
    $kb = $st + $kl;
2168
    $dk = '';
2169
2170
    for ($block = 1; $block <= $kb; $block++) {
2171
        $ib = $h = hash_hmac($a, $s.pack('N', $block), $p, true);
2172
        for ($i = 1; $i < $c; $i++) {
2173
            $ib ^= ($h = hash_hmac($a, $h, $p, true));
2174
        }
2175
        $dk .= $ib;
2176
    }
2177
2178
    return substr($dk, $st, $kl);
2179
}
2180

sources/main.functions.php 1 location

@@ 52-65 (lines=14) @@
49
}
50
51
//generate pbkdf2 compliant hash
52
function strHashPbkdf2($p, $s, $c, $kl, $a = 'sha256', $st = 0)
53
{
54
    $kb = $st + $kl; // Key blocks to compute
55
    $dk = ''; // Derived key
56
57
    for ($block = 1; $block <= $kb; $block++) { // Create key
58
        $ib = $h = hash_hmac($a, $s.pack('N', $block), $p, true); // Initial hash for this block
59
        for ($i = 1; $i < $c; $i++) { // Perform block iterations
60
            $ib ^= ($h = hash_hmac($a, $h, $p, true)); // XOR each iterate
61
        }
62
        $dk .= $ib; // Append iterated block
63
    }
64
    return substr($dk, $st, $kl); // Return derived key of correct length
65
}
66
67
/**
68
 * stringUtf8Decode()