ntpsec-rs-keygen — ntpkeygen-rs
NTP symmetric key generation utility — generates keys for authenticated NTP communication.
Part of the ntpsec-rs workspace — a forensic Rust reconstruction of NTPsec. Version 0.3.48.
Overview
ntpkeygen-rs generates symmetric keys for NTP authentication. These keys are
used by ntpd-rs and other NTP tools to authenticate NTP packets using the
MAC (Message Authentication Code) field in NTP headers.
The tool produces keys in the standard ntp.keys format:
<keyno> <type> <key>
Where:
keyno— A unique numeric key identifier (1–65534)type— The digest/algorithm type:MD5,SHA1,SHA256, orAES-128-CMACkey— The hex-encoded key data
The output file is compatible with the NTPsec ntp.keys format and can be
used directly by ntpd-rs via the -k flag or keys directive in
ntp.conf.
Usage
Generate Default Keys
Generates 10 MD5 keys with 16-byte (128-bit) key material, writing to
/etc/ntp.keys:
# NTP keys generated by ntpkeygen-rs
# Digest: MD5, key length: 16 bytes
# Generated: 2025-01-15 12:34:56
1 MD5 a1b2c3d4e5f67890a1b2c3d4e5f67890
2 MD5 f0e1d2c3b4a5968778695a4b3c2d1e0f
...
10 MD5 0123456789abcdef0123456789abcdef
Specify Output File
Generate a Specific Number of Keys
Choose a Digest Algorithm
Supported digest types:
| Type | Description | Recommended Use |
|---|---|---|
MD5 |
128-bit MD5 MAC (default) | Legacy compatibility |
SHA1 |
160-bit SHA-1 HMAC | Legacy compatibility |
SHA256 |
256-bit SHA-256 HMAC | Production use |
AES-128-CMAC |
128-bit AES CMAC | High-security environments |
Custom Key Length
Generates 32-byte (256-bit) keys. Longer keys provide stronger cryptographic security but may not be supported by all NTP implementations.
Print Keys to stdout
Prints the generated keys to stdout instead of writing them to a file. Useful for piping to other commands or displaying on screen.
Command-Line Flags
| Flag | Description | Default |
|---|---|---|
-o, --output <file> |
Output file path | /etc/ntp.keys |
-n, --count <n> |
Number of keys to generate | 10 |
-d, --digest <type> |
Digest type: MD5, SHA1, SHA256, AES-128-CMAC | MD5 |
-l, --key-length <bytes> |
Key length in bytes | 16 |
-p, --print |
Print keys to stdout instead of writing to file | false |
Key File Format
The generated file follows the standard NTP key file format:
# NTP keys generated by ntpkeygen-rs
# Digest: MD5, key length: 16 bytes
# Generated: 2025-01-15 12:34:56
1 MD5 a1b2c3d4e5f67890a1b2c3d4e5f67890
2 SHA1 fedcba9876543210fedcba9876543210fedcba98
3 SHA256 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
4 AES-128-CMAC 00112233445566778899aabbccddeeff
Use this file with ntpd-rs:
Or in ntp.conf:
keys /etc/ntp.keys
trustedkey 1 2 3 4
Security Considerations
- Store the key file with restricted permissions (e.g.,
chmod 600) since it contains shared secrets. - Use a unique output file per host/MAC combination.
- For production deployments, prefer SHA-256 or AES-128-CMAC over MD5 or SHA-1, which are weakened by known cryptographic attacks.
- Rotate keys periodically, especially in high-traffic or sensitive environments.
Related Crates
All crates in the ntpsec-rs workspace on crates.io:
| Crate | Description | crates.io |
|---|---|---|
| ntpsec-rs-core | Deterministic engine, wire codec, Mode 6, auth, refclocks, NTS | |
| ntpsec-rs-io | Real I/O layer (system clock, network, state store) | |
| ntpsec-rs | Umbrella facade crate | |
| ntpsec-rs-d | ntpd-rs — NTP daemon binary | |
| ntpsec-rs-query | ntpq-rs — Mode 6 query client | |
| ntpsec-rs-dig | ntpdig-rs — NTP query tool | |
| ntpsec-rs-keygen | NTP key generation | |
| ntpsec-rs-leapfetch | Leap second file fetcher | |
| ntpsec-rs-mon | Real-time NTP monitoring tool | |
| ntpsec-rs-trace | NTP path trace tool | |
| ntpsec-rs-wait | Wait until NTP server reachable | |
| ntpsec-rs-viz | NTP data visualization | |
| ntpsec-rs-frob | NTP configuration manipulator | |
| ntpsec-rs-snmpd | SNMP monitoring daemon | |
| ntpsec-rs-time | Single-shot time query tool | |
| ntpsec-rs-sweep | Sweep through servers collecting stats | |
| ntpsec-rs-loggps | GPS reference clock logging | |
| ntpsec-rs-logtemp | System temperature logging |