From 16bb66edfc4500797baaf95147e3a0c947afa3af Mon Sep 17 00:00:00 2001 From: erana Date: Fri, 20 Jan 2012 17:38:32 +0900 Subject: [PATCH] blowfish fixes --- scsh/encryption/blowfish.scm | 58 +++++++++++++++++----------------- scsh/encryption/dictionary.scm | 7 ++-- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/scsh/encryption/blowfish.scm b/scsh/encryption/blowfish.scm index 4397cdd..3cffba9 100644 --- a/scsh/encryption/blowfish.scm +++ b/scsh/encryption/blowfish.scm @@ -1103,31 +1103,31 @@ (define blowfish-rounds 16) ;; (define blowfish-context (make-blowfish-record - (make-vector 256) - (make-vector 256) - (make-vector 256) - (make-vector 256) - (make-vector (+ blowfish-rounds) 2))) + (make-dictionary) ;; (make-vector 256) + (make-dictionary) + (make-dictionary) + (make-dictionary) + (make-dictionary)) -(define blowfish-ps (make-table)) -(table-set! blowfish-ps 0 '243F6A88) -(table-set! blowfish-ps 1 '85A308D3) -(table-set! blowfish-ps 2 '13198A2E) -(table-set! blowfish-ps 3 '03707344) -(table-set! blowfish-ps 4 'A4093822) -(table-set! blowfish-ps 5 '299F31D0) -(table-set! blowfish-ps 6 '082EFA98) -(table-set! blowfish-ps 7 'EC4E6C89) -(table-set! blowfish-ps 8 '452821E6) -(table-set! blowfish-ps 9 '38D01377) -(table-set! blowfish-ps 10 'BE5466CF) -(table-set! blowfish-ps 11 '34E90C6C) -(table-set! blowfish-ps 12 'C0AC29B7) -(table-set! blowfish-ps 13 'C97C50DD) -(table-set! blowfish-ps 14 '3F84D5B5) -(table-set! blowfish-ps 15 'B5470917) -(table-set! blowfish-ps 16 '9216D5D9) -(table-set! blowfish-ps 17 '8979FB1B) +(define blowfish-ps (make-dictionary)) +(dictionary-add! blowfish-ps 0 '243F6A88) +(dictionary-add! blowfish-ps 1 '85A308D3) +(dictionary-add! blowfish-ps 2 '13198A2E) +(dictionary-add! blowfish-ps 3 '03707344) +(dictionary-add! blowfish-ps 4 'A4093822) +(dictionary-add! blowfish-ps 5 '299F31D0) +(dictionary-add! blowfish-ps 6 '082EFA98) +(dictionary-add! blowfish-ps 7 'EC4E6C89) +(dictionary-add! blowfish-ps 8 '452821E6) +(dictionary-add! blowfish-ps 9 '38D01377) +(dictionary-add! blowfish-ps 10 'BE5466CF) +(dictionary-add! blowfish-ps 11 '34E90C6C) +(dictionary-add! blowfish-ps 12 'C0AC29B7) +(dictionary-add! blowfish-ps 13 'C97C50DD) +(dictionary-add! blowfish-ps 14 '3F84D5B5) +(dictionary-add! blowfish-ps 15 'B5470917) +(dictionary-add! blowfish-ps 16 '9216D5D9) +(dictionary-add! blowfish-ps 17 '8979FB1B) (define (blowfish-F-be x) (bitwise-xor (+ (vector-ref (blowfish-s0 blowfish-context) 0) @@ -1216,14 +1216,14 @@ (do ((i 0 (+ i 1))) ((>= i (+ blowfish-rounds 2))0) - (vector-set! (blowfish-p bc) i (table-ref blowfish-ps i))) + (dictionary-set! (blowfish-p bc) i (table-ref blowfish-ps i))) (do ((i 0 (+ i 1))) ((>= i 256)0) - (((blowfish-s0 bc) 'set-with-index) i (((blowfish-ks0 'get-with-index) i))) - (((blowfish-s1 bc) 'set-with-index) i (((blowfish-ks1 'get-with-index) i))) - (((blowfish-s2 bc) 'set-with-index) i (((blowfish-ks2 'get-with-index) i))) - (((blowfish-s3 bc) 'set-with-index) i (((blowfish-ks3 'get-with-index) i))) + (((blowfish-s0 bc) 'set-with-index) i (((blowfish-ks0 'ref-with-index) i))) + (((blowfish-s1 bc) 'set-with-index) i (((blowfish-ks1 'ref-with-index) i))) + (((blowfish-s2 bc) 'set-with-index) i (((blowfish-ks2 'ref-with-index) i))) + (((blowfish-s3 bc) 'set-with-index) i (((blowfish-ks3 'ref-with-index) i))) ) (do ((i 0 (+ i 1)) diff --git a/scsh/encryption/dictionary.scm b/scsh/encryption/dictionary.scm index d2d3312..d3fc4bd 100644 --- a/scsh/encryption/dictionary.scm +++ b/scsh/encryption/dictionary.scm @@ -36,7 +36,7 @@ (cadar l));;returns value )) - (define (get-with-index i) ;; get key + (define (ref-with-index i) ;; get key (do ((j 0 (+ j 1)) (l *dict (cdr l))) ((= j i) @@ -75,7 +75,7 @@ (lambda (msg) (cond ((eq? msg 'get) get) - ((eq? msg 'get-with-index) get-with-index) + ((eq? msg 'ref-with-index) ref-with-index) ((eq? msg 'set-with-index) set-with-index) ((eq? msg 'get-substring) get-substring) ((eq? msg 'set) set) @@ -85,8 +85,9 @@ (define make-dictionary make-dictionary1) (define (dictionary-ref dict key) ((dict 'get) key)) +(define (dictionary-ref-with-index dict i value) ((dict 'get-with-index) i)) ;; NOTE: dictionary-ref-substring: match key part with keys in dict (define (dictionary-ref-substring dict key) ((dict 'get-substring) key)) (define (dictionary-set! dict key value) ((dict 'set) key value)) (define (dictionary-add! dict key value) ((dict 'add) key value)) - +(define (dictionary-set-with-index! dict i value) ((dict 'set-with-index) i value))