Skip to Content
oxcrypto

DSA

Legacy DSA signatures with deterministic RFC 6979 nonces.

from oxcrypto.signature.dsa import DSA

private_key = DSA.generate(l=2048, n=256)
public_key = private_key.public_key()

signature = DSA.SHA256.sign(private_key, b"message")
assert DSA.SHA256.verify(public_key, signature, b"message")

Warning

DSA is legacy. FIPS 186-5 no longer approves DSA for generating signatures and allows it only to verify existing ones. Use it to interoperate with existing keys and signatures.

Variants name the hash: SHA1, SHA224, SHA256, SHA384, SHA512, SHA512_224, SHA512_256, SHA3_224, SHA3_256, SHA3_384 and SHA3_512. Signing derives the nonce deterministically from the key and digest with RFC 6979 and the variant's hash, so the same key and message always give the same signature. Signatures are DER-encoded (r, s) sequences.

generate creates FIPS 186-4 domain parameters and a key pair from the operating system CSPRNG. (l, n) must be (2048, 224), (2048, 256) (the default) or (3072, 256). Generating domain parameters takes from under a second to several seconds. Loading also accepts 1024-bit keys, for verifying existing signatures.

Private keys use PKCS#8 (format="pkcs8", with an optional password) and public keys use SubjectPublicKeyInfo (format="spki"), as DER or PEM.

Side channels

The dsa README states that the crate has never been independently audited and may contain timing variabilities or other side channels.

StandardFIPS 186-4 section 4 (superseded by FIPS 186-5, verification only); RFC 6979 (Informational)
Cratedsa 0.7.0 (RustCrypto, Apache-2.0 OR MIT), stable, with rfc6979 0.6.0
AuditNo published audit
MSRV1.85, builds with the project MSRV 1.88
ExperimentalNo (legacy)
Test vectorsWycheproof dsa_*_test.json; RFC 6979 appendices A.2.1 and A.2.2

On this page