密码运算
生成和验证签名、计算哈希、加密消息,以及协商共享密钥和派生密钥。
gost-cryptov0.3.0
OpenSSL gost-engine 的 Go 绑定
通过基于 OpenSSL gost-engine 的 Go 绑定,集成签名、Streebog 哈希、Kuznechik 加密和 MGM AEAD。
Go · MIT · 最近更新
这是开源绑定,不宣称已获认证或通过独立安全审计。
priv, err := gostcrypto.GenerateKey(
gostcrypto.CurveTC26_256_A,
)
if err != nil { return err }
defer priv.Zeroize()
sig, err := gostcrypto.Sign(priv, message)
if err != nil { return err }
valid, err := gostcrypto.Verify(
priv.PublicKey(), message, sig,
)
gost-crypto
生成和验证签名、计算哈希、加密消息,以及协商共享密钥和派生密钥。
哈希与密码包在适用时实现 hash.Hash、cipher.Block 和 cipher.AEAD。
需要 CGO、OpenSSL 和 gost-engine;部署指南说明服务所需的原生依赖。
OpenSSL gost-engine 的 Go 绑定
安装文档所述的 OpenSSL/gost-engine 组合,并启用 CGO。
参考示例,并按系统要求验证密钥格式、算法和运行环境。
01 / 安装
go get github.com/rekurt/gost-crypto02 / README
基于 OpenSSL gost-engine,在 Go 中提供 GOST 签名、哈希、加密和密钥协商。
配置说明、使用示例和 API 参考。
以下为仓库的原始文档,未作翻译;上方的示例与入门说明已本地化。
Go library for Russian GOST cryptographic standards (GOST R 34.10-2012, GOST R 34.11-2012 Streebog, GOST R 34.12-2015 Kuznechik, GOST R 34.13-2015 MGM), powered by OpenSSL gost-engine. Digital signatures, hashing, encryption, key agreement, and key derivation with zero external Go dependencies.
Project website · All projects by rekurt
API Reference | Examples | На русском | Contributing
hash.Hash, cipher.Block, cipher.AEAD — drop-in compatible with Go's crypto ecosystemgo.mod has no require directives; only OpenSSL + CGO at build time| Standard | Package | Description | Go Interface |
|---|---|---|---|
| GOST R 34.10-2012 | pkg/gost3410 |
Elliptic curve digital signatures | — |
| GOST R 34.11-2012 | pkg/gost3411 |
Streebog hash (256/512-bit) | hash.Hash |
| GOST R 34.12-2015 | pkg/gost3412 |
Kuznechik block cipher | cipher.Block |
| GOST R 34.13-2015 | pkg/gost3413 |
MGM authenticated encryption | cipher.AEAD |
| RFC 7836 | pkg/gost3410 |
VKO key agreement (ECDH) | — |
| R 50.1.113-2016 | pkg/kdf |
KDF_GOSTR3411, HKDF-Streebog | — |
| BIP-32 style | pkg/hd |
HD key derivation | — |
go get github.com/rekurt/gost-crypto
package main
import (
"fmt"
gostcrypto "github.com/rekurt/gost-crypto"
)
func main() {
priv, err := gostcrypto.GenerateKey(gostcrypto.CurveTC26_256_A)
if err != nil {
panic(err)
}
defer priv.Zeroize()
sig, err := gostcrypto.Sign(priv, []byte("Hello, GOST!"))
if err != nil {
panic(err)
}
ok, err := gostcrypto.Verify(priv.PublicKey(), []byte("Hello, GOST!"), sig)
if err != nil {
panic(err)
}
fmt.Println("valid:", ok) // valid: true
}
privA, _ := gostcrypto.GenerateKey(gostcrypto.CurveTC26_256_A)
privB, _ := gostcrypto.GenerateKey(gostcrypto.CurveTC26_256_A)
defer privA.Zeroize()
defer privB.Zeroize()
ukm := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
// Shared secret is symmetric: Agree(A, pubB) == Agree(B, pubA)
secretAB, _ := gostcrypto.Agree(privA, privB.PublicKey(), ukm)
secretBA, _ := gostcrypto.Agree(privB, privA.PublicKey(), ukm)
// bytes.Equal(secretAB, secretBA) == true
import "github.com/rekurt/gost-crypto/pkg/gost3413"
aead, _ := gost3413.NewMGMFromKey(key) // 32-byte key
nonce := make([]byte, aead.NonceSize())
rand.Read(nonce)
ciphertext := aead.Seal(nil, nonce, plaintext, additionalData)
More examples: docs/EXAMPLES.md | _examples/
All 8 TC26 elliptic curve parameter sets are supported:
| Curve | Size | OID | Notes |
|---|---|---|---|
CurveTC26_256_A |
256-bit | 1.2.643.7.1.2.1.1.1 | Recommended |
CurveTC26_256_B |
256-bit | 1.2.643.2.2.35.1 | CryptoPro-A |
CurveTC26_256_C |
256-bit | 1.2.643.2.2.35.2 | CryptoPro-B |
CurveTC26_256_D |
256-bit | 1.2.643.2.2.35.3 | CryptoPro-C |
CurveTC26_512_A |
512-bit | 1.2.643.7.1.2.1.2.1 | |
CurveTC26_512_B |
512-bit | 1.2.643.7.1.2.1.2.2 | |
CurveTC26_512_C |
512-bit | 1.2.643.7.1.2.1.2.3 | |
CurveTC26_512_D |
512-bit | 1.2.643.7.1.2.1.2.0 | Test curve |
gost-crypto/
├── gostcrypto.go # High-level facade: Sign, Verify, HashSum, Agree
├── keys.go # GenerateKey, LoadPrivKey, PrivKey/PubKey aliases
├── curves.go # Curve type, TC26 constants, AllCurves
├── errors.go # Re-exported sentinel errors
├── pkg/
│ ├── gost3410/ # GOST R 34.10-2012 signatures (OpenSSL backend)
│ ├── gost3411/ # GOST R 34.11-2012 Streebog hash (OpenSSL backend)
│ ├── gost3412/ # GOST R 34.12-2015 Kuznechik cipher
│ ├── gost3413/ # GOST R 34.13-2015 MGM AEAD
│ ├── hd/ # HD key derivation (HKDF, BIP32-style paths)
│ └── kdf/ # Key derivation functions (HKDF-Streebog, KDF_GOSTR3411)
├── internal/openssl/ # CGO bindings for OpenSSL gost-engine
└── _examples/ # Runnable examples
| Document | Description |
|---|---|
| API Reference | Complete API for all packages |
| Examples | Validated usage patterns |
| Deployment | OpenSSL + gost-engine setup |
| Migration v0 to v1 | Breaking changes and migration path |
| Threat Model | Security assumptions and limitations |
| Security Policy | Vulnerability disclosure |
This library implements the following Russian and international standards:
Contributions are welcome. See docs/CONTRIBUTING.md for guidelines.
MIT License. See LICENSE for details.
gost-crypto