summaryrefslogtreecommitdiff
path: root/src/pkg/crypto/xtea
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
committerOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
commit3e45412327a2654a77944249962b3652e6142299 (patch)
treebc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/pkg/crypto/xtea
parentc533680039762cacbc37db8dc7eed074c3e497be (diff)
downloadgolang-upstream/2011.01.12.tar.gz
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/pkg/crypto/xtea')
-rw-r--r--src/pkg/crypto/xtea/Makefile2
-rw-r--r--src/pkg/crypto/xtea/block.go4
-rw-r--r--src/pkg/crypto/xtea/cipher.go4
-rw-r--r--src/pkg/crypto/xtea/xtea_test.go28
4 files changed, 19 insertions, 19 deletions
diff --git a/src/pkg/crypto/xtea/Makefile b/src/pkg/crypto/xtea/Makefile
index 74cc1b0dc..301621168 100644
--- a/src/pkg/crypto/xtea/Makefile
+++ b/src/pkg/crypto/xtea/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/xtea
GOFILES=\
diff --git a/src/pkg/crypto/xtea/block.go b/src/pkg/crypto/xtea/block.go
index dfb82e1e2..3ac36d038 100644
--- a/src/pkg/crypto/xtea/block.go
+++ b/src/pkg/crypto/xtea/block.go
@@ -36,7 +36,7 @@ func uint32ToBlock(v0, v1 uint32, dst []byte) {
}
// encryptBlock encrypts a single 8 byte block using XTEA.
-func encryptBlock(c *Cipher, src, dst []byte) {
+func encryptBlock(c *Cipher, dst, src []byte) {
v0, v1 := blockToUint32(src)
// Two rounds of XTEA applied per loop
@@ -51,7 +51,7 @@ func encryptBlock(c *Cipher, src, dst []byte) {
}
// decryptBlock decrypt a single 8 byte block using XTEA.
-func decryptBlock(c *Cipher, src, dst []byte) {
+func decryptBlock(c *Cipher, dst, src []byte) {
v0, v1 := blockToUint32(src)
// Two rounds of XTEA applied per loop
diff --git a/src/pkg/crypto/xtea/cipher.go b/src/pkg/crypto/xtea/cipher.go
index 144fe9434..b0fa2a184 100644
--- a/src/pkg/crypto/xtea/cipher.go
+++ b/src/pkg/crypto/xtea/cipher.go
@@ -55,10 +55,10 @@ func (c *Cipher) BlockSize() int { return BlockSize }
// Note that for amounts of data larger than a block,
// it is not safe to just call Encrypt on successive blocks;
// instead, use an encryption mode like CBC (see crypto/block/cbc.go).
-func (c *Cipher) Encrypt(src, dst []byte) { encryptBlock(c, src, dst) }
+func (c *Cipher) Encrypt(dst, src []byte) { encryptBlock(c, dst, src) }
// Decrypt decrypts the 8 byte buffer src using the key k and stores the result in dst.
-func (c *Cipher) Decrypt(src, dst []byte) { decryptBlock(c, src, dst) }
+func (c *Cipher) Decrypt(dst, src []byte) { decryptBlock(c, dst, src) }
// Reset zeros the table, so that it will no longer appear in the process's memory.
func (c *Cipher) Reset() {
diff --git a/src/pkg/crypto/xtea/xtea_test.go b/src/pkg/crypto/xtea/xtea_test.go
index 94756f79f..03934f169 100644
--- a/src/pkg/crypto/xtea/xtea_test.go
+++ b/src/pkg/crypto/xtea/xtea_test.go
@@ -94,7 +94,7 @@ func TestEncodeDecode(t *testing.T) {
}
// Encrypt the input block
- c.Encrypt(input, output)
+ c.Encrypt(output, input)
// Check that the output does not match the input
differs := false
@@ -112,7 +112,7 @@ func TestEncodeDecode(t *testing.T) {
// Decrypt the block we just encrypted
input = output
output = make([]byte, BlockSize)
- c.Decrypt(input, output)
+ c.Decrypt(output, input)
// Check that the output from decrypt matches our initial input
for i := 0; i < len(input); i++ {
@@ -132,54 +132,54 @@ type CryptTest struct {
var CryptTests = []CryptTest{
// These were sourced from http://www.freemedialibrary.com/index.php/XTEA_test_vectors
- CryptTest{
+ {
[]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f},
[]byte{0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48},
[]byte{0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5},
},
- CryptTest{
+ {
[]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f},
[]byte{0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41},
[]byte{0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8},
},
- CryptTest{
+ {
[]byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f},
[]byte{0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f},
[]byte{0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41},
},
- CryptTest{
+ {
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48},
[]byte{0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5},
},
- CryptTest{
+ {
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41},
[]byte{0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d},
},
- CryptTest{
+ {
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55},
[]byte{0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41},
},
// These vectors are from http://wiki.secondlife.com/wiki/XTEA_Strong_Encryption_Implementation#Bouncy_Castle_C.23_API
- CryptTest{
+ {
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0xDE, 0xE9, 0xD4, 0xD8, 0xF7, 0x13, 0x1E, 0xD9},
},
- CryptTest{
+ {
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
[]byte{0x06, 0x5C, 0x1B, 0x89, 0x75, 0xC6, 0xA8, 0x16},
},
- CryptTest{
+ {
[]byte{0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A},
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
[]byte{0x1F, 0xF9, 0xA0, 0x26, 0x1A, 0xC6, 0x42, 0x64},
},
- CryptTest{
+ {
[]byte{0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A},
[]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
[]byte{0x8C, 0x67, 0x15, 0x5B, 0x2E, 0xF9, 0x1E, 0xAD},
@@ -196,7 +196,7 @@ func TestCipherEncrypt(t *testing.T) {
}
out := make([]byte, len(tt.plainText))
- c.Encrypt(tt.plainText, out)
+ c.Encrypt(out, tt.plainText)
for j := 0; j < len(out); j++ {
if out[j] != tt.cipherText[j] {
@@ -217,7 +217,7 @@ func TestCipherDecrypt(t *testing.T) {
}
out := make([]byte, len(tt.cipherText))
- c.Decrypt(tt.cipherText, out)
+ c.Decrypt(out, tt.cipherText)
for j := 0; j < len(out); j++ {
if out[j] != tt.plainText[j] {