karask / python-bitcoin-utils

Library to interact with the Bitcoin network. Ideal for low-level learning and experimenting.
MIT License
262 stars 99 forks source link

Preimage resistance of cryptographic hash funtions #94

Closed Hugongra closed 1 month ago

Hugongra commented 2 months ago

Overview

This pull request enriches the bitcoin-utils package by introducing a comprehensive suite of cryptographic hash functions and utility scripts designed to assess and demonstrate the robustness of these functions.

Modifications

hashfunctions.py Implemented Functions: hash_sha256(b: bytes) -> bytes: Computes SHA-256 hash. hash_ripemd160(b: bytes) -> bytes: Computes RIPEMD-160 hash. hash_sha1(b: bytes) -> bytes: Computes SHA-1 hash. calculate_hash_rate(hash_function, duration_seconds=1): Measures the computation rate for any given hash function. estimate_computers_needed(hash_rate_per_computer, years_to_break): Estimates the computational resources needed for breaking a hash via a preimage attack in specified years.

security_hash_functions.py Purpose: Demonstrates the use of hash functions to calculate hash rates and estimate the number of computers required to theoretically perform a preimage attack on SHA-256 within one year.

Rationale

This update aims to provide tools for understanding and evaluating the security implications of using different cryptographic hash functions in blockchain technologies. It also serves as an educational resource for learning about the computational demands and security strength of these cryptographic functions.

Invitation for Collaboration

Feedback and suggestions on these implementations are highly encouraged, especially in areas of enhancing security features and educational clarity. Contributions for further cryptographic explorations are also welcome.

karask commented 2 months ago

Hi @Hugongra

This code is independent of the library. You create new hashing functions (even those not needed by Bitcoin) although they also exist in the library. The measurements are also outside the scope of this project.