MD5
Cryptographic Library for Lua

Introduction

MD5 offers basic cryptographic facilities for Lua 5.1: a hash (digest) function, and a pair crypt/decrypt.

MD5 is free software and uses the same license as Lua.

Building

MD5 offers a Makefile and a separate configuration file, config, which should be edited to suit the particularities of the target platform before running make. The file has some definitions like paths to the external libraries, compiler options and the like. One important definition is the Lua version, which is not obtained from the installed software.

Installation

The compiled binary file should be copied to a directory called md5 in your C path with the name core.[so|dll]. Windows users can use the binary version of MD5 available at LuaForge.

The file md5.lua should be copied to a directory in your Lua path.

Reference

Lua API

All MD5 functions are registered inside a table md5.

md5.sum (message)
Computes the MD5 message-digest of the string message. This function takes as input a message of arbitrary length and content and returns as output a 128-bit "fingerprint" (or "message digest") of the input.
The output is formated as a binary string with 16 characters. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given pre-specified target message digest. (see RFC 1321)
md5.sumhexa (message)
Similar to md5.sum, but returns its value as a string of 32 hexadecimal digits.
md5.crypt (message, key [,seed])
Encrypts a string, using MD5 in CFB (Cipher-feedback mode). message is an arbitrary binary string to be encrypted. key is an arbitrary binary string to be used as a key. seed is an arbitrary binary string to be used as a seed; Returns the cyphertext (as a binary string).
If no seed is provided, the function uses the result of os.time() as a seed. It is recommended that you use different seeds for each message; the seed itself is not private, and should contain no private data, because it goes plain in the beginning of the encrypted message.
The length of the cyphertext is the length of the message plus the length of the seed plus one.
md5.decrypt (message, key)
Decrypts a string. The input message must be the result of a previous call to crypt. For any msg, key, and seed, we have that
md5.decrypt(md5.crypt(msg, key, seed), key) == msg
md5.exor (s1, s2)
Does a bit-a-bit exclusive or of strings s1 and s2. Both strings must have the same length, which will be also the length of the resulting string.

C API

The following functions are declared in md5.h

int luaopen_md5_core (lua_State *L)
Opens the library and registers the above Lua functions in the given state.
void md5 (const char *message, long len, char *output)
Computes the MD5 message-digest of message. len is the length of message. output is a buffer that receives the result; it must have at least 16 bytes (128 bits).

Valid XHTML 1.0!

$Id: manual.html,v 1.9 2007/05/08 21:18:14 carregal Exp $