XMSS
Sign with stateful XMSS and XMSS^MT hash-based signatures (RFC 8391, NIST SP 800-208).
Important
XMSS keys are stateful. Each signature advances the key, which must be stored durably before the signature is released. Reusing a saved state reuses one-time keys and breaks security.
import os
from oxcrypto.signature.xmss import XMSS
def store(state: bytes, path: str = "key.bin") -> None:
fd = os.open(path + ".tmp", os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
with os.fdopen(fd, "wb") as f:
f.write(state)
f.flush()
os.fsync(f.fileno())
os.replace(path + ".tmp", path) # also fsync the directory on POSIX
key = XMSS.XMSS_SHA2_10_256.generate()
signature = key.sign(b"hello")
store(key.to_bytes()) # durable before the signature is used
assert key.public_key().verify(signature, b"hello")
assert key.remaining == 1023XMSS is stateful. Each signature uses a one-time key at the next leaf index,
and signing twice with the same index can reveal the private key. The private
key advances its index before sign returns, and remaining reports how many
signatures are left; once it reaches 0, sign raises ValueError.
- Persist
to_bytes(), which includes the index, durably (written andfsynced) before you use a signature. If the process stops after you use a signature but before the new state is stored, reloading the old state reuses an index. - Never load the same state into two objects or two processes. Keys cannot be copied or pickled.
- After the last signature, the crate wipes the key material from the state.
public_key()still works on the object that signed, but raisesValueErroron an exhausted key loaded from bytes. - A key object can be shared between threads; signing is serialized by an internal lock.
Variant names follow RFC 8391 and SP 800-208: XMSS_<hash>_<height>_<bits>
for single trees and XMSSMT_<hash>_<height>_<layers>_<bits> for multi-tree
sets. NIST SP 800-208 approves the SHA2_*_192, SHA2_*_256,
SHAKE256_*_192 and SHAKE256_*_256 sets; the SHA2_*_512, SHAKE_*_256
and SHAKE_*_512 sets are from RFC 8391 only. Key generation and signing time
grow with the height of each tree layer: a height-10 tree takes seconds and
each extra level doubles the time.
Messages are signed without a context string. Keys load and serialize only in their raw encoding.
- Crate:
xmss0.1.0-pre.0 from RustCrypto, a pre-release with no published audit. It builds with Rust 1.88. - Tests: neither NIST ACVP nor the crate publish XMSS vectors. The tests cover round trips, index advance, exhaustion and rejection of bad input.