<?php

declare(strict_types=1);

namespace PhpWA\Crypto\Signal;

use InvalidArgumentException;
use PhpWA\Crypto\CryptoPrimitives;

final class SignalKdf
{
     
    public static function derive(string $input, string $salt, string $info, int $chunks): array
    {
        if ($chunks < 1 || $chunks > 8) { throw new InvalidArgumentException('Signal KDF chunk count is invalid.'); }
        $output = CryptoPrimitives::hkdf($input, $chunks * 32, $salt, $info);
        $result = [];
        for ($index = 0; $index < $chunks; $index++) { $result[] = substr($output, $index * 32, 32); }
        return $result;
    }

    private function __construct() {}
}
