Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Imported from 5.1/lmd5.tar.gz.

  • Loading branch information...
commit 0d5fb233ec49bbf97eec76d5fbe9da1ce4563eae 1 parent 198ed20
Luiz Henrique de Figueiredo authored
View
146 Makefile
@@ -1,68 +1,66 @@
-# makefile for md5/sha1 library for Lua
+# makefile for message digest library for Lua
# change these to reflect your Lua installation
-LUA= /tmp/lhf/lua-5.0
-LUAINC= $(LUA)/include
-LUALIB= $(LUA)/lib
-LUABIN= $(LUA)/bin
-
-### change these to reflect your MD5 library
-MYNAME= md5
-#
-# MD5 library available in libmd5 -- assumes md5global.h
-MD5LIB= -lmd5
-MD5INC= .
-#
-# MD5 library available in libcrypto (openssl)
-# make DEFS=-DUSE_MD5_OPENSSL MD5LIB=-lcrypto
-#DEFS= -DUSE_MD5_OPENSSL
-#MD5LIB= -lcrypto
-#
-# Rivest's MD5 library from source -- rename or link global.h as md5global.h
-# make DEFS=-DUSE_MD5_RIVEST MD5LIB=md5c.o
-#DEFS= -DUSE_MD5_RIVEST
-#MD5LIB= md5c.o
-#MD5OBJ= $(MD5LIB)
-#
-# Deutsch's MD5 library from source
-# make DEFS=-DUSE_MD5_DEUTSCH MD5LIB=md5.o
-#DEFS= -DUSE_MD5_DEUTSCH
-#MD5LIB= md5.o
-#MD5OBJ= $(MD5LIB)
-#
-# Plumb's MD5 library from source
-# make DEFS=-DUSE_MD5_PLUMB MD5LIB=md5.o
-#DEFS= -DUSE_MD5_PLUMB
-#MD5LIB= md5.o
-#MD5OBJ= $(MD5LIB)
-
-### change these to reflect your SHA1 library
-#MYNAME= sha1
-#
-# SHA1 library available in libcrypto (openssl)
-# make DEFS=-DUSE_SHA1_OPENSSL MD5LIB=-lcrypto MYNAME=sha1
-#DEFS= -DUSE_SHA1_OPENSSL
-#MD5LIB= -lcrypto
-#
-# rfc3174 SHA1 library from source
-# make DEFS=-DUSE_SHA1_RFC MD5LIB=sha1.o MYNAME=sha1
-#DEFS= -DUSE_SHA1_RFC
-#MD5LIB= sha1.o
-#MD5OBJ= $(MD5LIB)
-#
-# skalibs SHA1 SHA1 library from source
-# make DEFS=-DUSE_SHA1_SKALIBS MD5LIB=sha1.o MYNAME=sha1
-#DEFS= -DUSE_SHA1_SKALIBS
-#MD5LIB= sha1.o
-#MD5OBJ= $(MD5LIB)
-
-# no need to change anything below here
+LUA= /tmp/lhf/lua-5.1.4
+LUAINC= $(LUA)/src
+LUALIB= $(LUA)/src
+LUABIN= $(LUA)/src
+
+# these will probably work if Lua has been installed globally
+#LUA= /usr/local
+#LUAINC= $(LUA)/include
+#LUALIB= $(LUA)/lib
+#LUABIN= $(LUA)/bin
+
+# probably no need to change anything below here
+CC= gcc
CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 $G
-WARN= #-ansi -pedantic -Wall
-INCS= -I$(LUAINC) -I$(MD5INC)
+WARN= -ansi -pedantic -Wall
+INCS= -I$(LUAINC)
+MAKESO= $(CC) -shared
+#MAKESO= env MACOSX_DEPLOYMENT_TARGET=10.3 $(CC) -bundle -undefined dynamic_lookup
+
+# default is md5
+MYNAME=md5
+DEFS=-DUSE_MD5_OPENSSL
+SUM=$(MYNAME)sum
+
+default: all
+
+digests: md2 md4 md5 sha1 sha224 sha256 sha384 sha512 ripemd160
+
+md2:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_MD2_OPENSSL SUM="openssl $@"
+
+md4:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_MD4_OPENSSL SUM="openssl $@"
+
+md5:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_MD5_OPENSSL
+
+sha1:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_SHA1_OPENSSL
+
+sha224:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_SHA224_OPENSSL
+
+sha256:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_SHA256_OPENSSL
+
+sha384:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_SHA384_OPENSSL
+
+sha512:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_SHA512_OPENSSL
+
+ripemd160:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_RIPEMD160_OPENSSL SUM="openssl rmd160"
+
+mdc2:
+ $(MAKE) all MYNAME=$@ DEFS=-DUSE_MDC2_OPENSSL SUM="openssl mdc2"
MYLIB= l$(MYNAME)
-T= $(MYLIB).so
+T= $(MYNAME).so
OBJS= $(MYLIB).o
TEST= test.lua
@@ -70,37 +68,41 @@ all: test
test: $T
$(LUABIN)/lua -l$(MYNAME) $(TEST)
+ -@echo -n "$(MYNAME) " ; $(SUM) < README
o: $(MYLIB).o
so: $T
-$T: $(OBJS) $(MD5OBJ)
- $(CC) -o $@ -shared $(OBJS) $(MD5LIB)
+$T: $(OBJS)
+ $(MAKESO) -o $@ $(OBJS) -lcrypto
clean:
- rm -f $(OBJS) $T core core.* a.out $(MD5OBJ)
+ rm -f $(OBJS) $T core core.* l*.o *.so
doc:
- @echo "$(MYNAME) library:"
- @fgrep '/**' $(MYLIB).c | cut -f2 -d/ | tr -d '*' | sort | column
+ @echo "digest library:"
+ @fgrep '/**' lmd5.c | cut -f2 -d/ | tr -d '*' | sort | column
+
+$(MYLIB).o: lmd5.c lmd5.h
+ $(CC) $(CFLAGS) -o $@ -c lmd5.c
# distribution
-FTP= $(HOME)/public/ftp/lua
+FTP= www:www/ftp/lua/5.1
+F= http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.1/$A
D= $(MYNAME)
A= $(MYLIB).tar.gz
-TOTAR= Makefile,README,lmd5.c,lmd5.h,lsha1.c,md5.lua,sha1.lua,test.lua
+TOTAR= Makefile,README,ldigest.c,lmd5.c,lmd5.h,test.lua
-tar: clean
+distr: clean
tar zcvf $A -C .. $D/{$(TOTAR)}
-
-distr: tar
touch -r $A .stamp
- mv $A $(FTP)
+ scp -p $A $(FTP)
diff: clean
- tar zxf $(FTP)/$A
+ wget -q -N $F
+ tar zxf $A
diff $D .
# eof
View
69 README
@@ -1,10 +1,25 @@
-This is an MD5 library for Lua 5.0. It is based on the MD5 library by Rivest,
-described in rfc1321, but also it supports several other libraries that have
-a similar API (including libraries that compute SHA1 instead of MD5).
-
-To try the library, just edit Makefile to reflect your installation of Lua and
-your MD5 or SHA1 library (see below) and then run make. This will build the
-library and run a simple test. For detailed installation instructions, see
+This is a message digest library for Lua 5.1. It is based on the digest routines
+provided by OpenSSL. The library can be built to compute the following digests:
+md2, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160, mdc2.
+For more information on these digests, see
+ http://en.wikipedia.org/wiki/MD2_(cryptography)
+ http://en.wikipedia.org/wiki/MD4
+ http://en.wikipedia.org/wiki/MD5
+ http://en.wikipedia.org/wiki/SHA_hash_functions
+ http://en.wikipedia.org/wiki/RIPEMD-160
+ http://en.wikipedia.org/wiki/MDC2
+ http://en.wikipedia.org/wiki/Message_digest
+
+OpenSSL is available at
+ http://www.openssl.org/
+If you're running Unix, you probably already have OpenSSL installed.
+
+If you have trouble finding C source code for MD5 or SHA1 digests that
+does not depend on OpenSSL, please send me a note.
+
+To try the library, edit Makefile to reflect your installation of Lua and
+then run make. This will build the library and run a simple test.
+For detailed installation instructions, see
http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html
There is no manual but the library is simple and intuitive; see the summary
@@ -15,41 +30,9 @@ Please send comments, suggestions, and bug reports to lhf@tecgraf.puc-rio.br .
-------------------------------------------------------------------------------
-md5 library:
- clone(c) reset(c) version
- digest(c or s,[raw]) tostring(c)
- new() update(c,s)
+digest library:
+ __tostring(c) new() version
+ clone(c) reset(c)
+ digest(c or s,[raw]) update(c,s)
-------------------------------------------------------------------------------
-
-* Finding and selecting an MD5 library
-
-If you're running Linux, you probably already have Rivest's library installed
-somewhere. The problem is finding where. If you don't have libmd5, then try
-libcrypto, which seems to be part of openssli (or libsasl, but don't use
-/usr/include/sasl/md5.h).
-
-If you can't find an MD5 library in your system, then download one from
- http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html
-
-lmd5.c supports all three C libraries mentioned in that web page: Rivest's
-original library from rfc1321, Deutsch's library, and Plumb's public domain
-implementation, which can be downloaded at
- http://archiv.tu-chemnitz.de/pub/1999/0004/data/md5/
-
-Those libraries are quite small and easy to compile. They are not included in
-this package because they are easily available and have their own licenses.
-
-* Finding and selecting a SHA1 library
-
-lmd5.c also supports SHA1. If you're running Linux, you probably already have
-a SHA1 library installed somewhere. If you have libcrypto, then select it in
-the Makefile. Otherwise, extract the C code from rfc3174:
- http://www.faqs.org/rfcs/rfc3174.html
-
-A public domain SHA1 library is available in skalibs:
- http://www.skarnet.org/software/skalibs/libstdcrypto.html
- http://www.skarnet.org/software/skalibs/install.html
-but you'll have to spend a little time making its SHA1 module into a
-standalone module, without dependencies. It's not hard at all. If you have
-problems, let me know.
View
110 ldigest.c
@@ -0,0 +1,110 @@
+/*
+* ldigest.c
+* message digest library for Lua 5.1 based on OpenSSL
+* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
+* 24 Mar 2011 12:11:47
+* This code is hereby placed in the public domain.
+*/
+
+/* build with
+ make ldigest.o DEFS= ; make MYNAME=digest SUM=echo
+*/
+
+#define USE_MULTIPLE
+
+#ifdef OPENSSL_NO_MD2
+#define luaopen_md2(L)
+#else
+#define USE_MD2_OPENSSL
+#include "lmd5.c"
+#undef USE_MD2_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_MD4
+#define luaopen_md4(L)
+#else
+#define USE_MD4_OPENSSL
+#include "lmd5.c"
+#undef USE_MD4_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_MD5
+#define luaopen_md5(L)
+#else
+#define USE_MD5_OPENSSL
+#include "lmd5.c"
+#undef USE_MD5_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_SHA1
+#define luaopen_sha1(L)
+#else
+#define USE_SHA1_OPENSSL
+#include "lmd5.c"
+#undef USE_SHA1_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_SHA256
+#define luaopen_sha224(L)
+#else
+#define USE_SHA224_OPENSSL
+#include "lmd5.c"
+#undef USE_SHA224_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_SHA256
+#define luaopen_sha256(L)
+#else
+#define USE_SHA256_OPENSSL
+#include "lmd5.c"
+#undef USE_SHA256_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_SHA512
+#define luaopen_sha384(L)
+#else
+#define USE_SHA384_OPENSSL
+#include "lmd5.c"
+#undef USE_SHA384_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_SHA512
+#define luaopen_sha512(L)
+#else
+#define USE_SHA512_OPENSSL
+#include "lmd5.c"
+#undef USE_SHA512_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_RIPEMD160
+#define luaopen_ripemd160(L)
+#else
+#define USE_RIPEMD160_OPENSSL
+#include "lmd5.c"
+#undef USE_RIPEMD160_OPENSSL
+#endif
+
+#ifdef OPENSSL_NO_MDC2
+#define luaopen_mdc2(L)
+#else
+#define USE_MDC2_OPENSSL
+#include "lmd5.c"
+#undef USE_MDC2_OPENSSL
+#endif
+
+#undef luaopen_md5
+
+LUALIB_API int luaopen_digest(lua_State *L)
+{
+ luaopen_md2(L);
+ luaopen_md4(L);
+ luaopen_md5(L);
+ luaopen_sha1(L);
+ luaopen_sha224(L);
+ luaopen_sha256(L);
+ luaopen_sha384(L);
+ luaopen_sha512(L);
+ luaopen_ripemd160(L);
+ luaopen_mdc2(L);
+ return 0;
+}
View
54 lmd5.c
@@ -1,26 +1,23 @@
/*
* lmd5.c
-* MD5 library for Lua 5.0 based on Rivest's API
+* MD5 library for Lua 5.1 based on Rivest's API
* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
-* 05 Jul 2004 21:33:37
+* 24 Mar 2011 13:08:51
* This code is hereby placed in the public domain.
*/
-#include <stdio.h>
-
#include "lmd5.h"
#include "lua.h"
#include "lauxlib.h"
-#define MYVERSION MYNAME " library for " LUA_VERSION " / Jul 2004 / "\
+#define MYVERSION MYNAME " library for " LUA_VERSION " / Mar 2011 / "\
"using " AUTHOR
#define MYTYPE MYNAME " context"
static MD5_CTX *Pget(lua_State *L, int i)
{
- if (luaL_checkudata(L,i,MYTYPE)==NULL) luaL_typerror(L,i,MYTYPE);
- return lua_touserdata(L,i);
+ return luaL_checkudata(L,i,MYTYPE);
}
static MD5_CTX *Pnew(lua_State *L)
@@ -50,15 +47,18 @@ static int Lreset(lua_State *L) /** reset(c) */
{
MD5_CTX *c=Pget(L,1);
MD5Init(c);
- return 0;
+ lua_settop(L,1);
+ return 1;
}
static int Lupdate(lua_State *L) /** update(c,s) */
{
+ size_t l;
MD5_CTX *c=Pget(L,1);
- const char *s=luaL_checkstring(L,2);
- MD5Update(c,s,lua_strlen(L,2));
- return 0;
+ const char *s=luaL_checklstring(L,2,&l);
+ MD5Update(c,s,l);
+ lua_settop(L,1);
+ return 1;
}
static int Ldigest(lua_State *L) /** digest(c or s,[raw]) */
@@ -71,56 +71,58 @@ static int Ldigest(lua_State *L) /** digest(c or s,[raw]) */
}
else
{
- const char *s=luaL_checkstring(L,1);
+ size_t l;
+ const char *s=luaL_checklstring(L,1,&l);
MD5_CTX c;
MD5Init(&c);
- MD5Update(&c,s,lua_strlen(L,1));
+ MD5Update(&c,s,l);
MD5Final(digest,&c);
}
if (lua_toboolean(L,2))
- lua_pushlstring(L,digest,sizeof(digest));
+ lua_pushlstring(L,(char*)digest,sizeof(digest));
else
{
- char hex[2*N+1];
+ char *digit="0123456789abcdef";
+ char hex[2*N],*h;
int i;
- for (i=0; i<N; i++) sprintf(hex+2*i,"%02x",digest[i]);
- lua_pushlstring(L,hex,sizeof(hex)-1);
+ for (h=hex,i=0; i<N; i++)
+ {
+ *h++=digit[digest[i] >> 4];
+ *h++=digit[digest[i] & 0x0F];
+ }
+ lua_pushlstring(L,hex,sizeof(hex));
}
return 1;
}
-static int Ltostring(lua_State *L) /** tostring(c) */
+static int Ltostring(lua_State *L) /** __tostring(c) */
{
MD5_CTX *c=Pget(L,1);
- char s[64];
- sprintf(s,"%s %p",MYTYPE,c);
- lua_pushstring(L,s);
+ lua_pushfstring(L,"%s %p",MYTYPE,(void*)c);
return 1;
}
-static const luaL_reg R[] =
+static const luaL_Reg R[] =
{
{ "__tostring", Ltostring},
{ "clone", Lclone },
{ "digest", Ldigest },
{ "new", Lnew },
{ "reset", Lreset },
- { "tostring", Ltostring},
{ "update", Lupdate },
{ NULL, NULL }
};
LUALIB_API int luaopen_md5(lua_State *L)
{
- lua_pushliteral(L,MYNAME);
luaL_newmetatable(L,MYTYPE);
- luaL_openlib(L,NULL,R,0);
+ lua_setglobal(L,MYNAME);
+ luaL_register(L,MYNAME,R);
lua_pushliteral(L,"version"); /** version */
lua_pushliteral(L,MYVERSION);
lua_settable(L,-3);
lua_pushliteral(L,"__index");
lua_pushvalue(L,-2);
lua_settable(L,-3);
- lua_rawset(L,LUA_GLOBALSINDEX);
return 1;
}
View
287 lmd5.h
@@ -1,79 +1,260 @@
/*
* lmd5.h
-* MD5 library for Lua 5.0 based on Rivest's API
+* message digest library for Lua 5.1 based on OpenSSL
* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
-* 26 Mar 2004 17:49:20
+* 11 Nov 2010 22:58:59
* This code is hereby placed in the public domain.
*/
-#ifdef USE_SHA1_OPENSSL
-#define USING_SHA1
-#define AUTHOR "openssl"
-#define MD5_CTX SHA_CTX
-#define MD5Init SHA1_Init
-#define MD5Update SHA1_Update
-#define MD5Final SHA1_Final
-#include <openssl/sha.h>
-#endif
+#include <openssl/opensslv.h>
+
+#undef MYNAME
+#undef luaopen_md5
+#undef AUTHOR
+#undef MD5_CTX
+#undef MD5Init
+#undef MD5Update
+#undef MD5Final
+#undef N
+#undef Pget
+#undef Pnew
+#undef Lclone
+#undef Ldigest
+#undef Lnew
+#undef Lreset
+#undef Ltostring
+#undef Lupdate
+#undef R
-#ifdef USE_SHA1_RFC
-#define USING_SHA1
-#define AUTHOR "rfc3174"
-#define MD5_CTX SHA1Context
-#define MD5Init SHA1Reset
-#define MD5Update SHA1Input
-#define MD5Final(digest,c) SHA1Result(c,digest)
-#include "sha1.h"
+#ifdef USE_MD2_OPENSSL
+#include <openssl/md2.h>
+#define MYNAME "md2"
+#define luaopen_md5 luaopen_md2
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX MD2_CTX
+#define MD5Init MD2_Init
+#define MD5Update MD2_Update
+#define MD5Final MD2_Final
+#define N MD2_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget md2_Pget
+#define Pnew md2_Pnew
+#define Lclone md2_Lclone
+#define Ldigest md2_Ldigest
+#define Lnew md2_Lnew
+#define Lreset md2_Lreset
+#define Ltostring md2_Ltostring
+#define Lupdate md2_Lupdate
+#define R md2_R
+#endif
#endif
-#ifdef USE_SHA1_SKALIBS
-#define USING_SHA1
-#define AUTHOR "skalibs"
-#define MD5_CTX SHA1Schedule
-#define MD5Init sha1_init
-#define MD5Update sha1_update
-#define MD5Final(digest,c) sha1_final(c,digest)
-#include "sha1.h"
+#ifdef USE_MD4_OPENSSL
+#include <openssl/md4.h>
+#define MYNAME "md4"
+#define luaopen_md5 luaopen_md4
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX MD4_CTX
+#define MD5Init MD4_Init
+#define MD5Update MD4_Update
+#define MD5Final MD4_Final
+#define N MD4_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget md4_Pget
+#define Pnew md4_Pnew
+#define Lclone md4_Lclone
+#define Ldigest md4_Ldigest
+#define Lnew md4_Lnew
+#define Lreset md4_Lreset
+#define Ltostring md4_Ltostring
+#define Lupdate md4_Lupdate
+#define R md4_R
+#endif
#endif
#ifdef USE_MD5_OPENSSL
-#define AUTHOR "openssl"
-#define MD5CTX MD5_CTX
+#include <openssl/md5.h>
+#define MYNAME "md5"
+#define luaopen_md5 luaopen_md5
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX MD5_CTX
#define MD5Init MD5_Init
#define MD5Update MD5_Update
#define MD5Final MD5_Final
-#include <openssl/md5.h>
+#define N MD5_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget md5_Pget
+#define Pnew md5_Pnew
+#define Lclone md5_Lclone
+#define Ldigest md5_Ldigest
+#define Lnew md5_Lnew
+#define Lreset md5_Lreset
+#define Ltostring md5_Ltostring
+#define Lupdate md5_Lupdate
+#define R md5_R
+#endif
#endif
-#ifdef USE_MD5_DEUTSCH
-#define AUTHOR "Deutsch"
-#define MD5_CTX md5_state_t
-#define MD5Init(c) md5_init(c)
-#define MD5Update(c,s,n) md5_append(c,(const md5_byte_t *)s,n)
-#define MD5Final(digest,c) md5_finish(c,digest)
-#include "md5.h"
+#ifdef USE_SHA1_OPENSSL
+#include <openssl/sha.h>
+#define MYNAME "sha1"
+#define luaopen_md5 luaopen_sha1
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX SHA_CTX
+#define MD5Init SHA1_Init
+#define MD5Update SHA1_Update
+#define MD5Final SHA1_Final
+#define N SHA_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget sha1_Pget
+#define Pnew sha1_Pnew
+#define Lclone sha1_Lclone
+#define Ldigest sha1_Ldigest
+#define Lnew sha1_Lnew
+#define Lreset sha1_Lreset
+#define Ltostring sha1_Ltostring
+#define Lupdate sha1_Lupdate
+#define R sha1_R
+#endif
#endif
-#ifdef USE_MD5_PLUMB
-#define AUTHOR "Plumb"
-#include "md5.h"
+#ifdef USE_SHA224_OPENSSL
+#define SHA224_CTX SHA256_CTX
+#include <openssl/sha.h>
+#define MYNAME "sha224"
+#define luaopen_md5 luaopen_sha224
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX SHA224_CTX
+#define MD5Init SHA224_Init
+#define MD5Update SHA224_Update
+#define MD5Final SHA224_Final
+#define N SHA224_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget sha224_Pget
+#define Pnew sha224_Pnew
+#define Lclone sha224_Lclone
+#define Ldigest sha224_Ldigest
+#define Lnew sha224_Lnew
+#define Lreset sha224_Lreset
+#define Ltostring sha224_Ltostring
+#define Lupdate sha224_Lupdate
+#define R sha224_R
+#endif
#endif
-#ifndef AUTHOR
-#define USE_MD5_RIVEST
+#ifdef USE_SHA256_OPENSSL
+#include <openssl/sha.h>
+#define MYNAME "sha256"
+#define luaopen_md5 luaopen_sha256
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX SHA256_CTX
+#define MD5Init SHA256_Init
+#define MD5Update SHA256_Update
+#define MD5Final SHA256_Final
+#define N SHA256_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget sha256_Pget
+#define Pnew sha256_Pnew
+#define Lclone sha256_Lclone
+#define Ldigest sha256_Ldigest
+#define Lnew sha256_Lnew
+#define Lreset sha256_Lreset
+#define Ltostring sha256_Ltostring
+#define Lupdate sha256_Lupdate
+#define R sha256_R
+#endif
#endif
-#ifdef USE_MD5_RIVEST
-#define AUTHOR "Rivest"
-#include "md5global.h"
-#include "md5.h"
+#ifdef USE_SHA384_OPENSSL
+#define SHA384_CTX SHA512_CTX
+#include <openssl/sha.h>
+#define MYNAME "sha384"
+#define luaopen_md5 luaopen_sha384
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX SHA384_CTX
+#define MD5Init SHA384_Init
+#define MD5Update SHA384_Update
+#define MD5Final SHA384_Final
+#define N SHA384_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget sha384_Pget
+#define Pnew sha384_Pnew
+#define Lclone sha384_Lclone
+#define Ldigest sha384_Ldigest
+#define Lnew sha384_Lnew
+#define Lreset sha384_Lreset
+#define Ltostring sha384_Ltostring
+#define Lupdate sha384_Lupdate
+#define R sha384_R
+#endif
#endif
-#ifdef USING_SHA1
-#define MYNAME "sha1"
-#define N 20
-#define luaopen_md5 luaopen_sha1
-#else
-#define MYNAME "md5"
-#define N 16
+#ifdef USE_SHA512_OPENSSL
+#include <openssl/sha.h>
+#define MYNAME "sha512"
+#define luaopen_md5 luaopen_sha512
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX SHA512_CTX
+#define MD5Init SHA512_Init
+#define MD5Update SHA512_Update
+#define MD5Final SHA512_Final
+#define N SHA512_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget sha512_Pget
+#define Pnew sha512_Pnew
+#define Lclone sha512_Lclone
+#define Ldigest sha512_Ldigest
+#define Lnew sha512_Lnew
+#define Lreset sha512_Lreset
+#define Ltostring sha512_Ltostring
+#define Lupdate sha512_Lupdate
+#define R sha512_R
+#endif
+#endif
+
+#ifdef USE_RIPEMD160_OPENSSL
+#include <openssl/ripemd.h>
+#define MYNAME "ripemd160"
+#define luaopen_md5 luaopen_ripemd160
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX RIPEMD160_CTX
+#define MD5Init RIPEMD160_Init
+#define MD5Update RIPEMD160_Update
+#define MD5Final RIPEMD160_Final
+#define N RIPEMD160_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget ripemd160_Pget
+#define Pnew ripemd160_Pnew
+#define Lclone ripemd160_Lclone
+#define Ldigest ripemd160_Ldigest
+#define Lnew ripemd160_Lnew
+#define Lreset ripemd160_Lreset
+#define Ltostring ripemd160_Ltostring
+#define Lupdate ripemd160_Lupdate
+#define R ripemd160_R
#endif
+#endif
+
+#ifdef USE_MDC2_OPENSSL
+#include <openssl/mdc2.h>
+#define MYNAME "mdc2"
+#define luaopen_md5 luaopen_mdc2
+#define AUTHOR "OpenSSL " SHLIB_VERSION_NUMBER
+#define MD5_CTX MDC2_CTX
+#define MD5Init MDC2_Init
+#define MD5Update MDC2_Update
+#define MD5Final MDC2_Final
+#define N MDC2_DIGEST_LENGTH
+#ifdef USE_MULTIPLE
+#define Pget mdc2_Pget
+#define Pnew mdc2_Pnew
+#define Lclone mdc2_Lclone
+#define Ldigest mdc2_Ldigest
+#define Lnew mdc2_Lnew
+#define Lreset mdc2_Lreset
+#define Ltostring mdc2_Ltostring
+#define Lupdate mdc2_Lupdate
+#define R mdc2_R
+#endif
+#endif
+
View
9 lsha1.c
@@ -1,9 +0,0 @@
-/*
-* lsha1.c
-* sha1 library for Lua 5.0 based on Rivest's API
-* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
-* 26 Mar 2004 17:39:16
-* This code is hereby placed in the public domain.
-*/
-
-#include "lmd5.c"
View
10 md5.lua
@@ -1,10 +0,0 @@
--- md5.lua
--- support code for md5 library
--- usage lua -lmd5 ...
-
-local function so(x)
- local SOPATH= os.getenv"LUA_SOPATH" or "./"
- assert(loadlib(SOPATH.."l"..x..".so","luaopen_"..x))()
-end
-
-so"md5"
View
10 sha1.lua
@@ -1,10 +0,0 @@
--- sha1.lua
--- support code for sha1 library
--- usage lua -lsha1 ...
-
-local function so(x)
- local SOPATH= os.getenv"LUA_SOPATH" or "./"
- assert(loadlib(SOPATH.."l"..x..".so","luaopen_"..x))()
-end
-
-so"sha1"
View
91 test.lua
@@ -1,48 +1,61 @@
-- test md5 library
-if md5 then
- KNOWN="f6ad58224a015825d7bb3cb953239f01"
- COMMAND="echo -en 'md5sum\t'; md5sum "
-else
- md5=sha1
- KNOWN="d1f1133ee1093f164391b89bf9cefb2a34b9a557"
- COMMAND="echo -en 'sha1sum\t'; sha1sum "
-end
-
-print(md5.version)
-print""
-
function report(w,s,F)
print(w,s.." "..F)
assert(s==KNOWN)
end
-F="md5.lua"
-
-assert(io.input(F))
-report("all",md5.digest(io.read"*a"),F)
-
-assert(io.input(F))
-d=md5.new()
-while true do
- local c=io.read(1)
- if c==nil then break end
- d:update(c)
-end
-report("loop",d:digest(),F)
-report("again",d:digest(),F)
-
-assert(io.input(F))
-d:reset()
-while true do
- local c=io.read(math.random(1,16))
- if c==nil then break end
- d:update(c)
+function test(D,known)
+ if D==nil then return end
+ KNOWN=known
+ print""
+ print(D.version)
+ print""
+
+ assert(io.input(F))
+ report("all",D.digest(io.read"*a"),F)
+
+ assert(io.input(F))
+ d=D.new()
+ while true do
+ local c=io.read(1)
+ if c==nil then break end
+ d:update(c)
+ end
+ report("loop",d:digest(),F)
+ report("again",d:digest(),F)
+
+ assert(io.input(F))
+ d:reset()
+ while true do
+ local c=io.read(math.random(1,16))
+ if c==nil then break end
+ d:update(c)
+ end
+ report("reset",d:digest(),F)
+
+ report("known",KNOWN,F)
+
+ local A="hello"
+ local B="world"
+ local C=A..B
+ local a=D.digest(C)
+ local b=d:reset():update(C):digest()
+ assert(a==b)
+ local b=d:reset():update(A):update(B):digest()
+ assert(a==b)
end
-report("reset",d:digest(),F)
-
-os.execute(COMMAND..F)
-report("known",KNOWN,F)
-print""
-print(md5.version)
+F="README"
+test(md2,'4cea4d55c69fc5b1c8a2db32a9491114')
+test(md4,'2447a1c4ee46a1561742e7fd96dc6a9e')
+test(md5,'876e33dfc2a7cd1e46e534d0c00fd4f1')
+test(sha1,'e189103170f22bbb25fc6251ef3724c98f2be033')
+test(sha224,'37c8c186ed4d7a86249b593deb1741b36c7d6c32b7bd71bf9e67f3f5')
+test(sha256,'05ac5c8d98b2a089d87fc911848ba3767d1190dad091dff89010794808ed754a')
+test(sha384,'285e6a2ea0ac429146a363e06cc21237579a84aa2529e92605393d03e0fe22d7bbddeecc74e8a3e3e343b11a40a81ab8')
+test(sha512,'72adc6409162f81b8ceca616bd5bf931a740c2416ba23a38385f7052e7061bdea66c90fa78847f4df37287e4d072a585d9dfa91428c7f112507fadfee9582300')
+test(ripemd160,'f24a89b2be6872480ade3c3b7cd25b6e0fb8212f')
+test(mdc2,'94f5b21d365c093dcafa4bfaa9a91b37')
+
+-- eof
Please sign in to comment.
Something went wrong with that request. Please try again.