protected function _verifyPadding(array $P, string $A): int
    {
        // extract mli
        $mli = substr($A, -4);
        $len = unpack("N1", $mli)[1];
        // check under and overflow
        $n = count($P);
        if (8 * ($n - 1) >= $len || $len > 8 * $n) {
            throw new \UnexpectedValueException("Invalid message length.");
        }
        // if key is padded
        $b = 8 - ($len % 8);
        if ($b < 8) {
            // last block (note that the first index in P is 1)
            $Pn = $P[$n];
            // check that padding consists of zeroes
            if (substr($Pn, -$b) != str_repeat("\0", $b)) {
                throw new \UnexpectedValueException("Invalid padding.");
            }
        }
        return $len;
    }