> 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/ripemd-160-input-and-processing.md). Agents can also search and read this documentation through its [MCP server](https://hub.bsvblockchain.org/~gitbook/mcp).

# RIPEMD-160 Input and Processing

{% embed url="<https://youtu.be/6wpJenWEXfA>" %}

#### The Three Steps

Input and processing can be divided into three sub-sections:

1. **Input**
2. **Message Block Construction**
3. **Message Schedule Construction**

***

#### 1. Input

Our RIPEMD-160 implementation must first take an **input value**. In Go, this is easy: we can cast a string into an **array of bytes** (8-bit units).

Example:

```
message := []byte("abc") 
fmt.Printf("Output: %b", message)
// Output: [1100001 1100010 1100011]
```

&#x20;

👉 `"abc"` is now represented in binary form.

***

#### 2. Message Block Construction

Next, we construct **message blocks** from the input.

* RIPEMD-160 requires blocks of **512 bits**.
* Messages must be padded to **448 bits**, leaving **64 bits** for the message length.

**Padding process:**

1. Append a **single 1 bit**.
2. Add **zero bits** until the message length = 448 mod 512.
3. Append the **message length** as a 64-bit value.

Example Go functions:

```
func AddZeroPaddingBits(messageBlock []byte, message []byte) []byte {
    zeros := make([]byte, HowMuchPadding(message))
    zeros[0] += 0x80 // separator bit
    return append(messageBlock, zeros...)
}

func AddMessageLength(messageBlock []byte, message []byte) []byte {
    messageLength := len(message) << 3
    messageLengthInBits := make([]byte, 8)
    binary.LittleEndian.PutUint64(messageLengthInBits, uint64(messageLength))
    return append(messageBlock, messageLengthInBits...)
}
```

&#x20;

👉 Note: Unlike SHA-256, RIPEMD-160 appends the message length using **Little-Endian** format (least significant byte on the right).

Example with `"abc"`:

```
SHA-256 style:  [0 0 0 0 0 0 0 11000]
RIPEMD-160 style: [11000 0 0 0 0 0 0 0]
```

&#x20;

This difference is crucial to the algorithm’s design.

***

#### 3. Message Schedule Construction

Now that we have padded message blocks, we build the **message schedule**.

* RIPEMD-160 uses **16 words**, each 32 bits long.
* Each word is created by grouping 4 bytes of the message block, read in **Little-Endian** order.

Example Go function:

```
func BuildMessageSchedule(messageBlock []byte) [16]uint32 {
    var schedule [16]uint32
    i := 0
    for j := 0; j < 16; j++ {
        schedule[j] = binary.LittleEndian.Uint32(messageBlock[i:])
        i += 4
    }
    return schedule
}
```

&#x20;

Example output for `"abc"`:

```
fmt.Printf("Output: %x\n", schedule)
// Output: [80636261 0 0 0 0 0 0 0 0 0 0 0 0 0 18 0]
```

&#x20;

✅ **Summary:**

* **Input:** String → bytes.
* **Message Block Construction:** Pad to 448 bits, append message length (Little-Endian).
* **Message Schedule Construction:** Build 16 × 32-bit words from the block.

This prepares the message for the **compression function**, where the real cryptographic mixing begins.


---

# 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/ripemd-160-input-and-processing.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.
