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:

# 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.0.tar.gz (16.7 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.0-cp313-cp313-win_amd64.whl (136.3 kB view details)

Uploaded CPython 3.13Windows x86-64

cypher_cell-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (274.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (264.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.0-cp313-cp313-macosx_11_0_x86_64.whl (243.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ x86-64

cypher_cell-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (237.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cypher_cell-0.1.0-cp312-cp312-win_amd64.whl (136.7 kB view details)

Uploaded CPython 3.12Windows x86-64

cypher_cell-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (274.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (264.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.0-cp312-cp312-macosx_11_0_x86_64.whl (244.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ x86-64

cypher_cell-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (237.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cypher_cell-0.1.0-cp311-cp311-win_amd64.whl (137.3 kB view details)

Uploaded CPython 3.11Windows x86-64

cypher_cell-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (276.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (267.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.0-cp311-cp311-macosx_11_0_x86_64.whl (244.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

cypher_cell-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (238.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cypher_cell-0.1.0-cp310-cp310-win_amd64.whl (137.1 kB view details)

Uploaded CPython 3.10Windows x86-64

cypher_cell-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (276.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cypher_cell-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (267.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

cypher_cell-0.1.0-cp310-cp310-macosx_11_0_x86_64.whl (244.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

cypher_cell-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (238.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: cypher_cell-0.1.0.tar.gz
  • Upload date:
  • Size: 16.7 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.0.tar.gz
Algorithm Hash digest
SHA256 7006f6b6180e0913e500685b0c083d906147d41ad6ffdd6df2fcae71664d5169
MD5 ebbd71952773bd9b29650e533e56d831
BLAKE2b-256 3c720ae9f86d2098a25a043a6b1a59fe374b8e6718b68adbfd41ff4c2cc046c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 23376fb5af4ccd572e2661f82adf2cffe44553579d097daf6799aa99d829135a
MD5 9cca5f781f47c164a6e66f1bf7506889
BLAKE2b-256 258316e40a56c99207c7db382def004a7e8bce65a731f8fd8ae2c53b257f8b18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93b0c0cdd9521dc9948d9b1f9d02fdfe6888ba2ca8fee9559583e7e05ebbec2b
MD5 95666c4443efcb315860fccbe72ffe5c
BLAKE2b-256 02169da6b75ce25ea0e44bf790fbb31f5e006e295412b324dc9064d02be5d1da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bed633e97bdd091fd9c9c385d9c1fc459396a24883663fc91671d5feb53cf4e9
MD5 bb264102ab787ea5c8a7a53bfd01c4a0
BLAKE2b-256 67732f056f0341fcf44d0932785b15c0e21044d936459a30ac1e5763ee4bc017

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ef9706cc6ccaf6f6deb398c5acfe1b16f02f8c35aa9d4661e14c0e52f52c9f69
MD5 2e52fa7ad6669c1ef45e80ada005c9ff
BLAKE2b-256 feea02f9e947faeff204d18d8dec23a6f44710d353051c01d8e79eae8ab09f57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b24d09e88759cd6b3033143a8195abfd0e4f92215f76635f57d8a7c7f0580de5
MD5 7b7d11cef6f9be7de3f98081f50d169f
BLAKE2b-256 f7fc590f7838d1a190eb72284e0234153e77752f0ecb89e256efc6eeab3d03f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 189ccb9fa6bf9095e311177a8af64c36e9dd113c7a7d32135f22d1ea0405d9fb
MD5 62272b22dcb0cdb57fed0fe7a625cf0f
BLAKE2b-256 83f445eec29f60f0c7525710bdf0d6c94dcf91b5a96ff73a21fda74ef87242f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7d8fb4085ee3cd9721fe36b3e352b94cfadb7a35b006bf43b0c30e3d2204a9e
MD5 70ca0b954289009ca8c7cb3057f30b8b
BLAKE2b-256 402cf101c0d93422da05cbe32138e661327b088f05cf2cccb7327b9eb0dbc994

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4215134dd7b092133be038210a47c636d603ffd4605867a8dda67f6e31c369ef
MD5 299791555e525a9d3badbded6d963eee
BLAKE2b-256 265183f69176f1db21f724cbf5c418d824656cc063071e69b12ca3e73ad80adb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7a287cfd3d6ae61e846a7aa022766792546c9547c3beabb6f16d7f4f671818ff
MD5 1f4f2da912f819c2aeb85e5d276086d6
BLAKE2b-256 f85c44ad15af37333fd58c75332e7c51ec61403573a86507490fbd0fff3e3517

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c23532352f7c42142faf483fe835327a088ab3fb3db4e864226ac67d02f14088
MD5 eda44681ed5c933e5757350bec058ab4
BLAKE2b-256 aa50f1fae74b1f13e844ecb32ed961a248331dddb4ce6c5b81bd3188b0719b0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 43e0554d565a4320286466e6004dd2924c32cb36a938f07c012c0d8c03c844bd
MD5 2cfe88383934ebaf16c5d9d2af79e67c
BLAKE2b-256 80752f60b6f211ece6f9aa6c8fb1c4b4eaacebb222d0345fa802a44188670db7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ebc69bf7a9cf4cd7df85803a9a1c4d1dda2f04d45111e12cd7a5c0242a781061
MD5 1e656d426d9cd25c6611f9c731364e3a
BLAKE2b-256 43902a2d2a115c31163490076c1428ec368143ace4fae072125b6b7ca62a69d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 039542472ca2f605abe83131b612441e12bfe6780b5322203d7c9e2ce1439699
MD5 1ef363f97e1e42dcc366c37d574a39ab
BLAKE2b-256 70266bc2cbe33e7163e0b7f1918d216684da29376daa425e65582acca9eb08c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 5715ce310401bb4f8c362128d27637097828d202fc665c665f01acc745661352
MD5 3a020514233472284f4dbbaf6c6c9707
BLAKE2b-256 43fd15a7163aa76fc09aff8854e89e58af8ed40d15287554b6b5b5eded586336

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a035eb572fa0a7fa46473b6586cb94dea5960cbed39e42c297dcd261e87f1a04
MD5 24ddff984df81b586e78bb9fdd0c5d84
BLAKE2b-256 d83bd952d29cf14637c87273bc03ac5cccdd305f6c5160564587b319f51e7624

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6f855fe5e882c061c254ceb6c86fcca41854eb12977b7351cd7fd849fe306b28
MD5 18dad4c33e6dc9baf9bed7a4be42e238
BLAKE2b-256 3772c653d064c6622f23414e93e6f5fe5a665fe5056a7a04984168a6246f3606

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 61209d40bdb203362fe093aaf93ecb50abba08bfe0e29528167245e0c3a8479d
MD5 0e5fe20e9ac6e464e0d7b6a15c97b23c
BLAKE2b-256 b084e8ff00ee338582d591f587efb8dab0e699af8a0c405592809223e6082e32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 81f8ff0d3a60a40e953d9e9e9ce9cfeebe5b494a6714b34b61b44ee4e6e4f042
MD5 e933c93eedcc4538d078ebde8b0b8db9
BLAKE2b-256 da1575288ffc04e50df21a1a2db9a151c9f158f675294dddd94b45d273652fac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 9d2a7dbfd73c4f6c70a4556c33d7672882d064bb7891b093876122d375e0a587
MD5 d733c69ee13da0e2f7b7e0d4c316a634
BLAKE2b-256 4e5f7d5d29d4aa0cacd47a344298fa76cd332e649f8ccd929c0f7468e28a120f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cypher_cell-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 43afec1b19faaf008a5f301af042704aec3cc4c3dab3f5cacc0685fbffc255a3
MD5 5d7716e25524f8981873cfabb4445e2f
BLAKE2b-256 b00d7e3b8fcd36be3290b3857ed420825564ce7af3ed924c224c525819a656ff

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