# guanzhi/gmssl architecture

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

- Interactive diagram: https://gitdiagram.com/guanzhi/gmssl
- Repository: https://github.com/guanzhi/gmssl

## Overview

GmSSL is a C cryptography library and command-line suite. A typical user invokes a `gmssl` command to perform cryptographic operations or handle certificates and then uses the result in an application; TLS/TLCP and QUIC provide separate secure-communication workflows. The map preserves documented algorithm, certificate, post-quantum, and hardware capabilities. Source excerpts are limited, so some connections between command front ends and implementation modules are shown as unverified rather than asserted.

Main entry points: [`tools/gmssl.c`](https://github.com/guanzhi/gmssl/blob/master/tools/gmssl.c) (Command dispatcher), [`tools/sm4.c`](https://github.com/guanzhi/gmssl/blob/master/tools/sm4.c) (Crypto commands), [`src/tls13.c`](https://github.com/guanzhi/gmssl/blob/master/src/tls13.c) (TLS and TLCP), [`tools/certgen.c`](https://github.com/guanzhi/gmssl/blob/master/tools/certgen.c) (Certificate commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command-line tools"]
  node_gmssl["Command dispatcher<br/>[gmssl.c]"]
  node_crypto_tools["Crypto commands<br/>[sm4.c]"]
  node_cert_tools["Certificate commands<br/>[certgen.c]"]
  node_cms_tools["CMS commands<br/>[cmsencrypt.c]"]
  node_pq_tools["PQ commands<br/>[kyberkeygen.c]"]
  node_tls_clients["TLS clients<br/>[tls13_client.c]"]
  node_tlcp_client["TLCP client<br/>[tlcp_client.c]"]
  node_quic_client["QUIC client<br/>[quic_client.c]"]
  node_quic_server["QUIC server<br/>[quic_server.c]"]
end

subgraph group_crypto["Cryptographic primitives"]
  node_block_ciphers["Block ciphers<br/>[sm4.c]"]
  node_hashes["Hash functions<br/>[sm3.c]"]
  node_public_key["Public-key crypto<br/>[sm2_key.c]"]
  node_post_quantum["Post-quantum crypto<br/>[kyber.c]"]
  node_kdf_mac["KDF and MAC<br/>[hkdf.c]"]
end

subgraph group_pki["Certificates and envelopes"]
  node_x509["X.509 and CRL<br/>[x509_cer.c]"]
  node_cms["CMS envelopes<br/>[cms.c]"]
  node_ocsp["OCSP status<br/>[ocsp.c]"]
end

subgraph group_protocols["Secure protocols"]
  node_tls_core["TLS and TLCP<br/>[tls13.c]"]
  node_tls12["TLS 1.2<br/>[tls12.c]"]
  node_tlcp_core["TLCP protocol<br/>[tlcp.c]"]
  node_quic_core["QUIC protocol<br/>[quic.c]"]
end

subgraph group_hardware["Hardware providers"]
  node_sdf["SDF provider<br/>[sdf_lib.c]"]
  node_skf["SKF provider<br/>[skf_lib.c]"]
end

node_user(("CLI user"))
node_hardware_device["Crypto hardware"]

node_user -.->|"invokes"| node_gmssl
node_gmssl -.->|"dispatches"| node_crypto_tools
node_gmssl -.->|"dispatches"| node_cert_tools
node_gmssl -.->|"dispatches"| node_cms_tools
node_gmssl -.->|"dispatches"| node_pq_tools
node_crypto_tools -.->|"uses"| node_block_ciphers
node_crypto_tools -.->|"uses"| node_hashes
node_crypto_tools -.->|"uses"| node_public_key
node_pq_tools -.->|"uses"| node_post_quantum
node_cert_tools -.->|"uses"| node_x509
node_cms_tools -.->|"uses"| node_cms
node_tls_clients -.->|"calls"| node_tls_core
node_tls_core -.->|"supports"| node_tls12
node_tlcp_client -.->|"calls"| node_tlcp_core
node_quic_client -.->|"uses"| node_quic_core
node_quic_server -.->|"uses"| node_quic_core
node_tls_core -.->|"verifies certificates"| node_x509
node_tls_core -.->|"supports status"| node_ocsp
node_sdf -.->|"dispatches operations"| node_hardware_device
node_skf -.->|"dispatches operations"| node_hardware_device

click node_gmssl "https://github.com/guanzhi/gmssl/blob/master/tools/gmssl.c"
click node_crypto_tools "https://github.com/guanzhi/gmssl/blob/master/tools/sm4.c"
click node_cert_tools "https://github.com/guanzhi/gmssl/blob/master/tools/certgen.c"
click node_cms_tools "https://github.com/guanzhi/gmssl/blob/master/tools/cmsencrypt.c"
click node_pq_tools "https://github.com/guanzhi/gmssl/blob/master/tools/kyberkeygen.c"
click node_tls_clients "https://github.com/guanzhi/gmssl/blob/master/tools/tls13_client.c"
click node_tlcp_client "https://github.com/guanzhi/gmssl/blob/master/tools/tlcp_client.c"
click node_quic_client "https://github.com/guanzhi/gmssl/blob/master/tools/quic_client.c"
click node_quic_server "https://github.com/guanzhi/gmssl/blob/master/tools/quic_server.c"
click node_block_ciphers "https://github.com/guanzhi/gmssl/blob/master/src/sm4.c"
click node_hashes "https://github.com/guanzhi/gmssl/blob/master/src/sm3.c"
click node_public_key "https://github.com/guanzhi/gmssl/blob/master/src/sm2_key.c"
click node_post_quantum "https://github.com/guanzhi/gmssl/blob/master/src/kyber.c"
click node_kdf_mac "https://github.com/guanzhi/gmssl/blob/master/src/hkdf.c"
click node_x509 "https://github.com/guanzhi/gmssl/blob/master/src/x509_cer.c"
click node_cms "https://github.com/guanzhi/gmssl/blob/master/src/cms.c"
click node_ocsp "https://github.com/guanzhi/gmssl/blob/master/src/ocsp.c"
click node_tls_core "https://github.com/guanzhi/gmssl/blob/master/src/tls13.c"
click node_tls12 "https://github.com/guanzhi/gmssl/blob/master/src/tls12.c"
click node_tlcp_core "https://github.com/guanzhi/gmssl/blob/master/src/tlcp.c"
click node_quic_core "https://github.com/guanzhi/gmssl/blob/master/src/quic.c"
click node_sdf "https://github.com/guanzhi/gmssl/blob/master/src/sdf/sdf_lib.c"
click node_skf "https://github.com/guanzhi/gmssl/blob/master/src/skf/skf_lib.c"

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_gmssl,node_crypto_tools,node_cert_tools,node_cms_tools,node_pq_tools,node_tls_clients,node_tlcp_client,node_quic_client,node_quic_server,node_user toneBlue
class node_block_ciphers,node_hashes,node_public_key,node_post_quantum,node_kdf_mac toneAmber
class node_x509,node_cms,node_ocsp toneMint
class node_tls_core,node_tls12,node_tlcp_core,node_quic_core toneRose
class node_sdf,node_skf,node_hardware_device toneIndigo
```

## Components

### Command-line tools

- [Command dispatcher](https://github.com/guanzhi/gmssl/blob/master/tools/gmssl.c): `tools/gmssl.c`
- [Crypto commands](https://github.com/guanzhi/gmssl/blob/master/tools/sm4.c): `tools/sm4.c`
- [Certificate commands](https://github.com/guanzhi/gmssl/blob/master/tools/certgen.c): `tools/certgen.c`
- [CMS commands](https://github.com/guanzhi/gmssl/blob/master/tools/cmsencrypt.c): `tools/cmsencrypt.c`
- [PQ commands](https://github.com/guanzhi/gmssl/blob/master/tools/kyberkeygen.c): `tools/kyberkeygen.c`
- [TLS clients](https://github.com/guanzhi/gmssl/blob/master/tools/tls13_client.c): `tools/tls13_client.c`
- [TLCP client](https://github.com/guanzhi/gmssl/blob/master/tools/tlcp_client.c): `tools/tlcp_client.c`
- [QUIC client](https://github.com/guanzhi/gmssl/blob/master/tools/quic_client.c): `tools/quic_client.c`
- [QUIC server](https://github.com/guanzhi/gmssl/blob/master/tools/quic_server.c): `tools/quic_server.c`

### Cryptographic primitives

- [Block ciphers](https://github.com/guanzhi/gmssl/blob/master/src/sm4.c): `src/sm4.c`
- [Hash functions](https://github.com/guanzhi/gmssl/blob/master/src/sm3.c): `src/sm3.c`
- [Public-key crypto](https://github.com/guanzhi/gmssl/blob/master/src/sm2_key.c): `src/sm2_key.c`
- [Post-quantum crypto](https://github.com/guanzhi/gmssl/blob/master/src/kyber.c): `src/kyber.c`
- [KDF and MAC](https://github.com/guanzhi/gmssl/blob/master/src/hkdf.c): `src/hkdf.c`

### Certificates and envelopes

- [X.509 and CRL](https://github.com/guanzhi/gmssl/blob/master/src/x509_cer.c): `src/x509_cer.c`
- [CMS envelopes](https://github.com/guanzhi/gmssl/blob/master/src/cms.c): `src/cms.c`
- [OCSP status](https://github.com/guanzhi/gmssl/blob/master/src/ocsp.c): `src/ocsp.c`

### Secure protocols

- [TLS and TLCP](https://github.com/guanzhi/gmssl/blob/master/src/tls13.c): `src/tls13.c`
- [TLS 1.2](https://github.com/guanzhi/gmssl/blob/master/src/tls12.c): `src/tls12.c`
- [TLCP protocol](https://github.com/guanzhi/gmssl/blob/master/src/tlcp.c): `src/tlcp.c`
- [QUIC protocol](https://github.com/guanzhi/gmssl/blob/master/src/quic.c): `src/quic.c`

### Hardware providers

- [SDF provider](https://github.com/guanzhi/gmssl/blob/master/src/sdf/sdf_lib.c): `src/sdf/sdf_lib.c`
- [SKF provider](https://github.com/guanzhi/gmssl/blob/master/src/skf/skf_lib.c): `src/skf/skf_lib.c`

### Other components

- **CLI user**
- **Crypto hardware**

## Connections

- CLI user → Command dispatcher: invokes (evidence: `README.md`)
- Command dispatcher → Crypto commands: dispatches
- Command dispatcher → Certificate commands: dispatches
- Command dispatcher → CMS commands: dispatches
- Command dispatcher → PQ commands: dispatches
- Crypto commands → Block ciphers: uses (evidence: `README.md`)
- Crypto commands → Hash functions: uses (evidence: `README.md`)
- Crypto commands → Public-key crypto: uses (evidence: `README.md`)
- PQ commands → Post-quantum crypto: uses (evidence: `README.md`)
- Certificate commands → X.509 and CRL: uses (evidence: `README.md`)
- CMS commands → CMS envelopes: uses (evidence: `README.md`)
- TLS clients → TLS and TLCP: calls
- TLS and TLCP → TLS 1.2: supports (evidence: `README.md`)
- TLCP client → TLCP protocol: calls
- QUIC client → QUIC protocol: uses
- QUIC server → QUIC protocol: uses
- TLS and TLCP → X.509 and CRL: verifies certificates (evidence: `README.md`)
- TLS and TLCP → OCSP status: supports status (evidence: `README.md`)
- SDF provider → Crypto hardware: dispatches operations (evidence: `src/sdf/sdf_lib.c`)
- SKF provider → Crypto hardware: dispatches operations
