From c454f93410a8c1faef9cbd59f874c10672c85753 Mon Sep 17 00:00:00 2001 From: erana Date: Fri, 20 Jan 2012 18:28:22 +0900 Subject: [PATCH] blowfish fixes - 9 --- scsh/encryption/blowfish.scm | 22 +++++++++++----------- scsh/encryption/dictionary.scm | 20 ++++++++++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/scsh/encryption/blowfish.scm b/scsh/encryption/blowfish.scm index c20465c..e06be53 100644 --- a/scsh/encryption/blowfish.scm +++ b/scsh/encryption/blowfish.scm @@ -32,7 +32,7 @@ (getenv "BIG_ENDIAN_HOST") #t)) ;; NOTE : Do not forget to set this ! -(define blowfish-ks0 (make-dictionary)) +(define blowfish-ks0 (make-dictionary 256)) (dictionary-add! blowfish-ks0 0 '0xD1310BA6) (dictionary-add! blowfish-ks0 1 '0x98DFB5AC) (dictionary-add! blowfish-ks0 2 '0x2FFD72DB) @@ -290,7 +290,7 @@ (dictionary-add! blowfish-ks0 254 '0x08BA4799) (dictionary-add! blowfish-ks0 255 '0x6E85076A) -(define blowfish-ks1 (make-dictionary)) +(define blowfish-ks1 (make-dictionary 256)) (dictionary-add! blowfish-ks1 0 '0x4B7A70E9) (dictionary-add! blowfish-ks1 1 '0xB5B32944) (dictionary-add! blowfish-ks1 2 '0xDB75092E) @@ -549,7 +549,7 @@ (dictionary-add! blowfish-ks1 255 '0xDB83ADF7) -(define blowfish-ks2 (make-dictionary)) +(define blowfish-ks2 (make-dictionary 256)) (dictionary-add! blowfish-ks2 0 '0xE93D5A68) (dictionary-add! blowfish-ks2 1 '0x948140F7) (dictionary-add! blowfish-ks2 2 '0xF64C261C) @@ -807,7 +807,7 @@ (dictionary-add! blowfish-ks2 254 '0x670EFA8E) (dictionary-add! blowfish-ks2 255 '0x406000E0) -(define blowfish-ks3 (make-dictionary)) +(define blowfish-ks3 (make-dictionary 256)) (dictionary-add! blowfish-ks3 0 '0x3A39CE37) (dictionary-add! blowfish-ks3 1 '0xD3FAF5CF) (dictionary-add! blowfish-ks3 2 '0xABC27737) @@ -1103,13 +1103,13 @@ (define blowfish-rounds 16) ;; (define blowfish-context (make-blowfish-record - (make-dictionary) ;; (make-vector 256) - (make-dictionary) - (make-dictionary) - (make-dictionary) - (make-dictionary))) + (make-dictionary 256) ;; (make-vector 256) + (make-dictionary 256) + (make-dictionary 256) + (make-dictionary 256) + (make-dictionary 256))) -(define blowfish-ps (make-dictionary)) +(define blowfish-ps (make-dictionary 256));;FIXME2 (dictionary-add! blowfish-ps 0 '243F6A88) (dictionary-add! blowfish-ps 1 '85A308D3) (dictionary-add! blowfish-ps 2 '13198A2E) @@ -1212,7 +1212,7 @@ ))) (define (blowfish-set-key bc keyvec keylen) ;; NOTE key is a table - (let ((data (make-dictionary))) + (let ((data (make-dictionary 256))) (do ((i 0 (+ i 1))) ((>= i (+ blowfish-rounds 2))0) diff --git a/scsh/encryption/dictionary.scm b/scsh/encryption/dictionary.scm index 1747b8a..e54e612 100644 --- a/scsh/encryption/dictionary.scm +++ b/scsh/encryption/dictionary.scm @@ -26,9 +26,9 @@ ;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF ;;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -(define (make-dictionary1) +(define (make-dictionary1 n) ;; methods are FIFO (first fixed first out) - (let ((*dict '())) + (let ((*dict (make-list n))) (define (get key) ;; get key (do ((l *dict (cdr l))) @@ -38,7 +38,7 @@ (define (ref-with-index i) ;; get key (if (>= i (length *dict)) - (begin (display "dictionary - index out of range") + (begin (display "dictionary - get - index out of range") 0) (do ((j 0 (+ j 1)) (l *dict (cdr l))) @@ -47,11 +47,15 @@ ))) (define (set-with-index i value) ;; set value - (do ((j 0 (+ j 1)) - (l *dict (cdr l))) - ((= j i) - (set-car! (list-ref *dict j) value));;sets value FIXME - )) + (if (>= i (length *dict)) + (begin (display "dictionary - set - index out of range") + 0) + (do ((j 0 (+ j 1)) + (l *dict (cdr l))) + ((= j i) + (display "FOO!") + (set-car! l value));;sets value FIXME + ))) (define (get-substring key) ;; get key (do ((l *dict (cdr l)))