LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package aes | 5 package aes |
6 | 6 |
7 import ( | 7 import ( |
8 "testing" | 8 "testing" |
9 ) | 9 ) |
10 | 10 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 214 |
215 // Test key expansion against FIPS 197 examples. | 215 // Test key expansion against FIPS 197 examples. |
216 func TestExpandKey(t *testing.T) { | 216 func TestExpandKey(t *testing.T) { |
217 L: | 217 L: |
218 for i, tt := range keyTests { | 218 for i, tt := range keyTests { |
219 enc := make([]uint32, len(tt.enc)) | 219 enc := make([]uint32, len(tt.enc)) |
220 var dec []uint32 | 220 var dec []uint32 |
221 if tt.dec != nil { | 221 if tt.dec != nil { |
222 dec = make([]uint32, len(tt.dec)) | 222 dec = make([]uint32, len(tt.dec)) |
223 } | 223 } |
224 » » expandKey(tt.key, enc, dec) | 224 » » // This test could only test Go version of expandKey because asm |
| 225 » » // version might use different memory layout for expanded keys |
| 226 » » // This is OK because we don't expose expanded keys to the outsi
de |
| 227 » » expandKeyGo(tt.key, enc, dec) |
225 for j, v := range enc { | 228 for j, v := range enc { |
226 if v != tt.enc[j] { | 229 if v != tt.enc[j] { |
227 t.Errorf("key %d: enc[%d] = %#x, want %#x", i, j
, v, tt.enc[j]) | 230 t.Errorf("key %d: enc[%d] = %#x, want %#x", i, j
, v, tt.enc[j]) |
228 continue L | 231 continue L |
229 } | 232 } |
230 } | 233 } |
231 if dec != nil { | 234 if dec != nil { |
232 for j, v := range dec { | 235 for j, v := range dec { |
233 if v != tt.dec[j] { | 236 if v != tt.dec[j] { |
234 t.Errorf("key %d: dec[%d] = %#x, want %#
x", i, j, v, tt.dec[j]) | 237 t.Errorf("key %d: dec[%d] = %#x, want %#
x", i, j, v, tt.dec[j]) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 384 |
382 func BenchmarkExpand(b *testing.B) { | 385 func BenchmarkExpand(b *testing.B) { |
383 tt := encryptTests[0] | 386 tt := encryptTests[0] |
384 n := len(tt.key) + 28 | 387 n := len(tt.key) + 28 |
385 c := &aesCipher{make([]uint32, n), make([]uint32, n)} | 388 c := &aesCipher{make([]uint32, n), make([]uint32, n)} |
386 b.ResetTimer() | 389 b.ResetTimer() |
387 for i := 0; i < b.N; i++ { | 390 for i := 0; i < b.N; i++ { |
388 expandKey(tt.key, c.enc, c.dec) | 391 expandKey(tt.key, c.enc, c.dec) |
389 } | 392 } |
390 } | 393 } |
LEFT | RIGHT |