# Chapter 11 - ELF 签名开销评估

## 11.1 开销分析

ELF 签名程序所带来的开销主要来自于：

* 遍历 ELF 文件中的每个 section，将需要被签名的 section 装入内存
* 对装入内存的 section 计算摘要，并用公私钥生成数字签名
* 将数字签名作为新的 section 加入 ELF 文件中

## 11.2 时间开销

时间开销与 ELF 文件中需要被签名的 section 个数呈正相关。目前版本中，我们仅对 `.text` 进行签名和验证。但 ELF 数字签名验证模块与 ELF 数字签名程序都是以验证或签名多个 section 为目标设计的。

对于单个 section 的签名来说，时间开销与 section 的数据长度呈正相关。越长的 section 需要越多的时间把数据装入内存并计算摘要。由于对 section 计算出的摘要是一个定长的序列，因此通过摘要计算数字签名的时间开销可被认为是固定的。

由于计算出的 section 摘要长度固定，并且长度较短，因此 ELF 文件的签名工作基本在每一台机器上都能快速完成。

## 11.3 空间开销

这里主要关注签名数据作为新的 section 被加入原 ELF 文件后，会使 ELF 文件大小增加多少。

上面已经提到，由于对一个 section 计算出的摘要是一个 **定长** 序列，那么计算得到的数字签名也是定长的。以 SHA-256 和 RSA-2048 作为签名工具链，我们测试得到每个被签名保护的 section 会为 ELF 文件带来 560 字节左右的额外开销，其中包含：

* 签名数据
* Section header table 中新的 section header 项
* Section header string table 中该 section 的名称字符串

对于现代计算机的硬件来说，这个空间开销基本上可以忽略。规模越大的 ELF 文件，这个开销所占的百分比越小。以 [chromium](http://www.chromium.org/) 的 ELF 文件为例 (`/usr/lib/chromium/chromium`)，签名前的程序大小为 134147808 字节 (127.9333 MB)，签名后的程序大小为 134148352 字节 (127.9338 MB)，产生的额外开销为 544 字节 (0.0004%)。


---

# 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://mrdrivingduck.gitbook.io/linux-elf-sv/group-4-evaluation-and-testing/chapter-11-elf-signature-overhead-evaluation.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.
