PeculiarVentures/pqc-ratchet

GitHub: PeculiarVentures/pqc-ratchet

一个后量子时代的 Double Ratchet 和 X3DH 协议实现,提供 Go 和 TypeScript 两种语言版本,采用混合密钥交换机制抵御量子计算攻击。

Stars: 0 | Forks: 0

# pqc-ratchet Go 和 TypeScript 中的后量子 Double Ratchet + X3DH。 ``` go/ — Go implementation (FIPS 203/204, circl, standard library) ts/ — TypeScript implementation (WebCrypto, @noble/post-quantum) ``` 两种实现共享相同的二进制传输格式,并通过跨语言互操作测试 (`go/pqcratchet/interop_test.go`) 进行了验证。 ## 算法 | 角色 | 算法 | 标准 | |------|-----------|----------| | 签名 | ML-DSA-65 | FIPS 204 | | 密钥交换 | ML-KEM-768 + X25519 (hybrid) | FIPS 203 + RFC 7748 | | 消息加密 | AES-256-GCM | FIPS 197 | | 消息认证 | HMAC-SHA-256 | FIPS 198 | | KDF | HKDF-SHA-256 | SP 800-56C | ## 快速开始 ``` # Go cd go && go test ./pqcratchet/... # TypeScript cd ts && npm install && npm test # 跨语言互操作测试 (Go ↔ TypeScript 采用相同 wire format) cd ts && npx tsc && cd .. cd go && go test ./pqcratchet/... -run TestInteropGoTS -v ``` ### 发送消息 (TypeScript) ``` import { generateIdentity, createSessionInitiator, createSessionResponder } from "@peculiarventures/pqc-ratchet"; const alice = await generateIdentity(1, 2, 10); const bob = await generateIdentity(2, 2, 10); const bundle = { registrationId: bob.id, identitySigningPub: bob.signingKey.publicKey, identityExchangePub: bob.exchangeKey.publicKey, signedPreKeyPub: bob.signedPreKeys[0].publicKey, signedPreKeyIndex: 0, signedPreKeySig: bob.signedPreKeySigs[0], oneTimePreKeyPub: bob.preKeys[0]!.publicKey, oneTimePreKeyIndex: 0, }; const { session: aliceSess, preKeyMessage } = await createSessionInitiator(alice, bundle); const bobSess = await createSessionResponder(bob, preKeyMessage); // seal() and open() handle marshalling, HMAC, and signing internally const wire = await aliceSess.seal(new TextEncoder().encode("hello")); const pt = await bobSess.open(wire); console.log(new TextDecoder().decode(pt)); // "hello" ``` ### 发送消息 (Go) ``` import pqc "github.com/PeculiarVentures/pqc-ratchet/pqcratchet" aliceID, _ := pqc.GenerateIdentity(1, 2, 10) bobID, _ := pqc.GenerateIdentity(2, 2, 10) bundleWire, _ := pqc.MakeBundleWire(bobID, 0, 0) bundle, _ := pqc.ParseBundleWire(bundleWire) aliceSess, result, _ := pqc.CreateSessionInitiator(aliceID, bundle) pkmBytes := pqc.MarshalPreKeyMessageWire(result.ToPreKeyMessageWire(aliceID, bundle)) raw, _ := pqc.UnmarshalPreKeyMessageWire(bytes.NewReader(pkmBytes)) pkm, _ := pqc.ParsePreKeyMessageWire(raw) bobSess, _ := pqc.CreateSessionResponder(bobID, pkm) wire, _ := aliceSess.Seal([]byte("hello")) plaintext, _ := bobSess.Open(wire) fmt.Println(string(plaintext)) // "hello" ``` ## 仓库结构 ``` go/ pqcratchet/ core library cmd/interop_gen/ standalone fixture generator DESIGN.md full design rationale and security analysis README.md ts/ src/ TypeScript source scripts/ interop_verify.mjs SECURITY_REVIEW.md TS-specific security review README.md ``` ## v0 稳定性 不保证 API 或传输格式的稳定性。尚未达到生产就绪状态。
标签:AES-256-GCM, CIRCL, CVE, Dilithium, Double Ratchet, E2EE, EVTX分析, FIPS 203, FIPS 204, Go, HKDF, HMAC-SHA-256, JSONLines, Kyber, ML-DSA-65, ML-KEM-768, PQC, Ruby工具, Signal 协议, TypeScript, WebCrypto, X25519, X3DH, 后量子密码学, 域名收集, 安全开发套件, 安全插件, 安全通信, 密码学库, 密钥交换, 抗量子计算, 数字签名, 日志审计, 混合加密, 端到端加密, 网络安全, 蓝队防御, 跨语言互操作, 隐私保护, 零信任