Another D cryptography library.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a simple Cryptography library written in D.

Let's start with a practical example:

	import cryptod.blockcipher.aes;
	import cryptod.mac.hmac;
	import cryptod.hash.sha1;
	import cryptod.kdf.pbkdf2;
	import cryptod.prng.mersennetwister;
	import std.datetime;
	ulong t = Clock.currTime().stdTime();
	//makes a seed from the current time
	uint[] seed = (cast(uint *)&t)[0..2];
	//seeds a MersenneTwister
	MersenneTwister mt = new MersenneTwister(seed);
	//Generates a random salt (ideally this would be stored in a database after generating.)
	uint s = mt.getNextInt();
	ubyte[4] salt = (cast(ubyte*)&s)[0..4];
	//This generates a 128-bit key from the password "password" using a 10,000 iteration PBKDF2 function.
	ubyte[] key = PBKDF2(&HMAC_SHA1, "password", salt, 10000, 16); 
	//Creates a new AES context for the generated key.
	AES aes = new AES(key);
	//converts a 16 byte input to a ubyte array
	ubyte[] input = cast(ubyte[])"A 16-byte input.";
	//Enciphers the input
	ubyte[] enciphered = aes.Cipher(input);
	//Deciphers the enciphered output
	ubyte[] deciphered = aes.InvCipher(enciphered);
	assert(input == deciphered);


Block Ciphers:

  • AES
  • Blowfish
  • Threefish

Stream Ciphers:

  • PRNG xor cipher (takes any deterministic prng as input.)


  • Assymetric Crypto
  • Twofish
  • Serpent
  • Stream Ciphers


Context Hashes:

  • SHA1
  • MD2
  • MD4
  • MD5
  • RIPEMD-160
  • (BROKEN) Tiger


  • SHA2 Family
  • All SHA3 finalists (Skein &al)

Pseudo Random Number Generators

  • Mersenne Twister
  • BlumBlumShub (Note: the design of the algorithm is suppossed to be slow and is great for heavy-duty crypto)
  • Counter Mode Block Cipher PRNG (takes any block cipher as input.)

Key Derivation Functions

  • PBKDF1 (might be broken, not sure, but that might be an obscure case of sha1)
  • PBKDF2 (might be broken, not sure, but that might be an obscure case of sha1)

More to come.


Tons of stuff is way too slow right now.

	Compiled with -O -inline -noboundscheck

	2048 md2 in 788 milliseconds: 20.3046 Mib/s
	32768 md4 in 369 milliseconds: 693.767 Mib/s
	32768 md5 in 273 milliseconds: 937.729 Mib/s
	8192 ripemd160 in 226 milliseconds: 283.186 Mib/s
	4096 sha1 in 145 milliseconds: 220.69 Mib/s
	16777216 ints generated by mersenne twister in 449 milliseconds: 1140.31 Mib/s
	256 ints generated by BlumBlumShub in 545 milliseconds: 0.0143348 Mib/s
	1048576 texts blowfish encrypted in 321 milliseconds: 199.377 Mib/s
	65536 texts threefish encrypted in 1349 milliseconds: 11.8606 Mib/s
	131072 texts AES128 encrypted in 354 milliseconds: 45.1977 Mib/s