jedisct1/libhydrogen logo

jedisct1/libhydrogen

Free

A lightweight, secure, easy-to-use crypto library suitable for constrained environments.

FreeFree tier
Type
Open Source

About jedisct1/libhydrogen

The Hydrogen library is a small, easy-to-use, hard-to-misuse cryptographic library designed for constrained environments. It exposes a consistent high-level API inspired by libsodium, built using only the Curve25519 elliptic curve and the Gimli permutation. The code is implemented as one tiny file per set of operations, making it simple to audit and integrate. It requires zero dynamic memory allocations and has low stack requirements (median 32 bytes, maximum 128 bytes), enabling use on microcontrollers and embedded systems. Written in portable C99, it supports Linux, *BSD, macOS, Windows, and the Arduino IDE out of the box. The library can generate cryptographically secure random numbers even on Arduino boards and attempts to mitigate the implications of accidental misuse. It is released under the permissive ISC license.

Key Features

Consistent high-level API inspired by libsodium
Built using only two cryptographic primitives: Curve25519 (elliptic curve) and Gimli permutation
Small codebase: one tiny .c file per set of operations
Zero dynamic memory allocations
Low stack requirements: median 32 bytes, max 128 bytes
Portable: written in standard C99, supports Linux, BSD, macOS, Windows, Arduino IDE
Can generate cryptographically secure random numbers on Arduino boards
Mitigates accidental misuse, even on systems with unreliable PRG or no clock
Released under the permissive ISC license
Easy to audit due to minimal code size

Pros & Cons

Pros
  • Very small footprint and low resource usage
  • Hard to misuse by design, with built-in safety mitigations
  • Single liberal license (ISC) simplifies integration
  • Supports Arduino and other constrained platforms without external dependencies
  • Only two cryptographic building blocks, reducing attack surface
Cons
  • No interoperability with other crypto libraries or protocols
  • Limited to Curve25519 and Gimli; no fallback or alternative primitives
  • Networking not included (though key exchange based on Noise is available)
  • Not intended to replace more feature-rich libraries like libsodium
  • No official releases or versioning on GitHub (no releases published)

Best For

Embedded systems and microcontrollers (e.g., ATmega328P, Arduino)Constrained IoT devices with limited memory and processing powerProjects requiring a minimal, auditable cryptographic libraryEducation and research in lightweight cryptographyApplications where dynamic memory allocation is not available or undesirable

FAQ

What makes libhydrogen different from libsodium?
Libhydrogen is designed for constrained environments with minimal code size and zero dynamic memory allocation. It uses only Curve25519 and Gimli, whereas libsodium offers many more primitives and is aimed at general-purpose applications.
Is libhydrogen suitable for Arduino?
Yes, libhydrogen supports the Arduino IDE out of the box and can generate cryptographically secure random numbers on Arduino boards, making it suitable for embedded projects.
How do I integrate libhydrogen into my project?
Simply add the required .c file (e.g., hydrogen.c) to your project and include the header. The library is designed to be used as a single file per operation set.
What license is libhydrogen released under?
The library is released under the permissive ISC license, which allows free use, modification, and distribution.