# Example Implementation of RIPEMD-160 in GoLang

![](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-e41a9413effc9f3a734d4d5b946e898bc0200334%252FBSVA-HashFunctions_Ch5L1_DA1.gif%3Falt%3Dmedia\&width=768\&dpr=4\&quality=100\&sign=e31153ec\&sv=2)

⚠️ **Note:** This implementation is for **learning purposes only**. It has **not been optimized or rigorously tested** and should not be used in production. Always rely on **widely accepted and verified libraries** for cryptographic functions.

***

#### Overview

Like **SHA-256**, **RIPEMD-160** is based on the **Merkle–Damgård construction**. This means the algorithm processes data in **fixed-size blocks** and chains results together.

It can be broken down into **three main phases**:

***

#### 1. Input and Processing

* **Input**: Accept a message (string, file, etc.).
* **Message Block Construction**: Break the input into **fixed-size blocks** and **pad** them so their length is congruent with the algorithm’s requirements.
* **Message Schedule Construction**: Expand each block into a sequence of **words** for use in the compression step.

***

#### 2. Compression

* **Initialization of Working Variables**: Set registers to predefined constants (based on RIPEMD’s design).
* **Temporary Word Computation**: Use **bitwise operations** and **logical functions** to mix input words.
* **Register Mutation**: Continuously update and rotate the working variables through multiple rounds.
* **Integration**: Combine mutated values with the initial constants to produce a chained state.

***

#### 3. Final Value Construction and Output

* **Concatenate the working variables** into a final **160-bit value**.
* Output the **RIPEMD-160 digest**, typically represented in **hexadecimal**.

***

✅ **Summary:**\
The GoLang implementation of RIPEMD-160 follows the same **high-level flow as SHA-256**:

1. **Input & preprocessing**
2. **Compression & mixing**
3. **Final digest output**

While SHA-256 produces a **256-bit output**, RIPEMD-160 generates a **160-bit digest**, which makes it particularly useful in Bitcoin for **address creation (HASH-160)**.

### &#x20;<a href="#example-implementation-of-ripemd-160-in-golang" id="example-implementation-of-ripemd-160-in-golang"></a>


---

# 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/walkthrough-implementation-of-ripemd-160-in-golang-overview/example-implementation-of-ripemd-160-in-golang.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.
