Hi there!

As it was needed by something else I had to port, I did a quick port of pbkdf2 and md2 to chicken 5 - using cond-expand so the same codebase can work for C5 and C4, it's not a fork.

Also, I have a copy of a patch to md2 by Andy Bennett for C89 support that I based the C5 port on top of, and he'd be delighted if that got merged in upstream as well.

I've attached them all as patches, if you'd like to commit it to the repo I'd be happy to add them to the C5 egg list so it can be installed with chicken-install :-)

Hope you like it & thanks for the eggs in the first place,

Alaric Snell-Pym
From dc512f953cf5cda5bb1de4af0960f4f93e391c57 Mon Sep 17 00:00:00 2001
From: Alaric Snell-Pym <ala...@register-dynamics.co.uk>
Date: Tue, 24 Nov 2020 13:06:19 +0000
Subject: Support Chicken 5


diff --git a/pbkdf2.egg b/pbkdf2.egg
new file mode 100644
index 0000000..b0ff965
--- /dev/null
+++ b/pbkdf2.egg
@@ -0,0 +1,10 @@
+((license "BSD")
+ (category crypt)
+ (dependencies message-digest hmac sha2 sha1 md5 md2)
+ (test-dependencies test)
+ (version "1.2")
+ (author "Tobias Heilig")
+ (synopsis "Password-Based Key Derivation Function as defined in RFC2898")
+ (components
+  (extension pbkdf2)))
+
diff --git a/pbkdf2.scm b/pbkdf2.scm
index 687afab..c8bf42c 100644
--- a/pbkdf2.scm
+++ b/pbkdf2.scm
@@ -48,9 +48,27 @@
          pbkdf2-hmac-sha512)
 
 
-  (import chicken scheme)
+  (import scheme)
+
+  (cond-expand
+   (chicken-4
+    (import chicken)
+    (use srfi-1 srfi-4 srfi-13 message-digest hmac sha2 sha1 md5 md2))
+   (chicken-5
+    (import (chicken base))
+    (import (chicken bitwise))
+    (import (chicken blob))
+    (import srfi-1)
+    (import srfi-4)
+    (import srfi-13)
+    (import message-digest)
+    (import hmac)
+    (import sha2)
+    (import sha1)
+    (import md5)
+    (import md2)))
+
 
-  (use srfi-1 srfi-4 srfi-13 message-digest hmac sha2 sha1 md5 md2)
 
 
   (define (^ s1 s2)
diff --git a/tests/run.scm b/tests/run.scm
index 2235ef8..3345982 100644
--- a/tests/run.scm
+++ b/tests/run.scm
@@ -5,7 +5,13 @@
 
 
 
-(use test pbkdf2)
+(cond-expand
+ (chicken-4
+  (use test pbkdf2))
+ (chicken-5
+  (import (chicken blob))
+  (import test)
+  (import pbkdf2)))
 
 
 
From ffb6f4aa296e93cdb534cacaad467609defdf302 Mon Sep 17 00:00:00 2001
From: Alaric Snell-Pym <ala...@register-dynamics.co.uk>
Date: Tue, 24 Nov 2020 13:04:17 +0000
Subject: Support Chicken 5


diff --git a/md2.egg b/md2.egg
new file mode 100644
index 0000000..7c7b90f
--- /dev/null
+++ b/md2.egg
@@ -0,0 +1,10 @@
+((license "BSD")
+ (category crypt)
+ (dependencies message-digest)
+ (test-dependencies test message-digest)
+ (author "Tobias Heilig")
+ (synopsis "Message Digest 2 algorithm as defined in RFC1319")
+ (version "1.2")
+ (components
+  (extension md2)))
+
diff --git a/md2.scm b/md2.scm
index dba2f3d..09e27a1 100644
--- a/md2.scm
+++ b/md2.scm
@@ -41,10 +41,18 @@
         (md2-primitive)
 
 
-  (import chicken scheme foreign)
-
-  (use message-digest)
+  (import scheme)
 
+  (cond-expand
+   (chicken-4
+    (import chicken)
+    (import foreign)
+    (use message-digest))
+   (chicken-5
+    (import (chicken base))
+    (import (chicken foreign))
+    (import message-digest)))
+  
 
   #>#include "md2-base.c"<#
 
From 90c6a5b7cc94a6c84b917ada29ffd84e49268d0e Mon Sep 17 00:00:00 2001
From: Andy Bennett <andy...@register-dynamics.co.uk>
Date: Wed, 24 Jul 2019 14:54:27 +0100
Subject: Support C89 for CHICKEN 4.9
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With GCC 4.9.2 (Debian Jessie 8.11) installation fails:
-----
In file included from md2.c:13:0:
md2-base.c: In function ‘MD2_Update’:
md2-base.c:149:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
     for (size_t i = 0; i < len; ++i) {
     ^
md2-base.c:149:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
-----

However, GCC Version 5.1.0 changed the default from -std=gnu90 to
-std=gnu11.

Signed-off-by: Andy Bennett <andy...@ashurst.eu.org>

diff --git a/md2-base.c b/md2-base.c
index 808c453..24e3617 100644
--- a/md2-base.c
+++ b/md2-base.c
@@ -145,8 +145,9 @@ MD2_Init (MD2_CTX *ctx)
 void
 MD2_Update (MD2_CTX *ctx, const BYTE *data, size_t len)
 {
+    size_t i = 0;
 
-    for (size_t i = 0; i < len; ++i) {
+    for (i = 0; i < len; ++i) {
 
 		ctx->data[ctx->len] = data[i];
 		ctx->len++;

Reply via email to