Skip to main content

Hardened, self-destructing memory cells for Python secrets, powered by Rust.

Project description

cypher_cell

Python Versions License Unit Tests Latest Release Platform Rust Backend

Hardened, self-destructing memory cells for Python secrets, powered by Rust.

cypher_cell is a Python extension module (written in Rust) that provides a secure, zero-leakage memory container for sensitive data such as API keys, passwords, cryptographic material, and tokens. Unlike standard Python strings and bytes, which are immutable, interned, and can linger in RAM or swap, cypher_cell ensures your secrets are:

  • Locked in RAM: Prevented from being swapped to disk using OS-level memory locking.
  • Zeroized: Overwritten with zeros immediately when no longer needed, leaving no trace in memory.
  • Ephemeral: Optionally destroyed after a single access or a configurable time-to-live (TTL).
  • Leak-resistant: Never exposed in logs, tracebacks, or accidental prints.

Why use cypher_cell?

Python's default memory model is not designed for handling secrets. Sensitive data can be copied, cached, or swapped to disk without your control. Attackers with access to memory dumps, swap files, or process introspection tools can easily recover secrets. cypher_cell is designed for developers and security engineers who need:

  • In-memory protection for credentials in long-running apps, CLI tools, or servers
  • Defense-in-depth for cryptographic operations
  • Secure handling of ephemeral secrets (e.g., one-time tokens, session keys)
  • Compliance with security standards that require memory zeroization

Features

  • 🔒 Memory Locking: Prevents secrets from being swapped to disk (OS-level protection).
  • 🧹 Guaranteed Zeroization: Memory is physically overwritten with zeros the moment the object is dropped or expires.
  • 👻 Volatile Mode: "Burn-after-reading" logic—the cell wipes itself immediately after one access.
  • ⏳ Time-To-Live (TTL): Secrets automatically vanish after a configurable duration.
  • 🛡️ Anti-Leak repr: Prevents accidental logging; print(cell) always shows [REDACTED].

🛡️ Advanced Hardening Features

cypher_cell includes several advanced memory and security hardening techniques beyond standard secret management:

Feature Implementation Benefit
Direct Env Loading from_env Secrets loaded directly from environment variables, never touching Python's heap.
Timing Protection verify (constant-time) Protects against timing attacks by using constant-time comparison for secret verification.
Anti-Core Dump MADV_DONTDUMP On Linux, secrets are excluded from core dumps if the process crashes.
Anti-Fork MADV_DONTFORK Prevents child processes from inheriting secret memory regions.
Binary Safety reveal_bytes Safely handles raw cryptographic keys and binary secrets, even if not valid UTF-8.

Implementation Details

  • Direct Env Loading: CypherCell.from_env("VAR") loads secrets directly from environment variables, minimizing exposure to Python's garbage-collected memory.
  • Timing Protection: The verify() method uses constant-time comparison to prevent attackers from inferring secrets via timing analysis.
  • Anti-Core Dump: On Linux, memory is marked with MADV_DONTDUMP so secrets are never written to disk in crash dumps.
  • Anti-Fork: Memory is marked with MADV_DONTFORK so child processes cannot inherit secret memory.
  • Binary Safety: reveal_bytes() allows safe handling of raw binary secrets (e.g., cryptographic keys) that may not be valid UTF-8, avoiding crashes and leaks.

🚀 Installation

Clone and build locally:

git clone https://github.com/yourusername/cypher_cell.git
cd cypher_cell
pip install maturin
maturin develop

🛠 Usage

⚠️ Pro Tip: To prevent the secret from ever hitting the Python heap, avoid CypherCell(b"my-secret"). Instead, use CypherCell.from_env("MY_SECRET") or (in future) CypherCell.from_file("/path/to/key") to load secrets directly from secure sources.

1. Basic Secure Vault

Keep a secret locked in RAM and ensure it is wiped as soon as you are done.

from cypher_cell import CypherCell

# Use as a Context Manager for maximum safety
with CypherCell(b"super-secret-key") as cell:
    # Use the secret
    db_connect(cell.reveal())
# Memory is now zeroed and unlocked

2. "Mission Impossible" Cell (Volatile + TTL)

Create a secret that disappears after one read or 30 seconds, whichever comes first.

vault = CypherCell(b"transient-key", volatile=True, ttl_sec=30)
print(vault.reveal())  # Works
print(vault.reveal())  # Raises ValueError (already wiped)

3. Masked Debugging

Reveal only what you need for logs.

cell = CypherCell(b"SK-7721-9904-1234")
print(cell.reveal_masked(suffix_len=4))  # Output: *************1234

4. Load Secret Directly from Environment

Avoids Python heap exposure by loading secrets straight from environment variables.

import os
from cypher_cell import CypherCell

os.environ["MY_SECRET"] = "env-value"
cell = CypherCell.from_env("MY_SECRET")
print(cell.reveal())  # env-value

5. Constant-Time Secret Verification

Protects against timing attacks when checking secrets.

cell = CypherCell(b"top-secret")
if cell.verify(b"top-secret"):
    print("Access granted!")
else:
    print("Access denied!")

6. Safe Binary Secret Handling

Safely work with raw cryptographic keys or binary data.

key = b"\x01\x02\x03\x04\x05\x06"
cell = CypherCell(key)
raw = cell.reveal_bytes()
assert raw == key

🏗 Architecture

cypher_cell bridges Python with low-level Rust primitives:

  • Creation: Data is copied into a Vec<u8> in Rust.
  • Locking: Calls libc::mlock (Unix) or VirtualLock (Windows) to pin memory to RAM.
  • Destruction: When the Python reference count hits zero or __exit__ is called, Rust executes the Drop trait, which calls zeroize and then unlocks the memory.

Known Weaknesses & Usage Tips

While cypher_cell protects the data within its vault, the act of passing a string to CypherCell or calling .reveal() creates temporary copies in Python's unmanaged memory. For maximum security, use the context manager and minimize the lifetime of the revealed string.

Note on .reveal(): When you call .reveal(), Python creates a standard, immutable string. While cypher_cell wipes its own internal memory, it cannot wipe the string Python just created. Always use secrets in the narrowest scope possible:

Warning on Literals: Avoid passing string literals directly like CypherCell("my_secret"). Python may intern these strings, keeping them in memory for the duration of the process regardless of what cypher_cell does. Always load from environment variables, files, or buffers.

# GOOD: String is short-lived
authenticate(cell.reveal())

# BAD: Secret lingers in the 'key' variable
key = cell.reveal()
authenticate(key)

🧪 Testing

Run the test suite with:

pytest tests/

⚖️ License

MIT © Rivendael

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cypher_cell-0.1.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cypher_cell-0.1.1-cp313-cp313-win_amd64.whl (116.9 kB view details)

Uploaded CPython 3.13Windows x86-64

cypher_cell-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (207.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.1-cp313-cp313-macosx_11_0_x86_64.whl (198.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ x86-64

cypher_cell-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (184.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cypher_cell-0.1.1-cp312-cp312-win_amd64.whl (117.1 kB view details)

Uploaded CPython 3.12Windows x86-64

cypher_cell-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.1-cp312-cp312-macosx_11_0_x86_64.whl (198.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ x86-64

cypher_cell-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (184.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cypher_cell-0.1.1-cp311-cp311-win_amd64.whl (116.3 kB view details)

Uploaded CPython 3.11Windows x86-64

cypher_cell-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (207.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.1-cp311-cp311-macosx_11_0_x86_64.whl (198.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

cypher_cell-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (184.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cypher_cell-0.1.1-cp310-cp310-win_amd64.whl (116.4 kB view details)

Uploaded CPython 3.10Windows x86-64

cypher_cell-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (207.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (197.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.1-cp310-cp310-macosx_11_0_x86_64.whl (198.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

cypher_cell-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (184.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file cypher_cell-0.1.1.tar.gz.

File metadata

  • Download URL: cypher_cell-0.1.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cypher_cell-0.1.1.tar.gz
Algorithm Hash digest
SHA256 380216f0d37aa9a522b86ad523a4c55daf3757f669ab64bcf50ea952ea26abd4
MD5 aead094bc7ca298f25ddca901d707b5a
BLAKE2b-256 44ec252ad961f8270c4270f66e4effd006cd58bd800ba6ff02f1f129b246068b

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6dfd487f14d4f566ad08c40c53cbe3c24ace1aebc344151600682ded779b545d
MD5 5c10012475c52bd9c0cce34f958cd829
BLAKE2b-256 74b607de77c8c633ceae6a7e40758414efc0479729781c2f2703ff303db48ba1

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b43156e7be020dce30ddfa902fe654a178498440fa22910b3ab2e568be0ea4d7
MD5 e44bb58fcf87e0ce5d4e2dcd1c550406
BLAKE2b-256 820cdb5137be13761224b437fca6a4b86dff194296fe8f64ee6d10a764e90688

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 38e1e0762e8f3a37152fd12a078659d80fb43164928ed136cd9443ff1f10c25d
MD5 ae1ba3c0a84d1c5eb96866c5f122ea36
BLAKE2b-256 aae6ebd170da214b5e1203751ace6b166b3b175550f068bdae0e39e0330679d4

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp313-cp313-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0c3a6f35269a91f87bd4af3073792437e29d03961866422243be01dcd5c7be55
MD5 7f72df918d4af1c126183e8e601a8ec5
BLAKE2b-256 fc6a992249019ebbb9b28f61f60a3164233ff89c118a71af26cdcda33de7878d

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 52d3b4e815b6f674ed099542066f0165582754de7f6d8264838670267e113937
MD5 d03d1359f3847ab5c4c9f59d870b371d
BLAKE2b-256 316b78aa0f0a695d45dcdf2d649365312f663f754cea7eb3574381ffe3c1189b

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 de2942a6df1028c47adc3229126a6e80eec315b9d934c7dc53f18d10e6cdb88b
MD5 fff6c6407314ccd354162ab05d9106ff
BLAKE2b-256 6bd70679218f9c5d26c4dcf729ad488615e2e94099380eb007e6668c98a2cb21

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb167ef4c3b71aa39bc1fc9464f3877517da5eed982912e3d856721d31024c96
MD5 4cf3e785535afbd811b3131baf45e7cc
BLAKE2b-256 ccd09d5778a906a572c53e41e215cb659545e22fa8ed23c48df37d0342b6fbe3

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2b64a69b13ca96fd10d02f9f3b38685741275bdeda1b44c7e8555b27fd51bfd0
MD5 8be28372b24a27aa711e5fce0b33191c
BLAKE2b-256 07113ae890f708aa18ae22b5c0916c661d9a09151eb0a2517f93c4d8b399d3f6

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp312-cp312-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 107585e4ebd0d6797af2fd33e9b6269e5c6d227c83f9ec49913f7cd58eb182ea
MD5 de1f9785d1957e1bfa20614fa9ab4e46
BLAKE2b-256 8ab47862930068ca371cece27b3f0f1bdc9583dd3eb3ecb7791c043aee30aaeb

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b498f3f6cee6db263e8322ec2b190ad47a17e485e288e24befb5ed0bf3bf19c
MD5 d8cb7ad799b7d777dc673f2c250160a8
BLAKE2b-256 89e80289f471a26d1ef81f06613783f2c10dae31823c00748506c78bfe7e11be

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 40d9401a3a6d42c6e338b8f1afbdb6d8b832e9b004ff2c4118c52899e6e826a7
MD5 e52acd79cdc462487501f3a8dcb51eee
BLAKE2b-256 526160aeebdc0f8b41e767a42c8ff976c51780d4dd97cd7ced4f10a93b3bb561

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b0feb4517da50164e03e8cebd9972c9e7e15615ab008bc7cd236623d8889143
MD5 f199fac37c11fe1f223241fe9033b2fd
BLAKE2b-256 fd5305f0daaa5256a16bd1efba33fb584792be9511e977f7e215528764ddd438

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9b0d0052c5ab708fdb3d9a1b2872d204cb5079dea9f66e870e55ef2b4778e350
MD5 ebc9f6cb5fba3060d213fa7bf88c34a6
BLAKE2b-256 5970f63976280dc70b6f98ae3908d2edc068dd80eabdc4b1603470765c260ebe

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f26a872b271ef89dd1a59ffcd66dda7ef13eeaa8c92a27dfb0a86686314ac976
MD5 4166f503d3102854d417bc7526f9540e
BLAKE2b-256 e28ddb34a77ccb21ccff5d7fd2bf170fabe7a916174fa1a59b14b4e989e14640

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8965982bd3ce666fced4a94087a065595fb2d3cefc25b66af894e44f3d2f6f93
MD5 c42b35fdfca20407e6f0657fab5aca4c
BLAKE2b-256 62e8fe096343522d6068c00fc777c123fb838bf63e56343afdb8e076d9dba3d5

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1ad4d6bb576adf02692cd6b44b858fe546748bf69b770ca7b7358a52bb9bbc30
MD5 ac523cc8b507e2a4adf44e33c0add790
BLAKE2b-256 44d1ffe3a2136e479682c27ebfd5a6e55b1ac1573e2b380e0845bc687ac77f44

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af9a1a0978ee8246b82a667a3bbe7773aca469bc378593243584f0ec677424c3
MD5 8cb00f3574d0d9f68f3f4366c3694a86
BLAKE2b-256 aba5f8da68b09a09288c05894b11ff51e5214e8abdcb4c8049ba52b70526f9b8

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 551e245509583a450b46b4e92f03f3ee33cb7ee9a6517341150cc27146a95fb5
MD5 87cb5b225d04fbe7240f0807a6aa9519
BLAKE2b-256 c9d12260aee917a574b57a37700398fd125a18511cc959e9293f69a846777ce2

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 8ec8c8937eb2b8829a13cd971943b9815856c3b834b799668b455dbffad5de53
MD5 e16188ea6e49417c4d6bfd3bbee0d31b
BLAKE2b-256 9644bc43be562e8a1b9c45597f2b1ee9cd0e19fa9ea876167943c7fa6e50c493

See more details on using hashes here.

File details

Details for the file cypher_cell-0.1.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypher_cell-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eac7b9b47a8f106aa75c506504668756708140b3b5dfdbe1447ed9eaf706dbd6
MD5 06c7e1392a1d663379e6e4b622e60d92
BLAKE2b-256 5d42736aafc6bda11f90366eac09c0666306ae0f9717de3b5e23a51f13af650c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page