summaryrefslogtreecommitdiff
path: root/src/pkg/crypto/rc4
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/crypto/rc4')
-rw-r--r--src/pkg/crypto/rc4/Makefile2
-rw-r--r--src/pkg/crypto/rc4/rc4.go10
-rw-r--r--src/pkg/crypto/rc4/rc4_test.go12
3 files changed, 12 insertions, 12 deletions
diff --git a/src/pkg/crypto/rc4/Makefile b/src/pkg/crypto/rc4/Makefile
index 7827b0817..50a3b7972 100644
--- a/src/pkg/crypto/rc4/Makefile
+++ b/src/pkg/crypto/rc4/Makefile
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-include ../../../Make.$(GOARCH)
+include ../../../Make.inc
TARG=crypto/rc4
GOFILES=\
diff --git a/src/pkg/crypto/rc4/rc4.go b/src/pkg/crypto/rc4/rc4.go
index e47a01513..65fd195f3 100644
--- a/src/pkg/crypto/rc4/rc4.go
+++ b/src/pkg/crypto/rc4/rc4.go
@@ -45,14 +45,14 @@ func NewCipher(key []byte) (*Cipher, os.Error) {
return &c, nil
}
-// XORKeyStream will XOR each byte of the given buffer with a byte of the
-// generated keystream.
-func (c *Cipher) XORKeyStream(buf []byte) {
- for i := range buf {
+// XORKeyStream sets dst to the result of XORing src with the key stream.
+// Dst and src may be the same slice but otherwise should not overlap.
+func (c *Cipher) XORKeyStream(dst, src []byte) {
+ for i := range src {
c.i += 1
c.j += c.s[c.i]
c.s[c.i], c.s[c.j] = c.s[c.j], c.s[c.i]
- buf[i] ^= c.s[c.s[c.i]+c.s[c.j]]
+ dst[i] = src[i] ^ c.s[c.s[c.i]+c.s[c.j]]
}
}
diff --git a/src/pkg/crypto/rc4/rc4_test.go b/src/pkg/crypto/rc4/rc4_test.go
index 1d39b2f17..6265d9408 100644
--- a/src/pkg/crypto/rc4/rc4_test.go
+++ b/src/pkg/crypto/rc4/rc4_test.go
@@ -15,25 +15,25 @@ type rc4Test struct {
var golden = []rc4Test{
// Test vectors from the original cypherpunk posting of ARC4:
// http://groups.google.com/group/sci.crypt/msg/10a300c9d21afca0?pli=1
- rc4Test{
+ {
[]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
[]byte{0x74, 0x94, 0xc2, 0xe7, 0x10, 0x4b, 0x08, 0x79},
},
- rc4Test{
+ {
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0xde, 0x18, 0x89, 0x41, 0xa3, 0x37, 0x5d, 0x3a},
},
- rc4Test{
+ {
[]byte{0xef, 0x01, 0x23, 0x45},
[]byte{0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf, 0xbd, 0x61},
},
// Test vectors from the Wikipedia page: http://en.wikipedia.org/wiki/RC4
- rc4Test{
+ {
[]byte{0x4b, 0x65, 0x79},
[]byte{0xeb, 0x9f, 0x77, 0x81, 0xb7, 0x34, 0xca, 0x72, 0xa7, 0x19},
},
- rc4Test{
+ {
[]byte{0x57, 0x69, 0x6b, 0x69},
[]byte{0x60, 0x44, 0xdb, 0x6d, 0x41, 0xb7},
},
@@ -48,7 +48,7 @@ func TestGolden(t *testing.T) {
return
}
keystream := make([]byte, len(g.keystream))
- c.XORKeyStream(keystream)
+ c.XORKeyStream(keystream, keystream)
for j, v := range keystream {
if g.keystream[j] != v {
t.Errorf("Failed at golden index %d", i)