ntpsec-rs-keygen 0.3.50

NTP key generator — forensic Rust reconstruction of ntpkeygen
ntpsec-rs-keygen-0.3.50 is not a library.

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, or AES-128-CMAC
  • key — 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

ntpkeygen-rs

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

ntpkeygen-rs -o /etc/ntp/ntp.keys

Generate a Specific Number of Keys

ntpkeygen-rs -n 4

Choose a Digest Algorithm

ntpkeygen-rs -d SHA256
ntpkeygen-rs -d AES-128-CMAC

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

ntpkeygen-rs -l 32 -d SHA256

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

ntpkeygen-rs -p

Prints the generated keys to stdout instead of writing them to a file. Useful for piping to other commands or displaying on screen.

ntpkeygen-rs -p -d SHA256 -n 2

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:

ntpd-rs -k /etc/ntp.keys --trustedkey 1 --trustedkey 2

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 crates.io
ntpsec-rs-io Real I/O layer (system clock, network, state store) crates.io
ntpsec-rs Umbrella facade crate crates.io
ntpsec-rs-d ntpd-rs — NTP daemon binary crates.io
ntpsec-rs-query ntpq-rs — Mode 6 query client crates.io
ntpsec-rs-dig ntpdig-rs — NTP query tool crates.io
ntpsec-rs-keygen NTP key generation crates.io
ntpsec-rs-leapfetch Leap second file fetcher crates.io
ntpsec-rs-mon Real-time NTP monitoring tool crates.io
ntpsec-rs-trace NTP path trace tool crates.io
ntpsec-rs-wait Wait until NTP server reachable crates.io
ntpsec-rs-viz NTP data visualization crates.io
ntpsec-rs-frob NTP configuration manipulator crates.io
ntpsec-rs-snmpd SNMP monitoring daemon crates.io
ntpsec-rs-time Single-shot time query tool crates.io
ntpsec-rs-sweep Sweep through servers collecting stats crates.io
ntpsec-rs-loggps GPS reference clock logging crates.io
ntpsec-rs-logtemp System temperature logging crates.io

GitHub Repository

https://github.com/infinityabundance/ntpsec-rs