--- canlock-2b.orig/Makefile
+++ canlock-2b/Makefile
@@ -1,65 +1,38 @@
-ANALFLAGS= -pg -W -Wall -pedantic -Wcast-align \
-           -Wcast-qual -Wchar-subscripts -Winline \
-           -Wmissing-prototypes -Wpointer-arith \
-           -Wredundant-decls -Wshadow -Wstrict-prototypes -Wwrite-strings
-CFLAGS = -O -Iinclude
+CFLAGS = -Iinclude
 LDFLAGS = -L. -lcanlock
-LIBOBJS = src/sha1.o src/hmac_sha1.o src/base64.o src/canlock.o
-LOCKLIB = libcanlock.a
+CC = gcc
+STATIC_LIB = libcanlock.a
 
-.c.o:
-	$(CC) $(CFLAGS) -c $< -o $@
+all: hmactest canlocktest $(STATIC_LIB)
 
-all: sha1test hmactest canlocktest
-
-anal:
-	$(MAKE) CFLAGS="$(CFLAGS) $(ANALFLAGS)"
-
-sha1test: t/sha1test.c $(LOCKLIB)
+sha1test: t/sha1test.c $(STATIC_LIB)
 	$(CC) $(CFLAGS) t/$@.c -o $@ $(LDFLAGS)
 
-hmactest: t/hmactest.c $(LOCKLIB)
+hmactest: t/hmactest.c $(STATIC_LIB)
 	$(CC) $(CFLAGS) t/$@.c -o $@ $(LDFLAGS)
 
-canlocktest: t/canlocktest.c $(LOCKLIB)
+canlocktest: t/canlocktest.c $(STATIC_LIB)
 	$(CC) $(CFLAGS) t/$@.c -o $@ $(LDFLAGS)
 
-src/base64.o: src/base64.c include/base64.h
-src/canlock.o: src/canlock.c include/canlock.h
-src/hmac_sha1.o: src/hmac_sha1.c include/hmac_sha1.h
-src/sha1.o: src/sha1.c include/sha1.h
-
-libs: $(LOCKLIB)
-$(LOCKLIB): $(LIBOBJS)
-	@echo "Arr, ye be makin' the library matey!"
-	ar r $@ $(LIBOBJS)
-	ranlib $@
-	ln -s include/canlock.h .
+$(STATIC_LIB):
+	cd src && make
+	ln -s src/libcanlock.a libcanlock.a
 
 clean:
 	rm -f src/*.o t/*.o t/*.out *.gmon gmon.*
+	cd src && make clean
+	rm -f *.a canlocktest hmactest sha1test *.exe *.h lib-stamp
 
-nuke: clean
-	rm -f *.a canlocktest hmactest sha1test *.exe *.h
+install: all
+	cd src && make install DESTDIR=$(DESTDIR)
+	install --mode=644 include/canlock.h $(DESTDIR)/usr/include
 	
 test: all
-	@echo "sha1test: "
-	@./sha1test > t/sha1test.out
-	@diff t/sha1test.shouldbe t/sha1test.out && echo " Pass." || echo " **FAIL**"
-	@echo "=-=-=-="
 	@echo "hmactest: "
 	@./hmactest > t/hmactest.out || echo hmm
-	@diff t/hmactest.shouldbe t/hmactest.out && echo " Pass." || echo " **FAIL**"
+	@diff t/hmactest.shouldbe t/hmactest.out && echo " Pass." || (echo " **FAIL**" ; exit 1)
 	@echo "=-=-=-="
 	@echo "canlocktest: "
 	@./canlocktest > t/canlocktest.out
-	@diff t/canlocktest.shouldbe t/canlocktest.out && echo " Pass." || echo " **FAIL**"
+	@diff t/canlocktest.shouldbe t/canlocktest.out && echo " Pass." || (echo " **FAIL**" ; exit 1)
 	@echo "=-=-=-="
-
-help:
-	@echo make options:
-	@echo '   anal   compile with lots of warnings enabled.'
-	@echo '   libs   build only the library.'
-	@echo '   clean  delete stray object files.'
-	@echo '   nuke   clean up everything.'
-
--- canlock-2b.orig/debian/libcanlock2.install
+++ canlock-2b/debian/libcanlock2.install
@@ -0,0 +1 @@
+usr/lib/libcanlock.so.*	    usr/lib
--- canlock-2b.orig/debian/copyright
+++ canlock-2b/debian/copyright
@@ -0,0 +1,47 @@
+This package was debianized by Laurent Fousse <laurent@komite.net> on
+Thu, 29 Jan 2004 14:12:45 +0000.
+
+It was downloaded from http://homepage.mac.com/imeowbot/iblog/C1355421991/
+
+Upstream Author: GJ Andruk <meowing@banet.net>.
+
+Part of this library is copyright (c) 1995, 1996, 1997 Kungliga
+Tekniska H~Zgskolan (Royal Institute of Technology, Stockholm, Sweden)
+and is distributed under the terms of the BSD license. On Debian
+systems the complete texts of the BSD license can be found in
+`/usr/share/common-licenses/BSD'.
+
+Part of this library is copyright (c) 2003 G.J. Andruk and is
+distributed under the following terms :
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, and/or sell copies of the Software, and to permit persons
+ to whom the Software is furnished to do so, provided that the above
+ copyright notice(s) and this permission notice appear in all copies
+ of the Software and that both the above copyright notice(s) and this
+ permission notice appear in supporting documentation.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
+ SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ 
+ Except as contained in this notice, the name of a copyright holder
+ shall not be used in advertising or otherwise to promote the sale,
+ use or other dealings in this Software without prior written
+ authorization of the copyright holder.
+
+Part of this library is copyright (C) 1995 A.M. Kuchling and is
+distributed under the following terms:
+
+ Distribute and use freely; there are no restrictions on further 
+ dissemination and usage except those imposed by the laws of your 
+ country of residence.
--- canlock-2b.orig/debian/changelog
+++ canlock-2b/debian/changelog
@@ -0,0 +1,50 @@
+canlock (2b-6.4.201403160329) ucs4-0-0-0; urgency=low
+
+  * UCS auto build. No patches were applied to the original source package
+
+ -- Univention builddaemon <buildd@univention.de>  Sun, 16 Mar 2014 03:29:27 +0100
+
+canlock (2b-6) unstable; urgency=low
+
+  * Remove bashism in debian/rules (closes: #526455).
+    Thanks Michael Bienia.
+
+ -- Laurent Fousse <laurent@komite.net>  Wed, 13 May 2009 22:06:47 +0200
+
+canlock (2b-5) unstable; urgency=low
+
+  * Fix several memleaks (closes: #520444)
+    Thanks to Urs Janßen for reporting and providing an initial patch.
+  * Update packaging to debhelper compat 7.
+  * Update Standard-Version (no change needed).
+
+ -- Laurent Fousse <laurent@komite.net>  Sun, 29 Mar 2009 00:07:35 +0100
+
+canlock (2b-4) unstable; urgency=low
+
+  * Fix insecure buffer usage, could cause stack corruption.
+    Thanks Andrey Melnikov for the patch (closes: #355596).
+  * Code cleanup: included string.h in sha1.c, no more warning.
+
+ -- Laurent Fousse <laurent@komite.net>  Mon,  6 Mar 2006 23:37:19 +0100
+
+canlock (2b-3) unstable; urgency=low
+
+  * Added missing CFLAGS.
+
+ -- Laurent Fousse <laurent@komite.net>  Fri, 20 Feb 2004 11:34:44 +0100
+
+canlock (2b-2) unstable; urgency=low
+
+  * Failed test target now causes the entire build to fail.
+  * No longer need libtool.
+  * Fixed buffer size bug in hmac_sha1.c.
+
+ -- Laurent Fousse <laurent@komite.net>  Thu, 19 Feb 2004 12:21:33 +0100
+
+canlock (2b-1) unstable; urgency=low
+
+  * Initial Release (closes: #207389, #204933).
+
+ -- Laurent Fousse <laurent@komite.net>  Thu, 29 Jan 2004 14:12:45 +0000
+
--- canlock-2b.orig/debian/compat
+++ canlock-2b/debian/compat
@@ -0,0 +1 @@
+7
--- canlock-2b.orig/debian/libcanlock2-dev.dirs
+++ canlock-2b/debian/libcanlock2-dev.dirs
@@ -0,0 +1,2 @@
+usr/lib
+usr/include
--- canlock-2b.orig/debian/libcanlock2.shlibs
+++ canlock-2b/debian/libcanlock2.shlibs
@@ -0,0 +1 @@
+libcanlock 2 libcanlock2 (>= 2b-1)
--- canlock-2b.orig/debian/rules
+++ canlock-2b/debian/rules
@@ -0,0 +1,96 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# GNU copyright 1997 to 1999 by Joey Hess.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+	CFLAGS += -O0
+else
+	CFLAGS += -O2
+endif
+ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+	INSTALL_PROGRAM += -s
+endif
+
+# shared library versions, option 1
+version=2.0.0
+major=2
+# option 2, assuming the library is created as src/.libs/libfoo.so.2.0.5 or so
+#version=`ls src/.libs/lib*.so.* | \
+# awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
+#major=`ls src/.libs/lib*.so.* | \
+# awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`
+
+configure: configure-stamp
+configure-stamp:
+	dh_testdir
+	# Add here commands to configure the package.
+
+	touch configure-stamp
+
+
+build: build-stamp
+build-stamp: configure-stamp 
+	dh_testdir
+
+	# Add here commands to compile the package.
+	$(MAKE)
+
+	touch build-stamp
+
+clean:
+	dh_testdir
+	dh_testroot
+	rm -f build-stamp configure-stamp
+
+	# Add here commands to clean up after the build process.
+	$(MAKE) clean
+
+	dh_clean 
+
+install: build
+	dh_testdir
+	dh_testroot
+	dh_prep
+	dh_installdirs
+
+	$(MAKE) test
+
+	# Add here commands to install the package into debian/tmp
+	mkdir -p $(CURDIR)/debian/tmp/usr/include
+	mkdir -p $(CURDIR)/debian/tmp/usr/lib
+	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+	dh_testdir
+	dh_testroot
+	dh_installchangelogs CHANGES
+	dh_installdocs
+	dh_installexamples
+	dh_install --sourcedir=debian/tmp
+	rm debian/tmp/usr/lib/libcanlock.so.2*
+	dh_link
+	dh_strip
+	dh_compress
+	dh_fixperms
+	dh_makeshlibs
+	dh_installdeb -plibcanlock2
+	dh_installdeb -plibcanlock2-dev
+	dh_shlibdeps
+	dh_gencontrol
+	dh_md5sums
+	dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
--- canlock-2b.orig/debian/control
+++ canlock-2b/debian/control
@@ -0,0 +1,33 @@
+Source: canlock
+Priority: optional
+Section: news
+Maintainer: Laurent Fousse <laurent@komite.net>
+Build-Depends: debhelper (>= 7)
+Standards-Version: 3.8.0
+
+Package: libcanlock2-dev
+Section: libdevel
+Architecture: any
+Depends: libcanlock2 (= ${binary:Version})
+Description: development files for Usenet cancel lock library
+ Cancel locks are used by Usenet article posters to authenticate their
+ authorship of an article. It may then by used by servers to prevent
+ cancel and supersede abuse. The use of this feature remains the
+ newsmaster's decision.
+ .
+ This library may be used for both the generation and the verification
+ of cancel locks. The header file and the static library are included
+ in this package.
+
+Package: libcanlock2
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: library for creating and verifying Usenet cancel locks
+ Cancel locks are used by Usenet article posters to authenticate their
+ authorship of an article. It may then by used by servers to prevent
+ cancel and supersede abuse. The use of this feature remains the
+ newsmaster's decision.
+ .
+ This library may be used for both the generation and the verification
+ of cancel locks.
--- canlock-2b.orig/debian/README.Debian
+++ canlock-2b/debian/README.Debian
@@ -0,0 +1,10 @@
+canlock for Debian
+------------------
+
+The relevant technical documents (RFCs and IETF draft) have been
+removed from the package for licence reasons.
+
+The non-free sha1 implementation from the original tarball has been
+replaced by the one from mhash.
+
+ -- Laurent Fousse <laurent@komite.net>, Thu, 29 Jan 2004 14:12:45 +0000
--- canlock-2b.orig/debian/docs
+++ canlock-2b/debian/docs
@@ -0,0 +1,2 @@
+README
+doc/HOWTO
--- canlock-2b.orig/debian/libcanlock2-dev.install
+++ canlock-2b/debian/libcanlock2-dev.install
@@ -0,0 +1,3 @@
+usr/lib/libcanlock.so	usr/lib
+usr/lib/libcanlock.a	usr/lib
+usr/include/canlock.h	usr/include
--- canlock-2b.orig/t/hmactest.c
+++ canlock-2b/t/hmactest.c
@@ -50,7 +50,7 @@
     printf("Expected SHA Digest: %s\n",
            "0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79");
     printf("  Actual SHA Digest: 0x");
-    for (i = 0; i < SHA1HashSize; i++)
+    for (i = 0; i < SHA_DIGESTSIZE; i++)
         printf("%02x", hmachash[i]);
     putchar('\n');
 
@@ -65,7 +65,7 @@
     printf("Expected SHA Digest: %s\n",
            "0xb617318655057264e28bc0b6fb378c8ef146be00");
     printf("  Actual SHA Digest: 0x");
-    for (i = 0; i < SHA1HashSize; i++)
+    for (i = 0; i < SHA_DIGESTSIZE; i++)
         printf("%02x", hmachash[i]);
     putchar('\n');
 
@@ -78,7 +78,7 @@
     printf("Expected SHA Digest: %s\n",
            "0xaa4ae5e15272d00e95705637ce8a3b55ed402112");
     printf("  Actual SHA Digest: 0x");
-    for (i = 0; i < SHA1HashSize; i++)
+    for (i = 0; i < SHA_DIGESTSIZE; i++)
         printf("%02x", hmachash[i]);
     putchar('\n');
 
@@ -91,7 +91,7 @@
     printf("Expected SHA Digest: %s\n",
            "0xe8e99d0f45237d786d6bbaa7965c7808bbff1a91");
     printf("  Actual SHA Digest: 0x");
-    for (i = 0; i < SHA1HashSize; i++)
+    for (i = 0; i < SHA_DIGESTSIZE; i++)
         printf("%02x", hmachash[i]);
     putchar('\n');
 
@@ -107,7 +107,7 @@
     printf("Expected SHA Digest: %s\n",
            "0x4c9007f4026250c6bc8414f9bf50c86c2d7235da");
     printf("  Actual SHA Digest: 0x");
-    for (i = 0; i < SHA1HashSize; i++)
+    for (i = 0; i < SHA_DIGESTSIZE; i++)
         printf("%02x", hmachash[i]);
     putchar('\n');
 
--- canlock-2b.orig/include/sha1.h
+++ canlock-2b/include/sha1.h
@@ -0,0 +1,50 @@
+#ifndef _SHA1_H_
+#define _SHA1_H_
+
+/* The SHA block size and message digest sizes, in bytes */
+
+#define SHA_DATASIZE    64
+#define SHA_DATALEN     16
+#define SHA_DIGESTSIZE  20
+#define SHA_DIGESTLEN    5
+/* The structure for storing SHA info */
+
+#include <stdint.h>
+
+typedef struct sha_ctx {
+  uint32_t digest[SHA_DIGESTLEN];  /* Message digest */
+  uint32_t count_l, count_h;       /* 64-bit block count */
+  uint8_t block[SHA_DATASIZE];     /* SHA data buffer */
+  int index;                             /* index into buffer */
+  int finalized;
+} SHA_CTX;
+
+int sha_init(struct sha_ctx *ctx);
+int sha_update(struct sha_ctx *ctx, const uint8_t *buffer, uint32_t len);
+void sha_final(struct sha_ctx *ctx);
+int sha_digest(struct sha_ctx *ctx, uint8_t *s);
+void sha_copy(struct sha_ctx *dest, struct sha_ctx *src);
+
+#if 1
+
+#ifndef EXTRACT_UCHAR
+#define EXTRACT_UCHAR(p)  (*(unsigned char *)(p))
+#endif
+
+#define STRING2INT(s) ((((((EXTRACT_UCHAR(s) << 8)    \
+			 | EXTRACT_UCHAR(s+1)) << 8)  \
+			 | EXTRACT_UCHAR(s+2)) << 8)  \
+			 | EXTRACT_UCHAR(s+3))
+#else
+uint32_t STRING2INT(uint8_t *s)
+{
+  uint32_t r;
+  int i;
+  
+  for (i = 0, r = 0; i < 4; i++, s++)
+    r = (r << 8) | *s;
+  return r;
+}
+#endif
+
+#endif
--- canlock-2b.orig/src/canlock.c
+++ canlock-2b/src/canlock.c
@@ -51,41 +51,24 @@
 char *
 lock_strip_alpha(const char *key, char *type)
 {
-    char
-        *c,
-        *typetext,
-        *mykey = (char *)key;
-    size_t
-        ttpos = 0,
-        ttlen = 256;
-
-    typetext = (char *) malloc(ttlen);
-    if (!typetext)
-        return NULL;
-    *typetext = 0;
-
-    while (*mykey && *mykey != ':') {
-        if (ttpos >= ttlen) {
-            ttlen += 256;
-            typetext = (char *) realloc( (void *)typetext, ttlen);
-            if (!typetext)
-                return NULL;
-        }
-        typetext[ttpos++] = *mykey++;
-    }
-    if (! *mykey)
-        type = NULL;
-    else {
-        mykey++;
-        for (c = mykey; *c; c++) {
-            if (*c == ':')
-                *c = '\0';
-        }
-        strcpy(type, typetext);
-        for (c = type; *c; ++c)
-            *c = tolower(*c);
-    }
-    return (mykey);
+    char *ret;
+    int offset;
+    do {
+      *type = tolower(*key);
+      type++;
+      key++;
+    } while (*key && *key != ':');
+    
+    *type = '\0';
+    key++;
+    ret = strdup (key);
+    /* Strip the "Clue-string", no longer part of the lastest
+     * draft but could still be present */
+    offset = 0;
+    while (ret[offset] && ret[offset] != ':')
+	offset++;
+    ret[offset] = '\0';
+    return ret;
 }
 
 
@@ -113,7 +96,7 @@
     hmacbuff = hmac_sha1(secret, seclen, message, msglen);
     if (!hmacbuff)
         return NULL;
-    keysize = base64_encode(hmacbuff, SHA1HashSize, cankey);
+    keysize = base64_encode(hmacbuff, SHA_DIGESTSIZE, cankey);
     free ((void *) hmacbuff);
     if (!keysize)
         return NULL;
@@ -135,26 +118,33 @@
 {
     char
         *canlock[1],
-        junk[SHA1HashSize];
+	*tmp,
+        junk[SHA_DIGESTSIZE];
     unsigned char
         *cankey,
-        hmacbuff[SHA1HashSize];
+        hmacbuff[SHA_DIGESTSIZE];
     size_t
         locksize;
-    SHA1Context
+    SHA_CTX
         hash_ctx;
 
-    cankey = (unsigned char *) lock_strip_alpha(
-                            sha_key(secret, seclen, message, msglen), junk);
+    tmp = sha_key(secret, seclen, message, msglen);
+    cankey = (unsigned char *) lock_strip_alpha(tmp, junk);
+    free (tmp);
     if (!cankey)
         return NULL;
-    if (SHA1Reset(&hash_ctx))
-        return NULL;
-    if (SHA1Input(&hash_ctx, cankey, strlen((char *) cankey)))
+    if (sha_init(&hash_ctx)) {
+    	free(cankey);
         return NULL;
-    if (SHA1Result(&hash_ctx, hmacbuff))
+	}
+    if (sha_update(&hash_ctx, cankey, strlen((char *) cankey))) {
+    	free(cankey);
+        return NULL;
+	}
+	free(cankey);
+    if (sha_digest(&hash_ctx, hmacbuff))
         return NULL;
-    locksize = base64_encode(hmacbuff, SHA1HashSize, canlock);
+    locksize = base64_encode(hmacbuff, SHA_DIGESTSIZE, canlock);
     if (!locksize)
         return NULL;
     *canlock = (char *) realloc((void *) *canlock, locksize + 6);
@@ -174,14 +164,14 @@
 sha_verify(const char *key, const char *lock)
 {
     unsigned char
-        binkey[SHA1HashSize + 4],
-        hmacbuff[SHA1HashSize];
+        binkey[SHA_DIGESTSIZE + 4],
+        hmacbuff[SHA_DIGESTSIZE];
     char
         *templock[1];
     size_t
         keysize,
         locksize;
-    SHA1Context
+    SHA_CTX
         hash_ctx;
 
 
@@ -190,14 +180,14 @@
     if (!keysize)
         return -1;
 
-    if (SHA1Reset(&hash_ctx))
+    if (sha_init(&hash_ctx))
         return -1;
-    if (SHA1Input(&hash_ctx, (unsigned char *)key, strlen(key)))
+    if (sha_update(&hash_ctx, (unsigned char *)key, strlen(key)))
         return -1;
-    if (SHA1Result(&hash_ctx, hmacbuff))
+    if (sha_digest(&hash_ctx, hmacbuff))
         return -1;
 
-    locksize = base64_encode(hmacbuff, SHA1HashSize, templock);
+    locksize = base64_encode(hmacbuff, SHA_DIGESTSIZE, templock);
     if (!locksize)
         return -1;
 
--- canlock-2b.orig/src/sha1.c
+++ canlock-2b/src/sha1.c
@@ -31,11 +31,9 @@
 effort (for example the reengineering of a great many Capstone chips).
 */
 
-#include "libdefs.h"
-
-#ifdef ENABLE_SHA1
-
-#include "mhash_sha1.h"
+#include "sha1.h"
+#include <stdlib.h>
+#include <string.h>
 
 void sha_copy(struct sha_ctx *dest, struct sha_ctx *src)
 {
@@ -99,7 +97,6 @@
 		      ROTL( 1, ( W[ i & 15 ] ^ W[ (i - 14) & 15 ] ^ \
 				 W[ (i - 8) & 15 ] ^ W[ (i - 3) & 15 ] ) ) )
 
-
 /* The prototype SHA sub-round.  The fundamental sub-round is:
 
         a' = e + ROTL( 5, a ) + f( b, c, d ) + k + data;
@@ -118,7 +115,7 @@
 
 /* Initialize the SHA values */
 
-void sha_init(struct sha_ctx *ctx)
+int sha_init(struct sha_ctx *ctx)
 {
   /* Set the h-vars to their initial values */
   ctx->digest[ 0 ] = h0init;
@@ -132,6 +129,8 @@
   
   /* Initialize buffer */
   ctx->index = 0;
+  ctx->finalized = 0;
+  return 0;
 }
 
 /* Perform the SHA transformation.  Note that this code, like MD5, seems to
@@ -141,9 +140,9 @@
 
    Note that this function destroys the data area */
 
-static void sha_transform(struct sha_ctx *ctx, word32 *data )
+static void sha_transform(struct sha_ctx *ctx, uint32_t *data )
 {
-  register word32 A, B, C, D, E;     /* Local vars */
+  register uint32_t A, B, C, D, E;     /* Local vars */
 
   /* Set up first buffer and local data buffer */
   A = ctx->digest[0];
@@ -246,9 +245,9 @@
 }
 
 
-static void sha_block(struct sha_ctx *ctx, word8 *block)
+static void sha_block(struct sha_ctx *ctx, const uint8_t *block)
 {
-  word32 data[SHA_DATALEN];
+  uint32_t data[SHA_DATALEN];
   int i;
   
   /* Update block count */
@@ -262,7 +261,7 @@
   sha_transform(ctx, data);
 }
 
-void sha_update(struct sha_ctx *ctx, word8 *buffer, word32 len)
+int sha_update(struct sha_ctx *ctx, const uint8_t *buffer, uint32_t len)
 {
   if (ctx->index)
     { /* Try to fill partial block */
@@ -271,7 +270,7 @@
 	{
 	  memcpy(ctx->block + ctx->index, buffer, len);
 	  ctx->index += len;
-	  return; /* Finished */
+	  return 0; /* Finished */
 	}
       else
 	{
@@ -290,6 +289,7 @@
   if ((ctx->index = len))     /* This assignment is intended */
     /* Buffer leftovers */
     memcpy(ctx->block, buffer, len);
+  return 0;
 }
 	  
 /* Final wrapup - pad to SHA_DATASIZE-byte boundary with the bit pattern
@@ -297,7 +297,7 @@
 
 void sha_final(struct sha_ctx *ctx)
 {
-  word32 data[SHA_DATALEN];
+  uint32_t data[SHA_DATALEN];
   int i;
   int words;
   
@@ -331,11 +331,14 @@
   data[SHA_DATALEN-2] = (ctx->count_h << 9) | (ctx->count_l >> 23);
   data[SHA_DATALEN-1] = (ctx->count_l << 9) | (ctx->index << 3);
   sha_transform(ctx, data);
+  ctx->finalized = 1;
 }
 
-void sha_digest(struct sha_ctx *ctx, word8 *s)
+int sha_digest(struct sha_ctx *ctx, uint8_t *s)
 {
   int i;
+  if (ctx->finalized == 0)
+    sha_final (ctx);
 
   if (s!=NULL)
 	  for (i = 0; i < SHA_DIGESTLEN; i++)
@@ -345,6 +348,6 @@
 	      *s++ = 0xff & (ctx->digest[i] >> 8);
 	      *s++ = 0xff &  ctx->digest[i];
 	    }
+  return 0;
 }
 
-#endif /* ENABLE_SHA1 */
--- canlock-2b.orig/src/hmac_sha1.c
+++ canlock-2b/src/hmac_sha1.c
@@ -53,34 +53,34 @@
             int Tlen            /* and its size */
         )
 {
-    SHA1Context
+    SHA_CTX
         hash_ctx;
     unsigned char
-        keyin[SHA1HashSize],
+        keyin[SHA_DATASIZE],
         *step2,
-        step4[SHA1HashSize],
-        step5[SHA1Block + SHA1HashSize],
+        step4[SHA_DIGESTSIZE],
+        step5[SHA_DATASIZE + SHA_DIGESTSIZE],
         *hmac_out,
         *c;
     int
         i,
         j;
 
-    if (SHA1Reset(&hash_ctx))
+    if (sha_init(&hash_ctx))
         return NULL;
 
-    /* If the key is bigger than SHA1Block we need to hash it. */
-    if (Klen > SHA1Block) {
-        if (SHA1Input(&hash_ctx, K, Klen))
+    /* If the key is bigger than SHA_DATASIZE we need to hash it. */
+    if (Klen > SHA_DATASIZE) {
+        if (sha_update(&hash_ctx, K, Klen))
             return NULL;
-        if (SHA1Result(&hash_ctx, keyin))
+        if (sha_digest(&hash_ctx, keyin))
             return NULL;
-        Klen = SHA1HashSize;
+        Klen = SHA_DIGESTSIZE;
     }
     else
         memcpy(keyin, K, Klen);
 
-    step2 = (unsigned char *) malloc(Tlen + SHA1Block);
+    step2 = (unsigned char *) malloc(Tlen + SHA_DATASIZE);
 
     c = keyin;
     for (i = 0; i < Klen; i++) {
@@ -88,32 +88,43 @@
         step5[i] = *c ^ opad;
         c++;
     }
-    for (j = i; j < SHA1Block; j++) {
-        step2[j] = 0x36;
+    for (j = i; j < SHA_DATASIZE; j++) {
+        step2[j] = ipad;
         step5[j] = opad;
     }
+    
+    memcpy(&step2[SHA_DATASIZE], T, Tlen);
 
-    memcpy(&step2[SHA1Block], T, Tlen);
-
-    if (SHA1Reset(&hash_ctx))
+    if (sha_init(&hash_ctx)) {
+    	free(step2);
         return NULL;
-    if (SHA1Input(&hash_ctx, step2, SHA1Block + Tlen))
+	}
+    if (sha_update(&hash_ctx, step2, SHA_DATASIZE + Tlen)) {
+    	free(step2);
         return NULL;
-    if (SHA1Result(&hash_ctx, step4))
+	}
+	free(step2);
+    if (sha_digest(&hash_ctx, step4))
         return NULL;
 
-    memcpy(&step5[SHA1Block], step4, SHA1HashSize);
+    memcpy(&step5[SHA_DATASIZE], step4, SHA_DIGESTSIZE);
 
-    hmac_out = (unsigned char *) malloc(SHA1HashSize);
+    hmac_out = (unsigned char *) malloc(SHA_DIGESTSIZE);
     if (!hmac_out)
         return NULL;
 
-    if (SHA1Reset(&hash_ctx))
-        return NULL;
-    if (SHA1Input(&hash_ctx, step5, SHA1Block + SHA1HashSize))
+    if (sha_init(&hash_ctx)) {
+    	free(hmac_out);
         return NULL;
-    if (SHA1Result(&hash_ctx, hmac_out))
+	}
+    if (sha_update(&hash_ctx, step5, SHA_DATASIZE + SHA_DIGESTSIZE)) {
+    	free(hmac_out);
+        return NULL;
+	}
+    if (sha_digest(&hash_ctx, hmac_out)) {
+    	free(hmac_out);
         return NULL;
+	}
 
     return hmac_out;
 }
--- canlock-2b.orig/src/Makefile
+++ canlock-2b/src/Makefile
@@ -0,0 +1,32 @@
+LIBOBJS = base64.lo canlock.lo hmac_sha1.lo sha1.lo
+CC = gcc
+LIBTOOL = libtool
+CFLAGS = -I../include
+SOURCES = base64.c canlock.c hmac_sha1.c sha1.c
+OBJS = base64.o canlock.o hmac_sha1.o sha1.o
+SHARELINKFLAGS = -Wl,-soname -Wl,libcanlock.so.2
+SHAREDFLAGS = -fPIC -DPIC
+LIBS = libcanlock.a libcanlock.so.2.0.0
+INSTALL = install
+
+all: $(LIBS)
+
+libcanlock.a:
+	$(CC) $(CFLAGS) -c $(SOURCES)
+	ar cru libcanlock.a $(OBJS)
+	ranlib libcanlock.a
+	rm $(OBJS)
+
+libcanlock.so.2.0.0:
+	$(CC) $(CFLAGS) $(SHAREDFLAGS) -c $(SOURCES)
+	$(CC) -shared $(OBJS) $(SHARELINKFLAGS) -o libcanlock.so.2.0.0
+
+install: all
+	$(INSTALL) libcanlock.so.2.0.0 $(DESTDIR)/usr/lib
+	cd $(DESTDIR)/usr/lib && ln -s libcanlock.so.2.0.0 libcanlock.so.2
+	cd $(DESTDIR)/usr/lib && ln -s libcanlock.so.2.0.0 libcanlock.so
+	$(INSTALL) libcanlock.a $(DESTDIR)/usr/lib/libcanlock.a
+	ranlib $(DESTDIR)/usr/lib/libcanlock.a
+	
+clean:
+	rm -f $(OBJS) $(LIBS)
