forked from olcxjas-softworks/LarpixClient
56 lines
No EOL
2.7 KiB
TypeScript
56 lines
No EOL
2.7 KiB
TypeScript
import { type CHash, type KDFInput, type TArg, type TRet } from './utils.ts';
|
|
/**
|
|
* PBKDF2 options:
|
|
* * c: iterations, should probably be higher than 100_000
|
|
* * dkLen: desired length of derived key in bytes, must be `>= 1` per RFC 8018 §5.2
|
|
* * asyncTick: max time in ms for which async function can block execution
|
|
*/
|
|
export type Pbkdf2Opt = {
|
|
/** Iteration count. Higher values increase CPU cost. */
|
|
c: number;
|
|
/** Desired derived key length in bytes, must be `>= 1` per RFC 8018 §5.2. */
|
|
dkLen?: number;
|
|
/** Max scheduler block time in milliseconds for the async variant. */
|
|
asyncTick?: number;
|
|
};
|
|
/**
|
|
* PBKDF2-HMAC: RFC 8018 key derivation function.
|
|
* @param hash - hash function that would be used e.g. sha256
|
|
* @param password - password from which a derived key is generated;
|
|
* JS string inputs are UTF-8 encoded first
|
|
* @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
|
|
* @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
|
|
* must be `>= 1` per RFC 8018 §5.2. See {@link Pbkdf2Opt}.
|
|
* @returns Derived key bytes.
|
|
* @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
|
|
* @example
|
|
* PBKDF2-HMAC: RFC 2898 key derivation function.
|
|
* ```ts
|
|
* import { pbkdf2 } from '@noble/hashes/pbkdf2.js';
|
|
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
* const key = pbkdf2(sha256, 'password', 'salt', { dkLen: 32, c: Math.pow(2, 18) });
|
|
* ```
|
|
*/
|
|
export declare function pbkdf2(hash: TArg<CHash>, password: TArg<KDFInput>, salt: TArg<KDFInput>, opts: TArg<Pbkdf2Opt>): TRet<Uint8Array>;
|
|
/**
|
|
* PBKDF2-HMAC: RFC 8018 key derivation function. Async version.
|
|
* @param hash - hash function that would be used e.g. sha256
|
|
* @param password - password from which a derived key is generated;
|
|
* JS string inputs are UTF-8 encoded first
|
|
* @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
|
|
* @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
|
|
* must be `>= 1` per RFC 8018 §5.2. `asyncTick` is only a local
|
|
* scheduler-yield knob for this JS wrapper, not part of RFC 8018.
|
|
* See {@link Pbkdf2Opt}.
|
|
* @returns Promise resolving to derived key bytes.
|
|
* @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
|
|
* @example
|
|
* PBKDF2-HMAC: RFC 2898 key derivation function.
|
|
* ```ts
|
|
* import { pbkdf2Async } from '@noble/hashes/pbkdf2.js';
|
|
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
* const key = await pbkdf2Async(sha256, 'password', 'salt', { dkLen: 32, c: 500_000 });
|
|
* ```
|
|
*/
|
|
export declare function pbkdf2Async(hash: TArg<CHash>, password: TArg<KDFInput>, salt: TArg<KDFInput>, opts: TArg<Pbkdf2Opt>): Promise<TRet<Uint8Array>>;
|
|
//# sourceMappingURL=pbkdf2.d.ts.map
|