Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Python classes and exceptions

Import names from the public quantaegis module. Keys, packets, messages and signatures in the tutorials are Python bytes. Keep secret keys and their copies out of logs. Type declarations · Public exports and SecurityPolicy

OperationResult
Envelope.generate_keypair("ml-kem-768")A tuple containing the serialized public key and secret key, in that order
Envelope.seal(public_key, plaintext, aad=..., aead=..., policy=...)Packet bytes for transmission
Envelope.open(secret_key, packet, aad=...)Authenticated plaintext. Failed authentication raises DecryptionError
Envelope.inspect(packet)KEM name, AEAD name and KEM ciphertext length from the unauthenticated header
MlDsa65.sign(signing_key, message, ctx=...)Signature bytes
MlDsa65.verify(verify_key, message, signature, ctx=...)None on success. A mismatched signature raises VerificationError

See the SDK examples for migrating stored envelopes, rotating signing keys, and importing recipient keys from PEM.

Receiving packets and rotating keys

Before checking the authentication tag, open checks the KEM declared in the header against the policy and recipient key. A forbidden KEM raises PolicyViolationError. An allowed KEM that differs from the key’s algorithm raises InvalidKeyError. An AAD mismatch or failed tag check raises DecryptionError. Even inspect can raise DecryptionError for an unreadable header. After validating local keys and arguments, a receiver can catch the common base QuantAegisError to reject an incoming packet.

Envelope.open_with_keyring accepts a sequence of bytes keys from different algorithms. It reads every key header and parses every matching key before trying decryption. An unreadable key header or malformed matching key raises InvalidKeyError, even when the ring contains a working key. Migrate archived envelopes before tightening the policy to exclude their KEM. Use AgileSignature.verify_with_keyring to verify signatures across a key rotation.

SDK policies

policyAlgorithms admitted by this version
cryptrec_category3_plusDefault for key generation, decryption and key decoding. Category 3 and above. Excludes ML-KEM-512, ML-DSA-44 and SLH-DSA-SHAKE-128s/f
permissiveAll implemented algorithms
nist_post_2030Currently all implemented algorithms, including Category 1 and 2. Selecting it admits more algorithms than the default
hybrid_requiredX-Wing for KEMs and MLDSA65-Ed25519-SHA512 for signatures

Python DER/PEM encoders use the permissive policy. For example, exporting an ML-KEM-512 public key to PEM succeeds, but loading it under the default policy raises PolicyViolationError. Pass an explicit policy to the decoder when your application accepts that algorithm. The public-key inspection helpers on AgileKem and AgileSignature default to permissive.

Signing and verification accept a context of up to 255 bytes. An overlong context raises QuantAegisError, and a malformed verification key raises InvalidKeyError. Python owns immutable bytes and str objects holding keys, shared secrets, decrypted plaintext or private-key PEM. The library cannot wipe these objects. Minimize their lifetime and copies. Encryption tutorial · Signing tutorial