Nimcrypto is Nim's cryptographic library. It implements several popular cryptographic algorithms and their tests with some examples in the official repo.

Most notably, this library has been used in the Nimbus Ethereum client. To see the implementation, check out its Github repository.

The most basic usage

$ nimble install nimcrypto # installation
# example.nim
import nimcrypto

echo keccak_256.digest("Alice makes a hash") 
# outputs EF0CC652868DF797522FB1D5A39E58E069154D9E47E5D7DB288B7200DB6EDFEE

Algorithm Implementations

For usage examples of the below algorithm implementations see each module's individual page.

This module provides helper procedures for calculating secure digests supported by nimcrypto library.
This module implements SHA2 (Secure Hash Algorithm 2) set of cryptographic hash functions designed by National Security Agency, version FIPS-180-4. []

This module implements RIPEMD set of cryptographic hash functions, designed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel. []

This module is Nim adoptation of original C source code by Antoon Bosselaers. []

This module includes support of RIPEMD-128/160/256/320.


This module implements SHA3 (Secure Hash Algorithm 3) set of cryptographic hash functions designed by Guido Bertoni, Joan Daemen, Michaƫl Peeters and Gilles Van Assche.

This module supports SHA3-224/256/384/512 and SHAKE-128/256.


This module implements BLAKE2 set of cryptographic hash functions designed by Jean-Philippe Aumasson, Luca Henzen, Willi Meier, Raphael C.W. Phan.

This module supports BLAKE2s-224/256 and BLAKE2b-384/512.


This module implements HMAC (Keyed-Hashing for Message Authentication) [].


This module implements Rijndael(AES) crypto algorithm by Vincent Rijmen, Antoon Bosselaers and Paulo Barreto.

Code based on version 3.0 (December 2000) of Optimised ANSI C code for the Rijndael cipher [].


This module implements Blowfish crypto algorithm by Bruce Schneier

Code based on C implementation of the Blowfish algorithm created by Paul Kocher [].


This module implements Twofish crypto algorithm by Bruce Schneier.

Code based on Optimized C created by Drew Csillag [].


This module implements various Block Cipher Modes.

The five modes currently supported:

  • ECB (Electronic Code Book)
  • CBC (Cipher Block Chaining)
  • CFB (Cipher FeedBack)
  • OFB (Output FeedBack)
  • CTR (Counter)
  • GCM (Galois/Counter Mode)

You can use any of this modes with all the block ciphers of nimcrypto library

GHASH implementation is Nim version of ghash_ctmul64.c which is part of decent BearSSL project <>. Copyright (c) 2016 Thomas Pornin <>

Utility functions common to all submodules.

This module implements interface to operation system's random number generator.

Windows using BCryptGenRandom (if available), CryptGenRandom(PROV_INTEL_SEC) (if available), RtlGenRandom.

RtlGenRandom (available from Windows XP) BCryptGenRandom (available from Windows Vista SP1) CryptGenRandom(PROV_INTEL_SEC) (only when Intel SandyBridge CPU is available).

Linux using genrandom (if available), /dev/urandom.

OpenBSD using getentropy.

NetBSD, FreeBSD, MacOS, Solaris using /dev/urandom.