idris-hackers / idris-crypto

Implementation of cryptographic primitives using Idris
BSD 3-Clause "New" or "Revised" License
121 stars 13 forks source link

idris-crypto

Join the chat at https://gitter.im/idris-hackers/idris-crypto

This project looks to develop cryptographic primitives using the general purpose functional language Idris.

It is important to note that the Idris language is first and foremost a research project, and thus the tooling provided by idris-crypto should not necessarily be seen as production ready nor for industrial use.

Motivation

Cryptography is something that is important to get right. It is also difficult to get right. Most languages make it too easy to shoot yourself in the foot (buffer overflows, gotos, etc.) and even those that don’t offer limited help, but some languages make it possible to prove arbitrary properties of a program and this ability can give you more confidence that your program is doing what it should. However, a cryptography library also needs to be readily usable by other software, hopefully not tied to code written in its implementation language.

Idris is a win on both sides here. On the one hand, it allows us to prove things about the code, but unlike other proof assistants has LLVM and JS backends, which means that it can be linked to very much like a C library, and can also be used by JS, on both the server and client side. It is in a relatively unique position that is ideal for crypto.

Note on Security

The security of cryptographic software libraries and implementations is a tricky thing to get right. The notion of what makes a cryptographic software library secure can be a highly contested subject. It is not good enough that a crypto software library is just functionally correct, and contains no coding errors. A secure cryptographic software library needs to be resitant to many types of attack for instance:

A language that is safer than C only gets you so far. However, the use of a general purpose language that supports:

arguably provides an really interesting development environment in which to explore the development of possibly provably secure and demonstrably correct cryptographic primitives.

Which primitives

The list of supported primitives will be summarised here.

Encryption

MAC / cryptographic hash

Usage

The easiest way to use the library is simply using encrypt/decrypt. You can pass it either a stream cipher, or a pair of a block cypher and encryption mode:

> the String (encrypt (ARC4 key) "some message")
"cuhrclh,.urch,.lih.ulchu" : String
> the String (decrypt (TDEA1 [key, key, key], CFB iv) "t893gy'c.,aihntebgl'"
"some message" : String

If you already have lists of bytes, try encryptMessage/decryptMessage instead.

The other useful pair of operations is specific to stream ciphers:

> decryptStream (ARC4 key) stream
? : Stream

and now you’re pipelining!

Plans / Notes

Contributions

Every contribution is appreciated – from documentation, to fixing typos, to adding one little function to a data structure. Even if you’re just touching Idris, dependent types, etc. for the first time. Join in!