Miscreant (Python)

0.3.0 · abandoned · verified Sat Apr 11

Miscreant.py is a Python implementation of the Miscreant advanced symmetric encryption library, providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions. These algorithms offer misuse-resistant authenticated encryption, particularly AES-SIV, which prevents catastrophic failures from nonce reuse. The last stable version is 0.3.0, released in December 2017, and the project is effectively unmaintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the AES-SIV cipher, encrypt a plaintext message with associated data, and then decrypt it. Note the requirement for a key of 32 or 64 bytes.

import os
from miscreant.aes.siv import SIV

# AES-SIV requires a key twice the size of a standard AES key (e.g., 32 or 64 bytes)
# For a 128-bit AES-SIV key, generate 32 bytes (2 * 16 bytes)
key = os.urandom(32) 

siv = SIV(key)

plaintext = b"This is my secret message!"
# Associated data (AD) is authenticated but not encrypted
associated_data = [b"header1", b"header2"]

# Encrypt (seal) the message
ciphertext = siv.seal(plaintext, ad=associated_data)
print(f"Ciphertext: {ciphertext.hex()}")

# Decrypt (open) the message
try:
    decrypted_plaintext = siv.open(ciphertext, ad=associated_data)
    print(f"Decrypted: {decrypted_plaintext.decode()}")
except Exception as e:
    print(f"Decryption failed: {e}")

view raw JSON →