Wed, 16 Feb 2011 20:29:33 +0000
There are no secrets better kept than the secrets that everybody guesses.
0
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | AES for lua |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | ----------- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | This files contain an implementation of AES in lua. The only additional library |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | needed is bitlib. |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | Usage |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | ----- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | aeslua.lua contains a simple API to encrypt and decrypt lua strings. |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | To encrypt the string "geheim" with the password "password" use: |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | require("aeslua"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | cipher = aeslua.encrypt("password", "secret"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | and to decrypt the string again: |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | plain = aeslua.decrypt("password", cipher); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | You can also specify the key size and the encryption mode. For further examples |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | look into the file src/testcryptotest.lua. |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | To use AES directly, have a look at aes.lua and at the example usage in |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | testaes.lua. |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | Installation |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | ------------ |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | Edit the LIBDIR variable in the Makefile and run |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | make install |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | Speed |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | ----- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | The implementation is rather optimized (it uses tables for most AES operations) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | but still cannot compete with AES written in other languages. Typical AES |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | implementations reach several 100 MBit per second, this implementation only |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | reaches 400 kBit per second. The most plausible reason is the heavy reliance |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | of AES on bit operations. As lua numbers are doubles bitlib needs to convert |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | them to long values for each bit operation. |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | So if you need to encrypt much data with AES, do yourself a favor and use a |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | C-Implementation. But if you only need to encrypt short strings and you have |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | no control over the lua environment (like in games :-)) use this library. |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | Matthias Hilbig (hilbig@upb.de) |