Wrap an encryption key or password so its memory is cleared automatically when no longer used.
Lock secret data in memory so it is never written to disk swap space.
Compare authentication codes or tokens in constant time to avoid timing side-channel leaks.
Build embedded or no_std cryptography code that needs secure memory handling without an allocator.
| m-novotny/memguard-rs | suiyuebaobao/c-ssh | activetk/vramdisk | |
|---|---|---|---|
| Stars | 131 | 143 | 116 |
| Language | Rust | Rust | Rust |
| Setup difficulty | — | moderate | hard |
| Complexity | 3/5 | 2/5 | 4/5 |
| Audience | developer | ops devops | developer |
Figures from each repo's GitHub metadata at analysis time.
memguard-rs is a Rust library that provides tools for handling sensitive data, like encryption keys or passwords, safely in memory. Ordinary variables in a program can leave copies of secret data lingering in memory after they are no longer needed, or leak timing information when compared, and this library gives developers building security or cryptography code a set of building blocks to avoid those problems. The core type is a Secret wrapper that only lets code access the value inside a closure, so it cannot easily be copied around by accident. When a Secret goes out of scope, its memory is cleared using volatile writes, a technique that stops the compiler from optimizing away the clearing step. Secrets can also be locked in memory using mlock on Unix or VirtualLock on Windows, which prevents the operating system from writing that memory to disk swap space, where it could persist longer than intended. The library also provides a constant-time comparison function for checking whether two byte sequences match without leaking how long the comparison took, which matters for things like verifying message authentication codes. A GuardedRegion type offers a fixed-size, automatically zeroized and lockable block of memory sized at compile time. The library has zero external dependencies, which keeps the amount of code that needs auditing small, and it can run in no_std environments, meaning it works without Rust's standard library, which matters for embedded systems. Optional features control whether standard library and heap-allocated support are enabled, and whether the memory locking feature is compiled in. The README documents exactly where it uses unsafe Rust code internally, covering the volatile memory writes, the direct system calls used for memory locking, and a mechanism to guarantee that data is zeroed before it is dropped, and states that no unsafe code is exposed through the public API. The minimum supported Rust version is 1.65. The project is dual-licensed under the MIT and Apache 2.0 licenses, and the README lists specific beginner-friendly issues for people who want to contribute, such as extending the zeroization support to more slice types.
A dependency-free Rust library for handling secrets safely in memory: zeroization on drop, memory locking, and constant-time comparison.
Mainly Rust. The stack also includes Rust, Cargo.
You can choose either the MIT license or the Apache 2.0 license, both of which allow free use, modification, and distribution, including commercially, as long as you keep the copyright and license notices.
Mainly developer.
This repo across BitVibe Labs
Don't trust strangers blindly. Verify against the repo.