# 曲線密碼學（ECC）

### 橢圓曲線密碼學（Elliptic Curve Cryptography, ECC）是一種利用橢圓曲線數學特性的加密技術。區塊鏈用它來生成公私鑰對——私鑰用來簽名交易，公鑰用來驗證簽名。

***

## 為什麼區塊鏈選擇 ECC？

傳統的 RSA 加密要達到足夠安全，需要 2048 甚至 4096 位元的金鑰。而 ECC 只需要 256 位元就能達到同等安全等級。

| 安全等級    | RSA 金鑰長度  | ECC 金鑰長度    |
| ------- | --------- | ----------- |
| 80 bit  | 1024 bit  | 160 bit     |
| 112 bit | 2048 bit  | 224 bit     |
| 128 bit | 3072 bit  | **256 bit** |
| 256 bit | 15360 bit | 512 bit     |

{% hint style="info" %}
**更短 = 更好**

更短的金鑰意味著更快的運算、更小的儲存空間、更少的網路流量。對於每秒處理數千筆交易的區塊鏈來說，這至關重要。
{% endhint %}

***

## 橢圓曲線是什麼？

橢圓曲線並不是橢圓形的曲線！它是一種數學方程式：

```
y² = x³ + ax + b
```

這個方程式在座標平面上畫出來的曲線，有一些神奇的數學特性，可以用來做加密。

比特幣和以太坊使用的曲線叫做 **secp256k1**。

***

## 公私鑰如何產生？

### 1. 生成私鑰

私鑰就是一個隨機的 256 位元數字。

### 2. 計算公鑰

把私鑰乘以曲線上的一個特定點（生成點 G），得到另一個點，這就是公鑰。

```
公鑰 = 私鑰 × G
```

### 3. 單向性

從私鑰計算公鑰很容易，但從公鑰反推私鑰在數學上是不可行的。這就是 ECC 的安全基礎。

{% hint style="success" %}
**為什麼反推不了？**

這叫做「離散對數問題」。就像你知道 3 × 5 = 15 很容易，但如果只告訴你答案是 15，要你猜出原來的數字是 3 和 5，就難多了。ECC 的版本比這複雜得多。
{% endhint %}

***

## 數位簽名（ECDSA）

區塊鏈用 ECC 來做數位簽名，證明交易是由私鑰持有者發起的：

1. **簽名**：用私鑰對交易訊息簽名，產生簽名資料
2. **廣播**：把交易和簽名發送到網路
3. **驗證**：任何人都可以用公鑰驗證簽名是否有效

如果簽名有效，就證明這筆交易確實是私鑰持有者授權的。

***

## ECC 在區塊鏈中的應用

| 區塊鏈      | 使用的曲線     | 簽名算法  |
| -------- | --------- | ----- |
| Bitcoin  | secp256k1 | ECDSA |
| Ethereum | secp256k1 | ECDSA |
| Solana   | ed25519   | EdDSA |

***

## 延伸閱讀

* [密碼學總覽](https://www.0x1.academy/gei-kai-fa-zhe-de-zhi-nan/cryptography) — 區塊鏈安全的基礎
* [私鑰](https://www.0x1.academy/bao-guan-ni-de-jia-mi-zi-chan/si) — 你的數位資產鑰匙
* [公鑰](https://www.0x1.academy/bao-guan-ni-de-jia-mi-zi-chan/gong) — 從私鑰衍生而來
* [簽名](https://www.0x1.academy/bao-guan-ni-de-jia-mi-zi-chan/ming) — 證明交易授權

***

#### 參考資料

* [Elliptic Curve Cryptography - Wikipedia](https://en.wikipedia.org/wiki/Elliptic-curve_cryptography)
* [secp256k1 - Bitcoin Wiki](https://en.bitcoin.it/wiki/Secp256k1)


---

# 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://www.0x1.academy/gei-kai-fa-zhe-de-zhi-nan/cryptography/qu-mi-ecc.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.
