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
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions 'constant time' comparison (a key behavioral trait for security), it doesn't describe other important aspects: what happens if inputs aren't valid hashes, whether there are length/format constraints, error conditions, or what the return value indicates (e.g., boolean equality result). For a tool with zero annotation coverage, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise (5 words) and front-loaded with the core functionality. Every word earns its place: 'Compare' (action), 'two hashes' (resource), 'in constant time' (key constraint). There's no wasted verbiage or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (2 parameters, no output schema, no annotations), the description is incomplete. While it mentions the constant-time behavior, it doesn't explain the return value (presumably a boolean indicating equality), error handling, or practical use cases. For a comparison tool that might be used in security contexts, more context about why constant-time matters would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with both parameters ('hash1', 'hash2') clearly documented in the schema. The description doesn't add any parameter-specific information beyond what the schema provides. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description, which applies here.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Compare two hashes in constant time'. It specifies the verb ('compare') and resource ('two hashes'), and adds the important constraint 'in constant time' which distinguishes it from naive string comparison. However, it doesn't explicitly differentiate from sibling tools like 'hashData', which might be used for generating hashes rather than comparing them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'hashData' (for generating hashes) or explain scenarios where constant-time comparison is necessary (e.g., security-sensitive contexts to prevent timing attacks). There's no indication of prerequisites, exclusions, or recommended contexts for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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