Skip to main content
Glama

compareHashes

Compare two hashes in constant time to ensure secure and consistent verification without timing vulnerabilities. Ideal for cryptographic and data integrity checks.

Instructions

Compare two hashes in constant time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hash1YesFirst hash to compare
hash2YesSecond hash to compare

Implementation Reference

  • Executes constant-time hash comparison using Buffer.from and Buffer.compare to prevent timing attacks, returning match result and lengths.
    handler: async ({ hash1, hash2 }: { hash1: string; hash2: string }) => { try { // Convert strings to buffers for constant-time comparison const buf1 = Buffer.from(hash1); const buf2 = Buffer.from(hash2); // Ensure same length to prevent timing attacks if (buf1.length !== buf2.length) { return { content: [{ type: 'text', text: JSON.stringify({ match: false, reason: 'Length mismatch' }, null, 2) }] }; } // Constant-time comparison const match = Buffer.compare(buf1, buf2) === 0; return { content: [{ type: 'text', text: JSON.stringify({ match, hash1Length: buf1.length, hash2Length: buf2.length }, null, 2) }] }; } catch (error) { throw new Error(`Hash comparison failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
  • Input schema defining two required string properties: hash1 and hash2.
    inputSchema: { type: 'object', properties: { hash1: { type: 'string', description: 'First hash to compare' }, hash2: { type: 'string', description: 'Second hash to compare' } }, required: ['hash1', 'hash2'] },
  • src/index.ts:27-33 (registration)
    Registers compareHashes by spreading securityTools into allTools, used for tool listing (lines 112-116) and execution lookup (line 130).
    const allTools: ToolKit = { ...encodingTools, ...geoTools, ...generatorTools, ...dateTimeTools, ...securityTools };

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MissionSquad/mcp-helper-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server