/** * Generic KDF methods. Common logic for all targets. * Doesn't contain WASM-specific/JS-specific code. * @module */ import type { HashInstance } from './hashes-abstract.ts'; import type { ARGON2, SCRYPT } from './targets/types.ts'; import { type KDFInput, type TArg, type TRet } from './utils.ts'; type KDFOpts = { dkLen?: number; asyncTick?: number; maxmem?: number; onProgress?: (progress: number) => void; nextTick?: () => Promise; }; /** Generic installed KDF surface with sync/async entrypoints and backend metadata. */ export type KDF = ((password: TArg, salt: TArg, opts: TArg) => TRet) & { async: (password: TArg, salt: TArg, opts: TArg) => Promise>; getPlatform: () => string | undefined; getDefinition: () => TRet; }; type KDFRun = (password: TArg, salt: TArg, opts: TArg) => TRet; type KDFRunAsync = (password: TArg, salt: TArg, opts: TArg) => Promise>; /** * Wrap a noble-hashes KDF as an awasm KDF implementation. * @param definition - definition object exposed through `getDefinition()`. * @param run - synchronous noble KDF function. * @param runAsync - asynchronous noble KDF function. * @param platform - backend platform label. * @returns Installed noble-backed KDF surface. */ export declare function mkKDFNoble(definition: TArg, run: TArg>, runAsync: TArg>, platform?: string): TRet>; type InstallOpts = { onlyMissing?: boolean; }; type Stub = { install: (impl: KDF, opts?: InstallOpts) => void; }; /** * Create an installable KDF stub for targets that attach the real implementation later. * @param _def_ - definition factory that installed implementations must report via * `getDefinition()`. * @returns Frozen stub KDF that forwards to the installed implementation once available. */ export declare function mkKDFStub(_def_: TArg<(mod: any, deps: any, platform: string) => KDF>): TRet & Stub>; /** * Argon2 options. * * t: time cost, m: mem cost in kb, p: parallelization. * * key: optional key. personalization: arbitrary extra data. * * dkLen: desired number of output bytes. */ export type ArgonOpts = KDFOpts & { t: number; m: number; p: number; version?: number; key?: KDFInput; personalization?: KDFInput; }; /** * Local Argon2 backend block cap used to bound the resident working matrix per batch. * Kept as a pure exported constant so unrelated bundles can tree-shake it away. */ export declare const ARGON_MAX_BLOCKS: number; /** RFC 9106 sync-points constant `SL = 4`, fixed by the Argon2 design. */ export declare const ARGON2_SYNC_POINTS: number; /** argon2d GPU-resistant version. */ /** * Build the argon2d KDF for a concrete backend. * @param modFn - backend module factory. * @param deps - required hash dependencies. * @param platform - backend platform label. * @param definition - definition object exposed through `getDefinition()`. * @returns Installed argon2d KDF surface. */ export declare const mkArgon2d: (modFn: TArg<() => ARGON2>, deps: TArg<{ blake2b: HashInstance; }>, platform: string, definition?: any) => TRet>; /** argon2i side-channel-resistant version. */ /** * Build the argon2i KDF for a concrete backend. * @param modFn - backend module factory. * @param deps - required hash dependencies. * @param platform - backend platform label. * @param definition - definition object exposed through `getDefinition()`. * @returns Installed argon2i KDF surface. */ export declare const mkArgon2i: (modFn: TArg<() => ARGON2>, deps: TArg<{ blake2b: HashInstance; }>, platform: string, definition?: any) => TRet>; /** argon2id combining i+d, the most popular version from RFC 9106 */ /** * Build the argon2id KDF for a concrete backend. * @param modFn - backend module factory. * @param deps - required hash dependencies. * @param platform - backend platform label. * @param definition - definition object exposed through `getDefinition()`. * @returns Installed argon2id KDF surface. */ export declare const mkArgon2id: (modFn: TArg<() => ARGON2>, deps: TArg<{ blake2b: HashInstance; }>, platform: string, definition?: any) => TRet>; /** * PBKDF2 options: * * c: iterations, should probably be higher than 100_000 * * dkLen: desired length of derived key in bytes * * asyncTick: max time in ms for which async function can block execution */ export type Pbkdf2Opts = KDFOpts & { c: number; }; /** * Build a PBKDF2-HMAC KDF around the provided hash function. * @param hash - hash function used as the PBKDF2 PRF. * @returns Installed PBKDF2 surface with sync and async entrypoints. */ export declare function pbkdf2(hash: TArg>): TRet>; /** * Internal scrypt lane batch cap in 64-byte chunks. * Controls resident workspace size without changing RFC-visible output. */ export declare const SCRYPT_BATCH: number; /** Scrypt options: cost factor `N`, block size `r`, and parallelization `p`. */ export type ScryptOpts = KDFOpts & { N: number; r: number; p: number; }; /** * Build the scrypt KDF for a concrete backend. * @param modFn - backend module factory. * @param deps - required hash dependencies. * @param platform - backend platform label. * @param definition - definition object exposed through `getDefinition()`. * @returns Installed scrypt KDF surface. */ export declare function mkScrypt(modFn: TArg<() => SCRYPT>, deps: TArg<{ sha256: HashInstance; }>, platform: string, definition?: any): TRet>; export {}; //# sourceMappingURL=kdf.d.ts.map