gitwtfhub

wtf is memguard-rs?

m-novotny/memguard-rs — explained in plain English

Analysis updated 2026-05-18

131RustAudience · developerComplexity · 3/5License

TL;DR

A dependency-free Rust library for handling secrets safely in memory: zeroization on drop, memory locking, and constant-time comparison.

Mindmap

mindmap
  root((memguard-rs))
    What it does
      Zeroizes secrets on drop
      Locks memory from swap
      Constant-time comparison
      Guarded fixed-size regions
    Design
      Zero dependencies
      no_std compatible
      Unsafe code documented
    Tech stack
      Rust
      Cargo crate
    Use cases
      Store encryption keys safely
      Compare MACs without timing leak
      Build embedded crypto code
    Notes
      MSRV 1.65
      MIT or Apache-2.0

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Wrap an encryption key or password so its memory is cleared automatically when no longer used.

REASON 2

Lock secret data in memory so it is never written to disk swap space.

REASON 3

Compare authentication codes or tokens in constant time to avoid timing side-channel leaks.

REASON 4

Build embedded or no_std cryptography code that needs secure memory handling without an allocator.

What's in the stack?

RustCargo

How it stacks up

m-novotny/memguard-rssuiyuebaobao/c-sshactivetk/vramdisk
Stars131143116
LanguageRustRustRust
Setup difficultymoderatehard
Complexity3/52/54/5
Audiencedeveloperops devopsdeveloper

Figures from each repo's GitHub metadata at analysis time.

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.

Wtf does this do

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.

Yoink these prompts

Prompt 1
Show me how to wrap a secret key using memguard-rs's Secret type in my Rust project.
Prompt 2
Explain what mlock and VirtualLock do in memguard-rs and why locking secret memory matters.
Prompt 3
Help me use memguard-rs's constant-time comparison to verify a MAC safely.
Prompt 4
Explain where memguard-rs uses unsafe Rust internally and why it says that's safe.

Frequently asked questions

wtf is memguard-rs?

A dependency-free Rust library for handling secrets safely in memory: zeroization on drop, memory locking, and constant-time comparison.

What language is memguard-rs written in?

Mainly Rust. The stack also includes Rust, Cargo.

What license does memguard-rs use?

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.

Who is memguard-rs for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.