Skip to content

Commit

Permalink
removed rabbit, moved test
Browse files Browse the repository at this point in the history
  • Loading branch information
philanc committed Nov 19, 2016
1 parent f4e4e46 commit d634f56
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 1,460 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ AR= ar
CFLAGS= -Os -fPIC $(INCFLAGS)
LDFLAGS= -fPIC

LUAZEN_O= luazen.o base58.o lzf_c.o lzf_d.o md5.o rabbit.o rc4.o sha1.o
LUAZEN_O= luazen.o base58.o lzf_c.o lzf_d.o md5.o rc4.o sha1.o

luazen.so: src/*.c src/*.h
$(CC) -c $(CFLAGS) src/*.c
$(CC) -shared $(LDFLAGS) -o luazen.so $(LUAZEN_O)

test: luazen.so
lua test_luazen.lua
lua test/test_luazen.lua

clean:
rm -f *.o *.a *.so
Expand Down
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ The compression functions are based on the tiny **lzf** library. It is not as ef

Endoding and decoding functions are provided for **base64** and **base58** (for base58, the BitCoin encoding alphabet is used)

Cryptographic functions include **md5**, **sha1**, **rc4** and **rabbit**

Rabbit is a very fast stream cipher (faster and much stronger than rc4). It was one of the four eSTREAM finalists in 2008. See the rabbit presentation pages at [eSTREAM](http://www.ecrypt.eu.org/stream/rabbitpf.html) and at [ECRYPT II](http://www.ecrypt.eu.org/stream/e2-rabbit.html). Rabbit was also specified in [RFC 4503](http://www.ietf.org/rfc/rfc4503.txt)
Cryptographic functions include **md5**, **sha1**, and **rc4**.

### API
```
Expand Down Expand Up @@ -74,15 +72,6 @@ rc4(str, key)
arguments and return are the same as rc4raw()
key length must be 16 (or nil, error msg is returned)
rabbit(str, key, iv)
encrypt (or decrypt, as rabbit is symmetric) string str with
key string key and initial value string iv.
key must be 16 bytes. iv must be 8 bytes
return the encrypted string (same length as str)
or nil, error msg if the key or iv lengths are not correct
-- for more information and references on rabbit, see the comment
at the top of src/luazen/rabbit.c
md5(str)
return the md5 hash of string str as a binary string
(no hex encoding)
Expand All @@ -101,7 +90,6 @@ The luazen library includes some code from various authors (see src/):
- base58 functions by Luke Dashjr (MIT)
- md5, sha1 by Cameron Rich (BSD)
- lzf functions by Marc Alexander Lehmann (BSD, see src/lzf* headers)
- rabbit by Cryptico A/S (public domain, since 2008)

(the code from these sources has been significantly modified - all bugs are probably mine!)

Expand Down
9 changes: 0 additions & 9 deletions src/crypto_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,5 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
------------------------------------------------------------------------
--- rabbit
Original author/copyright owner: Cryptico A/S
Released into the public domain in 2008.
see http://www.ecrypt.eu.org/stream/phase3ip.html#rabbit
see also the rabbit.c header.
```
64 changes: 6 additions & 58 deletions src/luazen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,15 @@
// ---------------------------------------------------------------------
/* luazen
A small Lua extension library with crypto and compression functions
(stuff that is very slow and inefficient when done in pure Lua...)
160412
removed hmac_md5, hmac_sha1 (rather use tweetnacl)
added base58 encode/decode
150701
replaced nacl-unknown with tweetnacl-20140427, incl sha512
moved nacl to its own module ("luatweetnacl")
150628
added nacl (nacl-unknown, ca. 2008)
150624
test lzf to replace gzip (lzf is much smaller, albeit less efficient)
110622
added macros from roberto's lpeg for 5.1/5.2 compat
110123
fixed zip "dstln must be set to buf ln upon entry" (already fixed
but only for unzip...)
110122
fixed luaL_reg to luaL_Reg (for lua5.2)
fixed unzip "dstln must be set to buf ln upon entry"
A small Lua extension library with low grade crypto and compression
functions (stuff that is very slow when done in pure Lua...).
See README.md.
https://github.com/philanc/luazen
*/

#define LUAZEN_VERSION "luazen-0.6"
#define LUAZEN_VERSION "luazen-0.7"

#include <stdlib.h>
#include <stdio.h>
Expand All @@ -39,7 +23,6 @@ A small Lua extension library with crypto and compression functions
#include "md5.h"
#include "sha1.h"
#include "base58.h"
#include "rabbit-sync.h"

//=========================================================
// compatibility with Lua 5.2 --and lua 5.3, added 150621
Expand Down Expand Up @@ -202,35 +185,6 @@ static int luazen_rc4(lua_State *L) {
return 1;
}

//----------------------------------------------------------------------
// rabbit stream cipher
//
static int luazen_rabbit(lua_State *L) {
// Lua:
// rabbit(plaintext, key, iv) returns encrypted text
// rabbit(encrypted, key, iv) returns decrypted text
// key: the encryption key - must be a 16-byte string
// iv: the initial value - must be a 8-byte string
//
size_t pln, kln, ivln;
const char *p = luaL_checklstring (L, 1, &pln);
const char *k = luaL_checklstring (L, 2, &kln);
const char *iv = luaL_checklstring (L, 3, &ivln);
if ((kln != 16) || (ivln != 8)) {
lua_pushnil (L);
lua_pushliteral (L,
"luazen: rabbit key and iv must be 16 and 8 bytes");
return 2;
}
char * e = malloc(pln); // buffer for encrypted text
ECRYPT_ctx ctx;
ECRYPT_keysetup(&ctx, k, 16, 8);
ECRYPT_ivsetup(&ctx, iv);
ECRYPT_process_bytes(0, &ctx, p, e, pln); // 1st param is ignored
lua_pushlstring (L, e, pln);
free(e);
return 1;
}


//----------------------------------------------------------------------
Expand Down Expand Up @@ -364,9 +318,6 @@ static int luazen_b64decode(lua_State *L) /** decode(s) */
}
luaL_pushresult(&b);
return 1;
//~ case 0:
//~ luaL_pushresult(&b);
//~ return 1;
case '\n': case '\r': case '\t': case ' ': case '\f': case '\b':
break;
} //switch(c)
Expand Down Expand Up @@ -412,9 +363,7 @@ static int luazen_b58decode(lua_State *L) {
bufsz = eln; // more than enough!
unsigned char *buf = malloc(bufsz);
bln = bufsz; // give the result buffer size to b58tobin
//~ printf("dec bef eln=%d bln=%d \n", eln, bln);
bool r = b58tobin(buf, &bln, e, eln);
//~ printf("dec aft eln=%d bln=%d \n", eln, bln);
if (!r) {
free(buf);
lua_pushnil (L);
Expand All @@ -436,7 +385,6 @@ static const struct luaL_Reg luazenlib[] = {
{"unlzf", luazen_unlzf},
{"rc4", luazen_rc4},
{"rc4raw", luazen_rc4raw},
{"rabbit", luazen_rabbit},
{"md5", luazen_md5},
{"sha1", luazen_sha1},
{"b64encode", luazen_b64encode},
Expand Down
Loading

0 comments on commit d634f56

Please sign in to comment.