Documentation
¶
Overview ¶
Package brainpool implements the Brainpool elliptic curves (RFC 5639) as the gematik Telematikinfrastruktur uses them: the curves themselves, certificate and key parsing the standard library refuses for these curves, and the signing and key-agreement entry points behind the josebp JOSE layer.
Constant-time posture ¶
Only operations on a secret scalar need a constant-time implementation, and only brainpoolP256r1 — the curve gematik issues software-held keys on — has one, the formally-verified core in internal/bp256:
operation secret implementation ECDSA sign (SignFuncPrivateKey) k, d internal/bp256, RFC 6979 nonce, low-s ECDH d internal/bp256 public key from private (parse, GenerateKey) d internal/bp256 ECDSA verify, certificate/JWK parsing — standard library brainpoolP384r1 / P512r1, everything — standard library generic path
The generic path is the deprecated big.Int arithmetic of crypto/elliptic, reached through an isomorphism onto the twisted t1 curves; it is fine for public data and for the curves that never hold a software key.
Where to look ¶
curves.go P256r1/P384r1/P512r1, the curve table, the rcurve isomorphism x509.go ParseCertificate, ValidatePublicKey, MarshalPKIXPublicKey keys.go ParsePrivateKeyPEM, ParsePKCS8PrivateKey, ParseECPrivateKey sign.go SignFunc, SignFuncPrivateKey, ECDH, GenerateKey josebp/ JWS, JWE (ECDH-ES), JWK over these curves internal/bp256/ the constant-time brainpoolP256r1 core and its fiat fields
README.md carries the full security posture and references.
Index ¶
- func ECDH(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey) ([]byte, error)
- func GenerateKey(curve elliptic.Curve, rng io.Reader) (*ecdsa.PrivateKey, error)
- func MarshalPKIXPublicKey(pub any) ([]byte, error)
- func P256r1() elliptic.Curve
- func P384r1() elliptic.Curve
- func P512r1() elliptic.Curve
- func ParseCertificate(der []byte) (*x509.Certificate, error)
- func ParseCertificatePEM(pemBytes []byte) (*x509.Certificate, error)
- func ParseECPrivateKey(der []byte) (*ecdsa.PrivateKey, error)
- func ParsePKCS8PrivateKey(der []byte) (any, error)
- func ParsePrivateKeyPEM(pemBytes []byte) (*ecdsa.PrivateKey, error)
- func ValidatePublicKey(pub *ecdsa.PublicKey) error
- type SignFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ECDH ¶ added in v1.1.0
ECDH returns the shared secret of priv and pub: the x-coordinate of priv·pub as a fixed-width big-endian value (BSI TR-03111 §3.5.1), which is the Z input of the JOSE Concat KDF. pub is validated before any arithmetic. brainpoolP256r1 runs in the constant-time core; other curves on the generic path.
func GenerateKey ¶ added in v1.1.0
GenerateKey returns a fresh private key on curve. Brainpool keys derive their public point through derivePublicKey, so a brainpoolP256r1 secret is never multiplied by variable-time code; any other curve is handed to the standard library. A nil rng means crypto/rand.
func MarshalPKIXPublicKey ¶
MarshalPKIXPublicKey is x509.MarshalPKIXPublicKey with Brainpool support: the standard library cannot name these curves in an AlgorithmIdentifier.
func P256r1 ¶
P256r1 returns a Curve which implements Brainpool P256r1 (see RFC 5639, section 3.4)
func P384r1 ¶
P384r1 returns a Curve which implements Brainpool P384r1 (see RFC 5639, section 3.6)
func P512r1 ¶
P512r1 returns a Curve which implements Brainpool P512r1 (see RFC 5639, section 3.7)
func ParseCertificate ¶
func ParseCertificate(der []byte) (*x509.Certificate, error)
ParseCertificate parses a DER certificate, accepting Brainpool public keys that crypto/x509 rejects with "unsupported elliptic curve".
crypto/x509 parses every field of a certificate whose public key algorithm it does not recognise and leaves PublicKey nil — it only refuses the EC algorithm with a curve it does not have. So for a Brainpool certificate the SPKI algorithm OID is swapped for an unknown one of the same length, the standard library parses the whole certificate, and only the public key is decoded here. The Raw* fields are restored from the original bytes.
func ParseCertificatePEM ¶
func ParseCertificatePEM(pemBytes []byte) (*x509.Certificate, error)
ParseCertificatePEM parses the first PEM block of pemBytes as a certificate.
func ParseECPrivateKey ¶
func ParseECPrivateKey(der []byte) (*ecdsa.PrivateKey, error)
ParseECPrivateKey parses a SEC 1 EC private key; keys on other curves are handed to x509.ParseECPrivateKey.
func ParsePKCS8PrivateKey ¶
ParsePKCS8PrivateKey parses a PKCS#8 private key; anything but an EC key on a Brainpool curve is handed to x509.ParsePKCS8PrivateKey.
func ParsePrivateKeyPEM ¶
func ParsePrivateKeyPEM(pemBytes []byte) (*ecdsa.PrivateKey, error)
ParsePrivateKeyPEM parses a PKCS#8 ("PRIVATE KEY") or SEC 1 ("EC PRIVATE KEY") PEM block holding an ECDSA key.
func ValidatePublicKey ¶ added in v1.1.0
ValidatePublicKey reports whether pub is a valid affine point on its curve: both coordinates canonical in [0, p-1] and the point on the curve, which also rejects the point at infinity (SEC 1 §3.2.2.1, BSI TR-03111 §3.2.2). Keys that arrive from the network — certificates, JWKs, ECDH peers — go through this before any arithmetic touches them.
Types ¶
type SignFunc ¶
SignFunc signs a digest and returns the raw fixed-width r‖s ECDSA signature (RFC 7518 §3.4). It abstracts over software keys and hardware tokens (smartcards via the gematik connector), where the private key is not extractable. The JOSE layer lives in brainpool/josebp.
func SignFuncPrivateKey ¶
func SignFuncPrivateKey(key *ecdsa.PrivateKey) SignFunc
SignFuncPrivateKey returns a SignFunc backed by a software ECDSA private key. For brainpoolP256r1 it signs in the constant-time core with an RFC 6979 deterministic nonce and low-s normalisation; every other curve signs with the standard library, which for the remaining Brainpool curves is the generic variable-time path — acceptable because the TI does not issue software-held keys on them.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
bp256
Package bp256 implements constant-time arithmetic for the brainpoolP256r1 elliptic curve (RFC 5639 §3.4), used by the parent brainpool package for the secret-scalar operations that must resist timing side channels: ECDSA signing and ECDH.
|
Package bp256 implements constant-time arithmetic for the brainpoolP256r1 elliptic curve (RFC 5639 §3.4), used by the parent brainpool package for the secret-scalar operations that must resist timing side channels: ECDSA signing and ECDH. |
|
bp256/fiat
Package fiat provides constant-time arithmetic in the two fields of brainpoolP256r1 (RFC 5639 §3.4): Element is an integer modulo the field prime p, Scalar an integer modulo the group order n.
|
Package fiat provides constant-time arithmetic in the two fields of brainpoolP256r1 (RFC 5639 §3.4): Element is an integer modulo the field prime p, Scalar an integer modulo the group order n. |
|
Package josebp is a self-contained JOSE (JWS/JWT/JWK/JWE) implementation for the Brainpool elliptic curves used by the gematik telematik infrastructure (IDP-Dienst, SMC-B, ePA).
|
Package josebp is a self-contained JOSE (JWS/JWT/JWK/JWE) implementation for the Brainpool elliptic curves used by the gematik telematik infrastructure (IDP-Dienst, SMC-B, ePA). |