> 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/double-hashing-and-bsvs-security/what-are-hmacs.md).

# What are HMACs?

### Introduction to HMACs

An **HMAC** (keyed-hash message authentication code) is a type of **message authentication code (MAC)** that uses:

* A **hash function** (e.g., SHA-256), and
* A **secret key** shared between two parties.

The purpose of an HMAC is to ensure that a message is both **authentic** (it came from the expected sender) and **intact** (it hasn’t been tampered with).

👉 **In simpler terms:** An HMAC is like a digital stamp that proves “this message really came from me, and no one altered it.”

***

### How HMACs Work

* HMACs rely on a **symmetric shared secret**. Both parties must agree on this secret key before communication begins.
* Every message is accompanied by an HMAC, which the receiver can check using the same secret key.
* The message itself may or may not be encrypted—but its authenticity and integrity can still be verified.

For example: if the hash function used is SHA-256, the code would be called **HMAC-SHA-256**.

👉 **In simpler terms:** Think of two people agreeing on a secret handshake before they meet. Each time they send a message, they include the handshake. If the handshake checks out, the receiver knows the message is genuine.

***

### The Problem with HMACs

The biggest weakness of HMACs is the **shared secret** itself.

* If an attacker intercepts or discovers the key, they can impersonate one of the parties.
* This makes it possible to launch a **man-in-the-middle attack**, where the attacker secretly relays and even changes communications.
* As with PKI, this vulnerability can enable ransomware, malware injection, or sensitive data theft.

👉 **In simpler terms:** If someone learns the secret handshake, they can pretend to be you.

***

### Why This Matters for Our Discussion

HMACs highlight a common trade-off in cryptography:

* They’re **simpler and faster** than PKI’s digital signature systems.
* But they also suffer from **trust problems** because both parties must share—and protect—a single secret key.

BSV avoids these pitfalls by anchoring security in **hash functions, UTXOs, and on-chain digital signatures**. Instead of trusting hidden secrets, authenticity and integrity are **provable and auditable on the blockchain**.

👉 **Key takeaway:** HMACs show how hashing can secure communications, but they also expose the risks of secret-sharing. BSV solves these risks by building security on transparent, verifiable, and scalable mechanisms instead.


---

# 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/double-hashing-and-bsvs-security/what-are-hmacs.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.
