summaryrefslogtreecommitdiff
path: root/src/pkg/crypto/aes
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-12-15 15:33:31 -0800
committerRobert Griesemer <gri@golang.org>2009-12-15 15:33:31 -0800
commitd9527dd16f72598b54a64550607bf892efa12384 (patch)
tree2ad16a7db2d3c484b47426ad2568359ab633820c /src/pkg/crypto/aes
parentaea97e0bd7da9cef1cc631ddbd3578a0877a4fcc (diff)
downloadgolang-d9527dd16f72598b54a64550607bf892efa12384.tar.gz
1) Change default gofmt default settings for
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 1st set of files. R=rsc CC=agl, golang-dev, iant, ken2, r http://codereview.appspot.com/180047
Diffstat (limited to 'src/pkg/crypto/aes')
-rw-r--r--src/pkg/crypto/aes/aes_test.go132
-rw-r--r--src/pkg/crypto/aes/block.go142
-rw-r--r--src/pkg/crypto/aes/cipher.go24
-rw-r--r--src/pkg/crypto/aes/const.go2
4 files changed, 150 insertions, 150 deletions
diff --git a/src/pkg/crypto/aes/aes_test.go b/src/pkg/crypto/aes/aes_test.go
index 39933a824..1629a33ed 100644
--- a/src/pkg/crypto/aes/aes_test.go
+++ b/src/pkg/crypto/aes/aes_test.go
@@ -5,7 +5,7 @@
package aes
import (
- "testing";
+ "testing"
)
// See const.go for overview of math here.
@@ -13,12 +13,12 @@ import (
// Test that powx is initialized correctly.
// (Can adapt this code to generate it too.)
func TestPowx(t *testing.T) {
- p := 1;
+ p := 1
for i := 0; i < len(powx); i++ {
if powx[i] != byte(p) {
t.Errorf("powx[%d] = %#x, want %#x", i, powx[i], p)
}
- p <<= 1;
+ p <<= 1
if p&0x100 != 0 {
p ^= poly
}
@@ -27,25 +27,25 @@ func TestPowx(t *testing.T) {
// Multiply b and c as GF(2) polynomials modulo poly
func mul(b, c uint32) uint32 {
- i := b;
- j := c;
- s := uint32(0);
+ i := b
+ j := c
+ s := uint32(0)
for k := uint32(1); k < 0x100 && j != 0; k <<= 1 {
// Invariant: k == 1<<n, i == b * xⁿ
if j&k != 0 {
// s += i in GF(2); xor in binary
- s ^= i;
- j ^= k; // turn off bit to end loop early
+ s ^= i
+ j ^= k // turn off bit to end loop early
}
// i *= x in GF(2) modulo the polynomial
- i <<= 1;
+ i <<= 1
if i&0x100 != 0 {
i ^= poly
}
}
- return s;
+ return s
}
// Test all mul inputs against bit-by-bit n² algorithm.
@@ -53,7 +53,7 @@ func TestMul(t *testing.T) {
for i := uint32(0); i < 256; i++ {
for j := uint32(0); j < 256; j++ {
// Multiply i, j bit by bit.
- s := uint8(0);
+ s := uint8(0)
for k := uint(0); k < 8; k++ {
for l := uint(0); l < 8; l++ {
if i&(1<<k) != 0 && j&(1<<l) != 0 {
@@ -87,15 +87,15 @@ func TestSboxes(t *testing.T) {
// (Can adapt this code to generate them too.)
func TestTe(t *testing.T) {
for i := 0; i < 256; i++ {
- s := uint32(sbox0[i]);
- s2 := mul(s, 2);
- s3 := mul(s, 3);
- w := s2<<24 | s<<16 | s<<8 | s3;
+ s := uint32(sbox0[i])
+ s2 := mul(s, 2)
+ s3 := mul(s, 3)
+ w := s2<<24 | s<<16 | s<<8 | s3
for j := 0; j < 4; j++ {
if x := te[j][i]; x != w {
t.Fatalf("te[%d][%d] = %#x, want %#x", j, i, x, w)
}
- w = w<<24 | w>>8;
+ w = w<<24 | w>>8
}
}
}
@@ -104,17 +104,17 @@ func TestTe(t *testing.T) {
// (Can adapt this code to generate them too.)
func TestTd(t *testing.T) {
for i := 0; i < 256; i++ {
- s := uint32(sbox1[i]);
- s9 := mul(s, 0x9);
- sb := mul(s, 0xb);
- sd := mul(s, 0xd);
- se := mul(s, 0xe);
- w := se<<24 | s9<<16 | sd<<8 | sb;
+ s := uint32(sbox1[i])
+ s9 := mul(s, 0x9)
+ sb := mul(s, 0xb)
+ sd := mul(s, 0xd)
+ se := mul(s, 0xe)
+ w := se<<24 | s9<<16 | sd<<8 | sb
for j := 0; j < 4; j++ {
if x := td[j][i]; x != w {
t.Fatalf("td[%d][%d] = %#x, want %#x", j, i, x, w)
}
- w = w<<24 | w>>8;
+ w = w<<24 | w>>8
}
}
}
@@ -124,9 +124,9 @@ func TestTd(t *testing.T) {
// Appendix A of FIPS 197: Key expansion examples
type KeyTest struct {
- key []byte;
- enc []uint32;
- dec []uint32; // decryption expansion; not in FIPS 197, computed from C implementation.
+ key []byte
+ enc []uint32
+ dec []uint32 // decryption expansion; not in FIPS 197, computed from C implementation.
}
var keyTests = []KeyTest{
@@ -214,23 +214,23 @@ var keyTests = []KeyTest{
func TestExpandKey(t *testing.T) {
L:
for i, tt := range keyTests {
- enc := make([]uint32, len(tt.enc));
- var dec []uint32;
+ enc := make([]uint32, len(tt.enc))
+ var dec []uint32
if tt.dec != nil {
dec = make([]uint32, len(tt.dec))
}
- expandKey(tt.key, enc, dec);
+ expandKey(tt.key, enc, dec)
for j, v := range enc {
if v != tt.enc[j] {
- t.Errorf("key %d: enc[%d] = %#x, want %#x", i, j, v, tt.enc[j]);
- continue L;
+ t.Errorf("key %d: enc[%d] = %#x, want %#x", i, j, v, tt.enc[j])
+ continue L
}
}
if dec != nil {
for j, v := range dec {
if v != tt.dec[j] {
- t.Errorf("key %d: dec[%d] = %#x, want %#x", i, j, v, tt.dec[j]);
- continue L;
+ t.Errorf("key %d: dec[%d] = %#x, want %#x", i, j, v, tt.dec[j])
+ continue L
}
}
}
@@ -239,9 +239,9 @@ L:
// Appendix B, C of FIPS 197: Cipher examples, Example vectors.
type CryptTest struct {
- key []byte;
- in []byte;
- out []byte;
+ key []byte
+ in []byte
+ out []byte
}
var encryptTests = []CryptTest{
@@ -278,16 +278,16 @@ var encryptTests = []CryptTest{
// Test encryptBlock against FIPS 197 examples.
func TestEncryptBlock(t *testing.T) {
for i, tt := range encryptTests {
- n := len(tt.key) + 28;
- enc := make([]uint32, n);
- dec := make([]uint32, n);
- expandKey(tt.key, enc, dec);
- out := make([]byte, len(tt.in));
- encryptBlock(enc, tt.in, out);
+ n := len(tt.key) + 28
+ enc := make([]uint32, n)
+ dec := make([]uint32, n)
+ expandKey(tt.key, enc, dec)
+ out := make([]byte, len(tt.in))
+ encryptBlock(enc, tt.in, out)
for j, v := range out {
if v != tt.out[j] {
- t.Errorf("encryptBlock %d: out[%d] = %#x, want %#x", i, j, v, tt.out[j]);
- break;
+ t.Errorf("encryptBlock %d: out[%d] = %#x, want %#x", i, j, v, tt.out[j])
+ break
}
}
}
@@ -296,16 +296,16 @@ func TestEncryptBlock(t *testing.T) {
// Test decryptBlock against FIPS 197 examples.
func TestDecryptBlock(t *testing.T) {
for i, tt := range encryptTests {
- n := len(tt.key) + 28;
- enc := make([]uint32, n);
- dec := make([]uint32, n);
- expandKey(tt.key, enc, dec);
- plain := make([]byte, len(tt.in));
- decryptBlock(dec, tt.out, plain);
+ n := len(tt.key) + 28
+ enc := make([]uint32, n)
+ dec := make([]uint32, n)
+ expandKey(tt.key, enc, dec)
+ plain := make([]byte, len(tt.in))
+ decryptBlock(dec, tt.out, plain)
for j, v := range plain {
if v != tt.in[j] {
- t.Errorf("decryptBlock %d: plain[%d] = %#x, want %#x", i, j, v, tt.in[j]);
- break;
+ t.Errorf("decryptBlock %d: plain[%d] = %#x, want %#x", i, j, v, tt.in[j])
+ break
}
}
}
@@ -314,17 +314,17 @@ func TestDecryptBlock(t *testing.T) {
// Test Cipher Encrypt method against FIPS 197 examples.
func TestCipherEncrypt(t *testing.T) {
for i, tt := range encryptTests {
- c, err := NewCipher(tt.key);
+ c, err := NewCipher(tt.key)
if err != nil {
- t.Errorf("NewCipher(%d bytes) = %s", len(tt.key), err);
- continue;
+ t.Errorf("NewCipher(%d bytes) = %s", len(tt.key), err)
+ continue
}
- out := make([]byte, len(tt.in));
- c.Encrypt(tt.in, out);
+ out := make([]byte, len(tt.in))
+ c.Encrypt(tt.in, out)
for j, v := range out {
if v != tt.out[j] {
- t.Errorf("Cipher.Encrypt %d: out[%d] = %#x, want %#x", i, j, v, tt.out[j]);
- break;
+ t.Errorf("Cipher.Encrypt %d: out[%d] = %#x, want %#x", i, j, v, tt.out[j])
+ break
}
}
}
@@ -333,17 +333,17 @@ func TestCipherEncrypt(t *testing.T) {
// Test Cipher Decrypt against FIPS 197 examples.
func TestCipherDecrypt(t *testing.T) {
for i, tt := range encryptTests {
- c, err := NewCipher(tt.key);
+ c, err := NewCipher(tt.key)
if err != nil {
- t.Errorf("NewCipher(%d bytes) = %s", len(tt.key), err);
- continue;
+ t.Errorf("NewCipher(%d bytes) = %s", len(tt.key), err)
+ continue
}
- plain := make([]byte, len(tt.in));
- c.Decrypt(tt.out, plain);
+ plain := make([]byte, len(tt.in))
+ c.Decrypt(tt.out, plain)
for j, v := range plain {
if v != tt.in[j] {
- t.Errorf("decryptBlock %d: plain[%d] = %#x, want %#x", i, j, v, tt.in[j]);
- break;
+ t.Errorf("decryptBlock %d: plain[%d] = %#x, want %#x", i, j, v, tt.in[j])
+ break
}
}
}
diff --git a/src/pkg/crypto/aes/block.go b/src/pkg/crypto/aes/block.go
index dbd448f8b..a502554bd 100644
--- a/src/pkg/crypto/aes/block.go
+++ b/src/pkg/crypto/aes/block.go
@@ -38,92 +38,92 @@ package aes
// Encrypt one block from src into dst, using the expanded key xk.
func encryptBlock(xk []uint32, src, dst []byte) {
- var s0, s1, s2, s3, t0, t1, t2, t3 uint32;
+ var s0, s1, s2, s3, t0, t1, t2, t3 uint32
- s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]);
- s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]);
- s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11]);
- s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15]);
+ s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3])
+ s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7])
+ s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11])
+ s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15])
// First round just XORs input with key.
- s0 ^= xk[0];
- s1 ^= xk[1];
- s2 ^= xk[2];
- s3 ^= xk[3];
+ s0 ^= xk[0]
+ s1 ^= xk[1]
+ s2 ^= xk[2]
+ s3 ^= xk[3]
// Middle rounds shuffle using tables.
// Number of rounds is set by length of expanded key.
- nr := len(xk)/4 - 2; // - 2: one above, one more below
- k := 4;
+ nr := len(xk)/4 - 2 // - 2: one above, one more below
+ k := 4
for r := 0; r < nr; r++ {
- t0 = xk[k+0] ^ te[0][s0>>24] ^ te[1][s1>>16&0xff] ^ te[2][s2>>8&0xff] ^ te[3][s3&0xff];
- t1 = xk[k+1] ^ te[0][s1>>24] ^ te[1][s2>>16&0xff] ^ te[2][s3>>8&0xff] ^ te[3][s0&0xff];
- t2 = xk[k+2] ^ te[0][s2>>24] ^ te[1][s3>>16&0xff] ^ te[2][s0>>8&0xff] ^ te[3][s1&0xff];
- t3 = xk[k+3] ^ te[0][s3>>24] ^ te[1][s0>>16&0xff] ^ te[2][s1>>8&0xff] ^ te[3][s2&0xff];
- k += 4;
- s0, s1, s2, s3 = t0, t1, t2, t3;
+ t0 = xk[k+0] ^ te[0][s0>>24] ^ te[1][s1>>16&0xff] ^ te[2][s2>>8&0xff] ^ te[3][s3&0xff]
+ t1 = xk[k+1] ^ te[0][s1>>24] ^ te[1][s2>>16&0xff] ^ te[2][s3>>8&0xff] ^ te[3][s0&0xff]
+ t2 = xk[k+2] ^ te[0][s2>>24] ^ te[1][s3>>16&0xff] ^ te[2][s0>>8&0xff] ^ te[3][s1&0xff]
+ t3 = xk[k+3] ^ te[0][s3>>24] ^ te[1][s0>>16&0xff] ^ te[2][s1>>8&0xff] ^ te[3][s2&0xff]
+ k += 4
+ s0, s1, s2, s3 = t0, t1, t2, t3
}
// Last round uses s-box directly and XORs to produce output.
- s0 = uint32(sbox0[t0>>24])<<24 | uint32(sbox0[t1>>16&0xff])<<16 | uint32(sbox0[t2>>8&0xff])<<8 | uint32(sbox0[t3&0xff]);
- s1 = uint32(sbox0[t1>>24])<<24 | uint32(sbox0[t2>>16&0xff])<<16 | uint32(sbox0[t3>>8&0xff])<<8 | uint32(sbox0[t0&0xff]);
- s2 = uint32(sbox0[t2>>24])<<24 | uint32(sbox0[t3>>16&0xff])<<16 | uint32(sbox0[t0>>8&0xff])<<8 | uint32(sbox0[t1&0xff]);
- s3 = uint32(sbox0[t3>>24])<<24 | uint32(sbox0[t0>>16&0xff])<<16 | uint32(sbox0[t1>>8&0xff])<<8 | uint32(sbox0[t2&0xff]);
-
- s0 ^= xk[k+0];
- s1 ^= xk[k+1];
- s2 ^= xk[k+2];
- s3 ^= xk[k+3];
-
- dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0);
- dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1);
- dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2);
- dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3);
+ s0 = uint32(sbox0[t0>>24])<<24 | uint32(sbox0[t1>>16&0xff])<<16 | uint32(sbox0[t2>>8&0xff])<<8 | uint32(sbox0[t3&0xff])
+ s1 = uint32(sbox0[t1>>24])<<24 | uint32(sbox0[t2>>16&0xff])<<16 | uint32(sbox0[t3>>8&0xff])<<8 | uint32(sbox0[t0&0xff])
+ s2 = uint32(sbox0[t2>>24])<<24 | uint32(sbox0[t3>>16&0xff])<<16 | uint32(sbox0[t0>>8&0xff])<<8 | uint32(sbox0[t1&0xff])
+ s3 = uint32(sbox0[t3>>24])<<24 | uint32(sbox0[t0>>16&0xff])<<16 | uint32(sbox0[t1>>8&0xff])<<8 | uint32(sbox0[t2&0xff])
+
+ s0 ^= xk[k+0]
+ s1 ^= xk[k+1]
+ s2 ^= xk[k+2]
+ s3 ^= xk[k+3]
+
+ dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0)
+ dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1)
+ dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2)
+ dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3)
}
// Decrypt one block from src into dst, using the expanded key xk.
func decryptBlock(xk []uint32, src, dst []byte) {
- var s0, s1, s2, s3, t0, t1, t2, t3 uint32;
+ var s0, s1, s2, s3, t0, t1, t2, t3 uint32
- s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]);
- s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]);
- s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11]);
- s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15]);
+ s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3])
+ s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7])
+ s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11])
+ s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15])
// First round just XORs input with key.
- s0 ^= xk[0];
- s1 ^= xk[1];
- s2 ^= xk[2];
- s3 ^= xk[3];
+ s0 ^= xk[0]
+ s1 ^= xk[1]
+ s2 ^= xk[2]
+ s3 ^= xk[3]
// Middle rounds shuffle using tables.
// Number of rounds is set by length of expanded key.
- nr := len(xk)/4 - 2; // - 2: one above, one more below
- k := 4;
+ nr := len(xk)/4 - 2 // - 2: one above, one more below
+ k := 4
for r := 0; r < nr; r++ {
- t0 = xk[k+0] ^ td[0][s0>>24] ^ td[1][s3>>16&0xff] ^ td[2][s2>>8&0xff] ^ td[3][s1&0xff];
- t1 = xk[k+1] ^ td[0][s1>>24] ^ td[1][s0>>16&0xff] ^ td[2][s3>>8&0xff] ^ td[3][s2&0xff];
- t2 = xk[k+2] ^ td[0][s2>>24] ^ td[1][s1>>16&0xff] ^ td[2][s0>>8&0xff] ^ td[3][s3&0xff];
- t3 = xk[k+3] ^ td[0][s3>>24] ^ td[1][s2>>16&0xff] ^ td[2][s1>>8&0xff] ^ td[3][s0&0xff];
- k += 4;
- s0, s1, s2, s3 = t0, t1, t2, t3;
+ t0 = xk[k+0] ^ td[0][s0>>24] ^ td[1][s3>>16&0xff] ^ td[2][s2>>8&0xff] ^ td[3][s1&0xff]
+ t1 = xk[k+1] ^ td[0][s1>>24] ^ td[1][s0>>16&0xff] ^ td[2][s3>>8&0xff] ^ td[3][s2&0xff]
+ t2 = xk[k+2] ^ td[0][s2>>24] ^ td[1][s1>>16&0xff] ^ td[2][s0>>8&0xff] ^ td[3][s3&0xff]
+ t3 = xk[k+3] ^ td[0][s3>>24] ^ td[1][s2>>16&0xff] ^ td[2][s1>>8&0xff] ^ td[3][s0&0xff]
+ k += 4
+ s0, s1, s2, s3 = t0, t1, t2, t3
}
// Last round uses s-box directly and XORs to produce output.
- s0 = uint32(sbox1[t0>>24])<<24 | uint32(sbox1[t3>>16&0xff])<<16 | uint32(sbox1[t2>>8&0xff])<<8 | uint32(sbox1[t1&0xff]);
- s1 = uint32(sbox1[t1>>24])<<24 | uint32(sbox1[t0>>16&0xff])<<16 | uint32(sbox1[t3>>8&0xff])<<8 | uint32(sbox1[t2&0xff]);
- s2 = uint32(sbox1[t2>>24])<<24 | uint32(sbox1[t1>>16&0xff])<<16 | uint32(sbox1[t0>>8&0xff])<<8 | uint32(sbox1[t3&0xff]);
- s3 = uint32(sbox1[t3>>24])<<24 | uint32(sbox1[t2>>16&0xff])<<16 | uint32(sbox1[t1>>8&0xff])<<8 | uint32(sbox1[t0&0xff]);
-
- s0 ^= xk[k+0];
- s1 ^= xk[k+1];
- s2 ^= xk[k+2];
- s3 ^= xk[k+3];
-
- dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0);
- dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1);
- dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2);
- dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3);
+ s0 = uint32(sbox1[t0>>24])<<24 | uint32(sbox1[t3>>16&0xff])<<16 | uint32(sbox1[t2>>8&0xff])<<8 | uint32(sbox1[t1&0xff])
+ s1 = uint32(sbox1[t1>>24])<<24 | uint32(sbox1[t0>>16&0xff])<<16 | uint32(sbox1[t3>>8&0xff])<<8 | uint32(sbox1[t2&0xff])
+ s2 = uint32(sbox1[t2>>24])<<24 | uint32(sbox1[t1>>16&0xff])<<16 | uint32(sbox1[t0>>8&0xff])<<8 | uint32(sbox1[t3&0xff])
+ s3 = uint32(sbox1[t3>>24])<<24 | uint32(sbox1[t2>>16&0xff])<<16 | uint32(sbox1[t1>>8&0xff])<<8 | uint32(sbox1[t0&0xff])
+
+ s0 ^= xk[k+0]
+ s1 ^= xk[k+1]
+ s2 ^= xk[k+2]
+ s3 ^= xk[k+3]
+
+ dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0)
+ dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1)
+ dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2)
+ dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3)
}
// Apply sbox0 to each byte in w.
@@ -135,25 +135,25 @@ func subw(w uint32) uint32 {
}
// Rotate
-func rotw(w uint32) uint32 { return w<<8 | w>>24 }
+func rotw(w uint32) uint32 { return w<<8 | w>>24 }
// Key expansion algorithm. See FIPS-197, Figure 11.
// Their rcon[i] is our powx[i-1] << 24.
func expandKey(key []byte, enc, dec []uint32) {
// Encryption key setup.
- var i int;
- nk := len(key) / 4;
+ var i int
+ nk := len(key) / 4
for i = 0; i < nk; i++ {
enc[i] = uint32(key[4*i])<<24 | uint32(key[4*i+1])<<16 | uint32(key[4*i+2])<<8 | uint32(key[4*i+3])
}
for ; i < len(enc); i++ {
- t := enc[i-1];
+ t := enc[i-1]
if i%nk == 0 {
t = subw(rotw(t)) ^ (uint32(powx[i/nk-1]) << 24)
} else if nk > 6 && i%nk == 4 {
t = subw(t)
}
- enc[i] = enc[i-nk] ^ t;
+ enc[i] = enc[i-nk] ^ t
}
// Derive decryption key from encryption key.
@@ -162,15 +162,15 @@ func expandKey(key []byte, enc, dec []uint32) {
if dec == nil {
return
}
- n := len(enc);
+ n := len(enc)
for i := 0; i < n; i += 4 {
- ei := n - i - 4;
+ ei := n - i - 4
for j := 0; j < 4; j++ {
- x := enc[ei+j];
+ x := enc[ei+j]
if i > 0 && i+4 < n {
x = td[0][sbox0[x>>24]] ^ td[1][sbox0[x>>16&0xff]] ^ td[2][sbox0[x>>8&0xff]] ^ td[3][sbox0[x&0xff]]
}
- dec[i+j] = x;
+ dec[i+j] = x
}
}
}
diff --git a/src/pkg/crypto/aes/cipher.go b/src/pkg/crypto/aes/cipher.go
index 651c2651e..a7caf5576 100644
--- a/src/pkg/crypto/aes/cipher.go
+++ b/src/pkg/crypto/aes/cipher.go
@@ -5,8 +5,8 @@
package aes
import (
- "os";
- "strconv";
+ "os"
+ "strconv"
)
// The AES block size in bytes.
@@ -14,8 +14,8 @@ const BlockSize = 16
// A Cipher is an instance of AES encryption using a particular key.
type Cipher struct {
- enc []uint32;
- dec []uint32;
+ enc []uint32
+ dec []uint32
}
type KeySizeError int
@@ -29,7 +29,7 @@ func (k KeySizeError) String() string {
// either 16, 24, or 32 bytes to select
// AES-128, AES-192, or AES-256.
func NewCipher(key []byte) (*Cipher, os.Error) {
- k := len(key);
+ k := len(key)
switch k {
default:
return nil, KeySizeError(k)
@@ -37,27 +37,27 @@ func NewCipher(key []byte) (*Cipher, os.Error) {
break
}
- n := k + 28;
- c := &Cipher{make([]uint32, n), make([]uint32, n)};
- expandKey(key, c.enc, c.dec);
- return c, nil;
+ n := k + 28
+ c := &Cipher{make([]uint32, n), make([]uint32, n)}
+ expandKey(key, c.enc, c.dec)
+ return c, nil
}
// BlockSize returns the AES block size, 16 bytes.
// It is necessary to satisfy the Key interface in the
// package "crypto/modes".
-func (c *Cipher) BlockSize() int { return BlockSize }
+func (c *Cipher) BlockSize() int { return BlockSize }
// Encrypt encrypts the 16-byte buffer src using the key k
// and stores the result in dst.
// 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 AESCBC (see modes.go).
-func (c *Cipher) Encrypt(src, dst []byte) { encryptBlock(c.enc, src, dst) }
+func (c *Cipher) Encrypt(src, dst []byte) { encryptBlock(c.enc, src, dst) }
// Decrypt decrypts the 16-byte buffer src using the key k
// and stores the result in dst.
-func (c *Cipher) Decrypt(src, dst []byte) { decryptBlock(c.dec, src, dst) }
+func (c *Cipher) Decrypt(src, dst []byte) { decryptBlock(c.dec, src, dst) }
// Reset zeros the key data, so that it will no longer
// appear in the process's memory.
diff --git a/src/pkg/crypto/aes/const.go b/src/pkg/crypto/aes/const.go
index 862be087b..8ddcaff26 100644
--- a/src/pkg/crypto/aes/const.go
+++ b/src/pkg/crypto/aes/const.go
@@ -15,7 +15,7 @@ package aes
// Addition of these binary polynomials corresponds to binary xor.
// Reducing mod poly corresponds to binary xor with poly every
// time a 0x100 bit appears.
-const poly = 1<<8 | 1<<4 | 1<<3 | 1<<1 | 1<<0 // x⁸ + x⁴ + x² + x + 1
+const poly = 1<<8 | 1<<4 | 1<<3 | 1<<1 | 1<<0 // x⁸ + x⁴ + x² + x + 1
// Powers of x mod poly in GF(2).
var powx = [16]byte{