guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] md5: fix errors when input size modulo 64 is > 55 bytes


From: Daniel Hartwig
Subject: [PATCH] md5: fix errors when input size modulo 64 is > 55 bytes
Date: Sat, 12 Jan 2013 14:43:34 +0800

Originally reported as <http://bugs.debian.org/437214>.

Triggered when input has size modulo 64 is 56–63 bytes.

scheme@(guile-user)> (use-modules (md5))
scheme@(guile-user)> (md5 (open-input-string (make-string 60 #\0)))
ERROR: In procedure string-set!:
ERROR: In procedure string-set!: Wrong type argument in position 1 (expecting 
string): #f

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,bt
In /usr/share/guile/site/md5.scm:
   349:10  1 (md5-finalize ((values (a . 1732584193) (b . 4023233417) (c . 
2562383102) (. #)) # …))
In unknown file:
           0 (string-set! #f #f #\200)

Two errors in that section of the file.  The first is a simple typo:
context → 'context.

The second required looking up the libgcrypt source (the basis of this
module) to repair.  Lines 322–380 of md5.scm are equivalent to lines
288–301 of cipher/md5.c.  Attached patch repairs this part of the file
based on the algorithm in libgcrypt.

$ guile -c '(display (make-string 60 #\0))' | md5sum
5b19445b70b493c78f3bc06eb7962315  -
$ guile
[…]
scheme@(guile-user)> (use-modules (md5))
scheme@(guile-user)> (md5 (open-input-string (make-string 60 #\0)))
$1 = "5b19445b70b493c78f3bc06eb7962315"

Regards

>From 47c92db862ce846dbcc5d27843bc9d26b7708d5d Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <address@hidden>
Date: Sat, 12 Jan 2013 14:34:26 +0800
Subject: [PATCH] md5: fix errors when input size modulo 64 is > 55 bytes

* src/md5.scm (md5-finalize): Fix typos and missing parts of algorithm
  based on cipher/md5.c in libgcrypt.
---
 src/md5.scm |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/md5.scm b/src/md5.scm
index 571c857..1acc78b 100644
--- a/src/md5.scm
+++ b/src/md5.scm
@@ -347,11 +347,17 @@ referenced C implementation into Scheme.
                                           'data-size)
                                 1)))))
        (begin
-         (string-set! (assq-ref (assq-ref 'context 'buffer)
+         (string-set! (assq-ref (assq-ref context 'buffer)
                                 'space)
-                      (assq-ref (assq-ref 'context 'buffer)
+                      (assq-ref (assq-ref context 'buffer)
                                 'data-size)
                       (integer->char #x80))
+         (assq-set! (assq-ref context 'buffer)
+                    'data-size
+                    (+ (assq-ref (assq-ref context 'buffer)
+                                 'data-size)
+                       1))
+
          (while (< (assq-ref (assq-ref context 'buffer)
                              'data-size)
                    64)
@@ -360,7 +366,7 @@ referenced C implementation into Scheme.
                                          'space)
                                (assq-ref (assq-ref context 'buffer)
                                          'data-size)
-                               0)
+                               #\nul)
                   (assq-set! (assq-ref context 'buffer)
                              'data-size
                              (+ (assq-ref (assq-ref context 'buffer)
-- 
1.7.10.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]