1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>MD5: Cryptographic Library for Lua</title>
<link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo">
<a href="http://www.keplerproject.org"><img alt="MD5 logo" src="md5.png"/></a>
</div>
<div id="product_name"><big><strong>MD5</strong></big></div>
<div id="product_description">Cryptographic Library for Lua</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>MD5</h1>
<ul>
<li><a href="index.html">Home</a>
<ul>
<li><a href="index.html#overview">Overview</a></li>
<li><a href="index.html#status">Status</a></li>
<li><a href="index.html#download">Download</a></li>
<li><a href="index.html#history">History</a></li>
<li><a href="index.html#credits">Credits</a></li>
<li><a href="index.html#contact">Contact us</a></li>
</ul>
</li>
<li><strong>Manual</strong>
<ul>
<li><a href="manual.html#introduction">Introduction</a></li>
<li><a href="manual.html#building">Building</a></li>
<li><a href="manual.html#installation">Installation</a></li>
<li><a href="manual.html#reference">Reference</a>
<ul>
<li><a href="manual.html#lua_api">Lua API</a></li>
<li><a href="manual.html#c_api">C API</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="http://luaforge.net/projects/md5/">Project</a>
<ul>
<li><a href="http://luaforge.net/tracker/?group_id=155">Bug Tracker</a></li>
<li><a href="http://luaforge.net/scm/?group_id=155">CVS</a></li>
</ul>
</li>
<li><a href="license.html">License</a></li>
</ul>
</div> <!-- id="navigation" -->
<div id="content">
<h2><a name="introduction"></a>Introduction</h2>
<p>
MD5 offers basic cryptographic facilities for Lua 5.X:
a hash (digest) function, a pair crypt/decrypt based on MD5 and CFB,
and a pair crypt/decrypt based on DES with 56-bit keys.
</p>
<p>
MD5 is free software and uses the same <a href="license.html">license</a>
as Lua.
</p>
<h2><a name="building"></a>Building</h2>
<p>
If you are using Unix MD5 offers a Makefile and a separate configuration file,
<code>config</code>, which should be edited to suit the particularities of the target platform
before running <code>make</code>.
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.
</p>
<p>
If you want to build MD5 on Windows MD5 offers the equivalent <code>config.win</code>
and <code>Makefile.win</code> files to be used with Microsoft Visual Studio 2005.
</p>
<h2><a name="installation"></a>Installation</h2>
<p>
The easiest way to install MD5 is to use <a href="http://www.luarocks.org">LuaRocks</a>:
</p>
<pre class="example">
luarocks install md5
</pre>
<p>
If you prefer to install the files manually and are using Unix, the build generates
two compiled binary files, <code>core.so</code> and <code>des56.so</code>.
The first should be copied to a directory called <code>md5</code>
in your <a href="http://www.lua.org/manual/5.1/manual.html#pdf-package.cpath">C path</a>.
Just copy the second to a directory in your Lua C path.
</p>
<p>
Windows users can use the binary version of MD5 available at
<a href="http://luaforge.net/projects/md5/files">LuaForge</a>.</p>
<p>
In both Unix and Windows systems the file <code>md5.lua</code> should be copied to a directory in your
<a href="http://www.lua.org/manual/5.1/manual.html#pdf-package.path">Lua path</a>.
</p>
<h2><a name="reference"></a>Reference</h2>
<h3><a name="lua_api"></a>Lua API</h3>
<p>All MD5-based functions are registered inside a table <code>md5</code>.</p>
<dl>
<dt><strong>md5.sum (message)</strong></dt>
<dd>Computes the MD5 message-digest of the string <code>message</code>.
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.<br />
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 <a href="ftp://ftp.isi.edu/in-notes/rfc1321.txt">RFC 1321</a>)
</dd>
<dt><strong>md5.sumhexa (message)</strong></dt>
<dd>Similar to <code>md5.sum</code>, but returns its value as a
string of 32 hexadecimal digits.
</dd>
<dt><strong>md5.crypt (message, key [,seed])</strong></dt>
<dd>Encrypts a string, using MD5 in CFB (Cipher-feedback mode).
<code>message</code> is an arbitrary binary string to be encrypted.
<code>key</code> is an arbitrary binary string to be used as a key.
<code>seed</code> is an arbitrary binary string to be used as a seed;
Returns the cyphertext (as a binary string).<br />
If no seed is provided, the function uses the result of
<code>os.time()</code> 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.<br />
The length of the cyphertext is the length of the message plus the
length of the seed plus one.<br />
Note that MD5 based encryption should not be considered a strong solution.
MD5 collision can cause to messages with different keys and the same seed
to encrypt to the same value, which can then be decrypted with either key.
The bigger the key the lesser the chance of this happening. More details
about the weaknesses involved can be found
<a href="http://pajhome.org.uk/crypt/md5/">here</a>.
</dd>
<dt><strong>md5.decrypt (message, key)</strong></dt>
<dd>Decrypts a string. The input <code>message</code> must be the result of
a previous call to <code>crypt</code>. For any <code>msg</code>,
<code>key</code>, and <code>seed</code>, we have that
<pre>md5.decrypt(md5.crypt(msg, key, seed), key) == msg</pre>
</dd>
<dt><strong>md5.exor (s1, s2)</strong></dt>
<dd>Does a bit-a-bit exclusive or of strings <code>s1</code> and <code>s2</code>.
Both strings must have the same length, which will be also the length of
the resulting string.
</dd>
</dl>
<p>The DES-based functions are registered inside a table <code>des56</code>.</p>
<dl>
<dt><strong>des56.crypt (message, key)</strong></dt>
<dd>Encrypts a string, using DES with a 56-bit key.
<code>message</code> is an arbitrary binary string to be encrypted.
<code>key</code> is an 8-byte binary string to be used as a key.
Returns the cyphertext (as a binary string).<br />
</dd>
<dt><strong>des56.decrypt (message, key)</strong></dt>
<dd>Decrypts a string. The input <code>message</code> must be the result of
a previous call to <code>des56.crypt</code>. For any <code>msg</code>
and <code>key</code>, we have that
<pre>des56.decrypt(des56.crypt(msg, key), key) == msg</pre>
</dd>
</dl>
<h3><a name="c_api"></a>C API</h3>
<p>The following functions are declared in <code>md5.h</code></p>
<dl>
<dt><strong>int luaopen_md5_core (lua_State *L)</strong></dt>
<dd>Opens the library and registers the "md5" Lua functions in the given state.</dd>
<dt><strong>void md5 (const char *message, long len, char *output)</strong></dt>
<dd>Computes the MD5 message-digest of <code>message</code>.
<code>len</code> is the length of <code>message</code>.
<code>output</code> is a buffer that receives the result;
it must have at least 16 bytes (128 bits).
</dd>
</dl>
<p>The following function is declared in <code>ldes56.h</code></p>
<dl>
<dt><strong>int luaopen_des56 (lua_State *L)</strong></dt>
<dd>Opens the library and registers the "des56" Lua functions in the given state.</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
<p><small>$Id: manual.html,v 1.15 2009/03/03 21:00:56 carregal Exp $</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
|