Author: richard
Date: Tue Mar 17 10:01:06 2009
New Revision: 4824
URL: http://svn.slimdevices.com/jive?rev=4824&view=rev
Log:
Bug: N/A
Description:
Lua library for MD5 and SHA1.
Added:
7.4/trunk/squeezeplay/src/luamd5/
7.4/trunk/squeezeplay/src/luamd5/Makefile
7.4/trunk/squeezeplay/src/luamd5/README
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/EXPORT
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INCLUDE
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INTERNAL
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/Makefile
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/common.h
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5.h
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_final.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_init.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_internal.h
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_transform.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_update.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.h
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4_init.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1.h
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_feed.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_final.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_init.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_internal.h
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_transform.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_update.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/stdcrypto.h
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_pack_big.c
7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_reverse.c
7.4/trunk/squeezeplay/src/luamd5/lmd5.c
7.4/trunk/squeezeplay/src/luamd5/lmd5.h
7.4/trunk/squeezeplay/src/luamd5/lsha1.c
7.4/trunk/squeezeplay/src/luamd5/test.lua
Modified:
7.4/trunk/squeezeplay/src/Makefile.linux
Modified: 7.4/trunk/squeezeplay/src/Makefile.linux
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/Makefile.linux?rev=4824&r1=4823&r2=4824&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/Makefile.linux (original)
+++ 7.4/trunk/squeezeplay/src/Makefile.linux Tue Mar 17 10:01:06 2009
@@ -93,9 +93,9 @@
# lua
#####
-.PHONY: lua-all lua luasocket slnunicode luajson loop lualogging luaexpat
luafilesystem luaprofiler luazipfilter
-
-lua-all: lua tolua++ luasocket slnunicode luajson loop lualogging luaexpat
luafilesystem luaprofiler luazipfilter
+.PHONY: lua-all lua luasocket slnunicode luajson loop lualogging luaexpat
luafilesystem luaprofiler luazipfilter luamd5
+
+lua-all: lua tolua++ luasocket slnunicode luajson loop lualogging luaexpat
luafilesystem luaprofiler luazipfilter luamd5
# lua (requires readline ncurses)
lua:
@@ -119,6 +119,12 @@
luazipfilter: luazipfilter/Makefile
cd luazipfilter; make && cp .libs/zipfilter.so
${PREFIX}/lib/lua/5.1/zipfilter.so
+
+luamd5:
+ cd luamd5; make LUA=${PREFIX} MYNAME=sha1
+ cd luamd5; make LUA=${PREFIX} MYNAME=md5
+ cp luamd5/md5.so ${PREFIX}/lib/lua/5.1/md5.so
+ cp luamd5/sha1.so ${PREFIX}/lib/lua/5.1/sha1.so
loop:
-mkdir ${PREFIX}/share/lua/5.1/loop
@@ -266,6 +272,8 @@
-cd luajson; make distclean
-cd luazipfilter; make distclean
-cd luaprofiler-2.0; make -f Makefile.linux clean
+ -cd luamd5; make MYNAME=sha1 clean
+ -cd luamd5; make MYNAME=md5 clean
-cd tolua++-1.0.92/src/lib; rm libtolua++.so; rm *.o
-cd squeezeplay; make distclean
-cd squeezeplay_private; make distclean
Added: 7.4/trunk/squeezeplay/src/luamd5/Makefile
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/Makefile?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/Makefile (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/Makefile Tue Mar 17 10:01:06 2009
@@ -1,0 +1,121 @@
+# makefile for md5/sha1 library for Lua
+
+# change these to reflect your Lua installation
+#LUA= /tmp/lhf/lua-5.1.4
+LUAINC= $(LUA)/include
+LUALIB= $(LUA)/lib
+LUABIN= $(LUA)/bin
+
+# these will probably work if Lua has been installed globally
+#LUA= /usr/local
+#LUAINC= $(LUA)/include
+#LUALIB= $(LUA)/lib
+#LUABIN= $(LUA)/bin
+
+### change these to reflect your MD5 library
+#MYNAME= md5
+#
+# 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)
+
+
+# skalibs MD5 / SHA1 library from source
+ifeq ($(MYNAME),sha1)
+DEFS= -DUSE_SHA1_SKALIBS
+MD5INC = -Ilibstdcrypto
+MD5LIB = libstdcrypto/sha1_feed.o libstdcrypto/sha1_transform.o
libstdcrypto/sha1_final.o libstdcrypto/sha1_update.o libstdcrypto/sha1_init.o
libstdcrypto/uint32_pack_big.o
+else
+DEFS= -DUSE_MD5_SKALIBS
+MD5INC = -Ilibstdcrypto
+MD5LIB = libstdcrypto/md5_final.o libstdcrypto/md5_transform.o
libstdcrypto/md5_init.o libstdcrypto/md5_update.o libstdcrypto/uint32_reverse.o
+endif
+
+MD5OBJ= $(MD5LIB)
+
+# probably no need to change anything below here
+CC= gcc
+CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 $G
+WARN= #-ansi -pedantic -Wall
+INCS= -I$(LUAINC) $(MD5INC)
+
+MYLIB= l$(MYNAME)
+T= $(MYNAME).so
+OBJS= $(MYLIB).o
+TEST= test.lua
+
+all: $T
+
+test: $T
+ $(LUABIN)/lua -l$(MYNAME) $(TEST)
+
+o: $(MYLIB).o
+
+so: $T
+
+$T: $(OBJS) $(MD5OBJ)
+ $(CC) -o $@ -shared $(OBJS) $(MD5LIB)
+
+clean:
+ rm -f $(OBJS) $T core core.* $(MD5OBJ)
+
+doc:
+ @echo "$(MYNAME) library:"
+ @fgrep '/**' $(MYLIB).c | cut -f2 -d/ | tr -d '*' | sort | column
+
+# distribution
+
+FTP= $(HOME)/public/ftp/lua/5.1
+D= $(MYNAME)
+A= $(MYLIB).tar.gz
+TOTAR= Makefile,README,lmd5.c,lmd5.h,lsha1.c,test.lua
+
+distr: clean
+ tar zcvf $A -C .. $D/{$(TOTAR)}
+ touch -r $A .stamp
+ mv $A $(FTP)
+
+diff: clean
+ tar zxf $(FTP)/$A
+ diff $D .
+
+# eof
Added: 7.4/trunk/squeezeplay/src/luamd5/README
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/README?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/README (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/README Tue Mar 17 10:01:06 2009
@@ -1,0 +1,58 @@
+This is an MD5 library for Lua 5.1. 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). For
+more information in MD5 and SHA1, see
+ http://en.wikipedia.org/wiki/MD5
+ http://en.wikipedia.org/wiki/SHA_hash_functions
+
+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
+ 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
+below. Read also test.lua, which shows the library in action.
+
+This code is hereby placed in the public domain.
+Please send comments, suggestions, and bug reports to [email protected] .
+
+-------------------------------------------------------------------------------
+
+md5 library:
+ clone(c) reset(c) version
+ digest(c or s,[raw]) tostring(c)
+ new() 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. Most probably it's in libcrypto,
+which is part of openssl (or libsasl, but don't use /usr/include/sasl/md5.h).
+The Makefile assumes this as default.
+
+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.
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/EXPORT
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/EXPORT?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/EXPORT (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/EXPORT Tue Mar 17 10:01:06
2009
@@ -1,0 +1,1 @@
+libstdcrypto.a
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INCLUDE
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INCLUDE?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INCLUDE (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INCLUDE Tue Mar 17 10:01:06
2009
@@ -1,0 +1,4 @@
+rc4.h
+md5.h
+sha1.h
+stdcrypto.h
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INTERNAL
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INTERNAL?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INTERNAL (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/INTERNAL Tue Mar 17 10:01:06
2009
@@ -1,0 +1,11 @@
+md5_init.o
+md5_transform.o
+md5_update.o
+md5_final.o
+rc4.o
+rc4_init.o
+sha1_init.o
+sha1_transform.o
+sha1_feed.o
+sha1_update.o
+sha1_final.o
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/Makefile
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/Makefile?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/Makefile (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/Makefile Tue Mar 17 10:01:06
2009
@@ -1,0 +1,65 @@
+it: command include library library.so
+
+clean: EXPORT INTERNAL
+ rm -f `cat EXPORT INTERNAL`
+
+
+stdcrypto.h: rc4.h sha1.h md5.h
+ touch stdcrypto.h
+
+rc4.o: compile rc4.c rc4.h bytestr.h
+ ./compile rc4.c
+
+rc4_init.o: compile rc4_init.c rc4.h bytestr.h
+ ./compile rc4_init.c
+
+md5.h: uint32.h
+ touch md5.h
+
+md5_init.o: compile md5_init.c md5.h uint32.h
+ ./compile md5_init.c
+
+md5_transform.o: compile md5_transform.c md5_internal.h md5.h uint32.h
+ ./compile md5_transform.c
+
+md5_update.o: compile md5_update.c md5_internal.h md5.h bytestr.h uint32.h
+ ./compile md5_update.c
+
+md5_final.o: compile md5_final.c md5_internal.h md5.h uint32.h
+ ./compile md5_final.c
+
+sha1.h: uint32.h
+ touch sha1.h
+
+sha1_init.o: compile sha1_init.c sha1.h
+ ./compile sha1_init.c
+
+sha1_transform.o: compile sha1_transform.c sha1_internal.h sha1.h uint32.h
+ ./compile sha1_transform.c
+
+sha1_feed.o: compile sha1_feed.c sha1_internal.h sha1.h uint32.h bytestr.h
+ ./compile sha1_feed.c
+
+sha1_update.o: compile sha1_update.c sha1_internal.h sha1.h
+ ./compile sha1_update.c
+
+sha1_final.o: compile sha1_final.c sha1_internal.h sha1.h uint32.h
+ ./compile sha1_final.c
+
+libstdcrypto.a: makelib \
+rc4.o rc4_init.o \
+md5_init.o md5_transform.o md5_update.o md5_final.o \
+sha1_init.o sha1_transform.o sha1_feed.o sha1_update.o sha1_final.o
+ ./makelib libstdcrypto.a \
+ rc4.o rc4_init.o \
+ md5_init.o md5_transform.o md5_update.o md5_final.o \
+ sha1_init.o sha1_transform.o sha1_feed.o sha1_update.o sha1_final.o
+
+
+command:
+
+include: rc4.h md5.h sha1.h stdcrypto.h
+
+library: libstdcrypto.a
+
+library.so:
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/common.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/common.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/common.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/common.h Tue Mar 17 10:01:06
2009
@@ -1,0 +1,11 @@
+#ifndef _COMMON_H
+#define _COMMON_H
+
+#include <string.h>
+
+typedef unsigned int uint32;
+#define T8(x) ((x) & 0xffU)
+
+#define uint32_little_endian(s, n) //uint32_reverse((s), (n))
+
+#endif // _COMMON_H
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5.h Tue Mar 17 10:01:06 2009
@@ -1,0 +1,22 @@
+/* Public domain. */
+
+#ifndef MD5_H
+#define MD5_H
+
+//#include "uint32.h"
+#include "common.h"
+
+typedef struct MD5Schedule MD5Schedule, *MD5Schedule_ref ;
+struct MD5Schedule
+{
+ uint32 buf[4] ;
+ uint32 bits[2] ;
+ unsigned char in[64] ;
+} ;
+
+#define MD5_INIT() { {0x67452301UL, 0xefcdab89UL, 0x98badcfeUL, 0x10325476UL},
{0, 0},
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
}
+extern void md5_init (MD5Schedule_ref) ;
+extern void md5_update (MD5Schedule_ref, char const *, unsigned int) ;
+extern void md5_final (MD5Schedule_ref, char * /* 16 chars */) ;
+
+#endif
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_final.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_final.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_final.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_final.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,30 @@
+/* Public domain. */
+
+//#include "uint32.h"
+//#include "bytestr.h"
+#include "md5.h"
+#include "md5_internal.h"
+
+void md5_final (MD5Schedule_ref ctx, char *digest /* 16 chars */)
+{
+ register unsigned int count = (ctx->bits[0] >> 3) & 0x3F ;
+ register unsigned char *p = ctx->in + count ;
+ *p++ = 0x80;
+ count = 63 - count ;
+ if (count < 8)
+ {
+ memset(p, 0, count) ;
+ uint32_little_endian(ctx->in, 16) ;
+ md5_transform(ctx->buf, (uint32 *)ctx->in) ;
+ memset(ctx->in, 0, 56) ;
+ }
+ else memset(p, 0, count - 8) ;
+ uint32_little_endian(ctx->in, 14) ;
+
+ ((uint32 *)ctx->in)[14] = ctx->bits[0] ;
+ ((uint32 *)ctx->in)[15] = ctx->bits[1] ;
+
+ md5_transform(ctx->buf, (uint32 *)ctx->in) ;
+ uint32_little_endian((char *)ctx->buf, 4) ;
+ memmove(digest, (char *)ctx->buf, 16) ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_init.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_init.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_init.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_init.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,13 @@
+/* Public domain. */
+
+#include "md5.h"
+
+void md5_init (MD5Schedule_ref ctx)
+{
+ ctx->buf[0] = 0x67452301UL ;
+ ctx->buf[1] = 0xefcdab89UL ;
+ ctx->buf[2] = 0x98badcfeUL ;
+ ctx->buf[3] = 0x10325476UL ;
+ ctx->bits[0] = 0 ;
+ ctx->bits[1] = 0 ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_internal.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_internal.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_internal.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_internal.h Tue Mar 17
10:01:06 2009
@@ -1,0 +1,11 @@
+/* Public domain. */
+
+#ifndef MD5_INTERNAL_H
+#define MD5_INTERNAL_H
+
+//#include "uint32.h"
+#include "md5.h"
+
+extern void md5_transform (uint32 * /* 4 uint32s */, uint32 const * /* 16
uint32s */) ;
+
+#endif
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_transform.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_transform.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_transform.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_transform.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,91 @@
+/* Public domain. */
+
+//#include "uint32.h"
+#include "md5_internal.h"
+
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+#define MD5STEP(f, w, x, y, z, data, s) \
+ ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
+
+void md5_transform (uint32 *buf /* 4 uint32s */, uint32 const *in /* 16
uint32s */)
+{
+ register uint32 a = buf[0], b = buf[1], c = buf[2], d = buf[3] ;
+
+ MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7) ;
+ MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12) ;
+ MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17) ;
+ MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22) ;
+ MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7) ;
+ MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12) ;
+ MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17) ;
+ MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22) ;
+ MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7) ;
+ MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12) ;
+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17) ;
+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22) ;
+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7) ;
+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12) ;
+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17) ;
+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22) ;
+
+ MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5) ;
+ MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9) ;
+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14) ;
+ MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20) ;
+ MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5) ;
+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9) ;
+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14) ;
+ MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20) ;
+ MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5) ;
+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9) ;
+ MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14) ;
+ MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20) ;
+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5) ;
+ MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9) ;
+ MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14) ;
+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20) ;
+
+ MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4) ;
+ MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11) ;
+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16) ;
+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23) ;
+ MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4) ;
+ MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11) ;
+ MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16) ;
+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23) ;
+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4) ;
+ MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11) ;
+ MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16) ;
+ MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23) ;
+ MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4) ;
+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11) ;
+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16) ;
+ MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23) ;
+
+ MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6) ;
+ MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10) ;
+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15) ;
+ MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21) ;
+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6) ;
+ MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10) ;
+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15) ;
+ MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21) ;
+ MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6) ;
+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10) ;
+ MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15) ;
+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21) ;
+ MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6) ;
+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10) ;
+ MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15) ;
+ MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21) ;
+
+ buf[0] += a ;
+ buf[1] += b ;
+ buf[2] += c ;
+ buf[3] += d ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_update.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_update.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_update.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/md5_update.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,37 @@
+/* Public domain. */
+
+//#include "uint32.h"
+//#include "bytestr.h"
+#include "md5.h"
+#include "md5_internal.h"
+
+void md5_update (MD5Schedule_ref ctx, char const *s, unsigned int len)
+{
+ register uint32 t = ctx->bits[0] ;
+ if ((ctx->bits[0] = t + (len << 3)) < t)
+ ctx->bits[1]++ ;
+ ctx->bits[1] += len >> 29 ;
+ t = (t >> 3) & 0x3f ;
+ if (t)
+ {
+ unsigned char *p = ctx->in + t ;
+ t = 64 - t ;
+ if (len < t)
+ {
+ memmove((char *)p, s, len) ;
+ return ;
+ }
+ memmove((char *)p, s, t) ;
+ uint32_little_endian(ctx->in, 16) ;
+ md5_transform(ctx->buf, (uint32 *)ctx->in) ;
+ s += t ; len -= t ;
+ }
+ while (len >= 64)
+ {
+ memmove((char *)ctx->in, s, 64) ;
+ uint32_little_endian(ctx->in, 16) ;
+ md5_transform(ctx->buf, (uint32 *)ctx->in) ;
+ s += 64 ; len -= 64 ;
+ }
+ memmove((char *)ctx->in, s, len) ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.c Tue Mar 17 10:01:06 2009
@@ -1,0 +1,20 @@
+/* Public domain. */
+/* Thanks to Thomas Pornin <[email protected]> */
+
+#include "bytestr.h"
+#include "rc4.h"
+
+void rc4 (RC4Schedule_ref r, char const *in, char *out, unsigned int n)
+{
+ register unsigned int i = 0 ;
+ for (; i < n ; i++)
+ {
+ register unsigned char t ;
+ r->x = T8(r->x + 1) ;
+ t = r->tab[r->x] ;
+ r->y = T8(r->y + t) ;
+ r->tab[r->x] = r->tab[r->y] ;
+ r->tab[r->y] = t ;
+ out[i] = (unsigned char)in[i] ^ T8(r->tab[r->x] + r->tab[r->y]) ;
+ }
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4.h Tue Mar 17 10:01:06 2009
@@ -1,0 +1,19 @@
+/* Public domain. */
+
+#ifndef RC4_H
+#define RC4_H
+
+#define RC4_THROWAWAY 128
+
+typedef struct RC4Schedule RC4Schedule, *RC4Schedule_ref ;
+
+struct RC4Schedule
+{
+ unsigned char tab[256] ;
+ unsigned char x, y ;
+} ;
+
+extern void rc4_init (RC4Schedule_ref, char const *, unsigned int) ;
+extern void rc4 (RC4Schedule_ref, char const *, char *, unsigned int) ;
+
+#endif
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4_init.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4_init.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4_init.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/rc4_init.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,26 @@
+/* Public domain. */
+/* Thanks to Thomas Pornin <[email protected]> */
+
+#include "bytestr.h"
+#include "rc4.h"
+
+void rc4_init (RC4Schedule_ref r, char const *key, unsigned int ksize)
+{
+ register unsigned int i = 0, j = 0 ;
+ register unsigned char c = 0;
+
+ r->x = r->y = 0 ;
+ for (; i < 256 ; i++) r->tab[i] = i ;
+ for (i = 0 ; i < 256 ; i++)
+ {
+ unsigned char t = r->tab[i] ;
+ c = T8(c + (unsigned char)key[j] + t) ;
+ r->tab[i] = r->tab[c] ;
+ r->tab[c] = t ;
+ if (++j == ksize) j = 0 ;
+ }
+ {
+ char tmp[RC4_THROWAWAY] ;
+ rc4(r, tmp, tmp, RC4_THROWAWAY) ;
+ }
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1.h Tue Mar 17 10:01:06
2009
@@ -1,0 +1,23 @@
+/* Public domain. */
+
+#ifndef SHA1_H
+#define SHA1_H
+
+//#include "uint32.h"
+#include "common.h"
+
+typedef struct SHA1Schedule SHA1Schedule, *SHA1Schedule_ref ;
+struct SHA1Schedule
+{
+ uint32 buf[5] ;
+ uint32 bits[2] ;
+ uint32 in[16] ;
+ unsigned char b ;
+} ;
+
+#define SHA1_INIT() { {0x67452301UL, 0xefcdab89UL, 0x98badcfeUL, 0x10325476UL,
0xc3d2e1f0UL}, {0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0 }
+extern void sha1_init (SHA1Schedule_ref) ;
+extern void sha1_update (SHA1Schedule_ref, char const *, unsigned int) ;
+extern void sha1_final (SHA1Schedule_ref, char * /* 20 chars */) ;
+
+#endif
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_feed.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_feed.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_feed.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_feed.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,24 @@
+/* Public domain. */
+
+//#include "uint32.h"
+//#include "bytestr.h"
+#include "sha1.h"
+#include "sha1_internal.h"
+
+void sha1_feed (SHA1Schedule_ref ctx, unsigned char inb)
+{
+ register uint32 tmp ;
+
+ ctx->in[ctx->b>>2] <<= 8 ;
+ ctx->in[ctx->b>>2] |= T8(inb) ;
+ if (++ctx->b >= 64)
+ {
+ register unsigned int i = 0 ;
+ sha1_transform(ctx->buf, ctx->in) ;
+ ctx->b = 0 ;
+ for (i = 0 ; i < 16 ; i++) ctx->in[i] = 0 ;
+ }
+ tmp = ctx->bits[0] ;
+ ctx->bits[0] += 8 ;
+ if (tmp > ctx->bits[0]) ctx->bits[1]++ ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_final.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_final.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_final.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_final.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,18 @@
+/* Public domain. */
+
+//#include "uint32.h"
+#include "sha1.h"
+#include "sha1_internal.h"
+
+void sha1_final (SHA1Schedule_ref ctx, char *digest)
+{
+ char pack[8] ;
+ register unsigned int i = 0 ;
+ uint32_pack_big(pack, ctx->bits[1]) ;
+ uint32_pack_big(pack+4, ctx->bits[0]) ;
+ sha1_feed(ctx, 0x80) ;
+ while (ctx->b != 56) sha1_feed(ctx, 0) ;
+ sha1_update(ctx, pack, 8) ;
+ for (; i < 5 ; i++)
+ uint32_pack_big(digest + (i<<2), ctx->buf[i]) ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_init.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_init.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_init.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_init.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,16 @@
+/* Public domain. */
+
+#include "sha1.h"
+
+void sha1_init (SHA1Schedule_ref ctx)
+{
+ register unsigned int i = 0 ;
+ ctx->buf[0] = 0x67452301UL ;
+ ctx->buf[1] = 0xefcdab89UL ;
+ ctx->buf[2] = 0x98badcfeUL ;
+ ctx->buf[3] = 0x10325476UL ;
+ ctx->buf[4] = 0xc3d2e1f0UL ;
+ ctx->bits[0] = ctx->bits[1] = 0 ;
+ for (; i < 16 ; i++) ctx->in[i] = 0 ;
+ ctx->b = 0 ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_internal.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_internal.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_internal.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_internal.h Tue Mar 17
10:01:06 2009
@@ -1,0 +1,11 @@
+/* Public domain. */
+
+#ifndef SHA1_INTERNAL_H
+#define SHA1_INTERNAL_H
+
+#include "sha1.h"
+
+extern void sha1_feed (SHA1Schedule_ref, unsigned char) ;
+extern void sha1_transform (uint32 * /* 5 uint32s */, uint32 const * /* 16
uint32s */) ;
+
+#endif
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_transform.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_transform.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_transform.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_transform.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,42 @@
+/* Public domain. */
+
+//#include "uint32.h"
+#include "sha1_internal.h"
+
+#define F1(x, y, z) ((x & y) | ((~x) & z))
+#define F2(x, y, z) (x ^ y ^ z)
+#define F3(x, y, z) ((x & y) | (x & z) | (y & z))
+#define F4(x, y, z) (x ^ y ^ z)
+
+#define SHA1STEP(f, data) \
+{ \
+ register uint32 tmp = e + f(b, c, d) + data + ((a<<5) | (a>>27)); \
+ e = d ; \
+ d = c ; \
+ c = (b<<30) | (b>>2) ; \
+ b = a ; \
+ a = tmp ; \
+}
+
+void sha1_transform (uint32 *buf, uint32 const *in)
+{
+ register uint32 a = buf[0], b = buf[1], c = buf[2], d = buf[3], e = buf[4] ;
+ uint32 w[80] ;
+ register unsigned int i = 0 ;
+
+ for (; i < 16 ; i++) w[i] = in[i] ;
+ for (; i < 80 ; i++)
+ {
+ w[i] = w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16] ;
+ w[i] = (w[i]<<1) | (w[i]>>31) ;
+ }
+ for (i = 0 ; i < 20 ; i++)
+ SHA1STEP(F1, w[i] + 0x5a827999UL) ;
+ for (; i < 40 ; i++)
+ SHA1STEP(F2, w[i] + 0x6ed9eba1UL) ;
+ for (; i < 60 ; i++)
+ SHA1STEP(F3, w[i] + 0x8f1bbcdcUL) ;
+ for (; i < 80 ; i++)
+ SHA1STEP(F4, w[i] + 0xca62c1d6UL) ;
+ buf[0] += a ; buf[1] += b ; buf[2] += c ; buf[3] += d ; buf[4] += e ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_update.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_update.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_update.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/sha1_update.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,10 @@
+/* Public domain. */
+
+#include "sha1.h"
+#include "sha1_internal.h"
+
+void sha1_update (SHA1Schedule_ref ctx, char const *buf, unsigned int len)
+{
+ register unsigned int i = 0 ;
+ for (; i < len ; i++) sha1_feed(ctx, (unsigned char)buf[i]) ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/stdcrypto.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/stdcrypto.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/stdcrypto.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/stdcrypto.h Tue Mar 17
10:01:06 2009
@@ -1,0 +1,10 @@
+/* Public domain. */
+
+#ifndef STDCRYPTO_H
+#define STDCRYPTO_H
+
+#include "rc4.h"
+#include "md5.h"
+#include "sha1.h"
+
+#endif
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_pack_big.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_pack_big.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_pack_big.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_pack_big.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,13 @@
+/* Public domain. */
+
+//#include "uint32.h"
+//#include "bytestr.h"
+#include "common.h"
+
+void uint32_pack_big (char *s, uint32 u)
+{
+ ((unsigned char *)s)[3] = T8(u) ; u >>= 8 ;
+ ((unsigned char *)s)[2] = T8(u) ; u >>= 8 ;
+ ((unsigned char *)s)[1] = T8(u) ; u >>= 8 ;
+ ((unsigned char *)s)[0] = T8(u) ;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_reverse.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_reverse.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_reverse.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/libstdcrypto/uint32_reverse.c Tue Mar 17
10:01:06 2009
@@ -1,0 +1,17 @@
+/* Public domain. */
+
+//#include "uint32.h"
+
+void uint32_reverse (char *s, unsigned int n)
+{
+ while (n--)
+ {
+ char c = s[0] ;
+ s[0] = s[3] ;
+ s[3] = c ;
+ c = s[1] ;
+ s[1] = s[2] ;
+ s[2] = c ;
+ s += 4 ;
+ }
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/lmd5.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/lmd5.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/lmd5.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/lmd5.c Tue Mar 17 10:01:06 2009
@@ -1,0 +1,128 @@
+/*
+* lmd5.c
+* MD5 library for Lua 5.0 based on Rivest's API
+* Luiz Henrique de Figueiredo <[email protected]>
+* 12 Nov 2008 20:09:42
+* 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 " / Nov 2008 / "\
+ "using " AUTHOR
+#define MYTYPE MYNAME " context"
+
+static MD5_CTX *Pget(lua_State *L, int i)
+{
+ return luaL_checkudata(L,i,MYTYPE);
+}
+
+static MD5_CTX *Pnew(lua_State *L)
+{
+ MD5_CTX *c=lua_newuserdata(L,sizeof(MD5_CTX));
+ luaL_getmetatable(L,MYTYPE);
+ lua_setmetatable(L,-2);
+ return c;
+}
+
+static int Lnew(lua_State *L) /** new() */
+{
+ MD5_CTX *c=Pnew(L);
+ MD5Init(c);
+ return 1;
+}
+
+static int Lclone(lua_State *L) /** clone(c) */
+{
+ MD5_CTX *c=Pget(L,1);
+ MD5_CTX *d=Pnew(L);
+ *d=*c;
+ return 1;
+}
+
+static int Lreset(lua_State *L) /** reset(c) */
+{
+ MD5_CTX *c=Pget(L,1);
+ MD5Init(c);
+ return 0;
+}
+
+static int Lupdate(lua_State *L) /** update(c,s) */
+{
+ size_t l;
+ MD5_CTX *c=Pget(L,1);
+ const char *s=luaL_checklstring(L,2,&l);
+ MD5Update(c,s,l);
+ return 0;
+}
+
+static int Ldigest(lua_State *L) /** digest(c or s,[raw]) */
+{
+ unsigned char digest[N];
+ if (lua_isuserdata(L,1))
+ {
+ MD5_CTX c=*Pget(L,1);
+ MD5Final(digest,&c);
+ }
+ else
+ {
+ size_t l;
+ const char *s=luaL_checklstring(L,1,&l);
+ MD5_CTX c;
+ MD5Init(&c);
+ MD5Update(&c,s,l);
+ MD5Final(digest,&c);
+ }
+ if (lua_toboolean(L,2))
+ lua_pushlstring(L,digest,sizeof(digest));
+ else
+ {
+ char hex[2*N+1];
+ int i;
+ for (i=0; i<N; i++) sprintf(hex+2*i,"%02x",digest[i]);
+ lua_pushlstring(L,hex,sizeof(hex)-1);
+ }
+ return 1;
+}
+
+static int Ltostring(lua_State *L) /** tostring(c) */
+{
+ MD5_CTX *c=Pget(L,1);
+ lua_pushfstring(L,"%s %p",MYTYPE,(void*)c);
+ return 1;
+}
+
+static const luaL_reg R[] =
+{
+ { "clone", Lclone },
+ { "digest", Ldigest },
+ { "new", Lnew },
+ { "reset", Lreset },
+ { "tostring", Ltostring},
+ { "update", Lupdate },
+ { NULL, NULL }
+};
+
+LUALIB_API int luaopen_md5(lua_State *L)
+{
+ luaL_newmetatable(L,MYTYPE);
+ lua_pushvalue(L,-1);
+ luaL_openlib(L,NULL,R,0);
+ 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_pushliteral(L,"__tostring");
+ lua_pushliteral(L,"tostring");
+ lua_gettable(L,-3);
+ lua_settable(L,-3);
+ lua_setglobal(L,MYNAME);
+ return 1;
+}
Added: 7.4/trunk/squeezeplay/src/luamd5/lmd5.h
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/lmd5.h?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/lmd5.h (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/lmd5.h Tue Mar 17 10:01:06 2009
@@ -1,0 +1,89 @@
+/*
+* lmd5.h
+* MD5 library for Lua 5.0 based on Rivest's API
+* Luiz Henrique de Figueiredo <[email protected]>
+* 26 Mar 2004 17:49:20
+* 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
+
+#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"
+#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"
+#endif
+
+#ifdef USE_MD5_SKALIBS
+#define USING_MD5
+#define AUTHOR "skalibs"
+#define MD5_CTX MD5Schedule
+#define MD5Init md5_init
+#define MD5Update md5_update
+#define MD5Final(digest,c) md5_final(c,digest)
+#include "md5.h"
+#endif
+
+#ifdef USE_MD5_OPENSSL
+#define AUTHOR "openssl"
+#define MD5CTX MD5_CTX
+#define MD5Init MD5_Init
+#define MD5Update MD5_Update
+#define MD5Final MD5_Final
+#include <openssl/md5.h>
+#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"
+#endif
+
+#ifdef USE_MD5_PLUMB
+#define AUTHOR "Plumb"
+#include "md5.h"
+#endif
+
+#ifndef AUTHOR
+#define USE_MD5_RIVEST
+#endif
+
+#ifdef USE_MD5_RIVEST
+#define AUTHOR "Rivest"
+#include "md5global.h"
+#include "md5.h"
+#endif
+
+#ifdef USING_SHA1
+#define MYNAME "sha1"
+#define N 20
+#define luaopen_md5 luaopen_sha1
+#else
+#define MYNAME "md5"
+#define N 16
+#endif
Added: 7.4/trunk/squeezeplay/src/luamd5/lsha1.c
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/lsha1.c?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/lsha1.c (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/lsha1.c Tue Mar 17 10:01:06 2009
@@ -1,0 +1,9 @@
+/*
+* lsha1.c
+* sha1 library for Lua 5.0 based on Rivest's API
+* Luiz Henrique de Figueiredo <[email protected]>
+* 26 Mar 2004 17:39:16
+* This code is hereby placed in the public domain.
+*/
+
+#include "lmd5.c"
Added: 7.4/trunk/squeezeplay/src/luamd5/test.lua
URL:
http://svn.slimdevices.com/jive/7.4/trunk/squeezeplay/src/luamd5/test.lua?rev=4824&view=auto
==============================================================================
--- 7.4/trunk/squeezeplay/src/luamd5/test.lua (added)
+++ 7.4/trunk/squeezeplay/src/luamd5/test.lua Tue Mar 17 10:01:06 2009
@@ -1,0 +1,50 @@
+-- test md5 library
+
+if md5 then
+ KNOWN="df30c0941d1f8eef9a5df9e482f0a3da"
+ COMMAND="echo -n 'md5sum\t'; md5sum "
+else
+ md5=sha1
+ KNOWN="562abb5ed8f9d5ab3e12387108aa36ca2c61b7e9"
+ COMMAND="echo -n 'sha1sum\t'; sha1sum "
+end
+
+print(md5.version)
+print""
+
+function report(w,s,F)
+ print(w,s.." "..F)
+ assert(s==KNOWN)
+end
+
+F="README"
+
+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)
+end
+report("reset",d:digest(),F)
+
+os.execute(COMMAND..F)
+report("known",KNOWN,F)
+
+print""
+print(md5.version)
+
+-- eof
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins