CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-crypto-browserify

Browser-compatible implementation of Node.js crypto module providing cryptographic operations in web environments.

Overall
score

100%

Overview
Eval results
Files

task.mdevals/scenario-9/

Message Authentication System

Build a message authentication system that verifies the integrity and authenticity of messages using cryptographic techniques.

Requirements

Create a module that provides functionality to:

  1. Generate authentication tags for messages using a secret key
  2. Verify message authenticity by comparing authentication tags
  3. Support multiple hash algorithms for tag generation
  4. Handle incremental message processing for large messages that arrive in chunks

Functional Requirements

  • Accept messages as strings or binary data
  • Accept secret keys for authentication
  • Support at least SHA-256 and SHA-512 hash algorithms
  • Allow messages to be processed in multiple chunks before generating the final tag
  • Return authentication tags in hexadecimal format
  • Provide a verification function that returns true/false based on tag comparison

Test Cases

  • Generating an authentication tag for the message "Hello, World!" with a secret key "my-secret" using SHA-256 produces a consistent tag @test
  • The same message and key produce the same tag when verified @test
  • Processing a message in multiple chunks produces the same tag as processing it all at once @test
  • Using SHA-512 algorithm produces a different tag than SHA-256 for the same message @test

Implementation

@generates

API

/**
 * Generates an authentication tag for a message.
 *
 * @param {string} algorithm - The hash algorithm to use (e.g., 'sha256', 'sha512')
 * @param {string|Buffer} key - The secret key for authentication
 * @param {string|Buffer} message - The message to authenticate
 * @returns {string} The authentication tag in hexadecimal format
 */
function generateTag(algorithm, key, message) {
  // IMPLEMENTATION HERE
}

/**
 * Verifies a message's authentication tag.
 *
 * @param {string} algorithm - The hash algorithm used
 * @param {string|Buffer} key - The secret key for authentication
 * @param {string|Buffer} message - The message to verify
 * @param {string} expectedTag - The expected authentication tag in hexadecimal
 * @returns {boolean} True if the tag matches, false otherwise
 */
function verifyTag(algorithm, key, message, expectedTag) {
  // IMPLEMENTATION HERE
}

/**
 * Creates an incremental message authenticator for processing data in chunks.
 *
 * @param {string} algorithm - The hash algorithm to use
 * @param {string|Buffer} key - The secret key for authentication
 * @returns {Object} An object with update(chunk) and finalize() methods
 */
function createAuthenticator(algorithm, key) {
  // IMPLEMENTATION HERE
  // Returns object with:
  // - update(chunk): adds a chunk to the message
  // - finalize(): returns the final authentication tag in hexadecimal
}

module.exports = {
  generateTag,
  verifyTag,
  createAuthenticator
};

Dependencies { .dependencies }

crypto-browserify { .dependency }

Provides cryptographic primitives for message authentication.

Install with Tessl CLI

npx tessl i tessl/npm-crypto-browserify

tile.json