Skip to content

ECDSA signing uses incorrect hash algorithm (Keccak-256 vs SHA-256 mismatch) #2198

Description

@mohityadav8

Description

Problem

The ECDSA signing implementation hashes data using Keccak-256 but passes the result to the cryptography library using Prehashed(hashes.SHA256()).

This creates a mismatch between the actual hash algorithm used and the one declared during signing.

Code Reference

private_key.py:286–287

data_hash = keccak256(data)
signature_der = self._private_key.sign(
    data_hash,
    ec.ECDSA(asym_utils.Prehashed(hashes.SHA256()))
)

### Steps to reproduce
  1. Call the sign() function with input data
  2. Observe that data is hashed using keccak256
  3. Observe that Prehashed(hashes.SHA256()) is used during signing
  4. Verify mismatch between actual hash and declared hash algorithm

Additional context

This issue can lead to subtle cryptographic bugs and signature verification failures, especially in systems relying on strict hash algorithm consistency.

Hedera network

No response

Version

v0.2.5

Operating system

platform-independent

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions