summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-08-16 21:05:51 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-08-16 21:05:51 +0200
commit99190469366368062619ca11fd14bd76a8caf87b (patch)
tree71b686af14c96bd5cacdf89b0d4cdd2f01d4a725
parent8a5aa2f4b6b3f26daa886faceae6fe6547ab2187 (diff)
Salsa20: Fix a couple of bugs in the expansion and encryption procedures.
-rw-r--r--salsa-chacha.rkt12
1 files changed, 9 insertions, 3 deletions
diff --git a/salsa-chacha.rkt b/salsa-chacha.rkt
index e5a087d..bf7a6ee 100644
--- a/salsa-chacha.rkt
+++ b/salsa-chacha.rkt
@@ -159,7 +159,7 @@
[s3 (list->bytes '(116 101 32 107))]
[t0 s0]
[t1 (list->bytes '(110 100 32 49))]
- [t2 s2]
+ [t2 (list->bytes '( 54 45 98 121))]
[t3 s3])
(if (= (bytes-length k) 32)
(let ([k0 (subbytes k 0 16)]
@@ -169,12 +169,18 @@
(: salsa20 (Bytes Bytes (Sequenceof Byte) -> (Sequenceof Byte)))
(defineĀ (salsa20 k v m)
+ (assert (= (bytes-length v) 8))
+ (assert (member (bytes-length k) '(16 32)))
(let-values ([(next? next) (sequence-generate m)])
- (let: ([i : Word 0]
- [buffer : (Listof Byte) (list)])
+ (let: ([i : Word 0]
+ [buffer : (Listof Byte) (list)]
+ [first-iteration? : Boolean #t])
(in-producer
(Ī» ()
(when (null? buffer)
+ (if first-iteration?
+ (set! first-iteration? #f)
+ (set! i (add1 i)))
(let ([64bytes
(let: inner-loop : Bytes
([k : Integer 0]