Commits

Eric Roshan Eisner  committed ccb4625 Draft

stream: allow dst to be longer than src

Meets the unwritten API that other streams meet.

  • Participants
  • Parent commits d4f2624

Comments (0)

Files changed (2)

 }
 
 func (c *keccak) XORKeyStream(dst, src []byte) {
-	if len(dst) != len(src) {
-		panic("XORKeyStream: dst and src are different lengths")
+	if len(dst) < len(src) {
+		panic("XORKeyStream: len(dst) < len(src)")
 	}
 	// using buf[n:blocksize] to store unread data, buffer calls to
 	// squeeze. (0 < n <= blocksize when reading)
 	if c.n < c.blocksize {
-		if len(dst) < c.blocksize-c.n {
+		if len(src) < c.blocksize-c.n {
 			c.n += xor(dst, src, c.buf[c.n:])
 			return
 		} else {
 		}
 	}
 
-	for len(dst) >= c.blocksize {
+	for len(src) >= c.blocksize {
 		c.squeeze()
 		n := xor(dst, src, c.buf[:c.blocksize])
 		dst = dst[n:]
 		src = src[n:]
 	}
 
-	if len(dst) > 0 {
+	if len(src) > 0 {
 		c.squeeze()
 		c.n = xor(dst, src, c.buf[:c.blocksize])
 	}

File stream_test.go

 	b := make([]byte, 41<<10)
 	enc := NewCipher(key)
 	for i := 0; i < len(b); i += 41 {
-		enc.XORKeyStream(b[i:i+41], b[i:i+41])
+		enc.XORKeyStream(b[i:], b[i:i+41])
 	}
 
 	allZero := true