CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-scrypt-js

The scrypt password-based key derivation function with sync and cancellable async.

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-8/

Password-Based Key Derivation Service

A utility module that derives cryptographic keys from passwords using a computationally expensive key derivation function. The module should accept a password and salt, perform synchronous key derivation with specified parameters, and return the derived key as a byte array.

Capabilities

Derives keys from password and salt

  • Given a password array [112, 97, 115, 115] (representing "pass"), salt array [115, 97, 108, 116] (representing "salt"), N=1024, r=8, p=1, and dkLen=32, it returns a 32-byte derived key as a Uint8Array @test
  • The derived key should be deterministic - deriving with the same inputs twice produces identical output @test

Handles different parameter configurations

  • Using a higher N value (16384 instead of 1024) with the same password and salt produces a different derived key @test
  • Deriving a 64-byte key (dkLen=64) produces output of the correct length @test

Validates input parameters

  • Attempting to derive a key with N=1000 (not a power of 2) throws an error @test
  • Attempting to derive a key with an empty password array throws an error @test

Implementation

@generates

API

/**
 * Derives a cryptographic key from a password using scrypt algorithm (synchronous).
 *
 * @param {Array<number>|Uint8Array} password - The password as an array of bytes (0-255)
 * @param {Array<number>|Uint8Array} salt - The salt as an array of bytes (0-255)
 * @param {number} N - CPU/memory cost parameter (must be power of 2)
 * @param {number} r - Block size parameter
 * @param {number} p - Parallelization parameter
 * @param {number} dkLen - Desired length of derived key in bytes
 * @returns {Uint8Array} The derived key
 * @throws {Error} If parameters are invalid
 */
function deriveKey(password, salt, N, r, p, dkLen) {
  // IMPLEMENTATION HERE
}

module.exports = { deriveKey };

Dependencies { .dependencies }

scrypt-js { .dependency }

Provides password-based key derivation functionality.

Install with Tessl CLI

npx tessl i tessl/npm-scrypt-js

tile.json