# golang/crypto architecture

> Architecture diagram of the GitHub repository golang/crypto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/golang/crypto
- Repository: https://github.com/golang/crypto

## Overview

Go Cryptography is a collection of supplementary cryptographic primitives, protocol implementations, certificate tooling, and secure transport libraries. The principal workflow is: an application invokes a package API, the package parses or exchanges protocol data, applies cryptographic operations, and returns authenticated messages, keys, sessions, certificates, or trust roots. Major independent branches include SSH, ACME, OpenPGP, OTR, password/key derivation, AEAD/signatures, and certificate-root handling. The graph reflects the tree, README, and sampled source; unsampled package relationships are intentionally omitted.

Main entry points: [`ssh/client.go`](https://github.com/golang/crypto/blob/master/ssh/client.go) (SSH Client), [`acme/acme.go`](https://github.com/golang/crypto/blob/master/acme/acme.go) (ACME Client), [`ssh/server.go`](https://github.com/golang/crypto/blob/master/ssh/server.go) (SSH Server), [`ssh/agent/client.go`](https://github.com/golang/crypto/blob/master/ssh/agent/client.go) (Agent Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_protocols["Security Protocols"]
  node_ssh_client["SSH Client<br/>[client.go]"]
  node_ssh_auth["SSH Authentication<br/>[client_auth.go]"]
  node_ssh_server["SSH Server<br/>[server.go]"]
  node_agent_client["Agent Client<br/>[client.go]"]
  node_agent_server["Agent Server<br/>[server.go]"]
  node_acme_client["ACME Client<br/>[acme.go]"]
  node_otr_conversation["OTR Conversation<br/>[otr.go]"]
  node_openpgp["OpenPGP API<br/>[read.go]"]
end

subgraph group_crypto["Cryptographic Primitives"]
  node_argon2["Argon2 Derivation<br/>[argon2.go]"]
  node_chacha_aead["ChaCha20-Poly1305"]
  node_ed25519["Ed25519 Signatures<br/>[ed25519.go]"]
  node_curve25519["Curve25519 Exchange<br/>[curve25519.go]"]
  node_nacl_auth["NaCl Authentication<br/>[auth.go]"]
  node_hkdf["HKDF Derivation<br/>[hkdf.go]"]
end

subgraph group_formats["Encoding Layers"]
  node_cryptobyte["Cryptographic Bytes<br/>[string.go]"]
  node_openpgp_packet["OpenPGP Packets<br/>[packet.go]"]
end

subgraph group_trust["Certificate Trust"]
  node_nss_parser["NSS Root Parser<br/>[parser.go]"]
  node_fallback_roots["Fallback Roots<br/>[fallback.go]"]
  node_certificate_output["Certificate Results<br/>[types.go]"]
  node_trust_output[("Trusted Roots<br/>[roots.go]")]
end

node_application(("Application"))
node_ssh_peer(("SSH Peer"))
node_acme_ca(("ACME CA"))
node_agent_process(("SSH Agent"))
node_nss_source(("NSS Certdata"))

node_application -->|"opens connection"| node_ssh_client
node_ssh_client -->|"authenticates"| node_ssh_auth
node_ssh_client -->|"exchanges SSH"| node_ssh_peer
node_application -->|"accepts connection"| node_ssh_server
node_ssh_server -->|"serves SSH"| node_ssh_peer
node_application -->|"requests signatures"| node_agent_client
node_agent_client -->|"sends RPC"| node_agent_process
node_agent_process -->|"uses protocol"| node_agent_server
node_application -->|"manages certificates"| node_acme_client
node_acme_client -->|"requests issuance"| node_acme_ca
node_acme_client -->|"returns certificates"| node_certificate_output
node_application -->|"starts conversation"| node_otr_conversation
node_otr_conversation -.->|"exchanges messages"| node_ssh_peer
node_application -->|"reads or writes"| node_openpgp
node_openpgp -->|"encodes packets"| node_openpgp_packet
node_application -->|"derives password keys"| node_argon2
node_application -->|"seals messages"| node_chacha_aead
node_application -->|"signs messages"| node_ed25519
node_application -->|"establishes shared keys"| node_curve25519
node_application -->|"authenticates messages"| node_nacl_auth
node_application -->|"derives keys"| node_hkdf
node_application -->|"parses byte data"| node_cryptobyte
node_nss_source -->|"parses roots"| node_nss_parser
node_nss_parser -->|"returns trusted roots"| node_trust_output
node_application -->|"sets fallback roots"| node_fallback_roots
node_fallback_roots -->|"installs roots"| node_trust_output

click node_ssh_client "https://github.com/golang/crypto/blob/master/ssh/client.go"
click node_ssh_auth "https://github.com/golang/crypto/blob/master/ssh/client_auth.go"
click node_ssh_server "https://github.com/golang/crypto/blob/master/ssh/server.go"
click node_agent_client "https://github.com/golang/crypto/blob/master/ssh/agent/client.go"
click node_agent_server "https://github.com/golang/crypto/blob/master/ssh/agent/server.go"
click node_acme_client "https://github.com/golang/crypto/blob/master/acme/acme.go"
click node_otr_conversation "https://github.com/golang/crypto/blob/master/otr/otr.go"
click node_openpgp "https://github.com/golang/crypto/blob/master/openpgp/read.go"
click node_argon2 "https://github.com/golang/crypto/blob/master/argon2/argon2.go"
click node_chacha_aead "https://github.com/golang/crypto/blob/master/chacha20poly1305/chacha20poly1305.go"
click node_ed25519 "https://github.com/golang/crypto/blob/master/ed25519/ed25519.go"
click node_curve25519 "https://github.com/golang/crypto/blob/master/curve25519/curve25519.go"
click node_nacl_auth "https://github.com/golang/crypto/blob/master/nacl/auth/auth.go"
click node_hkdf "https://github.com/golang/crypto/blob/master/hkdf/hkdf.go"
click node_cryptobyte "https://github.com/golang/crypto/blob/master/cryptobyte/string.go"
click node_openpgp_packet "https://github.com/golang/crypto/blob/master/openpgp/packet/packet.go"
click node_nss_parser "https://github.com/golang/crypto/blob/master/x509roots/nss/parser.go"
click node_fallback_roots "https://github.com/golang/crypto/blob/master/x509roots/fallback/fallback.go"
click node_certificate_output "https://github.com/golang/crypto/blob/master/acme/types.go"
click node_trust_output "https://github.com/golang/crypto/blob/master/x509roots/fallback/bundle/roots.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ssh_client,node_ssh_auth,node_ssh_server,node_agent_client,node_agent_server,node_acme_client,node_otr_conversation,node_openpgp toneBlue
class node_argon2,node_chacha_aead,node_ed25519,node_curve25519,node_nacl_auth,node_hkdf toneAmber
class node_cryptobyte,node_openpgp_packet toneMint
class node_nss_parser,node_fallback_roots,node_certificate_output,node_trust_output toneRose
class node_application,node_ssh_peer,node_acme_ca,node_agent_process,node_nss_source toneIndigo
```

## Components

### Security Protocols

- [SSH Client](https://github.com/golang/crypto/blob/master/ssh/client.go): `ssh/client.go`
- [SSH Authentication](https://github.com/golang/crypto/blob/master/ssh/client_auth.go): `ssh/client_auth.go`
- [SSH Server](https://github.com/golang/crypto/blob/master/ssh/server.go): `ssh/server.go`
- [Agent Client](https://github.com/golang/crypto/blob/master/ssh/agent/client.go): `ssh/agent/client.go`
- [Agent Server](https://github.com/golang/crypto/blob/master/ssh/agent/server.go): `ssh/agent/server.go`
- [ACME Client](https://github.com/golang/crypto/blob/master/acme/acme.go): `acme/acme.go`
- [OTR Conversation](https://github.com/golang/crypto/blob/master/otr/otr.go): `otr/otr.go`
- [OpenPGP API](https://github.com/golang/crypto/blob/master/openpgp/read.go): `openpgp/read.go`

### Cryptographic Primitives

- [Argon2 Derivation](https://github.com/golang/crypto/blob/master/argon2/argon2.go): `argon2/argon2.go`
- [ChaCha20-Poly1305](https://github.com/golang/crypto/blob/master/chacha20poly1305/chacha20poly1305.go): `chacha20poly1305/chacha20poly1305.go`
- [Ed25519 Signatures](https://github.com/golang/crypto/blob/master/ed25519/ed25519.go): `ed25519/ed25519.go`
- [Curve25519 Exchange](https://github.com/golang/crypto/blob/master/curve25519/curve25519.go): `curve25519/curve25519.go`
- [NaCl Authentication](https://github.com/golang/crypto/blob/master/nacl/auth/auth.go): `nacl/auth/auth.go`
- [HKDF Derivation](https://github.com/golang/crypto/blob/master/hkdf/hkdf.go): `hkdf/hkdf.go`

### Encoding Layers

- [Cryptographic Bytes](https://github.com/golang/crypto/blob/master/cryptobyte/string.go): `cryptobyte/string.go`
- [OpenPGP Packets](https://github.com/golang/crypto/blob/master/openpgp/packet/packet.go): `openpgp/packet/packet.go`

### Certificate Trust

- [NSS Root Parser](https://github.com/golang/crypto/blob/master/x509roots/nss/parser.go): `x509roots/nss/parser.go`
- [Fallback Roots](https://github.com/golang/crypto/blob/master/x509roots/fallback/fallback.go): `x509roots/fallback/fallback.go`
- [Certificate Results](https://github.com/golang/crypto/blob/master/acme/types.go): `acme/types.go`
- [Trusted Roots](https://github.com/golang/crypto/blob/master/x509roots/fallback/bundle/roots.go): `x509roots/fallback/bundle/roots.go`

### Other components

- **Application**
- **SSH Peer**
- **ACME CA**
- **SSH Agent**
- **NSS Certdata**

## Connections

- Application → SSH Client: opens connection
- SSH Client → SSH Authentication: authenticates
- SSH Client → SSH Peer: exchanges SSH
- Application → SSH Server: accepts connection
- SSH Server → SSH Peer: serves SSH
- Application → Agent Client: requests signatures
- Agent Client → SSH Agent: sends RPC
- SSH Agent → Agent Server: uses protocol
- Application → ACME Client: manages certificates
- ACME Client → ACME CA: requests issuance
- ACME Client → Certificate Results: returns certificates
- Application → OTR Conversation: starts conversation
- OTR Conversation → SSH Peer: exchanges messages
- Application → OpenPGP API: reads or writes
- OpenPGP API → OpenPGP Packets: encodes packets
- Application → Argon2 Derivation: derives password keys
- Application → ChaCha20-Poly1305: seals messages
- Application → Ed25519 Signatures: signs messages
- Application → Curve25519 Exchange: establishes shared keys
- Application → NaCl Authentication: authenticates messages
- Application → HKDF Derivation: derives keys
- Application → Cryptographic Bytes: parses byte data
- NSS Certdata → NSS Root Parser: parses roots
- NSS Root Parser → Trusted Roots: returns trusted roots
- Application → Fallback Roots: sets fallback roots
- Fallback Roots → Trusted Roots: installs roots
