From 97c38ae7c1df6cf7bb08e7dd930270becebf8d8e Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Mon, 10 Apr 2000 03:34:03 +0000 Subject: [PATCH] Implement support for the mhash library. Generalize MD5 support to use mhash if available, otherwise the md5-karn library. --- v7/src/runtime/blowfish.scm | 50 +++++-------------------------------- v7/src/runtime/krypt.scm | 6 ++--- v7/src/runtime/runtime.pkg | 3 ++- 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/v7/src/runtime/blowfish.scm b/v7/src/runtime/blowfish.scm index 9a127ecd1..c4ac4dd5e 100644 --- a/v7/src/runtime/blowfish.scm +++ b/v7/src/runtime/blowfish.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Id: blowfish.scm,v 1.18 1999/12/21 19:05:18 cph Exp $ +$Id: blowfish.scm,v 1.19 2000/04/10 03:33:37 cph Exp $ -Copyright (c) 1997, 1999 Massachusetts Institute of Technology +Copyright (c) 1997, 1999, 2000 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,17 +19,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |# -;;;; Interface to Blowfish and MD5 +;;;; Interface to Blowfish ;;; package: () (declare (usual-integrations)) -(define-primitives - (md5 1) - (md5-init 0) - (md5-update 4) - (md5-final 1)) - (define blowfish-available?) (define blowfish-set-key) (define blowfish-ecb) @@ -48,7 +42,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (define (initialize-key) (if (eq? 'UNKNOWN unlocked?) (set! unlocked? - (and (implemented-primitive-procedure? md5-init) + (and (md5-available?) (implemented-primitive-procedure? (ucode-primitive blowfish-cfb64-substring-v2 9)) (let ((pathname @@ -63,7 +57,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (system-library-pathname "blowfish.key"))))))) (and pathname (string=? key-sum - (md5-sum->hexadecimal + (mhash-sum->hexadecimal (md5-file pathname))))))))) (set! blowfish-available? @@ -165,36 +159,4 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (string=? line blowfish-file-header-v2))))) (define blowfish-file-header-v1 "Blowfish, 16 rounds") -(define blowfish-file-header-v2 "Blowfish, 16 rounds, version 2") - -(define (md5-file filename) - (call-with-binary-input-file filename - (lambda (port) - (let ((buffer (make-string 4096)) - (context (md5-init))) - (dynamic-wind (lambda () - unspecific) - (lambda () - (let loop () - (let ((n (read-substring! buffer 0 4096 port))) - (if (fix:= 0 n) - (md5-final context) - (begin - (md5-update context buffer 0 n) - (loop)))))) - (lambda () - (string-fill! buffer #\NUL))))))) - -(define (md5-sum->number sum) - (let ((l (string-length sum))) - (do ((i 0 (fix:+ i 1)) - (n 0 (+ (* n #x100) (vector-8b-ref sum i)))) - ((fix:= i l) n)))) - -(define (md5-sum->hexadecimal sum) - (let ((s (number->string (md5-sum->number sum) 16))) - (string-downcase! s) - (let ((d (fix:- 32 (string-length s)))) - (if (fix:> d 0) - (string-append (make-string d #\0) s) - s)))) \ No newline at end of file +(define blowfish-file-header-v2 "Blowfish, 16 rounds, version 2") \ No newline at end of file diff --git a/v7/src/runtime/krypt.scm b/v7/src/runtime/krypt.scm index f93fc93a9..8909ee065 100644 --- a/v7/src/runtime/krypt.scm +++ b/v7/src/runtime/krypt.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: krypt.scm,v 1.10 1999/08/09 16:26:39 cph Exp $ +$Id: krypt.scm,v 1.11 2000/04/10 03:33:42 cph Exp $ Copyright (c) 1988-1999 Massachusetts Institute of Technology @@ -139,7 +139,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (define (initialize-key) (if (eq? 'UNKNOWN unlocked?) (set! unlocked? - (and (implemented-primitive-procedure? md5-init) + (and (md5-available?) (let ((pathname (call-with-current-continuation (lambda (k) @@ -152,7 +152,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (system-library-pathname "krypt.key"))))))) (and pathname (string=? key-sum - (md5-sum->hexadecimal + (mhash-sum->hexadecimal (md5-file pathname))))))))) (set! encrypt diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg index 51a8d2e8b..6466260f6 100644 --- a/v7/src/runtime/runtime.pkg +++ b/v7/src/runtime/runtime.pkg @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: runtime.pkg,v 14.339 2000/04/07 20:43:01 cph Exp $ +$Id: runtime.pkg,v 14.340 2000/04/10 03:34:03 cph Exp $ Copyright (c) 1988-2000 Massachusetts Institute of Technology @@ -26,6 +26,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. "bitstr" "boole" "boot" + "crypto" "equals" "fixart" "global" -- 2.25.1