Permalink
Browse files

Imported from 5.1/lmd5.tar.gz.

  • Loading branch information...
1 parent 198ed20 commit 0d5fb233ec49bbf97eec76d5fbe9da1ce4563eae Luiz Henrique de Figueiredo committed Mar 24, 2011
Showing with 524 additions and 262 deletions.
  1. +74 −72 Makefile
  2. +26 −43 README
  3. +110 −0 ldigest.c
  4. +28 −26 lmd5.c
  5. +234 −53 lmd5.h
  6. +0 −9 lsha1.c
  7. +0 −10 md5.lua
  8. +0 −10 sha1.lua
  9. +52 −39 test.lua
View
@@ -1,106 +1,108 @@
-# 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
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
@@ -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
@@ -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;
+}
Oops, something went wrong.

0 comments on commit 0d5fb23

Please sign in to comment.