> For the complete documentation index, see [llms.txt](https://hub.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](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). Agents can also search and read this documentation through its [MCP server](https://hub.bsvblockchain.org/~gitbook/mcp).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
