Skip to Content
oxcrypto

Signatures

Sign and verify messages with RSA, DSA, elliptic-curve, post-quantum and stateful hash-based signatures.

Each selector variant names a signature scheme, and for RSA and DSA its hash, for example RSA.PSS_SHA256 or ECDSA.P256. sign returns signature bytes and verify returns True or False. A signature that does not verify, including a malformed one, returns False. RSA and DSA also provide sign_prehash and verify_prehash, which take a digest computed with the variant's hash instead of the message.

Keys come from generate() or the selector's load functions, and private_key.public_key() returns the matching public key. Keys serialize with to_der() and to_pem(). PKCS#8 private keys accept a keyword-only password, which encrypts them with PBES2 (scrypt and AES-256-CBC, the pkcs8 crate's default). Before deriving a key, imports raise ValueError unless scrypt N is a power of two from 2 to 2**20, r * p is below 2**30 and the scrypt memory 128 * r * N is at most 1 GiB, and unless the PBKDF2 iteration count is at most 10,000,000.

Invalid parameters, malformed keys and wrong passwords raise ValueError. Inputs that are not bytes, int, the expected key type or a hash selector from oxcrypto.hash raise TypeError.

Algorithms

  • RSA RSASSA-PKCS1-v1_5 and RSASSA-PSS (RFC 8017).
  • DSA Legacy FIPS 186-4 DSA with deterministic RFC 6979 nonces.
  • ECDSA P-224, P-256, P-384, P-521, secp256k1, brainpoolP256r1, brainpoolP384r1, brainpoolP256t1 and brainpoolP384t1.
  • Schnorr BIP 340 Schnorr signatures over secp256k1.
  • Ed25519 Ed25519 and Ed25519ph (RFC 8032).
  • Ed448 Ed448 and Ed448ph (RFC 8032), experimental.
  • ML-DSA FIPS 204 module-lattice signatures (ml-dsa 0.1.2).
  • SLH-DSA FIPS 205 stateless hash-based signatures (slh-dsa 0.2.0-rc.5, pre-release).
  • FN-DSA Experimental: FIPS 206 is still a draft (fn-dsa 0.4.0).
  • XMSS and XMSS^MT RFC 8391 and NIST SP 800-208 stateful hash-based signatures (xmss 0.1.0-pre.0, pre-release).
  • BLS BLS signatures over BLS12-381 with aggregation and proofs of possession (experimental).
  • sr25519 Schnorr signatures over ristretto255 with a signing context (experimental).
  • RSA blind signatures RFC 9474 RSABSSA-SHA384 blind signatures (experimental).

ML-DSA, SLH-DSA, FN-DSA and XMSS keys also load from and serialize to their raw encodings with load_private_key, load_public_key and to_bytes(), and accept an optional context of up to 255 bytes where the standard defines one. XMSS keys are stateful: each signature advances the key, and remaining reports how many signatures are left.

Keys

Private keys are concrete classes per algorithm (for example ECDSAPrivateKey). Their repr does not show key material, they cannot be copied or pickled, and equality is computed in constant time. generate() draws key material from the operating system CSPRNG.

Zeroization

The upstream crates are written to zeroize the secret parts of the key objects oxcrypto keeps when they are freed: the RSA private exponent and primes (rsa), the DSA private component x (dsa) and the secret scalar of ecdsa::SigningKey and k256::schnorr::SigningKey, the ML-DSA seed and expanded key, the SLH-DSA SK.seed and SK.prf, the FN-DSA decoded signing key and the XMSS key bytes with their index. oxcrypto keeps the encoded FN-DSA key in a zeroizing buffer. oxcrypto has not verified this independently beyond reading the crate sources. The DER and raw buffers oxcrypto builds while serializing a private key are wiped before they are freed.

rsa 0.10 does not zeroize its cached CRT values (the coefficient qInv and the Montgomery parameters of p that it references). oxcrypto therefore drops the CRT values right after a key is generated or loaded, so the key object keeps only state that rsa zeroizes, and private-key operations use the non-CRT path.

Zeroization does not cover:

  • Messages, digests, signatures, passwords and serialized keys passed in or returned as Python bytes, including to_bytes(), to_der() and to_pem() output of a private key. Python owns these objects. oxcrypto does not wipe them, and Python may copy them or leave them in freed memory.
  • Short-lived copies the upstream crates make during a call:
    • RSA and DSA: the CRT values freed once at load or generation time, crypto-bigint temporaries during RSA private operations and DSA signing (blinding factors, resized copies of x, the nonce k and its inverse).
    • ECDSA and Schnorr: the encoded secret scalar and the ephemeral scalar k in ecdsa, and the BIP 340 nonce inputs in k256.
    • All deterministic-nonce schemes: the RFC 6979 HMAC_DRBG state K and V.
    • ML-DSA: the mask y, ρ″, w, c·s1, c·s2, c·t0 and the signing randomness. SLH-DSA: hash and WOTS+ chain temporaries. FN-DSA: sampler and key generation buffers. XMSS: chain values and key generation buffers.
    • The ML-DSA and SLH-DSA buffers built while encoding PKCS#8, before any password encryption.
  • The PBES2 key that pkcs5 derives from password while encrypting or decrypting a PKCS#8 document; pkcs5 0.8.1 does not wipe it.
  • Copies left behind when Rust moves a key into its Python object.

Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.

On this page