Files
EntitleForge-SDK-go/crypto/key.go
T
iceking2nd 81c7295893
sdk-ci / test (push) Failing after 8s
feat: 益铸 EntitleForge SDK 独立仓库首个版本
- 自主仓 git.wxccs.org/EntitleForge/EntitleForge 拆分(协议实现单一归属:
  license/crypto/ulid 随 SDK 迁出,服务端反向依赖本仓)
- sdk:Client 三模式(文件/远程/代理)、GRACE 状态机、查询 API(6.6ns/0 alloc)
- license:三段式编解码与严格解析;crypto:Ed25519 信任链 + Proxy 受约束证书
- 零第三方依赖(CI 有依赖闭包断言红线);go.mod 零 require
- CI:Gitea Actions(test + 零依赖断言 + 三平台交叉编译冒烟)
2026-11-09 15:42:22 +08:00

43 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package crypto 实现 EntitleForge 的密钥体系:签名/验签、信任链、
// 私钥加密存储与机器指纹。设计依据:docs/design/04-crypto.md。
//
// 安全约定:全部使用 Go 标准库,禁止引入第三方密码学依赖。
package crypto
import (
"crypto/ed25519"
"crypto/rand"
"encoding/hex"
)
// KeyPair 是一对 Ed25519 密钥。Signing Key 携带 kid;Root Key 的 kid 为空
// (root 不签发 license,只签 trust bundle)。
type KeyPair struct {
Kid string
Pub ed25519.PublicKey
Priv ed25519.PrivateKey
}
// GenerateSigningKey 生成签发密钥。kid 为私钥随机 8 字节的 hex(16 字符),
// 不派生自公钥(防指纹追踪,docs/design/04-crypto.md §1.2)。
func GenerateSigningKey() (*KeyPair, error) {
pub, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
var kidRaw [8]byte
if _, err := rand.Read(kidRaw[:]); err != nil {
return nil, err
}
return &KeyPair{Kid: hex.EncodeToString(kidRaw[:]), Pub: pub, Priv: priv}, nil
}
// GenerateRootKey 生成根密钥(离线保管,只用于签 trust bundle)。
func GenerateRootKey() (*KeyPair, error) {
pub, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
return &KeyPair{Pub: pub, Priv: priv}, nil
}