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-7/

Password Key Derivation Service

Build a password key derivation service that generates secure cryptographic keys from user passwords. The service should provide different security levels based on configurable parameters.

Requirements

Security Levels

Implement three security level presets:

  1. Low: Fast key derivation suitable for low-security scenarios
  2. Medium: Balanced security and performance for standard applications
  3. High: Maximum security with higher computational cost

Key Derivation Function

Implement a function that:

  • Accepts a password string
  • Accepts a salt (at least 16 bytes recommended)
  • Accepts a security level (low, medium, or high)
  • Accepts a desired key length in bytes
  • Returns the derived key

The function should use the following parameter configurations for each security level:

  • Low: N=1024, r=8, p=1
  • Medium: N=16384, r=8, p=1
  • High: N=32768, r=8, p=2

Input/Output Format

  • Password and salt should be accepted as byte arrays or compatible formats
  • The output key should be returned as a byte array
  • All numeric parameters must be properly validated as integers

Dependencies { .dependencies }

scrypt-js { .dependency }

Provides password-based key derivation functionality.

Test Cases

Test 1: Low Security Key Derivation { .test-case @test }

Input:

  • Password: [112, 97, 115, 115, 119, 111, 114, 100] (UTF-8 bytes for "password")
  • Salt: [115, 97, 108, 116] (UTF-8 bytes for "salt")
  • Security level: low
  • Key length: 32 bytes

Expected Output: The function should successfully return a 32-byte key derived using N=1024, r=8, p=1.

File: derive.test.js

Test 2: Medium Security Key Derivation { .test-case @test }

Input:

  • Password: [116, 101, 115, 116, 49, 50, 51] (UTF-8 bytes for "test123")
  • Salt: [115, 97, 108, 116, 121] (UTF-8 bytes for "salty")
  • Security level: medium
  • Key length: 64 bytes

Expected Output: The function should successfully return a 64-byte key derived using N=16384, r=8, p=1.

File: derive.test.js

Test 3: High Security Key Derivation { .test-case @test }

Input:

  • Password: [115, 101, 99, 117, 114, 101] (UTF-8 bytes for "secure")
  • Salt: [114, 97, 110, 100, 111, 109, 115, 97, 108, 116] (UTF-8 bytes for "randomsalt")
  • Security level: high
  • Key length: 32 bytes

Expected Output: The function should successfully return a 32-byte key derived using N=32768, r=8, p=2.

File: derive.test.js

Implementation Notes

  • Ensure all parameters are properly configured for each security level
  • The N parameter must be a power of 2
  • All numeric parameters must be integers
  • The implementation should handle both synchronous and asynchronous key derivation appropriately

Install with Tessl CLI

npx tessl i tessl/npm-scrypt-js

tile.json