unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] md5: fix errors when input size modulo 64 is > 55 bytes
@ 2013-01-12  6:43 Daniel Hartwig
  2013-01-12  6:56 ` Daniel Hartwig
  2013-01-21 21:16 ` Andy Wingo
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Hartwig @ 2013-01-12  6:43 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]


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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-md5-fix-errors-when-input-size-modulo-64-is-55-bytes.patch --]
[-- Type: text/x-diff, Size: 1409 bytes --]

From 47c92db862ce846dbcc5d27843bc9d26b7708d5d Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <mandyke@gmail.com>
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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-01-31 10:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-12  6:43 [PATCH] md5: fix errors when input size modulo 64 is > 55 bytes Daniel Hartwig
2013-01-12  6:56 ` Daniel Hartwig
2013-01-12  8:35   ` Nala Ginrut
2013-01-21 21:16 ` Andy Wingo
2013-01-31  5:31   ` Daniel Hartwig
2013-01-31  5:31     ` Daniel Hartwig
2013-01-31 10:09     ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).