blowfish fixes

This commit is contained in:
erana 2012-01-20 17:38:32 +09:00
parent c53f89828b
commit 16bb66edfc
2 changed files with 33 additions and 32 deletions

View File

@ -1103,31 +1103,31 @@
(define blowfish-rounds 16) ;; (define blowfish-rounds 16) ;;
(define blowfish-context (make-blowfish-record (define blowfish-context (make-blowfish-record
(make-vector 256) (make-dictionary) ;; (make-vector 256)
(make-vector 256) (make-dictionary)
(make-vector 256) (make-dictionary)
(make-vector 256) (make-dictionary)
(make-vector (+ blowfish-rounds) 2))) (make-dictionary))
(define blowfish-ps (make-table)) (define blowfish-ps (make-dictionary))
(table-set! blowfish-ps 0 '243F6A88) (dictionary-add! blowfish-ps 0 '243F6A88)
(table-set! blowfish-ps 1 '85A308D3) (dictionary-add! blowfish-ps 1 '85A308D3)
(table-set! blowfish-ps 2 '13198A2E) (dictionary-add! blowfish-ps 2 '13198A2E)
(table-set! blowfish-ps 3 '03707344) (dictionary-add! blowfish-ps 3 '03707344)
(table-set! blowfish-ps 4 'A4093822) (dictionary-add! blowfish-ps 4 'A4093822)
(table-set! blowfish-ps 5 '299F31D0) (dictionary-add! blowfish-ps 5 '299F31D0)
(table-set! blowfish-ps 6 '082EFA98) (dictionary-add! blowfish-ps 6 '082EFA98)
(table-set! blowfish-ps 7 'EC4E6C89) (dictionary-add! blowfish-ps 7 'EC4E6C89)
(table-set! blowfish-ps 8 '452821E6) (dictionary-add! blowfish-ps 8 '452821E6)
(table-set! blowfish-ps 9 '38D01377) (dictionary-add! blowfish-ps 9 '38D01377)
(table-set! blowfish-ps 10 'BE5466CF) (dictionary-add! blowfish-ps 10 'BE5466CF)
(table-set! blowfish-ps 11 '34E90C6C) (dictionary-add! blowfish-ps 11 '34E90C6C)
(table-set! blowfish-ps 12 'C0AC29B7) (dictionary-add! blowfish-ps 12 'C0AC29B7)
(table-set! blowfish-ps 13 'C97C50DD) (dictionary-add! blowfish-ps 13 'C97C50DD)
(table-set! blowfish-ps 14 '3F84D5B5) (dictionary-add! blowfish-ps 14 '3F84D5B5)
(table-set! blowfish-ps 15 'B5470917) (dictionary-add! blowfish-ps 15 'B5470917)
(table-set! blowfish-ps 16 '9216D5D9) (dictionary-add! blowfish-ps 16 '9216D5D9)
(table-set! blowfish-ps 17 '8979FB1B) (dictionary-add! blowfish-ps 17 '8979FB1B)
(define (blowfish-F-be x) (define (blowfish-F-be x)
(bitwise-xor (+ (vector-ref (blowfish-s0 blowfish-context) 0) (bitwise-xor (+ (vector-ref (blowfish-s0 blowfish-context) 0)
@ -1216,14 +1216,14 @@
(do ((i 0 (+ i 1))) (do ((i 0 (+ i 1)))
((>= i (+ blowfish-rounds 2))0) ((>= 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))) (do ((i 0 (+ i 1)))
((>= i 256)0) ((>= i 256)0)
(((blowfish-s0 bc) 'set-with-index) i (((blowfish-ks0 '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 'get-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 'get-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 'get-with-index) i))) (((blowfish-s3 bc) 'set-with-index) i (((blowfish-ks3 'ref-with-index) i)))
) )
(do ((i 0 (+ i 1)) (do ((i 0 (+ i 1))

View File

@ -36,7 +36,7 @@
(cadar l));;returns value (cadar l));;returns value
)) ))
(define (get-with-index i) ;; get key (define (ref-with-index i) ;; get key
(do ((j 0 (+ j 1)) (do ((j 0 (+ j 1))
(l *dict (cdr l))) (l *dict (cdr l)))
((= j i) ((= j i)
@ -75,7 +75,7 @@
(lambda (msg) (lambda (msg)
(cond ((eq? msg 'get) get) (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 'set-with-index) set-with-index)
((eq? msg 'get-substring) get-substring) ((eq? msg 'get-substring) get-substring)
((eq? msg 'set) set) ((eq? msg 'set) set)
@ -85,8 +85,9 @@
(define make-dictionary make-dictionary1) (define make-dictionary make-dictionary1)
(define (dictionary-ref dict key) ((dict 'get) key)) (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 ;; NOTE: dictionary-ref-substring: match key part with keys in dict
(define (dictionary-ref-substring dict key) ((dict 'get-substring) key)) (define (dictionary-ref-substring dict key) ((dict 'get-substring) key))
(define (dictionary-set! dict key value) ((dict 'set) key value)) (define (dictionary-set! dict key value) ((dict 'set) key value))
(define (dictionary-add! dict key value) ((dict 'add) 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))