* chore(deps): consolidate dependency and security bumps Dependabot PRs applied: - #12878 qs 6.15.2 -> 6.16.0 (web/web-runtime) - #13013 alpine 3.24.1 -> 3.24.2 - #13061 actions/checkout -> v7.0.1 (missed instance in k8s.yml) - #13062 actions/setup-node -> v7.0.0 (missed instance in k8s.yml) - #13075 simple-git 3.36.0 -> 4.0.1 (security) - #13076 katex 0.16.45 -> 0.18.2+ (security) - #13077 dompurify 3.4.13 -> 3.4.16 (security) - #13079 go deps minor-and-patch group, 18 updates (opa 1.19.0 -> 1.21.1, otel 1.46 -> 1.47, bleve, govips, grpc-gateway, lico, tablewriter, logrus, gjson, x/exp, x/image, genproto, etc.) Skipped (already satisfied on master): #12513, #12624, #12625, #12633 Manual security bumps via pnpm.overrides (no dependabot PR existed): - axios -> 1.20.0 - smol-toml -> 1.9.0 - postcss -> 8.5.23 - postcss-selector-parser -> 7.1.6 - colord -> 2.9.4 - unhead -> 2.1.13 - markdown-it -> 14.3.1 - esbuild -> 0.28.1 - brace-expansion 5.0.11 -> 5.0.12 Not fixable: sprintf-js and elliptic have no patched version released upstream yet; left as-is. go build and pnpm install verified clean. * chore(deps): fix residual transitive vulns found by trivy trivy flagged duplicate/stale resolutions that survived the earlier override pass: dompurify (3.4.12 -> 3.4.16), qs (6.14.2 -> 6.16.0), and fast-uri (3.1.7 -> 3.1.8, CVE-2026-86472). Added/bumped pnpm.overrides accordingly. trivy fs scan of web/pnpm-lock.yaml now clean. * chore(deps): bump reva to bac0e1ee144ab853a81c6b02142032f102dd245a Pins github.com/owncloud/reva/v2 to bac0e1ee144ab853a81c6b02142032f102dd245a, pulling in its go-playground/locales and huandu/xstrings version bumps. Appends this PR to changelog/unreleased/bump-reva.md. go build ./... verified clean after go mod vendor resync. * fix(ci): revert unhead override, breaks web build * revert: keep k8s.yml actions/checkout and setup-node pinned
212 lines
7.1 KiB
Markdown
212 lines
7.1 KiB
Markdown
# github.com/lestrrat-go/dsig [](https://github.com/lestrrat-go/dsig/actions/workflows/ci.yml) [](https://pkg.go.dev/github.com/lestrrat-go/dsig)
|
|
|
|
Go module providing low-level digital signature operations.
|
|
|
|
While there are many standards for generating and verifying digital signatures, the core operations are virtually the same. This module implements the core functionality of digital signature generation / verifications in a framework agnostic way.
|
|
|
|
# Features
|
|
|
|
* RSA signatures (PKCS1v15 and PSS)
|
|
* ECDSA signatures (P-256, P-384, P-521)
|
|
* EdDSA signatures (Ed25519, Ed448)
|
|
* ML-DSA post-quantum signatures (ML-DSA-44, ML-DSA-65, ML-DSA-87), on Go 1.27 and later
|
|
* HMAC signatures (SHA-256, SHA-384, SHA-512)
|
|
* Support for crypto.Signer interface
|
|
* Custom algorithm registration via `Signer`/`Verifier` interfaces
|
|
|
|
# SYNOPSIS
|
|
|
|
<!-- INCLUDE(examples/dsig_readme_example_test.go) -->
|
|
```go
|
|
package examples_test
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"crypto/ed25519"
|
|
"crypto/elliptic"
|
|
"crypto/rand"
|
|
"crypto/rsa"
|
|
"fmt"
|
|
|
|
"github.com/lestrrat-go/dsig"
|
|
)
|
|
|
|
func Example() {
|
|
payload := []byte("hello world")
|
|
|
|
// RSA signing and verification
|
|
{
|
|
privKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
|
if err != nil {
|
|
fmt.Printf("failed to generate RSA key: %s\n", err)
|
|
return
|
|
}
|
|
|
|
// Sign with RSA-PSS SHA256
|
|
signature, err := dsig.Sign(privKey, dsig.RSAPSSWithSHA256, payload, nil)
|
|
if err != nil {
|
|
fmt.Printf("failed to sign with RSA: %s\n", err)
|
|
return
|
|
}
|
|
|
|
// Verify with RSA-PSS SHA256
|
|
err = dsig.Verify(&privKey.PublicKey, dsig.RSAPSSWithSHA256, payload, signature)
|
|
if err != nil {
|
|
fmt.Printf("failed to verify RSA signature: %s\n", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
// ECDSA signing and verification
|
|
{
|
|
privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
if err != nil {
|
|
fmt.Printf("failed to generate ECDSA key: %s\n", err)
|
|
return
|
|
}
|
|
|
|
// Sign with ECDSA P-256 SHA256
|
|
signature, err := dsig.Sign(privKey, dsig.ECDSAWithP256AndSHA256, payload, nil)
|
|
if err != nil {
|
|
fmt.Printf("failed to sign with ECDSA: %s\n", err)
|
|
return
|
|
}
|
|
|
|
// Verify with ECDSA P-256 SHA256
|
|
err = dsig.Verify(&privKey.PublicKey, dsig.ECDSAWithP256AndSHA256, payload, signature)
|
|
if err != nil {
|
|
fmt.Printf("failed to verify ECDSA signature: %s\n", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
// EdDSA signing and verification
|
|
{
|
|
pubKey, privKey, err := ed25519.GenerateKey(rand.Reader)
|
|
if err != nil {
|
|
fmt.Printf("failed to generate Ed25519 key: %s\n", err)
|
|
return
|
|
}
|
|
|
|
// Sign with EdDSA
|
|
signature, err := dsig.Sign(privKey, dsig.EdDSA, payload, nil)
|
|
if err != nil {
|
|
fmt.Printf("failed to sign with EdDSA: %s\n", err)
|
|
return
|
|
}
|
|
|
|
// Verify with EdDSA
|
|
err = dsig.Verify(pubKey, dsig.EdDSA, payload, signature)
|
|
if err != nil {
|
|
fmt.Printf("failed to verify EdDSA signature: %s\n", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
// HMAC signing and verification
|
|
{
|
|
key := []byte("secret-key")
|
|
|
|
// Sign with HMAC SHA256
|
|
signature, err := dsig.Sign(key, dsig.HMACWithSHA256, payload, nil)
|
|
if err != nil {
|
|
fmt.Printf("failed to sign with HMAC: %s\n", err)
|
|
return
|
|
}
|
|
|
|
// Verify with HMAC SHA256
|
|
err = dsig.Verify(key, dsig.HMACWithSHA256, payload, signature)
|
|
if err != nil {
|
|
fmt.Printf("failed to verify HMAC signature: %s\n", err)
|
|
return
|
|
}
|
|
}
|
|
// OUTPUT:
|
|
}
|
|
```
|
|
source: [examples/dsig_readme_example_test.go](https://github.com/lestrrat-go/dsig/blob/v1/examples/dsig_readme_example_test.go)
|
|
<!-- END INCLUDE -->
|
|
|
|
# Supported Algorithms
|
|
|
|
| Constant | Algorithm | Key Type |
|
|
|----------|-----------|----------|
|
|
| `HMACWithSHA256` | HMAC using SHA-256 | []byte |
|
|
| `HMACWithSHA384` | HMAC using SHA-384 | []byte |
|
|
| `HMACWithSHA512` | HMAC using SHA-512 | []byte |
|
|
| `RSAPKCS1v15WithSHA256` | RSA PKCS#1 v1.5 using SHA-256 | *rsa.PrivateKey / *rsa.PublicKey |
|
|
| `RSAPKCS1v15WithSHA384` | RSA PKCS#1 v1.5 using SHA-384 | *rsa.PrivateKey / *rsa.PublicKey |
|
|
| `RSAPKCS1v15WithSHA512` | RSA PKCS#1 v1.5 using SHA-512 | *rsa.PrivateKey / *rsa.PublicKey |
|
|
| `RSAPSSWithSHA256` | RSA PSS using SHA-256 | *rsa.PrivateKey / *rsa.PublicKey |
|
|
| `RSAPSSWithSHA384` | RSA PSS using SHA-384 | *rsa.PrivateKey / *rsa.PublicKey |
|
|
| `RSAPSSWithSHA512` | RSA PSS using SHA-512 | *rsa.PrivateKey / *rsa.PublicKey |
|
|
| `ECDSAWithP256AndSHA256` | ECDSA using P-256 and SHA-256 | *ecdsa.PrivateKey / *ecdsa.PublicKey |
|
|
| `ECDSAWithP384AndSHA384` | ECDSA using P-384 and SHA-384 | *ecdsa.PrivateKey / *ecdsa.PublicKey |
|
|
| `ECDSAWithP521AndSHA512` | ECDSA using P-521 and SHA-512 | *ecdsa.PrivateKey / *ecdsa.PublicKey |
|
|
| `EdDSA` | EdDSA using Ed25519 or Ed448 | ed25519.PrivateKey / ed25519.PublicKey |
|
|
| `MLDSA44` | ML-DSA-44 (FIPS 204), NIST level 2 | *mldsa.PrivateKey / *mldsa.PublicKey |
|
|
| `MLDSA65` | ML-DSA-65 (FIPS 204), NIST level 3 | *mldsa.PrivateKey / *mldsa.PublicKey |
|
|
| `MLDSA87` | ML-DSA-87 (FIPS 204), NIST level 5 | *mldsa.PrivateKey / *mldsa.PublicKey |
|
|
|
|
The three ML-DSA algorithms need Go 1.27 or later, which is when `crypto/mldsa`
|
|
joins the standard library. On earlier toolchains the constants are not declared
|
|
and the algorithms are not registered.
|
|
|
|
Name the constant that matches the key you generated. A key knows its own
|
|
parameter set, and naming a different one is an error, so a key cannot be used
|
|
under a weaker set by accident:
|
|
|
|
```go
|
|
sk, _ := mldsa.GenerateKey(mldsa.MLDSA65())
|
|
|
|
sig, _ := dsig.Sign(sk, dsig.MLDSA65, payload, nil)
|
|
err := dsig.Verify(sk.PublicKey(), dsig.MLDSA65, payload, sig)
|
|
|
|
_, err = dsig.Sign(sk, dsig.MLDSA44, payload, nil)
|
|
// dsig.SignWithOpts: ML-DSA parameter set mismatch: key is ML-DSA-65, algorithm is ML-DSA-44
|
|
```
|
|
|
|
## ML-DSA context strings
|
|
|
|
ML-DSA can mix a caller-chosen string into the signature. Give each job a
|
|
different context and one key can sign for several of them without a signature
|
|
made for one job verifying as another, so a login token cannot be presented as
|
|
a file receipt.
|
|
|
|
Signing and verifying must use the same context. A verifier that supplies the
|
|
wrong one, or none at all, sees an ordinary invalid signature and cannot tell
|
|
which mistake was made:
|
|
|
|
```go
|
|
login := &mldsa.Options{Context: "my-app/login-token"}
|
|
receipt := &mldsa.Options{Context: "my-app/file-receipt"}
|
|
|
|
sig, _ := dsig.SignWithOpts(sk, dsig.MLDSA65, payload, login, nil)
|
|
|
|
err := dsig.VerifyWithOpts(sk.PublicKey(), dsig.MLDSA65, payload, sig, login)
|
|
// nil
|
|
|
|
err = dsig.VerifyWithOpts(sk.PublicKey(), dsig.MLDSA65, payload, sig, receipt)
|
|
// mldsa: invalid signature
|
|
```
|
|
|
|
A context is at most 255 bytes, and it is empty when opts is nil.
|
|
|
|
# Description
|
|
|
|
This library provides low-level digital signature operations. It does minimal parameter validation for performance, uses strongly typed APIs, and has minimal dependencies.
|
|
|
|
# Contributions
|
|
|
|
## Issues
|
|
|
|
For bug reports and feature requests, please include failing tests when possible.
|
|
|
|
## Pull Requests
|
|
|
|
Please include tests that exercise your changes.
|
|
|
|
# Related Libraries
|
|
|
|
* [github.com/lestrrat-go/jwx](https://github.com/lestrrat-go/jwx) - JOSE (JWA/JWE/JWK/JWS/JWT) implementation
|