From: Matt Birkholz Date: Fri, 22 Jun 2018 10:35:31 +0000 (-0700) Subject: Punt bfish µmodule; autoload blowfish plugin version 1.0. X-Git-Tag: mit-scheme-pucked-9.2.15~10^2~7 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=b849e75fd31e835ab14b919bb7cb027193e874d4;p=mit-scheme.git Punt bfish µmodule; autoload blowfish plugin version 1.0. --- diff --git a/src/blowfish/NEWS b/src/blowfish/NEWS index 345cc7c7a..68650e4ee 100644 --- a/src/blowfish/NEWS +++ b/src/blowfish/NEWS @@ -22,6 +22,12 @@ along with MIT/GNU Scheme; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +mit-scheme-blowfish 1.0 - Matt Birkholz, 2018-06-22 +=================================================== + +Replace the bfish µmodule. The deprecated (runtime blowfish) package +now autoloads this plugin. + mit-scheme-blowfish 0.2 - Matt Birkholz, 2017-05-18 =================================================== diff --git a/src/blowfish/README b/src/blowfish/README index 60186b802..6e11566fc 100644 --- a/src/blowfish/README +++ b/src/blowfish/README @@ -1,8 +1,7 @@ The Blowfish option. -This plugin creates a (blowfish) package, a drop-in replacement for -the microcode module based (runtime blowfish) package. It is built in -the customary GNU way: +This plugin creates a (blowfish) package. It is built in the +customary GNU way: ./configure [--with-openssl=directory]... make all check install @@ -14,8 +13,8 @@ To use: Import-blowfish will modify the REPL's current environment by adding bindings linked to the plugin's exports. They are not exported to the -global environment because they would conflict with the exports from -(runtime blowfish). +global environment because they would conflict with the deprecated +exports from (runtime blowfish). To import into a CREF package set, add this to your .pkg file: diff --git a/tests/runtime/test-blowfish.scm b/src/blowfish/blowfish-test.scm similarity index 100% rename from tests/runtime/test-blowfish.scm rename to src/blowfish/blowfish-test.scm diff --git a/src/blowfish/configure.ac b/src/blowfish/configure.ac index d56a9eded..5dc0afeca 100644 --- a/src/blowfish/configure.ac +++ b/src/blowfish/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([MIT/GNU Scheme blowfish plugin], - [0.2], + [1.0], [bug-mit-scheme@gnu.org], [mit-scheme-blowfish]) AC_CONFIG_SRCDIR([blowfish.pkg]) diff --git a/src/blowfish/make.scm b/src/blowfish/make.scm index 7677b3de4..ec00f8600 100644 --- a/src/blowfish/make.scm +++ b/src/blowfish/make.scm @@ -6,4 +6,4 @@ (lambda () (load-package-set "blowfish"))) -(add-subsystem-identification! "Blowfish" '(0 2)) \ No newline at end of file +(add-subsystem-identification! "Blowfish" '(1 0)) \ No newline at end of file diff --git a/src/microcode/configure.ac b/src/microcode/configure.ac index 28fb21468..965a95f04 100644 --- a/src/microcode/configure.ac +++ b/src/microcode/configure.ac @@ -130,11 +130,6 @@ AC_ARG_ENABLE([native-code], [Support native compiled code if available [[yes]]])) : ${enable_native_code='yes'} -AC_ARG_WITH([openssl], - AS_HELP_STRING([--with-openssl], - [Use OpenSSL crypto library if available [[yes]]])) -: ${with_openssl='yes'} - AC_ARG_WITH([mcrypt], AS_HELP_STRING([--with-mcrypt], [Use mcrypt library if available [[yes]]])) @@ -171,7 +166,6 @@ GC_HEAD_FILES="gccode.h cmpgc.h cmpintmd-config.h cmpintmd.h" OPTIONAL_BASES= OPTIONAL_SOURCES= OPTIONAL_OBJECTS= -PRBFISH_LIBS= SCHEME_DEFS=-DMIT_SCHEME SCHEME_LDFLAGS= MODULE_BASES= @@ -826,29 +820,6 @@ no) ;; esac -dnl The OpenSSL crypto library provides support for blowfish and MD5. -if test "${with_openssl}" != no; then - if test "${with_openssl}" != yes; then - CPPFLAGS="${CPPFLAGS} -I${with_openssl}/include" - LDFLAGS="${LDFLAGS} -L${with_openssl}/lib" - fi - FOUND= - AC_CHECK_HEADERS([openssl/blowfish.h openssl/md5.h], - [ - AC_CHECK_LIB([crypto], [BF_set_key], - [ - AC_DEFINE([HAVE_LIBCRYPTO], [1], - [Define to 1 if you have the `crypto' library (-lcrypto).]) - FOUND=yes - ]) - ]) - if test -n "${FOUND}"; then - MODULE_LIBS="-lcrypto ${MODULE_LIBS}" - MODULE_BASES="${MODULE_BASES} prbfish" - PRBFISH_LIBS="-lcrypto" - fi -fi - dnl These libraries might not be installed, so take care generating dnl file dependencies using "makegen/makegen.scm" when called on dnl "makegen/files-optional.scm". To wit, "prmcrypt.c" must @@ -1058,7 +1029,6 @@ AC_SUBST([M4_FLAGS]) AC_SUBST([M4]) AC_SUBST([OPTIONAL_SOURCES]) AC_SUBST([OPTIONAL_OBJECTS]) -AC_SUBST([PRBFISH_LIBS]) AC_SUBST([SCHEME_DEFS]) AC_SUBST([SCHEME_LDFLAGS]) AC_SUBST([MODULE_TARGETS]) diff --git a/src/microcode/makegen/Makefile.in.in b/src/microcode/makegen/Makefile.in.in index 52a7951db..ac2e19de0 100644 --- a/src/microcode/makegen/Makefile.in.in +++ b/src/microcode/makegen/Makefile.in.in @@ -101,7 +101,6 @@ STD_OBJECTS = @(write-objects "files-core")@ \ GC_HEAD_FILES = @GC_HEAD_FILES@ OPTIONAL_SOURCES = @OPTIONAL_SOURCES@ OPTIONAL_OBJECTS = @OPTIONAL_OBJECTS@ -PRBFISH_LIBS = @PRBFISH_LIBS@ MODULE_TARGETS = @MODULE_TARGETS@ MODULE_CFLAGS = @MODULE_CFLAGS@ @@ -191,9 +190,6 @@ extract-liarc-decls: extract-liarc-decls.o macosx-starter: macosx-starter.o $(LINK) macosx-starter.o -prbfish.so: prbfish.o @MODULE_LOADER@ - $(LINK_MODULE) prbfish.o $(PRBFISH_LIBS) $(MODULE_LIBS) - prmcrypt.so: prmcrypt.o @MODULE_LOADER@ $(LINK_MODULE) prmcrypt.o -lmcrypt $(MODULE_LIBS) diff --git a/src/microcode/makegen/files-optional.scm b/src/microcode/makegen/files-optional.scm index df88f1032..64f91a8a5 100644 --- a/src/microcode/makegen/files-optional.scm +++ b/src/microcode/makegen/files-optional.scm @@ -28,7 +28,6 @@ USA. "cmpint" "comutl" -"prbfish" "prmcrypt" "prpgsql" "pruxdld" diff --git a/src/microcode/ntutl/config.h b/src/microcode/ntutl/config.h index 2e285a978..59bc4b714 100644 --- a/src/microcode/ntutl/config.h +++ b/src/microcode/ntutl/config.h @@ -58,9 +58,6 @@ typedef unsigned char cc_t; /* Define to 1 if you have the header file. */ #define HAVE_ASSERT_H 1 -/* Define if you have the header file. */ -#define HAVE_BLOWFISH_H 1 - /* Define if you have the header file. */ #define HAVE_FCNTL_H 1 diff --git a/src/microcode/ntutl/makefile b/src/microcode/ntutl/makefile index 39b116816..2ff58a843 100644 --- a/src/microcode/ntutl/makefile +++ b/src/microcode/ntutl/makefile @@ -27,9 +27,9 @@ #### Makefile for Scheme under Win32 compiled by Microsoft Visual C++. !include -#USER_PRIM_SOURCES = prbfish.c prmd5.c prpgsql.c -#USER_PRIM_OBJECTS = prbfish.obj prmd5.obj prpgsql.obj -#USER_LIBS = blowfish.lib md5.lib pq.lib +#USER_PRIM_SOURCES = prmd5.c prpgsql.c +#USER_PRIM_OBJECTS = prmd5.obj prpgsql.obj +#USER_LIBS = md5.lib pq.lib # **** Microsoft supplies their assembler as a separate product, and # **** we don't currently have a copy, so use the Watcom assembler. @@ -469,7 +469,6 @@ utils.obj: utils.c $(SCHEME_H) $(PRIMS_H) $(HISTORY_H) \ vector.obj: vector.c $(SCHEME_H) $(PRIMS_H) wind.obj: wind.c $(OBSTACK_H) $(DSTACK_H) $(OUTF_H) -prbfish.obj: prbfish.c $(SCHEME_H) $(PRIMS_H) prmd5.obj: prmd5.c $(SCHEME_H) $(PRIMS_H) prpgsql.obj: prpgsql.c $(SCHEME_H) $(PRIMS_H) $(USRDEF_H) $(OS_H) prosenv.obj: prosenv.c $(SCHEME_H) $(PRIMS_H) $(OSENV_H) $(OSTOP_H) $(LIMITS_H) diff --git a/src/microcode/ntutl/makefile.wcc b/src/microcode/ntutl/makefile.wcc index 645af69f6..4d486a48c 100644 --- a/src/microcode/ntutl/makefile.wcc +++ b/src/microcode/ntutl/makefile.wcc @@ -27,9 +27,9 @@ #### Makefile for Scheme under Win32 compiled by Watcom C/C++ ### This makefile is meant to be used with Watcom make. -USER_PRIM_SOURCES = # prbfish.c prmd5.c prpgsql.c -USER_PRIM_OBJECTS = # prbfish.obj prmd5.obj prpgsql.obj -USER_LIBS = library wsock32.lib #,blowfish.lib,md5.lib,pq.lib +USER_PRIM_SOURCES = # prmd5.c prpgsql.c +USER_PRIM_OBJECTS = # prmd5.obj prpgsql.obj +USER_LIBS = library wsock32.lib #,md5.lib,pq.lib CC = wcc386 M4 = m4 diff --git a/src/microcode/prbfish.c b/src/microcode/prbfish.c deleted file mode 100644 index 6405b7919..000000000 --- a/src/microcode/prbfish.c +++ /dev/null @@ -1,271 +0,0 @@ -/* -*-C-*- - -Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, - 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, - 2017, 2018 Massachusetts Institute of Technology - -This file is part of MIT/GNU Scheme. - -MIT/GNU Scheme is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at -your option) any later version. - -MIT/GNU Scheme is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with MIT/GNU Scheme; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, -USA. - -*/ - -/* Interface to Blowfish library */ - -#include "scheme.h" -#include "prims.h" - -#if defined(HAVE_LIBCRYPTO) && defined(HAVE_OPENSSL_BLOWFISH_H) -# include -#else -# ifdef HAVE_BLOWFISH_H -# include -# endif -#endif - -/* This interface uses the Blowfish library from SSLeay. */ - -DEFINE_PRIMITIVE ("BLOWFISH-SET-KEY", Prim_blowfish_set_key, 1, 1, - "(BYTEVECTOR)\n\ -Generate a Blowfish key from BYTEVECTOR.\n\ -BYTEVECTOR must be 72 bytes or less in length.\n\ -For text-string keys, use MD5 on the text, and pass the digest here.") -{ - PRIMITIVE_HEADER (1); - unsigned long length; - uint8_t * bytes = (arg_bytevector (1, (&length))); - if (length > 72) - error_bad_range_arg (1); - SCHEME_OBJECT result = (allocate_bytevector (sizeof (BF_KEY))); - BF_set_key (((BF_KEY *) (BYTEVECTOR_POINTER (result))), length, bytes); - PRIMITIVE_RETURN (result); -} - -static uint8_t * -arg_bytevector_fixlen (unsigned int arg, unsigned long required) -{ - unsigned long length; - uint8_t * bytes = (arg_bytevector (arg, (&length))); - if (length != required) - error_bad_range_arg (arg); - return bytes; -} - -static BF_KEY * -key_arg (unsigned int arg) -{ - return ((BF_KEY *) (arg_bytevector_fixlen (arg, (sizeof (BF_KEY))))); -} - -static uint8_t * -init_vector_arg (unsigned int arg) -{ - return (arg_bytevector_fixlen (arg, 8)); -} - -DEFINE_PRIMITIVE ("BLOWFISH-ECB", Prim_blowfish_ecb, 4, 4, - "(INPUT OUTPUT KEY-VECTOR ENCRYPT?)\n\ -Apply Blowfish in Electronic Code Book mode.\n\ -INPUT is an 8-byte bytevector.\n\ -OUTPUT is an 8-byte bytevector.\n\ -KEY is a Blowfish key.\n\ -ENCRYPT? says whether to encrypt (#T) or decrypt (#F).") -{ - PRIMITIVE_HEADER (4); - CHECK_ARG (1, STRING_P); - unsigned long input_length; - uint8_t * input = (arg_bytevector (1, (&input_length))); - if (input_length != 8) - error_bad_range_arg (1); - unsigned long output_length; - uint8_t * output = (arg_bytevector (2, (&output_length))); - if (output_length != 8) - error_bad_range_arg (2); - BF_ecb_encrypt (input, - output, - (key_arg (3)), - ((BOOLEAN_ARG (4)) ? BF_ENCRYPT : BF_DECRYPT)); - PRIMITIVE_RETURN (UNSPECIFIC); -} - -DEFINE_PRIMITIVE ("BLOWFISH-CBC-V2", Prim_blowfish_cbc, 5, 5, - "(INPUT OUTPUT KEY INIT-VECTOR ENCRYPT?)\n\ -Apply Blowfish in Cipher Block Chaining mode.\n\ -INPUT is a bytevector whose length is a multiple of 8 bytes.\n\ -OUTPUT is a bytevector whose length is the same as INPUT.\n\ -KEY is a Blowfish key.\n\ -INIT-VECTOR is an 8-byte bytevector; it is modified after each call.\n\ - The value from any call may be passed in to a later call.\n\ -ENCRYPT? says whether to encrypt (#T) or decrypt (#F).") -{ - PRIMITIVE_HEADER (5); - unsigned long input_length; - uint8_t * input = (arg_bytevector (1, (&input_length))); - if ((input_length % 8) != 0) - error_bad_range_arg (1); - uint8_t * output = (arg_bytevector_fixlen (2, input_length)); - if (output == input) - error_bad_range_arg (2); - BF_cbc_encrypt (input, - output, - input_length, - (key_arg (3)), - (init_vector_arg (4)), - ((BOOLEAN_ARG (5)) ? BF_ENCRYPT : BF_DECRYPT)); - PRIMITIVE_RETURN (UNSPECIFIC); -} - -DEFINE_PRIMITIVE ("BLOWFISH-CFB64-SUBSTRING-V2", Prim_blowfish_cfb64_substring, 9, 9, - "(INPUT ISTART IEND OUTPUT OSTART KEY INIT-VECTOR NUM ENCRYPT?)\n\ -Apply Blowfish in Cipher Feed-Back mode.\n\ -(INPUT,ISTART,IEND) is an arbitrary bytevector range.\n\ -OUTPUT is a bytevector.\n\ -OSTART says where to start writing in OUTPUT.\n\ -KEY is a Blowfish key.\n\ -INIT-VECTOR is an 8-byte bytevector; it is modified after each call.\n\ - The value from any call may be passed in to a later call.\n\ - The initial value must be unique for each message/key pair.\n\ -NUM is a digit from 0 to 7 inclusive; it is the low 3 bits of the\n\ - number of bytes that have previously been processed in this stream.\n\ -ENCRYPT? says whether to encrypt (#T) or decrypt (#F).\n\ -Returned value is the new value of NUM.") -{ - PRIMITIVE_HEADER (9); - - unsigned long input_length; - uint8_t * input = (arg_bytevector (1, (&input_length))); - unsigned long iend = (arg_ulong_index_integer (3, (input_length + 1))); - unsigned long istart = (arg_ulong_index_integer (2, (iend + 1))); - unsigned long ilen = (iend - istart); - - unsigned long output_length; - uint8_t * output = (arg_bytevector (4, (&output_length))); - unsigned long ostart = (arg_ulong_index_integer (5, (output_length + 1))); - unsigned long oend = (ostart + ilen); - if (oend > output_length) - error_bad_range_arg (5); - /* Don't allow overlaps of input and output ranges in same bytevector. */ - if ((output == input) && (ostart < iend) && (istart < oend)) - error_bad_range_arg (4); - - int num = (arg_index_integer (8, 8)); - BF_cfb64_encrypt - (input, output, ilen, (key_arg (6)), (init_vector_arg (7)), (&num), - ((BOOLEAN_ARG (9)) ? BF_ENCRYPT : BF_DECRYPT)); - PRIMITIVE_RETURN (long_to_integer (num)); -} - -DEFINE_PRIMITIVE ("BLOWFISH-OFB64-SUBSTRING", Prim_blowfish_ofb64_substring, 8, 8, - "(INPUT ISTART IEND OUTPUT OSTART KEY INIT-VECTOR NUM)\n\ -Apply Blowfish in Output Feed-Back mode.\n\ -(INPUT,ISTART,IEND) is an arbitrary bytevector range.\n\ -OUTPUT is a bytevector.\n\ -OSTART says where to start writing in OUTPUT.\n\ -KEY is a Blowfish key.\n\ -INIT-VECTOR is an 8-byte bytevector; it is modified after each call.\n\ - The value from any call may be passed in to a later call.\n\ - The initial value must be unique for each message/key pair.\n\ -NUM is a digit from 0 to 7 inclusive; it is the low 3 bits of the\n\ - number of bytes that have previously been processed in this stream.\n\ -Returned value is the new value of NUM.") -{ - PRIMITIVE_HEADER (8); - - unsigned long input_length; - uint8_t * input = (arg_bytevector (1, (&input_length))); - unsigned long iend = (arg_ulong_index_integer (3, (input_length + 1))); - unsigned long istart = (arg_ulong_index_integer (2, (iend + 1))); - unsigned long ilen = (iend - istart); - - unsigned long output_length; - uint8_t * output = (arg_bytevector (4, (&output_length))); - unsigned long ostart = (arg_ulong_index_integer (5, (output_length + 1))); - unsigned long oend = (ostart + ilen); - if (oend > output_length) - error_bad_range_arg (5); - /* Don't allow overlaps of input and output ranges in same bytevector. */ - if ((output == input) && (ostart < iend) && (istart < oend)) - error_bad_range_arg (4); - - int num = (arg_index_integer (8, 8)); - BF_ofb64_encrypt - (input, output, ilen, (key_arg (6)), (init_vector_arg (7)), (&num)); - PRIMITIVE_RETURN (long_to_integer (num)); -} - -#ifdef COMPILE_AS_MODULE - -const char * -dload_initialize_file (void) -{ - declare_primitive - ("BLOWFISH-SET-KEY", Prim_blowfish_set_key, 1, 1, - "(BYTEVECTOR)\n\ -Generate a Blowfish key from BYTEVECTOR.\n\ -BYTEVECTOR must be 72 bytes or less in length.\n\ -For text-string keys, use MD5 on the text, and pass the digest here."); - declare_primitive - ("BLOWFISH-ECB", Prim_blowfish_ecb, 4, 4, - "(INPUT OUTPUT KEY-VECTOR ENCRYPT?)\n\ -Apply Blowfish in Electronic Code Book mode.\n\ -INPUT is an 8-byte bytevector.\n\ -OUTPUT is an 8-byte bytevector.\n\ -KEY is a Blowfish key.\n\ -ENCRYPT? says whether to encrypt (#T) or decrypt (#F)."); - declare_primitive - ("BLOWFISH-CBC-V2", Prim_blowfish_cbc, 5, 5, - "(INPUT OUTPUT KEY INIT-VECTOR ENCRYPT?)\n\ -Apply Blowfish in Cipher Block Chaining mode.\n\ -INPUT is a bytevector whose length is a multiple of 8 bytes.\n\ -OUTPUT is a bytevector whose length is the same as INPUT.\n\ -KEY is a Blowfish key.\n\ -INIT-VECTOR is an 8-byte bytevector; it is modified after each call.\n\ - The value from any call may be passed in to a later call.\n\ -ENCRYPT? says whether to encrypt (#T) or decrypt (#F)."); - declare_primitive - ("BLOWFISH-CFB64-SUBSTRING-V2", Prim_blowfish_cfb64_substring, 9, 9, - "(INPUT ISTART IEND OUTPUT OSTART KEY INIT-VECTOR NUM ENCRYPT?)\n\ -Apply Blowfish in Cipher Feed-Back mode.\n\ -(INPUT,ISTART,IEND) is an arbitrary bytevector range.\n\ -OUTPUT is a bytevector.\n\ -OSTART says where to start writing in OUTPUT.\n\ -KEY is a Blowfish key.\n\ -INIT-VECTOR is an 8-byte bytevector; it is modified after each call.\n\ - The value from any call may be passed in to a later call.\n\ - The initial value must be unique for each message/key pair.\n\ -NUM is a digit from 0 to 7 inclusive; it is the low 3 bits of the\n\ - number of bytes that have previously been processed in this stream.\n\ -ENCRYPT? says whether to encrypt (#T) or decrypt (#F).\n\ -Returned value is the new value of NUM."); - declare_primitive - ("BLOWFISH-OFB64-SUBSTRING", Prim_blowfish_ofb64_substring, 8, 8, - "(INPUT ISTART IEND OUTPUT OSTART KEY INIT-VECTOR NUM)\n\ -Apply Blowfish in Output Feed-Back mode.\n\ -(INPUT,ISTART,IEND) is an arbitrary bytevector range.\n\ -OUTPUT is a bytevector.\n\ -OSTART says where to start writing in OUTPUT.\n\ -KEY is a Blowfish key.\n\ -INIT-VECTOR is an 8-byte bytevector; it is modified after each call.\n\ - The value from any call may be passed in to a later call.\n\ - The initial value must be unique for each message/key pair.\n\ -NUM is a digit from 0 to 7 inclusive; it is the low 3 bits of the\n\ - number of bytes that have previously been processed in this stream.\n\ -Returned value is the new value of NUM."); - return "#prbfish"; -} - -#endif /* COMPILE_AS_MODULE */ diff --git a/src/runtime/blowfish.scm b/src/runtime/blowfish.scm index 3a5c293a3..0fca2a7a5 100644 --- a/src/runtime/blowfish.scm +++ b/src/runtime/blowfish.scm @@ -28,97 +28,50 @@ USA. ;;; package: (runtime blowfish) (declare (usual-integrations)) - -(define-primitives - (blowfish-set-key 1) - (blowfish-ecb 4) - (blowfish-cbc blowfish-cbc-v2 5) - (blowfish-cfb64 blowfish-cfb64-substring-v2 9) - (blowfish-ofb64 blowfish-ofb64-substring 8)) - -(define (blowfish-available?) - (load-library-object-file "prbfish" #f) - (implemented-primitive-procedure? - (ucode-primitive blowfish-cfb64-substring-v2 9))) -(define (blowfish-encrypt-port input output key init-vector encrypt?) - ;; Assumes that INPUT is in blocking mode. - (let ((key (blowfish-set-key key)) - (input-buffer (make-bytevector 4096)) - (output-buffer (make-bytevector 4096))) - (dynamic-wind - (lambda () - unspecific) - (lambda () - (let loop ((m 0)) - (let ((n (read-bytevector! input-buffer input))) - (if (and n (not (eof-object? n))) - (let ((m - (blowfish-cfb64 input-buffer 0 n output-buffer 0 - key init-vector m encrypt?))) - (let ((n* (write-bytevector output-buffer output 0 n))) - (if (not (eqv? n n*)) - (error "Short write (requested, actual):" n n*))) - (loop m)))))) - (lambda () - (bytevector-fill! input-buffer 0) - (bytevector-fill! output-buffer 0))))) - -(define (compute-blowfish-init-vector) - ;; This init vector includes a timestamp with a resolution of - ;; milliseconds, plus 20 random bits. This should make it very - ;; difficult to generate two identical vectors. - (let ((iv (make-bytevector 8))) - (do ((i 0 (fix:+ i 1)) - (t (+ (* (+ (* (get-universal-time) 1000) - (remainder (real-time-clock) 1000)) - #x100000) - (random #x100000)) - (quotient t #x100))) - ((not (fix:< i 8))) - (bytevector-u8-set! iv i (remainder t #x100))) - iv)) - -(define (write-blowfish-file-header port) - (write-bytevector blowfish-file-header-v2 port) - (let ((init-vector (compute-blowfish-init-vector))) - (write-bytevector init-vector port) - init-vector)) +;;; Access to blowfish functions is now accomplished with the FFI +;;; rather than a microcode module. The bindings in this package are +;;; linked to those in the (blowfish) package after the plugin is +;;; loaded. -(define (read-blowfish-file-header port) - (let ((version (try-read-blowfish-file-header port))) - (if (not version) - (error:bad-range-argument port 'read-blowfish-file-header)) - (if (= version 1) - (make-bytevector 8 0) - (or (%safe-read-bytevector 8 port) - (error "Short read while getting init-vector:" port))))) +(define linked? #f) -(define (try-read-blowfish-file-header port) - (let* ((n (bytevector-length blowfish-file-header-v1)) - (bv1 (%safe-read-bytevector n port))) - (and bv1 - (if (bytevector=? bv1 blowfish-file-header-v1) - 1 - (let* ((m (fix:- (bytevector-length blowfish-file-header-v2) n)) - (bv2 (%safe-read-bytevector m port))) - (and bv2 - (bytevector=? (bytevector-append bv1 bv2) - blowfish-file-header-v2) - 2)))))) - -(define (%safe-read-bytevector n port) - (let ((bv (read-bytevector n port))) - (and bv - (not (eof-object? bv)) - (fix:= (bytevector-length bv) n) - bv))) - -(define (blowfish-file? pathname) - (call-with-binary-input-file pathname try-read-blowfish-file-header)) - -(define-deferred blowfish-file-header-v1 - (string->utf8 "Blowfish, 16 rounds\n")) - -(define-deferred blowfish-file-header-v2 - (string->utf8 "Blowfish, 16 rounds, version 2\n")) \ No newline at end of file +(define (blowfish-available?) + (and (plugin-available? "blowfish") + (or linked? + (begin + (load-option 'blowfish) + (link!) + #t)))) + +(define (link!) + (for-each + (let ((runtime (->environment '(runtime blowfish))) + (blowfish (->environment '(blowfish)))) + (lambda (name) + (environment-link-name runtime blowfish name))) + names) + (set! linked? #t)) + +(define names + '(blowfish-cbc + blowfish-cfb64 + blowfish-ecb + blowfish-encrypt-port + blowfish-file? + blowfish-ofb64 + blowfish-set-key + compute-blowfish-init-vector + read-blowfish-file-header + write-blowfish-file-header)) + +(define blowfish-cbc) +(define blowfish-cfb64) +(define blowfish-ecb) +(define blowfish-encrypt-port) +(define blowfish-file?) +(define blowfish-ofb64) +(define blowfish-set-key) +(define compute-blowfish-init-vector) +(define read-blowfish-file-header) +(define write-blowfish-file-header) \ No newline at end of file diff --git a/src/runtime/make.scm b/src/runtime/make.scm index e03889bde..a289c1ef8 100644 --- a/src/runtime/make.scm +++ b/src/runtime/make.scm @@ -467,7 +467,6 @@ USA. (runtime memoizer) (runtime ucd-tables) (runtime ucd-glue) - (runtime blowfish) (runtime predicate) (runtime predicate-tagging) (runtime predicate-dispatch) diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 3e8f7c75c..ccd00e26d 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -105,7 +105,7 @@ USA. (define-package (runtime blowfish) (files "blowfish") (parent (runtime)) - (export () + (export () deprecated:blowfish blowfish-available? blowfish-cbc blowfish-cfb64 diff --git a/tests/check.scm b/tests/check.scm index 27568d848..6b47e87cd 100644 --- a/tests/check.scm +++ b/tests/check.scm @@ -49,7 +49,6 @@ USA. "microcode/test-lookup" "runtime/test-arith" "runtime/test-binary-port" - "runtime/test-blowfish" "runtime/test-bundle" "runtime/test-bytevector" ("runtime/test-char" (runtime))