# The Hash Functions Found in BSV

<img src="https://hub.bsvblockchain.org/~gitbook/image?url=https%3A%2F%2F2147185133-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FWtK4ab0ntyPZBmGoKq4t%252Fuploads%252Fgit-blob-055fb62103fb8c9757cf427a939578a226471ae8%252FBSVA-HashFunctions_Ch1L4_DA1.gif%3Falt%3Dmedia&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=b41f35d1&#x26;sv=2" alt="" height="900" width="1200">

#### Merkle–Damgård Construction

A fundamental challenge in building a hash function is that it must handle **inputs of arbitrary length** while producing a **fixed-length output**. This creates two issues:

* It’s hard to achieve **second preimage resistance** when input lengths vary.
* A **collision-resistant compression function** requires fixed-length inputs longer than its output.

The solution, discovered independently by **Ralph Merkle** and **Ivan Damgård** in 1979, is to use a **preprocessing step** that:

* **Pads the input** to a fixed length (e.g., 512 or 1024 bits).
* Appends the **length of the input itself** (*Merkle–Damgård strengthening*).

The padded input is then passed through a **compression function** that operates in rounds, linked with **chaining variables**. Finally, the output is concatenated and presented — usually in **hexadecimal format**.

👉 **Key takeaway:** The **Merkle–Damgård method** ensures that if the compression function is collision resistant, the entire hash function is too.

### MD4 and MD5

The first widely adopted Merkle–Damgård hash functions were **MD4** and **MD5**, created by **Ron Rivest** in the early 1990s:

* **MD4** was published in 1992 but quickly considered insecure.
* **MD5** followed shortly after and gained broad adoption, despite early warnings of weakness.
* In 1996, **Hans Dobbertin** demonstrated a collision in MD5’s compression function.
* By 2004, **Xiaoyun Wang and her team** developed an attack that could find collisions in about an hour, marking the end of MD5’s security.
* In 2008, the **CMU Software Engineering Institute** declared MD5 **“cryptographically broken and unsuitable for further use.”**

Even so, **MD4 and MD5 laid the foundation** for newer, stronger hash functions, including those used in Bitcoin.

#### BSV's Hash Functions

In the BSV blockchain, two main hash functions are used:

* **SHA-256**
* **RIPEMD-160**

They are often applied in **double-hash forms**:

* **HASH-256 = SHA-256(SHA-256)** → Used for blocks and transactions.
* **HASH-160 = RIPEMD-160(SHA-256)** → Used for address creation.

| **Hash Function**     | **Output Length** | **Description**                                                               | **Example Application in BSV**                 |
| --------------------- | ----------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- |
| SHA-256               | 32 Bytes          | Generates unique 256-bit value from input string                              | 1. Proof-of-work algorithm 2. Address Creation |
| RIPEMD-160            | 20 Bytes          | Generates unique 160-bit value from an input string                           | Address creation                               |
| HASH-256              | 32 Bytes          | SHA256 hash of a SHA256 hash                                                  | 1. Blocks 2. Transactions                      |
| HASH-160              | 20 Bytes          | RIPEMD160 hash of a SHA256 hash                                               | Address creation                               |
| SHA512                | 64 Bytes          | Generates unique 512-bit value from input string                              | Wallet encryption (AES)                        |
| SHA256HMAC/SHA512HMAC | 32 Bytes          | HMAC Prevents length extension attacks and can be used with any hash function | Address Creation                               |

&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hub.bsvblockchain.org/higher-learning/bsv-academy/bitcoin-primitives-hash-functions/what-are-hash-functions/the-hash-functions-found-in-bsv.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
