Complete API reference for gost-crypto.
- Root Package (gostcrypto)
- pkg/gost3410
- pkg/gost3411
- pkg/gost3412
- pkg/gost3413
- pkg/hd
- pkg/kdf
- Error Handling
- Thread Safety
import gostcrypto "github.com/rekurt/gost-crypto"
High-level facade that re-exports types from pkg/gost3410 and provides convenient Sign/Verify/Hash/Agree functions.
type Curve = gost3410.Curve
type PrivKey = gost3410.PrivKey
type PubKey = gost3410.PubKeyconst (
CurveTC26_256_A // id-tc26-gost-3410-2012-256-paramSetA
CurveTC26_256_B // CryptoPro-A
CurveTC26_256_C // CryptoPro-B
CurveTC26_256_D // CryptoPro-C
CurveTC26_512_A
CurveTC26_512_B
CurveTC26_512_C
CurveTC26_512_D // test
)Generates a new GOST R 34.10-2012 key pair for the given curve.
Creates a private key from raw big-endian bytes. The raw bytes must be exactly the key size (32 for 256-bit, 64 for 512-bit).
Hashes msg with Streebog (auto-selected based on curve size) and signs with GOST R 34.10-2012. Returns signature as r||s.
Hashes msg with Streebog and verifies the GOST R 34.10-2012 signature.
Returns the Streebog-256 digest of data.
Returns the Streebog-512 digest of data.
Performs VKO key agreement. Returns shared secret. Symmetric: Agree(A, pubB, ukm) == Agree(B, pubA, ukm).
Returns all 8 TC26 parameter sets.
var (
ErrUnknownCurve
ErrPointNotOnCurve
ErrInvalidKeySize
ErrInvalidSignature
ErrNilKey
ErrCurveMismatch
ErrEmptyUKM
)import "github.com/rekurt/gost-crypto/pkg/gost3410"
Low-level GOST R 34.10-2012 operations backed by OpenSSL gost-engine.
Generates a random key pair for the given curve.
Creates a private key from raw bytes via OpenSSL.
Signs a pre-computed digest. Digest must be exactly key size bytes.
Verifies a signature over a pre-computed digest.
Performs VKO key agreement.
Bytes() ([]byte, error)— returns raw private key bytes (sensitive!)Curve() Curve— returns the curve parameter setPublicKey() *PubKey— derives the public keyPublic() crypto.PublicKey— implementscrypto.SignerSign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)— implementscrypto.SignerMarshalBinary() ([]byte, error)— implementsencoding.BinaryMarshaler(format:[curve_id][raw_key])UnmarshalBinary(data []byte) error— implementsencoding.BinaryUnmarshalerZeroize()— securely wipes key material and frees OpenSSL handle
Bytes() ([]byte, error)— returns raw public key bytes (SPKI DER or raw X||Y)Curve() Curve— returns the curve parameter setValidate() error— checks that the point lies on the curveMarshalBinary() ([]byte, error)— implementsencoding.BinaryMarshaler
import "github.com/rekurt/gost-crypto/pkg/gost3411"
GOST R 34.11-2012 Streebog hash functions via OpenSSL gost-engine.
Returns a Streebog-256 hasher implementing hash.Hash.
Returns a Streebog-512 hasher implementing hash.Hash.
Computes Streebog-256 digest in one call.
Computes Streebog-512 digest in one call.
Returns HMAC-Streebog-256 with the given key.
Returns HMAC-Streebog-512 with the given key.
const (
HashStreebog256 crypto.Hash = 100 // registered via crypto.RegisterHash
HashStreebog512 crypto.Hash = 101
)These are registered with crypto.RegisterHash in init(), enabling standard Go crypto.Hash lookup.
import "github.com/rekurt/gost-crypto/pkg/gost3412"
GOST R 34.12-2015 block ciphers via OpenSSL gost-engine.
Creates a Kuznechik cipher block. Key must be 32 bytes. Block size is 16 bytes (128 bits).
Creates a Magma cipher block. Key must be 32 bytes. Block size is 8 bytes (64 bits).
import "github.com/rekurt/gost-crypto/pkg/gost3413"
GOST R 34.13-2015 block cipher modes of operation via OpenSSL gost-engine.
Creates a Kuznechik-MGM AEAD. Nonce: 16 bytes, tag: 16 bytes.
Creates a Magma-MGM AEAD. Nonce: 8 bytes, tag: 8 bytes.
Methods: Encrypt(iv, plaintext) ([]byte, error), Decrypt(iv, ciphertext) ([]byte, error), Zeroize().
Plaintext must be block-aligned. No padding. Methods: Encrypt, Decrypt, BlockSize, Zeroize.
Stream cipher mode. Methods: Encrypt, Decrypt, Zeroize.
Synchronous stream cipher. Methods: Encrypt, Decrypt, Zeroize.
Methods: MAC(message []byte) ([]byte, error), Zeroize(). Output: block-size bytes.
NewCTREncryptReader(ctr *CTR, iv []byte, r io.Reader) io.Reader
NewCTRDecryptReader(ctr *CTR, iv []byte, r io.Reader) io.Reader
NewCFBEncryptReader(cfb *CFB, iv []byte, r io.Reader) io.Reader
NewCFBDecryptReader(cfb *CFB, iv []byte, r io.Reader) io.Reader
NewOFBEncryptReader(ofb *OFB, iv []byte, r io.Reader) io.Reader
NewOFBDecryptReader(ofb *OFB, iv []byte, r io.Reader) io.Readerimport "github.com/rekurt/gost-crypto/pkg/hd"
Hierarchical deterministic key derivation using HKDF-Streebog.
Derives a master key from a seed (minimum 16 bytes). Both chain code and private key are deterministically derived via HKDF-Streebog.
Derives a child key along the given BIP-32 style path. Supports hardened (' or h suffix) and normal derivation.
Parses a BIP-32 path string into components.
type DerivedKey struct {
Key *PrivKey // GOST R 34.10-2012 private key
ChainCode []byte // 32-byte chain code for further derivation
}Zeroize()— securely wipes key and chain code
import "github.com/rekurt/gost-crypto/pkg/kdf"
Key derivation functions based on GOST primitives.
Derives length bytes using HKDF with HMAC-Streebog-256.
Derives length bytes using HKDF with HMAC-Streebog-512.
HKDF-Extract phase only.
HKDF-Expand phase only.
Russian national KDF. Output: 32 bytes.
Output: 64 bytes.
PBKDF2 with HMAC-Streebog-256.
PBKDF2 with HMAC-Streebog-512.
All operations return errors rather than panicking. Common error types:
| Error | When |
|---|---|
ErrNilKey |
nil or zeroized key passed |
ErrInvalidKeySize |
digest/key size mismatch |
ErrInvalidSignature |
wrong signature length |
ErrUnknownCurve |
invalid curve identifier |
ErrCurveMismatch |
VKO with keys on different curves |
ErrEmptyUKM |
VKO without User Keying Material |
- Key generation and signing are thread-safe (OpenSSL handles locking internally)
- A single
*PrivKeyor*PubKeyshould not be shared across goroutines without synchronization Zeroize()invalidates both the private key and any derived public keys