mtorun0x7cd/raven-one-simulink

GitHub: mtorun0x7cd/raven-one-simulink

一款教学用的 C# WinForms 桌面程序,逐步展示 RSA 与 MD5 算法的所有中间计算过程以帮助理解密码学原理。

Stars: 0 | Forks: 0

Raven One SimuLink

# Raven One SimuLink [![CI](https://img.shields.io/github/actions/workflow/status/mtorun0x7cd/raven-one-simulink/ci.yml?branch=main&style=for-the-badge&logo=githubactions&logoColor=white&label=CI)](https://github.com/mtorun0x7cd/raven-one-simulink/actions/workflows/ci.yml) ![C#](https://img.shields.io/badge/C%23-239120?style=for-the-badge&logo=csharp&logoColor=white) ![.NET 8](https://img.shields.io/badge/.NET%208-512BD4?style=for-the-badge&logo=dotnet&logoColor=white) ![WinForms](https://img.shields.io/badge/WinForms-0078D6?style=for-the-badge&logo=windows&logoColor=white) ![Cryptography](https://img.shields.io/badge/Cryptography-FF6F00?style=for-the-badge&logo=letsencrypt&logoColor=white) ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge) ## 概述 Raven One SimuLink 是一款 C# WinForms 桌面应用程序,它使得 RSA 公钥密码体制和 MD5 消息摘要算法完全透明化:每一个中间值——从 RSA 密钥参数到 MD5 每轮的状态——都被写出来供检查。它是作为学士论文《Password- / Keyless authentication》(科隆应用技术大学,2021 年 6 月)的实践部分而开发的,作者在其中将其描述为自己“本论文的主要工作”;该论文在实现章节中介绍了该程序,并在附录中 reproduced 了其全部源码。 该程序是一个教学工具,而不是生产级的密码学工具。这两种算法都是根据 RFC 8017 (RSA) [1] 和 RFC 1321 (MD5) [2] 中的定义,在不使用任何密码学库的情况下从头实现的。RSA 运行在固定的演示小素数(p = 11, q = 17)上,以便每一步都可以手动辨认:参数保存在 `System.Numerics.BigInteger` 中,公钥指数 `e` 是与 φ(n) 互质的大于 2 的最小整数,私钥指数取自闭式解 `d = (1 + 2·φ(n)) / e`,由此得出这些参数下的模逆元 `e⁻¹ mod φ(n)`。MD5 是一个完整的 64 轮 Merkle–Damgård [3][4] 结构,包含源自正弦的 K 常数和每轮的移位表。 摘要验证工作流并排比较两个 MD5 摘要,演示了作为数字签名验证基础的完整性检查。 ## 背景 | 维度 | 详情 | | :--- | :--- | | **机构** | 科隆应用技术大学 — 通信研究所 (INT) | | **专业** | 计算机科学与系统工程 (B.Sc.) | | **论文** | *Password- / Keyless authentication* (2021年6月) — Raven One SimuLink 是其实践密码学部分(第5章;源码在附录中) | | **第一评审人** | Prof. Dr. Michael Silverberg (科隆应用技术大学) | | **第二评审人** | Frank Mördel (Jamestown US-Immobilien GmbH) | | **学期** | 2021年夏季 | | **类型** | 个人 | ## 功能 - **RSA 密钥参数** — 显示固定演示素数的素数 p, q,模数 n = p·q,欧拉函数 φ(n) = (p−1)(q−1),公钥指数 e 和私钥指数 d - **RSA 加密 / 解密** — 计算 c = mᵉ mod n 和 m = cᵈ mod n,记录每一步的操作数 - **自定义 MD5 哈希** — 依据 RFC 1321 从头实现的 64 轮 Merkle–Damgård 摘要 - **摘要验证** — 并排比较两个 MD5 摘要,这是数字签名验证背后的完整性检查 - **透明计算** — 每个中间值(密钥、摘要、ASCII 码、操作数)都被写入详细面板,以便逐步研究 ## 架构 这里保留的源码是论文附录中的清单:两个密码学引擎、GUI 控制器和应用程序入口点。 | 文件 | 类 | 职责 | |------|-------|----------------| | `Program.cs` | `Program`, `Form1` (partial) | WinForms 入口点 (`Main`) 以及辅助的 `RSA` / `MD5` / `About` 表单存根 | | `Raven One.cs` | `Form1` (partial) | 主 GUI 控制器 — 驱动加密、解密、哈希和验证操作,并渲染中间值 | | `cRSA.cs` | `cRSA` | RSA 引擎 — 欧几里得 GCD、密钥派生、基于 `BigInteger` 的模幂运算 | | `cMD5.cs` | `cMD5` | MD5 引擎 — 包含每轮移位表和源自正弦的常数的 64 轮计算 | ### MD5 密码学数据流图 ``` %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#E8F5E9', 'edgeColor': '#4CAF50', 'primaryBorderColor': '#2E7D32', 'lineColor': '#4CAF50', 'textColor': '#1B5E20' }}}%% graph TD Input[Input Message] --> Padding[Padding Stage: Append 1 bit, Pad with 0s, Append Length: 32-bit value in the 64-bit field] Padding --> Blocks[512-bit Blocks] Blocks --> BlockProc[Block Processing Loop] subgraph Block Processing BlockProc --> MsgSched[Message Schedule: Split block into 16 32-bit words M_0..M_15] MsgSched --> InitReg[Initialize Registers A, B, C, D] InitReg --> Rounds[Round Operations: 64 Rounds in 4 Groups of 16] subgraph Round Operations Rounds --> RoundFunc[Apply Non-linear Function F, G, H, or I] RoundFunc --> Rotate[Add M_g, K_i, rotate left by s_i, add B] Rotate --> RegisterUpdate[Update Registers: A <- D, D <- C, C <- B, B <- NewB] end RegisterUpdate --> Accumulate[Add output of 64 rounds to previous hash state] end Accumulate --> Final[Concatenate final registers A, B, C, D to produce 128-bit digest] ```
“admin”的 MD5 执行跟踪
  • 输入字符串: admin
  • 填充块 (hex):
    61646d696e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002800000000000000
  • 初始寄存器状态:
    A = 0x67452301
    B = 0xefcdab89
    C = 0x98badcfe
    D = 0x10325476
  • 第 0 轮后的寄存器状态:
    A = 0x10325476
    B = 0x5bd217a9
    C = 0xefcdab89
    D = 0x98badcfe
  • 最终 MD5 摘要: 21232f297a57a5a743894a0e4a801fc3
### RSA 密钥生成流程 ``` 1. Fixed demo primes p = 11, q = 17 (constants, chosen for legibility) 2. Compute modulus n = p × q 3. Compute Euler totient φ(n) = (p − 1)(q − 1) 4. Public exponent e = smallest integer > 2 with gcd(e, φ(n)) = 1 5. Private exponent d = (1 + 2·φ(n)) / e ( = e⁻¹ mod φ(n) for these parameters ) 6. Encrypt c = mᵉ mod n 7. Decrypt m = cᵈ mod n ``` ### MD5 轮结构 (Merkle–Damgård) ``` Input → Pad to 512-bit blocks → For each block: ┌─────────────────────────────────────────────────┐ │ Initialize A, B, C, D from chaining variables │ │ │ │ Rounds 0–15: F(B,C,D) = (B ∧ C) ∨ (¬B ∧ D) │ │ Rounds 16–31: G(B,C,D) = (D ∧ B) ∨ (¬D ∧ C) │ │ Rounds 32–47: H(B,C,D) = B ⊕ C ⊕ D │ │ Rounds 48–63: I(B,C,D) = C ⊕ (B ∨ ¬D) │ │ │ │ Each round: B += leftRotate(A + F + K[i] + M[g],│ │ s[i]) │ │ Then rotate: A←D, D←C, C←B (updated) │ └─────────────────────────────────────────────────┘ Add round results to chaining variables (a0, b0, c0, d0) Output → Concatenate final a0 ‖ b0 ‖ c0 ‖ d0 as 128-bit hex digest ``` ## 技术栈 | 类别 | 技术 | |----------|-------------| | 语言 | C# — 目标框架为 .NET 8 (`net8.0-windows`);最初在 .NET Framework 4.7.2 上编写 | | UI 框架 | Windows Forms (WinForms) | | 运算 | 使用 `System.Numerics.BigInteger` 进行任意精度的 RSA 操作 | | 参考资料 | RFC 8017 (RSA), RFC 1321 (MD5) | ## 项目结构 ``` raven-one-simulink/ ├── src/ # Source code (as listed in the thesis appendix) │ ├── Program.cs # WinForms entry point and form stubs │ ├── Raven One.cs # Main GUI controller (Form1) │ ├── cRSA.cs # RSA engine │ └── cMD5.cs # MD5 engine ├── docs/ # Documentation │ ├── Bachelor Thesis.pdf # Thesis "Password-/Keyless authentication" (presents this software in Ch. 5 + appendix) │ ├── Handout.pdf # Colloquium handout │ └── social_preview.svg # Repository header graphic ├── RavenOneSimuLink.csproj # .NET 8 project file ├── LICENSE # MIT License └── README.md ``` ## 快速开始 ### 前置条件 - .NET 8 SDK - 需要 Windows 来运行应用程序 (WinForms);由于项目设置了 `EnableWindowsTargeting`,它也可以在 macOS 和 Linux 上构建 ### 构建和运行 ``` git clone https://github.com/mtorun0x7cd/raven-one-simulink.git cd raven-one-simulink dotnet build -c Release # compiles on Windows, macOS, or Linux dotnet run # run on Windows ``` 该项目配置为跨平台编译;运行 WinForms 应用程序需要 Windows。 ## 文档 | 文档 | 描述 | |----------|-------------| | [学士论文.pdf](docs/Bachelor%20Thesis.pdf) | 完整论文,*Password-/Keyless authentication*;Raven One SimuLink 在第 5 章中介绍,其源码在附录中重现 | | [讲义.pdf](docs/Handout.pdf) | 总结该论文的答辩讲义 | ## 参考文献 [1] K. Moriarty et al., "PKCS #1: RSA Cryptography Specifications Version 2.2," RFC 8017, 2016. [链接](https://tools.ietf.org/html/rfc8017) [2] R. Rivest, "The MD5 Message-Digest Algorithm," RFC 1321, 1992. [链接](https://tools.ietf.org/html/rfc1321) [3] R. Merkle, "A Certified Digital Signature," *Advances in Cryptology — CRYPTO '89*, 1989. [4] I. Damgård, "A Design Principle for Hash Functions," *Advances in Cryptology — CRYPTO '89*, 1989. ## 引用 引用元数据可在 [`CITATION.cff`](CITATION.cff) 中找到;GitHub 会基于此生成 *Cite this repository* 操作。 ## 安全 这是一个已归档的教育项目,未进行积极维护。其密码学实现是故意不安全的——MD5 已被破解,并且 RSA 实现使用了固定的、极小的素数,且没有进行填充。详情请参阅 [`SECURITY.md`](SECURITY.md)。 ## 许可证 该项目基于 MIT 许可证授权 — 详情请参阅 [LICENSE](LICENSE) 文件。2021 年的源文件头部带有最初论文提交时使用的早期 GNU GPLv3 声明;该声明已被仓库的 MIT 许可证所取代。 ## 作者 **Mert Torun, M.Sc.** — IT 安全架构师与系统工程师 mtorun0x7cd · 研发部 他的工作涉及安全关键系统的验证与确认、基础设施加固以及密码学完整性,这些都以他在科隆应用技术大学获得的计算机科学与系统工程理学硕士学位为基础。该仓库作为已完成项目的记录被保存下来,而未作为持续更新的工具进行维护。 - **电子邮件**: [info@mtorun0x7cd.com](mailto:info@mtorun0x7cd.com) - **网站**: [mtorun0x7cd.com](https://mtorun0x7cd.com) - **LinkedIn**: [linkedin.com/in/mtorun0x7cd](https://linkedin.com/in/mtorun0x7cd) - **GitHub**: [github.com/mtorun0x7cd](https://github.com/mtorun0x7cd)
标签:MD5, RSA, 密码学, 手动系统调用, 桌面应用